mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-28 01:25:48 -05:00
Consolidates setContext into commands
Adds context for toggling CodeLens
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
import { commands, Disposable, Event, EventEmitter, TextDocument, TextDocumentChangeEvent, TextEditor, window, workspace } from 'vscode';
|
||||
import { Disposable, Event, EventEmitter, TextDocument, TextDocumentChangeEvent, TextEditor, window, workspace } from 'vscode';
|
||||
import { CommandContext, setCommandContext } from './commands';
|
||||
import { TextDocumentComparer } from './comparers';
|
||||
import { BuiltInCommands } from './constants';
|
||||
import { GitProvider } from './gitProvider';
|
||||
|
||||
export interface BlameabilityChangeEvent {
|
||||
@@ -91,7 +91,7 @@ export class BlameabilityTracker extends Disposable {
|
||||
private updateBlameability(blameable: boolean, force: boolean = false) {
|
||||
if (!force && this._isBlameable === blameable) return;
|
||||
|
||||
commands.executeCommand(BuiltInCommands.SetContext, 'gitlens:isBlameable', blameable);
|
||||
setCommandContext(CommandContext.IsBlameable, blameable);
|
||||
this._onDidChange.fire({
|
||||
blameable: blameable,
|
||||
editor: this._editor
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
'use strict';
|
||||
import { commands } from 'vscode';
|
||||
import { BuiltInCommands } from './constants';
|
||||
|
||||
export { Keyboard } from './commands/keyboard';
|
||||
|
||||
export { ActiveEditorCommand, Command, Commands, EditorCommand, openEditor } from './commands/commands';
|
||||
@@ -20,4 +23,17 @@ export { ShowQuickFileHistoryCommand } from './commands/showQuickFileHistory';
|
||||
export { ShowQuickRepoHistoryCommand } from './commands/showQuickRepoHistory';
|
||||
export { ShowQuickRepoStatusCommand } from './commands/showQuickRepoStatus';
|
||||
export { ToggleBlameCommand } from './commands/toggleBlame';
|
||||
export { ToggleCodeLensCommand } from './commands/toggleCodeLens';
|
||||
export { ToggleCodeLensCommand } from './commands/toggleCodeLens';
|
||||
|
||||
export type CommandContext = 'gitlens:canToggleCodeLens' | 'gitlens:enabled' | 'gitlens:isBlameable' | 'gitlens:key';
|
||||
export const CommandContext = {
|
||||
CanToggleCodeLens: 'gitlens:canToggleCodeLens' as CommandContext,
|
||||
Enabled: 'gitlens:enabled' as CommandContext,
|
||||
IsBlameable: 'gitlens:isBlameable' as CommandContext,
|
||||
Key: 'gitlens:key' as CommandContext
|
||||
};
|
||||
|
||||
|
||||
export function setCommandContext(key: CommandContext, value: any) {
|
||||
return commands.executeCommand(BuiltInCommands.SetContext, key, value);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
import { commands, Disposable, ExtensionContext, QuickPickItem } from 'vscode';
|
||||
import { BuiltInCommands } from '../constants';
|
||||
import { CommandContext, setCommandContext } from '../commands';
|
||||
import { CommandQuickPickItem, OpenFileCommandQuickPickItem } from '../quickPicks/quickPicks';
|
||||
//import { Logger } from '../logger';
|
||||
|
||||
@@ -53,7 +53,7 @@ export class Keyboard extends Disposable {
|
||||
}
|
||||
|
||||
async enterScope(...keyCommands: [Keys, QuickPickItem][]) {
|
||||
await commands.executeCommand(BuiltInCommands.SetContext, 'gitlens:key', ++scopeCount);
|
||||
await setCommandContext(CommandContext.Key, ++scopeCount);
|
||||
if (keyCommands && Array.isArray(keyCommands) && keyCommands.length) {
|
||||
for (const [key, command] of keyCommands) {
|
||||
await this.setKeyCommand(key as Keys, command);
|
||||
@@ -62,7 +62,7 @@ export class Keyboard extends Disposable {
|
||||
}
|
||||
|
||||
async exitScope(clear: boolean = true) {
|
||||
await commands.executeCommand(BuiltInCommands.SetContext, 'gitlens:key', --scopeCount);
|
||||
await setCommandContext(CommandContext.Key, --scopeCount);
|
||||
if (clear && !scopeCount) {
|
||||
for (const key of keys) {
|
||||
await this.clearKeyCommand(key);
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
'use strict';
|
||||
import { commands, ExtensionContext, languages, window, workspace } from 'vscode';
|
||||
import { ExtensionContext, languages, window, workspace } from 'vscode';
|
||||
import { BlameabilityTracker } from './blameabilityTracker';
|
||||
import { BlameActiveLineController } from './blameActiveLineController';
|
||||
import { BlameAnnotationController } from './blameAnnotationController';
|
||||
import { configureCssCharacters } from './blameAnnotationFormatter';
|
||||
import { CommandContext, setCommandContext } from './commands';
|
||||
import { CloseUnchangedFilesCommand, OpenChangedFilesCommand } from './commands';
|
||||
import { CopyMessageToClipboardCommand, CopyShaToClipboardCommand } from './commands';
|
||||
import { DiffDirectoryCommand, DiffLineWithPreviousCommand, DiffLineWithWorkingCommand, DiffWithPreviousCommand, DiffWithWorkingCommand} from './commands';
|
||||
@@ -13,7 +14,7 @@ import { ShowQuickCommitDetailsCommand, ShowQuickCommitFileDetailsCommand, ShowQ
|
||||
import { ToggleCodeLensCommand } from './commands';
|
||||
import { Keyboard } from './commands';
|
||||
import { IAdvancedConfig, IBlameConfig } from './configuration';
|
||||
import { BuiltInCommands, WorkspaceState } from './constants';
|
||||
import { WorkspaceState } from './constants';
|
||||
import { GitContentProvider } from './gitContentProvider';
|
||||
import { Git, GitProvider } from './gitProvider';
|
||||
import { GitRevisionCodeLensProvider } from './gitRevisionCodeLensProvider';
|
||||
@@ -47,7 +48,7 @@ export async function activate(context: ExtensionContext) {
|
||||
if (ex.message.includes('Unable to find git')) {
|
||||
await window.showErrorMessage(`GitLens was 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);
|
||||
setCommandContext(CommandContext.Enabled, false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -59,11 +60,11 @@ export async function activate(context: ExtensionContext) {
|
||||
}
|
||||
|
||||
let gitEnabled = workspace.getConfiguration('git').get<boolean>('enabled');
|
||||
commands.executeCommand(BuiltInCommands.SetContext, 'gitlens:enabled', gitEnabled);
|
||||
setCommandContext(CommandContext.Enabled, gitEnabled);
|
||||
context.subscriptions.push(workspace.onDidChangeConfiguration(() => {
|
||||
if (gitEnabled !== workspace.getConfiguration('git').get<boolean>('enabled')) {
|
||||
gitEnabled = !gitEnabled;
|
||||
commands.executeCommand(BuiltInCommands.SetContext, 'gitlens:enabled', gitEnabled);
|
||||
setCommandContext(CommandContext.Enabled, gitEnabled);
|
||||
}
|
||||
}, this));
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
import { Iterables, Objects } from './system';
|
||||
import { Disposable, Event, EventEmitter, ExtensionContext, FileSystemWatcher, languages, Location, Position, Range, TextDocument, TextEditor, Uri, workspace } from 'vscode';
|
||||
import { CommandContext, setCommandContext } from './commands';
|
||||
import { CodeLensVisibility, IConfig } from './configuration';
|
||||
import { DocumentSchemes, WorkspaceState } from './constants';
|
||||
import Git, { GitBlameParserEnricher, GitBlameFormat, GitCommit, GitFileStatusItem, GitLogParserEnricher, IGitAuthor, IGitBlame, IGitBlameLine, IGitBlameLines, IGitLog } from './git/git';
|
||||
@@ -143,6 +144,8 @@ export class GitProvider extends Disposable {
|
||||
this._codeLensProviderDisposable = undefined;
|
||||
this._codeLensProvider = undefined;
|
||||
}
|
||||
|
||||
setCommandContext(CommandContext.CanToggleCodeLens, config.codeLens.visibility === CodeLensVisibility.OnDemand && (config.codeLens.recentChange.enabled || config.codeLens.authors.enabled));
|
||||
}
|
||||
|
||||
if (advancedChanged) {
|
||||
|
||||
Reference in New Issue
Block a user