diff --git a/include/eepp/core/string.hpp b/include/eepp/core/string.hpp index bdeab4a63..b18117e6a 100644 --- a/include/eepp/core/string.hpp +++ b/include/eepp/core/string.hpp @@ -347,7 +347,7 @@ class EE_API String { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wformat-security" #elif defined( __GNUC__ ) -#pragma GCC diagnostic warning "-Wformat-security" +#pragma GCC diagnostic ignored "-Wformat-security" #endif int size = std::snprintf( nullptr, 0, format.data(), diff --git a/src/tools/ecode/plugins/git/git.cpp b/src/tools/ecode/plugins/git/git.cpp index 10e4e9e38..8ac9fe2fa 100644 --- a/src/tools/ecode/plugins/git/git.cpp +++ b/src/tools/ecode/plugins/git/git.cpp @@ -302,7 +302,7 @@ static void parseAheadBehind( std::string_view aheadBehind, Git::Branch& branch } } -Git::Branch parseLocalBranch( const std::string_view& raw, const std::string& projectDir ) { +Git::Branch parseLocalBranch( const std::string_view& raw ) { auto split = String::split( raw, '\t', true ); if ( split.size() < 4 ) return {}; @@ -365,7 +365,7 @@ std::vector Git::getAllBranchesAndTags( RefType ref, const std::str readAllLines( buf, [&]( const std::string_view& line ) { auto branch = String::trim( String::trim( line, '\'' ), '\t' ); if ( ( ref & Head ) && String::startsWith( branch, "refs/heads/" ) ) { - branches.emplace_back( parseLocalBranch( branch, projectDir ) ); + branches.emplace_back( parseLocalBranch( branch ) ); } else if ( ( ref & Remote ) && String::startsWith( branch, "refs/remotes/" ) ) { branches.emplace_back( parseRemoteBranch( branch ) ); } else if ( ( ref & Tag ) && String::startsWith( branch, "refs/tags/" ) ) { diff --git a/src/tools/ecode/plugins/git/gitplugin.cpp b/src/tools/ecode/plugins/git/gitplugin.cpp index 94df24546..ad8034700 100644 --- a/src/tools/ecode/plugins/git/gitplugin.cpp +++ b/src/tools/ecode/plugins/git/gitplugin.cpp @@ -13,6 +13,7 @@ #include #include +using namespace EE::UI; using namespace EE::UI::Doc; using json = nlohmann::json; @@ -902,9 +903,6 @@ void GitPlugin::checkout( Git::Branch branch ) { } void GitPlugin::branchRename( Git::Branch branch ) { - if ( !mGit ) - return; - UIMessageBox* msgBox = UIMessageBox::New( UIMessageBox::INPUT, String::format( @@ -914,18 +912,9 @@ void GitPlugin::branchRename( Git::Branch branch ) { std::string newName( msgBox->getTextInput()->getText().toUtf8() ); if ( newName.empty() || branch.name == newName ) return; - - mLoader->setVisible( true ); msgBox->closeWindow(); - mThreadPool->run( [this, branch, newName] { - auto res = mGit->renameBranch( branch.name, newName ); - if ( res.fail() ) { - showMessage( LSPMessageType::Warning, res.result ); - return; - } - updateBranches(); - getUISceneNode()->runOnMainThread( [this] { mLoader->setVisible( false ); } ); - } ); + runAsync( [this, branch, newName]() { return mGit->renameBranch( branch.name, newName ); }, + false, true ); } ); msgBox->setCloseShortcut( { KEY_ESCAPE, KEYMOD_NONE } ); msgBox->setTitle( i18n( "git_rename_branch", "Rename Branch" ) ); @@ -935,62 +924,26 @@ void GitPlugin::branchRename( Git::Branch branch ) { } void GitPlugin::branchDelete( Git::Branch branch ) { - if ( !mGit ) - return; - mLoader->setVisible( true ); - mThreadPool->run( [this, branch] { - auto res = mGit->deleteBranch( branch.name ); - if ( res.fail() ) { - showMessage( LSPMessageType::Warning, res.result ); - return; - } - updateBranches(); - getUISceneNode()->runOnMainThread( [this] { mLoader->setVisible( false ); } ); - } ); + runAsync( [this, branch]() { return mGit->deleteBranch( branch.name ); }, false, true ); } void GitPlugin::pull() { - if ( !mGit ) - return; - mLoader->setVisible( true ); - mThreadPool->run( [this] { - auto res = mGit->pull(); - if ( res.fail() ) - showMessage( LSPMessageType::Warning, res.result ); - getUISceneNode()->runOnMainThread( [this] { mLoader->setVisible( false ); } ); - } ); + runAsync( [this]() { return mGit->pull(); }, true, true ); +} + +void GitPlugin::fetch() { + runAsync( [this]() { return mGit->fetch(); }, true, true ); } void GitPlugin::stage( const std::string& file ) { - if ( !mGit ) - return; - mLoader->setVisible( true ); - mThreadPool->run( [this, file] { - auto res = mGit->add( file ); - if ( res.fail() ) - showMessage( LSPMessageType::Warning, res.result ); - getUISceneNode()->runOnMainThread( [this] { mLoader->setVisible( false ); } ); - updateStatus( true ); - } ); + runAsync( [this, file]() { return mGit->add( file ); }, true, false ); } void GitPlugin::unstage( const std::string& file ) { - if ( !mGit ) - return; - mLoader->setVisible( true ); - mThreadPool->run( [this, file] { - auto res = mGit->reset( file ); - if ( res.fail() ) - showMessage( LSPMessageType::Warning, res.result ); - getUISceneNode()->runOnMainThread( [this] { mLoader->setVisible( false ); } ); - updateStatus( true ); - } ); + runAsync( [this, file]() { return mGit->reset( file ); }, true, false ); } void GitPlugin::discard( const std::string& file ) { - if ( !mGit ) - return; - UIMessageBox* msgBox = UIMessageBox::New( UIMessageBox::OK_CANCEL, String::format( i18n( "git_confirm_discard_changes", @@ -999,14 +952,7 @@ void GitPlugin::discard( const std::string& file ) { file ) ); msgBox->on( Event::OnConfirm, [this, file]( auto ) { - mLoader->setVisible( true ); - mThreadPool->run( [this, file] { - auto res = mGit->restore( file ); - if ( res.fail() ) - showMessage( LSPMessageType::Warning, res.result ); - getUISceneNode()->runOnMainThread( [this] { mLoader->setVisible( false ); } ); - updateStatus( true ); - } ); + runAsync( [this, file]() { return mGit->restore( file ); }, true, false ); } ); msgBox->setCloseShortcut( { KEY_ESCAPE, KEYMOD_NONE } ); msgBox->setTitle( i18n( "git_confirm", "Confirm" ) ); @@ -1151,7 +1097,7 @@ void GitPlugin::buildSidePanelTab() { - + )html" ); mTab = mSidePanel->add( i18n( "source_control", "Source Control" ), node, @@ -1180,11 +1126,15 @@ void GitPlugin::buildSidePanelTab() { static_cast( modelEvent->getModelIndex().internalData() ); switch ( modelEvent->getModelEventType() ) { - case EE::UI::Abstract::ModelEventType::Open: { + case Abstract::ModelEventType::Open: { checkout( *branch ); break; } - case EE::UI::Abstract::ModelEventType::OpenMenu: { + case Abstract::ModelEventType::OpenMenu: { + bool focusOnSelection = mBranchesTree->getFocusOnSelection(); + mBranchesTree->setFocusOnSelection( false ); + mBranchesTree->getSelection().set( modelEvent->getModelIndex() ); + mBranchesTree->setFocusOnSelection( focusOnSelection ); openBranchMenu( *branch ); break; } @@ -1218,7 +1168,7 @@ void GitPlugin::buildSidePanelTab() { return; switch ( modelEvent->getModelEventType() ) { - case EE::UI::Abstract::ModelEventType::OpenMenu: { + case Abstract::ModelEventType::OpenMenu: { bool focusOnSelection = mStatusTree->getFocusOnSelection(); mStatusTree->setFocusOnSelection( false ); mStatusTree->getSelection().set( modelEvent->getModelIndex() ); @@ -1243,6 +1193,8 @@ void GitPlugin::openBranchMenu( const Git::Branch& branch ) { ->setId( txtKey ); }; + addFn( "git-fetch", "Fetch" ); + if ( mGitBranch != branch.name ) { addFn( "git-checkout", "Check Out..." ); if ( branch.type == Git::RefType::Head ) { @@ -1250,7 +1202,9 @@ void GitPlugin::openBranchMenu( const Git::Branch& branch ) { addFn( "git-branch-delete", "Delete" ); } } else { - addFn( "git-pull", "Pull", "repo-pull" ); + if ( branch.type == Git::RefType::Head ) { + addFn( "git-pull", "Pull", "repo-pull" ); + } } menu->on( Event::OnItemClicked, [this, branch]( const Event* event ) { @@ -1266,6 +1220,8 @@ void GitPlugin::openBranchMenu( const Git::Branch& branch ) { branchDelete( branch ); } else if ( id == "git-branch-rename" ) { branchRename( branch ); + } else if ( id == "git-fetch" ) { + fetch(); } } ); @@ -1314,4 +1270,23 @@ void GitPlugin::openFileStatusMenu( const Git::DiffFile& file ) { menu->showOverMouseCursor(); } +void GitPlugin::runAsync( std::function fn, bool _updateStatus, + bool _updateBranches ) { + if ( !mGit ) + return; + mLoader->setVisible( true ); + mThreadPool->run( [&] { + auto res = fn(); + if ( res.fail() ) { + showMessage( LSPMessageType::Warning, res.result ); + return; + } + if ( _updateBranches ) + updateBranches(); + if ( _updateStatus ) + updateStatus( true ); + getUISceneNode()->runOnMainThread( [this] { mLoader->setVisible( false ); } ); + } ); +} + } // namespace ecode diff --git a/src/tools/ecode/plugins/git/gitplugin.hpp b/src/tools/ecode/plugins/git/gitplugin.hpp index 958aa3346..c55bf31d0 100644 --- a/src/tools/ecode/plugins/git/gitplugin.hpp +++ b/src/tools/ecode/plugins/git/gitplugin.hpp @@ -128,6 +128,8 @@ class GitPlugin : public PluginBase { void pull(); + void fetch(); + void stage( const std::string& file ); void unstage( const std::string& file ); @@ -153,6 +155,8 @@ class GitPlugin : public PluginBase { void openBranchMenu( const Git::Branch& branch ); void openFileStatusMenu( const Git::DiffFile& file ); + + void runAsync( std::function fn, bool updateStatus, bool updateBranches ); }; } // namespace ecode