mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-16 10:58:34 -05:00
Updates remotes context based on the active editor
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import { Objects } from './system';
|
import { Objects } from './system';
|
||||||
import { commands, ExtensionContext, extensions, languages, Uri, window, workspace } from 'vscode';
|
import { commands, Disposable, ExtensionContext, extensions, languages, TextEditor, Uri, window, workspace } from 'vscode';
|
||||||
import { BlameabilityTracker } from './blameabilityTracker';
|
import { BlameabilityTracker } from './blameabilityTracker';
|
||||||
import { BlameActiveLineController } from './blameActiveLineController';
|
import { BlameActiveLineController } from './blameActiveLineController';
|
||||||
import { BlameAnnotationController } from './blameAnnotationController';
|
import { BlameAnnotationController } from './blameAnnotationController';
|
||||||
@@ -160,6 +160,7 @@ async function notifyOnUnsupportedGitVersion(context: ExtensionContext, version:
|
|||||||
|
|
||||||
let savedGitEnabled: boolean;
|
let savedGitEnabled: boolean;
|
||||||
let savedInsiders: boolean;
|
let savedInsiders: boolean;
|
||||||
|
let insidersDisposable: Disposable;
|
||||||
|
|
||||||
async function setCommandsContext(context: ExtensionContext, git: GitService): Promise<void> {
|
async function setCommandsContext(context: ExtensionContext, git: GitService): Promise<void> {
|
||||||
onCommandsContextConfigurationChanged(git);
|
onCommandsContextConfigurationChanged(git);
|
||||||
@@ -177,11 +178,32 @@ async function onCommandsContextConfigurationChanged(git: GitService) {
|
|||||||
if (insiders !== savedInsiders) {
|
if (insiders !== savedInsiders) {
|
||||||
savedInsiders = insiders;
|
savedInsiders = insiders;
|
||||||
|
|
||||||
let hasRemotes = false;
|
insidersDisposable && insidersDisposable.dispose();
|
||||||
if (insiders) {
|
if (insiders) {
|
||||||
const remotes = await git.getRemotes(git.repoPath);
|
insidersDisposable = window.onDidChangeActiveTextEditor(e => onActiveTextEditorChanged(e, git));
|
||||||
hasRemotes = remotes.length !== 0;
|
onActiveTextEditorChanged(window.activeTextEditor, git);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
insidersDisposable = undefined;
|
||||||
|
setCommandContext(CommandContext.HasRemotes, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onActiveTextEditorChanged(editor: TextEditor, git: GitService) {
|
||||||
|
try {
|
||||||
|
let hasRemotes = false;
|
||||||
|
if (editor) {
|
||||||
|
const repoPath = await git.getRepoPathFromUri(editor.document.uri);
|
||||||
|
if (repoPath) {
|
||||||
|
const remotes = await git.getRemotes(repoPath);
|
||||||
|
hasRemotes = remotes.length !== 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setCommandContext(CommandContext.HasRemotes, hasRemotes);
|
setCommandContext(CommandContext.HasRemotes, hasRemotes);
|
||||||
}
|
}
|
||||||
|
catch (ex) {
|
||||||
|
Logger.error(ex, 'Extension.onActiveTextEditorChanged');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user