diff --git a/include/eepp/ui/keyboardshortcut.hpp b/include/eepp/ui/keyboardshortcut.hpp index a352ee375..43727102b 100644 --- a/include/eepp/ui/keyboardshortcut.hpp +++ b/include/eepp/ui/keyboardshortcut.hpp @@ -75,7 +75,7 @@ class EE_API KeyBindings { const std::map getKeybindings() const; - std::string getShortcutString( Shortcut shortcut ) const; + std::string getShortcutString( Shortcut shortcut, bool format = false ) const; protected: const Window::Input* mInput; diff --git a/src/eepp/ui/keyboardshortcut.cpp b/src/eepp/ui/keyboardshortcut.cpp index 228bf485d..411926bde 100644 --- a/src/eepp/ui/keyboardshortcut.cpp +++ b/src/eepp/ui/keyboardshortcut.cpp @@ -163,7 +163,7 @@ const std::map KeyBindings::getKeybindings() const { return mKeybindingsInvert; } -std::string KeyBindings::getShortcutString( KeyBindings::Shortcut shortcut ) const { +std::string KeyBindings::getShortcutString( KeyBindings::Shortcut shortcut, bool format ) const { std::vector mods; std::string keyname( String::toLower( mInput->getKeyName( shortcut.key ) ) ); const auto& MOD_MAP = KeyMod::getModMap(); @@ -180,8 +180,9 @@ std::string KeyBindings::getShortcutString( KeyBindings::Shortcut shortcut ) con if ( ( shortcut.mod & KEYMOD_META ) && KEYMOD_META != MOD_MAP.at( "mod" ) ) mods.emplace_back( "meta" ); if ( mods.empty() ) - return keyname; - return String::join( mods, '+' ) + "+" + keyname; + return format ? keybindFormat( keyname ) : keyname; + auto ret = String::join( mods, '+' ) + "+" + keyname; + return format ? keybindFormat( ret ) : ret; } }} // namespace EE::UI diff --git a/src/tools/ecode/plugins/git/gitbranchmodel.cpp b/src/tools/ecode/plugins/git/gitbranchmodel.cpp index 4afde7a81..79c3f647f 100644 --- a/src/tools/ecode/plugins/git/gitbranchmodel.cpp +++ b/src/tools/ecode/plugins/git/gitbranchmodel.cpp @@ -129,4 +129,8 @@ Variant GitBranchModel::data( const ModelIndex& index, ModelRole role ) const { return {}; } +Git::Branch GitBranchModel::branch( const ModelIndex& index ) const { + return *static_cast( index.internalData() ); +} + } // namespace ecode diff --git a/src/tools/ecode/plugins/git/gitbranchmodel.hpp b/src/tools/ecode/plugins/git/gitbranchmodel.hpp index 8a57922ca..26dbbbec3 100644 --- a/src/tools/ecode/plugins/git/gitbranchmodel.hpp +++ b/src/tools/ecode/plugins/git/gitbranchmodel.hpp @@ -53,6 +53,8 @@ class GitBranchModel : public Model { size_t getHash() const { return mHash; } + Git::Branch branch( const ModelIndex& index ) const; + protected: std::vector mBranches; GitPlugin* mPlugin{ nullptr }; diff --git a/src/tools/ecode/plugins/git/gitplugin.cpp b/src/tools/ecode/plugins/git/gitplugin.cpp index 8e2b669ec..26008ca8c 100644 --- a/src/tools/ecode/plugins/git/gitplugin.cpp +++ b/src/tools/ecode/plugins/git/gitplugin.cpp @@ -945,6 +945,25 @@ void GitPlugin::buildSidePanelTab() { } } ); + mBranchesTree->on( Event::KeyDown, [this]( const Event* event ) { + const KeyEvent* keyEvent = event->asKeyEvent(); + ModelIndex modelIndex = mBranchesTree->getSelection().first(); + if ( !modelIndex.isValid() || modelIndex.internalId() == -1 ) + return; + Git::Branch branch = + static_cast( mBranchesTree->getModel() )->branch( modelIndex ); + + switch ( keyEvent->getKeyCode() ) { + case KEY_F7: + branchCreate(); + break; + case KEY_F2: + branchRename( branch ); + default: + break; + } + } ); + auto listBox = mPanelSwicher->getListBox(); listBox->addListBoxItems( { i18n( "branches", "Branches" ), i18n( "status", "Status" ) } ); mStackMap.resize( 2 ); @@ -1066,22 +1085,20 @@ void GitPlugin::openBranchMenu( const Git::Branch& branch ) { if ( gitBranch() != branch.name ) { addMenuItem( menu, "git-checkout", "Check Out..." ); - if ( branch.type == Git::RefType::Head ) { - addMenuItem( menu, "git-branch-rename", "Rename" ); - addMenuItem( menu, "git-branch-delete", "Delete" ); - } - } else { - if ( branch.type == Git::RefType::Head ) { - addMenuItem( menu, "git-pull", "Pull", "repo-pull" ); - if ( branch.ahead ) - addMenuItem( menu, "git-push", "Push", "repo-push" ); - } } - if ( branch.type == Git::RefType::Head && branch.behind ) - addMenuItem( menu, "git-fast-forward-merge", "Fast Forward Merge" ); + if ( branch.type == Git::RefType::Head ) { + addMenuItem( menu, "git-branch-rename", "Rename", "", { KEY_F2 } ); + addMenuItem( menu, "git-pull", "Pull", "repo-pull" ); + if ( branch.ahead ) + addMenuItem( menu, "git-push", "Push", "repo-push" ); + if ( branch.behind ) + addMenuItem( menu, "git-fast-forward-merge", "Fast Forward Merge" ); + menu->addSeparator(); + addMenuItem( menu, "git-branch-delete", "Delete" ); + } - addMenuItem( menu, "git-create-branch", "Create Branch", "repo-forked" ); + addMenuItem( menu, "git-create-branch", "Create Branch", "repo-forked", { KEY_F7 } ); menu->on( Event::OnItemClicked, [this, branch]( const Event* event ) { if ( !mGit ) @@ -1165,9 +1182,13 @@ void GitPlugin::runAsync( std::function fn, bool _updateStatus, b } void GitPlugin::addMenuItem( UIMenu* menu, const std::string& txtKey, const std::string& txtVal, - const std::string& icon ) { + const std::string& icon, + const KeyBindings::Shortcut& forcedKeybinding ) { + menu->add( i18n( txtKey, txtVal ), iconDrawable( icon, 12 ), - KeyBindings::keybindFormat( mKeyBindings[txtKey] ) ) + forcedKeybinding.empty() ? KeyBindings::keybindFormat( mKeyBindings[txtKey] ) + : getUISceneNode()->getKeyBindings().getShortcutString( + forcedKeybinding, true ) ) ->setId( txtKey ); } diff --git a/src/tools/ecode/plugins/git/gitplugin.hpp b/src/tools/ecode/plugins/git/gitplugin.hpp index c7fdcbda6..1077cccbc 100644 --- a/src/tools/ecode/plugins/git/gitplugin.hpp +++ b/src/tools/ecode/plugins/git/gitplugin.hpp @@ -184,7 +184,8 @@ class GitPlugin : public PluginBase { bool displaySuccessMsg = false ); void addMenuItem( UIMenu* menu, const std::string& txtKey, const std::string& txtVal, - const std::string& icon = "" ); + const std::string& icon = "", + const KeyBindings::Shortcut& forcedKeybinding = KeyBindings::Shortcut() ); std::string repoSelected();