Przeglądaj źródła

Consolidates setContext into commands

Adds context for toggling CodeLens
main
Eric Amodio 7 lat temu
rodzic
commit
0480477136
6 zmienionych plików z 36 dodań i 16 usunięć
  1. +4
    -4
      package.json
  2. +3
    -3
      src/blameabilityTracker.ts
  3. +17
    -1
      src/commands.ts
  4. +3
    -3
      src/commands/keyboard.ts
  5. +6
    -5
      src/extension.ts
  6. +3
    -0
      src/gitProvider.ts

+ 4
- 4
package.json Wyświetl plik

@ -491,7 +491,7 @@
},
{
"command": "gitlens.toggleCodeLens",
"when": "gitlens:enabled"
"when": "gitlens:enabled && gitlens:canToggleCodeLens"
},
{
"command": "gitlens.showBlameHistory",
@ -669,7 +669,7 @@
"command": "gitlens.toggleCodeLens",
"key": "alt+shift+b",
"mac": "alt+shift+b",
"when": "editorTextFocus && gitlens:enabled"
"when": "editorTextFocus && gitlens:enabled && gitlens:canToggleCodeLens"
},
{
"command": "gitlens.showQuickFileHistory",
@ -746,11 +746,11 @@
"devDependencies": {
"@types/copy-paste": "^1.1.30",
"@types/mocha": "^2.2.39",
"@types/node": "^7.0.7",
"@types/node": "^7.0.8",
"@types/tmp": "^0.0.32",
"mocha": "^3.2.0",
"tslint": "^4.5.1",
"typescript": "^2.2.1",
"vscode": "^1.0.5"
"vscode": "^1.1.0"
}
}

+ 3
- 3
src/blameabilityTracker.ts Wyświetl plik

@ -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

+ 17
- 1
src/commands.ts Wyświetl plik

@ -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);
}

+ 3
- 3
src/commands/keyboard.ts Wyświetl plik

@ -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);

+ 6
- 5
src/extension.ts Wyświetl plik

@ -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));

+ 3
- 0
src/gitProvider.ts Wyświetl plik

@ -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) {

Ładowanie…
Anuluj
Zapisz