Git - add stage/unstage commands to editor title (#237257)

pull/230693/merge
Ladislau Szomoru 2025-01-04 19:15:35 +01:00 committed by GitHub
parent 2bdb3e9b41
commit aa6a38114c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 39 additions and 1 deletions

View File

@ -2050,9 +2050,19 @@
"group": "navigation",
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0 && isInNotebookTextDiffEditor && resourceScheme =~ /^git$|^file$/"
},
{
"command": "git.stage",
"group": "navigation@1",
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0 && !isInDiffEditor && !isMergeEditor && resourceScheme == file && git.activeResourceHasUnstagedChanges"
},
{
"command": "git.unstage",
"group": "navigation@1",
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0 && !isInDiffEditor && !isMergeEditor && resourceScheme == file && git.activeResourceHasStagedChanges"
},
{
"command": "git.openChange",
"group": "navigation",
"group": "navigation@2",
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0 && !isInDiffEditor && !isMergeEditor && resourceScheme == file && scmActiveResourceHasChanges"
},
{

View File

@ -272,6 +272,7 @@ export class Model implements IRepositoryResolver, IBranchProtectionProviderRegi
workspace.onDidChangeWorkspaceFolders(this.onDidChangeWorkspaceFolders, this, this.disposables);
window.onDidChangeVisibleTextEditors(this.onDidChangeVisibleTextEditors, this, this.disposables);
window.onDidChangeActiveTextEditor(this.onDidChangeActiveTextEditor, this, this.disposables);
workspace.onDidChangeConfiguration(this.onDidChangeConfiguration, this, this.disposables);
const fsWatcher = workspace.createFileSystemWatcher('**');
@ -519,6 +520,31 @@ export class Model implements IRepositoryResolver, IBranchProtectionProviderRegi
}
}
private onDidChangeActiveTextEditor(): void {
const textEditor = window.activeTextEditor;
if (textEditor === undefined) {
commands.executeCommand('setContext', 'git.activeResourceHasUnstagedChanges', false);
commands.executeCommand('setContext', 'git.activeResourceHasStagedChanges', false);
return;
}
const repository = this.getRepository(textEditor.document.uri);
if (!repository) {
commands.executeCommand('setContext', 'git.activeResourceHasUnstagedChanges', false);
commands.executeCommand('setContext', 'git.activeResourceHasStagedChanges', false);
return;
}
const indexResource = repository.indexGroup.resourceStates
.find(resource => pathEquals(resource.resourceUri.fsPath, textEditor.document.uri.fsPath));
const workingTreeResource = repository.workingTreeGroup.resourceStates
.find(resource => pathEquals(resource.resourceUri.fsPath, textEditor.document.uri.fsPath));
commands.executeCommand('setContext', 'git.activeResourceHasStagedChanges', indexResource !== undefined);
commands.executeCommand('setContext', 'git.activeResourceHasUnstagedChanges', workingTreeResource !== undefined);
}
@sequentialize
async openRepository(repoPath: string, openIfClosed = false): Promise<void> {
this.logger.trace(`[Model][openRepository] Repository: ${repoPath}`);
@ -727,8 +753,10 @@ export class Model implements IRepositoryResolver, IBranchProtectionProviderRegi
const statusListener = repository.onDidRunGitStatus(() => {
checkForSubmodules();
updateMergeChanges();
this.onDidChangeActiveTextEditor();
});
checkForSubmodules();
this.onDidChangeActiveTextEditor();
const updateOperationInProgressContext = () => {
let operationInProgress = false;