Skip to content

Commit

Permalink
the selection by keyboard is now managed by the tabview itself
Browse files Browse the repository at this point in the history
  • Loading branch information
Freaxed committed Feb 15, 2025
1 parent 402e7b0 commit 4251934
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 25 deletions.
38 changes: 37 additions & 1 deletion src/editor/EditorTabView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "EditorTabManager"

#define kSelectByKey 'seta'



EditorTabView::EditorTabView(BMessenger target):GTabView("_editor_tabview_",
Expand Down Expand Up @@ -55,8 +57,11 @@ EditorTabView::~EditorTabView()


void
EditorTabView::AddEditor(const char* label, Editor* editor, BMessage* info, int32 index)
EditorTabView::AddEditor(const char* label, Editor* editor, BMessage* info)
{
//by default the new editor is placed next to the selected one.

int32 index = SelectedTabIndex() + 1;
GTabEditor* tab = new GTabEditor(label, this, editor);
AddTab (tab, editor, index);

Expand Down Expand Up @@ -186,6 +191,37 @@ EditorTabView::ReverseForEachEditor(const std::function<bool(Editor*)>& op)
}
}

void
EditorTabView::AttachedToWindow()
{
// Shortcuts
for (int32 index = 1; index < 10; index++) {
constexpr auto kAsciiPos {48};
BMessage* selectTab = new BMessage(kSelectByKey);
selectTab->AddInt32("index", index - 1);
Window()->AddShortcut(index + kAsciiPos, B_COMMAND_KEY, selectTab, this);
}
}


void
EditorTabView::MessageReceived(BMessage* message)
{
switch(message->what) {
case kSelectByKey:
int32 index;
// Shortcut selection, be careful
if (message->FindInt32("index", &index) == B_OK) {
if (index < Container()->CountTabs())
SelectTab(index);
}
break;
default:
GTabView::MessageReceived(message);
break;
};
}


Editor*
EditorTabView::_GetEditor_(const entry_ref* ref)
Expand Down
5 changes: 4 additions & 1 deletion src/editor/EditorTabView.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class EditorTabView : public GTabView {
EditorTabView(BMessenger target);
~EditorTabView();

void AddEditor(const char* label, Editor* editor, BMessage* info = nullptr, int32 index = -1);
void AddEditor(const char* label, Editor* editor, BMessage* info = nullptr);

Editor* SelectedEditor();

Expand Down Expand Up @@ -59,6 +59,9 @@ class EditorTabView : public GTabView {
void ForEachEditor(const std::function<bool(Editor*)>& op);
void ReverseForEachEditor(const std::function<bool(Editor*)>& op);

void AttachedToWindow() override;
void MessageReceived(BMessage*) override;

protected:
friend GTabEditor;

Expand Down
23 changes: 1 addition & 22 deletions src/ui/GenioWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,6 @@ GenioWindow::GenioWindow(BRect frame)

_UpdateTabChange(nullptr, "GenioWindow");

// Shortcuts
for (int32 index = 1; index < 10; index++) {
constexpr auto kAsciiPos {48};
BMessage* selectTab = new BMessage(MSG_SELECT_TAB);
selectTab->AddInt32("index", index - 1);
AddShortcut(index + kAsciiPos, B_COMMAND_KEY, selectTab);
}

// TODO: we use ALT+N (where N is 1-9) to switch tab (like Web+), and CTRL+LEFT/RIGHT to switch
// to previous/next. Too bad ALT+LEFT/RIGHT are already taken. Maybe we should change to
Expand Down Expand Up @@ -1031,17 +1024,6 @@ GenioWindow::MessageReceived(BMessage* message)
case MSG_RUN_TARGET:
_RunTarget();
break;
case MSG_SELECT_TAB:
{
int32 index;
// Shortcut selection, be careful
if (message->FindInt32("index", &index) == B_OK) {
if (index < fTabManager->CountTabs()
&& index != fTabManager->SelectedTabIndex())
fTabManager->SelectTab(index);
}
break;
}
case MSG_SHOW_HIDE_LEFT_PANE:
gCFG["show_projects"] = !bool(gCFG["show_projects"]);
break;
Expand Down Expand Up @@ -1527,11 +1509,8 @@ GenioWindow::QuitRequested()
Editor*
GenioWindow::_AddEditorTab(entry_ref* ref, BMessage* addInfo)
{
int32 index = fTabManager->SelectedTabIndex() + 1;

Editor* editor = new Editor(ref, BMessenger(this));
fTabManager->AddEditor(ref->name, editor, addInfo, index);

fTabManager->AddEditor(ref->name, editor, addInfo);
return editor;
}

Expand Down
1 change: 0 additions & 1 deletion src/ui/GenioWindowMessages.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ enum {
MSG_SHOW_HIDE_BOTTOM_PANE = 'shou',
MSG_FULLSCREEN = 'fscr',
MSG_FOCUS_MODE = 'focu',
MSG_SELECT_TAB = 'seta',

MSG_ESCAPE_KEY = 'escp',

Expand Down

0 comments on commit 4251934

Please sign in to comment.