Skip to content

Commit

Permalink
added proper actions (menu and toolbar icons) to navigate the history
Browse files Browse the repository at this point in the history
  • Loading branch information
Freaxed committed Jan 20, 2025
1 parent de714cc commit 5dfcd79
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 22 deletions.
6 changes: 0 additions & 6 deletions src/helpers/JumpNavigator.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ typedef entry_ref JumpPosition;

class JumpNavigator {
public:
enum {
kJumpPrev = 'jmpp',
kJumpNext = 'jmpn'
};



static JumpNavigator* getInstance() {
static JumpNavigator instance;
Expand Down
48 changes: 32 additions & 16 deletions src/ui/GenioWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,6 @@ GenioWindow::GenioWindow(BRect frame)
AddCommonFilter(new EditorMouseWheelMessageFilter());
AddCommonFilter(new EditorMessageFilter(B_MOUSE_MOVED, &Editor::BeforeMouseMoved));

//JumpNavigator (this should be Action with icon and menu items..)
AddCommonFilter(new KeyDownMessageFilter(JumpNavigator::kJumpPrev, B_LEFT_ARROW,
B_SHIFT_KEY|B_COMMAND_KEY));
AddCommonFilter(new KeyDownMessageFilter(JumpNavigator::kJumpNext, B_RIGHT_ARROW,
B_SHIFT_KEY|B_COMMAND_KEY));

// Load workspace - reopen projects
// Disable MSG_NOTIFY_PROJECT_SET_ACTIVE and MSG_NOTIFY_PROJECT_LIST_CHANGE while we populate
// the workspace
Expand Down Expand Up @@ -294,6 +288,9 @@ GenioWindow::Show()
bool same = ((bool)gCFG["show_white_space"] && (bool)gCFG["show_line_endings"]);
ActionManager::SetPressed(MSG_TOGGLE_SPACES_ENDINGS, same);

ActionManager::SetEnabled(MSG_JUMP_GO_BACK, false);
ActionManager::SetEnabled(MSG_JUMP_GO_FORWARD, false);

be_app->StartWatching(this, gCFG.UpdateMessageWhat());
be_app->StartWatching(this, kMsgProjectSettingsUpdated);
UnlockLooper();
Expand All @@ -316,16 +313,7 @@ void
GenioWindow::MessageReceived(BMessage* message)
{
switch (message->what) {
case JumpNavigator::kJumpPrev:
{
JumpNavigator::getInstance()->JumpToPrev();
break;
}
case JumpNavigator::kJumpNext:
{
JumpNavigator::getInstance()->JumpToNext();
break;
}

case MSG_INVOKE_EXTENSION:
{
entry_ref ref;
Expand Down Expand Up @@ -1224,6 +1212,12 @@ GenioWindow::MessageReceived(BMessage* message)
case kMsgCapabilitiesUpdated:
_UpdateTabChange(fTabManager->SelectedEditor(), "kMsgCapabilitiesUpdated");
break;
case MSG_JUMP_GO_BACK:
JumpNavigator::getInstance()->JumpToPrev();
break;
case MSG_JUMP_GO_FORWARD:
JumpNavigator::getInstance()->JumpToNext();
break;
default:
BWindow::MessageReceived(message);
break;
Expand Down Expand Up @@ -1840,6 +1834,10 @@ GenioWindow::_FileOpen(BMessage* msg)
}
}

ActionManager::SetEnabled(MSG_JUMP_GO_BACK, JumpNavigator::getInstance()->HasPrev());
ActionManager::SetEnabled(MSG_JUMP_GO_FORWARD, JumpNavigator::getInstance()->HasNext());


if (firstAdded > -1 && fTabManager->CountTabs() > firstAdded) {
fTabManager->SelectTab(firstAdded);
}
Expand Down Expand Up @@ -3003,6 +3001,15 @@ GenioWindow::_InitActions()
B_TRANSLATE("Open in Terminal"),
B_TRANSLATE("Open in Terminal"));


ActionManager::RegisterAction(MSG_JUMP_GO_FORWARD, B_TRANSLATE("Go Forward"),
B_TRANSLATE("Go Forward"), "kIconForward_2", B_RIGHT_ARROW,
B_SHIFT_KEY|B_COMMAND_KEY);

ActionManager::RegisterAction(MSG_JUMP_GO_BACK, B_TRANSLATE("Go Back"),
B_TRANSLATE("Go Back"), "kIconBack_1", B_LEFT_ARROW,
B_SHIFT_KEY|B_COMMAND_KEY);

}


Expand Down Expand Up @@ -3193,6 +3200,11 @@ GenioWindow::_InitMenu()
ActionManager::AddItem(MSG_GOTODECLARATION, searchMenu);
ActionManager::AddItem(MSG_GOTOIMPLEMENTATION, searchMenu);

searchMenu->AddSeparatorItem();

ActionManager::AddItem(MSG_JUMP_GO_BACK, searchMenu);
ActionManager::AddItem(MSG_JUMP_GO_FORWARD, searchMenu);

ActionManager::SetEnabled(MSG_GOTODEFINITION, false);
ActionManager::SetEnabled(MSG_GOTODECLARATION, false);
ActionManager::SetEnabled(MSG_GOTOIMPLEMENTATION, false);
Expand Down Expand Up @@ -3401,6 +3413,10 @@ GenioWindow::_InitToolbar()
fToolBar->AddSeparator();

ActionManager::AddItem(MSG_RUN_CONSOLE_PROGRAM_SHOW, fToolBar);
ActionManager::AddItem(MSG_JUMP_GO_BACK, fToolBar);
ActionManager::AddItem(MSG_JUMP_GO_FORWARD, fToolBar);


fToolBar->AddGlue();

ActionManager::AddItem(MSG_BUFFER_LOCK, fToolBar);
Expand Down
2 changes: 2 additions & 0 deletions src/ui/GenioWindowMessages.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ enum {
MSG_FIND_IN_FILES = 'fifi',
MSG_RUN_CONSOLE_PROGRAM_SHOW = 'rcps',
MSG_RUN_CONSOLE_PROGRAM = 'rcpr',
MSG_JUMP_GO_FORWARD = 'jpfw',
MSG_JUMP_GO_BACK = 'jpba',

MSG_REPLACE_GROUP_TOGGLED = 'regt',
MSG_SHOW_HIDE_PROJECTS = 'shpr',
Expand Down

0 comments on commit 5dfcd79

Please sign in to comment.