From 4d0c18f330366fab2bea5e9e554cb2b26c10fcf1 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Thu, 16 Feb 2017 10:43:28 -0500 Subject: [PATCH] Fixes #31 - Disable gitlens if no `.git` folder --- package.json | 84 ++++++++++++++++++++++++++++++++++++++++++++++---------- src/constants.ts | 3 +- src/extension.ts | 14 ++++++++-- 3 files changed, 83 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 60d27a6..6090dad 100644 --- a/package.json +++ b/package.json @@ -378,87 +378,141 @@ } ], "menus": { + "commandPalette": [ + { + "command": "gitlens.diffWithPrevious", + "when": "gitlens:enabled" + }, + { + "command": "gitlens.diffLineWithPrevious", + "when": "gitlens:enabled" + }, + { + "command": "gitlens.diffWithWorking", + "when": "gitlens:enabled" + }, + { + "command": "gitlens.diffLineWithWorking", + "when": "gitlens:enabled" + }, + { + "command": "gitlens.showBlame", + "when": "gitlens:enabled" + }, + { + "command": "gitlens.toggleBlame", + "when": "gitlens:enabled" + }, + { + "command": "gitlens.toggleCodeLens", + "when": "gitlens:enabled" + }, + { + "command": "gitlens.showBlameHistory", + "when": "gitlens:enabled" + }, + { + "command": "gitlens.showFileHistory", + "when": "gitlens:enabled" + }, + { + "command": "gitlens.showQuickCommitDetails", + "when": "gitlens:enabled" + }, + { + "command": "gitlens.showQuickFileHistory", + "when": "gitlens:enabled" + }, + { + "command": "gitlens.showQuickRepoHistory", + "when": "gitlens:enabled" + }, + { + "command": "gitlens.copyShaToClipboard", + "when": "gitlens:enabled" + } + ], "explorer/context": [ { "command": "gitlens.showQuickFileHistory", - "when": "config.git.enabled", + "when": "gitlens:enabled", "group": "gitlens" }, { "command": "gitlens.diffWithPrevious", - "when": "config.gitlens.menus.diff.enabled && config.git.enabled", + "when": "config.gitlens.menus.diff.enabled && gitlens:enabled", "group": "gitlens_diff" }, { "command": "gitlens.diffWithWorking", - "when": "config.gitlens.menus.diff.enabled && config.git.enabled", + "when": "config.gitlens.menus.diff.enabled && gitlens:enabled", "group": "gitlens_diff" } ], "editor/title": [ { "command": "gitlens.toggleBlame", - "when": "config.git.enabled", + "when": "gitlens:enabled", "group": "navigation@100" }, { "command": "gitlens.showQuickFileHistory", - "when": "config.git.enabled", + "when": "gitlens:enabled", "group": "1_gitlens" }, { "command": "gitlens.diffWithPrevious", - "when": "config.gitlens.menus.diff.enabled && config.git.enabled", + "when": "config.gitlens.menus.diff.enabled && gitlens:enabled", "group": "1_gitlens_diff" }, { "command": "gitlens.diffWithWorking", - "when": "config.gitlens.menus.diff.enabled && config.git.enabled", + "when": "config.gitlens.menus.diff.enabled && gitlens:enabled", "group": "1_gitlens_diff" } ], "editor/title/context": [ { "command": "gitlens.toggleBlame", - "when": "config.git.enabled", + "when": "gitlens:enabled", "group": "gitlens@1" }, { "command": "gitlens.showQuickFileHistory", - "when": "config.git.enabled", + "when": "gitlens:enabled", "group": "gitlens@2" } ], "editor/context": [ { "command": "gitlens.diffLineWithPrevious", - "when": "editorTextFocus && config.gitlens.menus.diff.enabled && config.git.enabled", + "when": "editorTextFocus && config.gitlens.menus.diff.enabled && gitlens:enabled", "group": "1_gitlens@1" }, { "command": "gitlens.diffLineWithWorking", - "when": "editorTextFocus && config.gitlens.menus.diff.enabled && config.git.enabled", + "when": "editorTextFocus && config.gitlens.menus.diff.enabled && gitlens:enabled", "group": "1_gitlens@2" }, { "command": "gitlens.showQuickCommitDetails", - "when": "editorTextFocus && config.git.enabled", + "when": "editorTextFocus && gitlens:enabled", "group": "1_gitlens@3" }, { "command": "gitlens.toggleBlame", - "when": "editorTextFocus && config.git.enabled", + "when": "editorTextFocus && gitlens:enabled", "group": "2_gitlens@1" }, { "command": "gitlens.showQuickFileHistory", "alt": "gitlens.showFileHistory", - "when": "config.git.enabled", + "when": "gitlens:enabled", "group": "2_gitlens@2" }, { "command": "gitlens.copyShaToClipboard", - "when": "editorTextFocus && config.git.enabled", + "when": "editorTextFocus && gitlens:enabled", "group": "9_gitlens@1" } ] diff --git a/src/constants.ts b/src/constants.ts index 50de002..7259bc6 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -2,7 +2,7 @@ export const RepoPath = 'repoPath'; -export type BuiltInCommands = 'cursorMove' | 'editor.action.showReferences' | 'editor.action.toggleRenderWhitespace' | 'editorScroll' | 'revealLine' | 'vscode.diff' | 'vscode.executeDocumentSymbolProvider' | 'vscode.executeCodeLensProvider'; +export type BuiltInCommands = 'cursorMove' | 'editor.action.showReferences' | 'editor.action.toggleRenderWhitespace' | 'editorScroll' | 'revealLine' | 'vscode.diff' | 'vscode.executeDocumentSymbolProvider' | 'vscode.executeCodeLensProvider' | 'setContext'; export const BuiltInCommands = { CursorMove: 'cursorMove' as BuiltInCommands, Diff: 'vscode.diff' as BuiltInCommands, @@ -10,6 +10,7 @@ export const BuiltInCommands = { ExecuteDocumentSymbolProvider: 'vscode.executeDocumentSymbolProvider' as BuiltInCommands, ExecuteCodeLensProvider: 'vscode.executeCodeLensProvider' as BuiltInCommands, RevealLine: 'revealLine' as BuiltInCommands, + SetContext: 'setContext' as BuiltInCommands, ShowReferences: 'editor.action.showReferences' as BuiltInCommands, ToggleRenderWhitespace: 'editor.action.toggleRenderWhitespace' as BuiltInCommands }; diff --git a/src/extension.ts b/src/extension.ts index fb7207d..4f7fd9c 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,5 +1,5 @@ 'use strict'; -import { ExtensionContext, languages, window, workspace } from 'vscode'; +import { commands, ExtensionContext, languages, window, workspace } from 'vscode'; import BlameActiveLineController from './blameActiveLineController'; import BlameAnnotationController from './blameAnnotationController'; import { configureCssCharacters } from './blameAnnotationFormatter'; @@ -17,7 +17,7 @@ import ShowQuickRepoHistoryCommand from './commands/showQuickRepoHistory'; import ToggleBlameCommand from './commands/toggleBlame'; import ToggleCodeLensCommand from './commands/toggleCodeLens'; import { IAdvancedConfig, IBlameConfig } from './configuration'; -import { WorkspaceState } from './constants'; +import { BuiltInCommands, WorkspaceState } from './constants'; import GitContentProvider from './gitContentProvider'; import GitProvider, { Git } from './gitProvider'; import GitRevisionCodeLensProvider from './gitRevisionCodeLensProvider'; @@ -49,9 +49,19 @@ export async function activate(context: ExtensionContext) { if (ex.message.includes('Unable to find git')) { await window.showErrorMessage(`GitLens: Unable to find Git. Please make sure Git is installed. Also ensure that Git is either in the PATH, or that 'gitlens.advanced.git' is pointed to its installed location.`); } + commands.executeCommand(BuiltInCommands.SetContext, 'gitlens:enabled', false); return; } + let gitEnabled = workspace.getConfiguration('git').get('enabled'); + commands.executeCommand(BuiltInCommands.SetContext, 'gitlens:enabled', gitEnabled); + context.subscriptions.push(workspace.onDidChangeConfiguration(() => { + if (gitEnabled !== workspace.getConfiguration('git').get('enabled')) { + gitEnabled = !gitEnabled; + commands.executeCommand(BuiltInCommands.SetContext, 'gitlens:enabled', gitEnabled); + } + }, this)); + context.workspaceState.update(WorkspaceState.RepoPath, repoPath); const git = new GitProvider(context);