From ee40dc632531f7d0ca1ebdd1d4afb3fd48697138 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Fri, 24 Mar 2017 14:25:37 -0400 Subject: [PATCH] Allows dynamic switching of insiders --- src/extension.ts | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 2a2d24a..d4b0585 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -62,21 +62,12 @@ export async function activate(context: ExtensionContext) { notifyOnUnsupportedGitVersion(context, gitVersion); notifyOnNewGitLensVersion(context, gitlensVersion); - let gitEnabled = workspace.getConfiguration('git').get('enabled'); - setCommandContext(CommandContext.Enabled, gitEnabled); - context.subscriptions.push(workspace.onDidChangeConfiguration(() => { - if (gitEnabled !== workspace.getConfiguration('git').get('enabled')) { - gitEnabled = !gitEnabled; - setCommandContext(CommandContext.Enabled, gitEnabled); - } - }, this)); - context.workspaceState.update(WorkspaceState.RepoPath, repoPath); const git = new GitService(context); context.subscriptions.push(git); - setRemoteCommandsContext(context, git); + setCommandsContext(context, git); const blameabilityTracker = new BlameabilityTracker(git); context.subscriptions.push(blameabilityTracker); @@ -154,11 +145,30 @@ async function notifyOnUnsupportedGitVersion(context: ExtensionContext, version: } } -async function setRemoteCommandsContext(context: ExtensionContext, git: GitService): Promise { - let hasRemotes = false; - if (git.config.insiders) { - const remotes = await git.getRemotes(git.repoPath); - hasRemotes = remotes.length !== 0; +let savedGitEnabled: boolean; +let savedInsiders: boolean; + +async function setCommandsContext(context: ExtensionContext, git: GitService): Promise { + onCommandsContextConfigurationChanged(git); + context.subscriptions.push(workspace.onDidChangeConfiguration(() => onCommandsContextConfigurationChanged(git), this)); +} + +async function onCommandsContextConfigurationChanged(git: GitService) { + const gitEnabled = workspace.getConfiguration('git').get('enabled'); + if (gitEnabled !== savedGitEnabled) { + savedGitEnabled = gitEnabled; + setCommandContext(CommandContext.Enabled, gitEnabled); + } + + const insiders = workspace.getConfiguration('gitlens').get('insiders'); + if (insiders !== savedInsiders) { + savedInsiders = insiders; + + let hasRemotes = false; + if (insiders) { + const remotes = await git.getRemotes(git.repoPath); + hasRemotes = remotes.length !== 0; + } + setCommandContext(CommandContext.HasRemotes, hasRemotes); } - setCommandContext(CommandContext.HasRemotes, hasRemotes); } \ No newline at end of file