mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-06-02 03:26:29 +03:00
More git plugin fixes.
This commit is contained in:
@@ -219,6 +219,10 @@ Git::Result Git::reset( std::vector<std::string> files, const std::string& proje
|
||||
return gitSimple( String::format( "reset -q HEAD -- %s", asList( files ) ), projectDir );
|
||||
}
|
||||
|
||||
Git::Result Git::diff( const std::string& file, const std::string& projectDir ) {
|
||||
return gitSimple( String::format( "diff \"%s\"", file ), projectDir );
|
||||
}
|
||||
|
||||
Git::Result Git::createBranch( const std::string& branchName, bool _checkout,
|
||||
const std::string& projectDir ) {
|
||||
auto res = gitSimple( String::format( "branch --no-track %s", branchName ), projectDir );
|
||||
|
||||
@@ -75,11 +75,11 @@ class Git {
|
||||
};
|
||||
|
||||
enum class GitStatusType {
|
||||
Staged,
|
||||
Changed,
|
||||
Untracked,
|
||||
Unmerged,
|
||||
Ignored,
|
||||
Staged = 1 << 1,
|
||||
Changed = 1 << 2,
|
||||
Untracked = 1 << 3,
|
||||
Unmerged = 1 << 4,
|
||||
Ignored = 1 << 5,
|
||||
};
|
||||
|
||||
static constexpr auto ANY = 0;
|
||||
@@ -237,6 +237,8 @@ class Git {
|
||||
|
||||
Result reset( std::vector<std::string> files, const std::string& projectDir = "" );
|
||||
|
||||
Result diff( const std::string& file, const std::string& projectDir = "" );
|
||||
|
||||
Result createBranch( const std::string& branchName, bool checkout = false,
|
||||
const std::string& projectDir = "" );
|
||||
|
||||
|
||||
@@ -241,7 +241,7 @@ void GitPlugin::updateStatusBarSync() {
|
||||
if ( childCount > 2 )
|
||||
mStatusButton->toPosition( mStatusBar->getChildCount() - 2 );
|
||||
|
||||
mStatusButton->on( Event::MouseClick, [this]( const Event* ) {
|
||||
mStatusButton->onClick( [this]( const Event* ) {
|
||||
if ( mTab ) {
|
||||
mTab->setTabSelected();
|
||||
if ( mGitStatus.totalInserts || mGitStatus.totalDeletions )
|
||||
@@ -736,6 +736,14 @@ static bool isPath( const std::string& file ) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string GitPlugin::fixFilePath( const std::string& file ) {
|
||||
std::string path;
|
||||
if ( !isPath( file ) ) {
|
||||
path = ( mProjectPath + file );
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
std::vector<std::string> GitPlugin::fixFilePaths( const std::vector<std::string>& files ) {
|
||||
std::vector<std::string> paths;
|
||||
paths.reserve( files.size() );
|
||||
@@ -766,7 +774,6 @@ void GitPlugin::unstage( const std::vector<std::string>& files ) {
|
||||
},
|
||||
true, false );
|
||||
}
|
||||
// File operations
|
||||
|
||||
void GitPlugin::discard( const std::string& file ) {
|
||||
UIMessageBox* msgBox = UIMessageBox::New(
|
||||
@@ -792,6 +799,26 @@ void GitPlugin::openFile( const std::string& file ) {
|
||||
} );
|
||||
}
|
||||
|
||||
void GitPlugin::diff( const std::string& file ) {
|
||||
mThreadPool->run( [this, file] {
|
||||
auto res = mGit->diff( fixFilePath( file ), mGit->repoPath( file ) );
|
||||
if ( res.fail() )
|
||||
return;
|
||||
|
||||
getUISceneNode()->runOnMainThread( [this, file, res] {
|
||||
auto ret = mManager->getSplitter()->createEditorInNewTab();
|
||||
auto doc = ret.second->getDocumentRef();
|
||||
doc->setDefaultFileName( FileSystem::fileNameFromPath( file ) + ".diff" );
|
||||
doc->setSyntaxDefinition( SyntaxDefinitionManager::instance()->getByLSPName( "diff" ) );
|
||||
doc->textInput( res.result, false );
|
||||
doc->moveToStartOfDoc();
|
||||
doc->resetUndoRedo();
|
||||
} );
|
||||
} );
|
||||
}
|
||||
|
||||
// File operations
|
||||
|
||||
void GitPlugin::onRegister( UICodeEditor* editor ) {
|
||||
PluginBase::onRegister( editor );
|
||||
|
||||
@@ -1019,14 +1046,15 @@ void GitPlugin::buildSidePanelTab() {
|
||||
node->bind( "git_panel_loader", mLoader );
|
||||
node->bind( "git_repo", mRepoDropDown );
|
||||
|
||||
node->find( "branch_pull" )->on( Event::MouseClick, [this]( auto ) { pull(); } );
|
||||
node->find( "branch_push" )->on( Event::MouseClick, [this]( auto ) { push(); } );
|
||||
node->find( "branch_add" )->on( Event::MouseClick, [this]( auto ) { branchCreate(); } );
|
||||
node->find( "branch_pull" )->onClick( [this]( auto ) { pull(); } );
|
||||
node->find( "branch_push" )->onClick( [this]( auto ) { push(); } );
|
||||
node->find( "branch_add" )->onClick( [this]( auto ) { branchCreate(); } );
|
||||
|
||||
mBranchesTree->setAutoExpandOnSingleColumn( true );
|
||||
mBranchesTree->setHeadersVisible( false );
|
||||
mBranchesTree->setExpandersAsIcons( true );
|
||||
mBranchesTree->setIndentWidth( PixelDensity::dpToPx( 16 ) );
|
||||
mBranchesTree->setScrollViewType( UIScrollableWidget::Inclusive );
|
||||
mBranchesTree->on( Event::OnModelEvent, [this]( const Event* event ) {
|
||||
const ModelEvent* modelEvent = static_cast<const ModelEvent*>( event );
|
||||
if ( !modelEvent->getModelIndex().hasParent() )
|
||||
@@ -1086,6 +1114,7 @@ void GitPlugin::buildSidePanelTab() {
|
||||
mStatusTree->setAutoColumnsWidth( true );
|
||||
mStatusTree->setHeadersVisible( false );
|
||||
mStatusTree->setExpandersAsIcons( true );
|
||||
mStatusTree->setScrollViewType( UIScrollableWidget::Inclusive );
|
||||
mStatusTree->on( Event::OnRowCreated, [this]( const Event* event ) {
|
||||
UITableRow* row = event->asRowCreatedEvent()->getRow();
|
||||
row->on( Event::MouseUp, [this, row]( const Event* event ) {
|
||||
@@ -1113,6 +1142,10 @@ void GitPlugin::buildSidePanelTab() {
|
||||
openFileStatusMenu( *file );
|
||||
break;
|
||||
}
|
||||
case Abstract::ModelEventType::Open: {
|
||||
diff( file->file );
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -1245,6 +1278,7 @@ void GitPlugin::openFileStatusMenu( const Git::DiffFile& file ) {
|
||||
menu->setId( "git_file_status_menu" );
|
||||
|
||||
addMenuItem( menu, "git-open-file", "Open File" );
|
||||
addMenuItem( menu, "git-diff", "Open Diff" );
|
||||
|
||||
if ( file.report.type != Git::GitStatusType::Staged ) {
|
||||
addMenuItem( menu, "git-stage", "Stage" );
|
||||
@@ -1269,6 +1303,8 @@ void GitPlugin::openFileStatusMenu( const Git::DiffFile& file ) {
|
||||
discard( file.file );
|
||||
} else if ( id == "git-open-file" ) {
|
||||
openFile( file.file );
|
||||
} else if ( id == "git-diff" ) {
|
||||
diff( file.file );
|
||||
}
|
||||
} );
|
||||
|
||||
@@ -1288,7 +1324,7 @@ void GitPlugin::runAsync( std::function<Git::Result()> fn, bool _updateStatus, b
|
||||
return;
|
||||
}
|
||||
if ( _updateBranches )
|
||||
updateBranches();
|
||||
updateBranches( true );
|
||||
|
||||
if ( _updateStatus )
|
||||
updateStatus( true );
|
||||
|
||||
@@ -166,6 +166,8 @@ class GitPlugin : public PluginBase {
|
||||
|
||||
void discard( const std::string& file );
|
||||
|
||||
void diff( const std::string& file );
|
||||
|
||||
void openFile( const std::string& file );
|
||||
|
||||
void updateStatus( bool force = false );
|
||||
@@ -195,6 +197,8 @@ class GitPlugin : public PluginBase {
|
||||
|
||||
std::string repoSelected();
|
||||
|
||||
std::string fixFilePath( const std::string& file );
|
||||
|
||||
std::vector<std::string> fixFilePaths( const std::vector<std::string>& files );
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user