Some minor changes in git plugin

This commit is contained in:
Martín Lucas Golini
2024-01-26 23:15:25 -03:00
parent bed3581364
commit 76e2026ed7
6 changed files with 49 additions and 20 deletions
+4 -3
View File
@@ -163,7 +163,7 @@ const std::map<std::string, Uint64> 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<std::string> 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
@@ -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<Git::Branch*>( index.internalData() );
}
} // namespace ecode
@@ -53,6 +53,8 @@ class GitBranchModel : public Model {
size_t getHash() const { return mHash; }
Git::Branch branch( const ModelIndex& index ) const;
protected:
std::vector<BranchData> mBranches;
GitPlugin* mPlugin{ nullptr };
+36 -15
View File
@@ -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<const GitBranchModel*>( 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<Git::Result()> 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 );
}
+2 -1
View File
@@ -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();