From a2f4c4c953a291c768030dc84b1a9292047ae1a4 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sat, 25 Feb 2017 02:19:40 -0500 Subject: [PATCH] Moves Commands into commands file --- src/commands.ts | 71 ++++++++++++++++++++++++++++++++++ src/commands/commands.ts | 53 ------------------------- src/commands/copyMessageToClipboard.ts | 3 +- src/commands/copyShaToClipboard.ts | 3 +- src/commands/diffLineWithPrevious.ts | 4 +- src/commands/diffLineWithWorking.ts | 3 +- src/commands/diffWithPrevious.ts | 4 +- src/commands/diffWithWorking.ts | 4 +- src/commands/showBlame.ts | 3 +- src/commands/showBlameHistory.ts | 4 +- src/commands/showFileHistory.ts | 4 +- src/commands/showQuickCommitDetails.ts | 3 +- src/commands/showQuickFileHistory.ts | 3 +- src/commands/showQuickRepoHistory.ts | 3 +- src/commands/toggleBlame.ts | 3 +- src/commands/toggleCodeLens.ts | 3 +- src/configuration.ts | 2 +- src/constants.ts | 18 --------- src/gitCodeLensProvider.ts | 3 +- src/gitRevisionCodeLensProvider.ts | 3 +- 20 files changed, 95 insertions(+), 102 deletions(-) create mode 100644 src/commands.ts delete mode 100644 src/commands/commands.ts diff --git a/src/commands.ts b/src/commands.ts new file mode 100644 index 0000000..74fc603 --- /dev/null +++ b/src/commands.ts @@ -0,0 +1,71 @@ +'use strict'; +import { commands, Disposable, TextEditor, TextEditorEdit, window } from 'vscode'; + +export type Commands = 'gitlens.copyMessageToClipboard' | 'gitlens.copyShaToClipboard' | 'gitlens.diffWithPrevious' | 'gitlens.diffLineWithPrevious' | 'gitlens.diffWithWorking' | 'gitlens.diffLineWithWorking' | 'gitlens.showBlame' | 'gitlens.showBlameHistory' | 'gitlens.showFileHistory' | 'gitlens.showQuickCommitDetails' | 'gitlens.showQuickFileHistory' | 'gitlens.showQuickRepoHistory' | 'gitlens.showQuickRepoStatus' | 'gitlens.toggleBlame' | 'gitlens.toggleCodeLens'; +export const Commands = { + CopyMessageToClipboard: 'gitlens.copyMessageToClipboard' as Commands, + CopyShaToClipboard: 'gitlens.copyShaToClipboard' as Commands, + DiffWithPrevious: 'gitlens.diffWithPrevious' as Commands, + DiffLineWithPrevious: 'gitlens.diffLineWithPrevious' as Commands, + DiffWithWorking: 'gitlens.diffWithWorking' as Commands, + DiffLineWithWorking: 'gitlens.diffLineWithWorking' as Commands, + ShowBlame: 'gitlens.showBlame' as Commands, + ShowBlameHistory: 'gitlens.showBlameHistory' as Commands, + ShowFileHistory: 'gitlens.showFileHistory' as Commands, + ShowQuickCommitDetails: 'gitlens.showQuickCommitDetails' as Commands, + ShowQuickFileHistory: 'gitlens.showQuickFileHistory' as Commands, + ShowQuickRepoHistory: 'gitlens.showQuickRepoHistory' as Commands, + ShowQuickRepoStatus: 'gitlens.showQuickRepoStatus' as Commands, + ToggleBlame: 'gitlens.toggleBlame' as Commands, + ToggleCodeLens: 'gitlens.toggleCodeLens' as Commands +}; + +export abstract class Command extends Disposable { + + private _disposable: Disposable; + + constructor(command: Commands) { + super(() => this.dispose()); + this._disposable = commands.registerCommand(command, this.execute, this); + } + + dispose() { + this._disposable && this._disposable.dispose(); + } + + abstract execute(...args: any[]): any; +} + +export abstract class EditorCommand extends Disposable { + private _disposable: Disposable; + + constructor(command: Commands) { + super(() => this.dispose()); + this._disposable = commands.registerTextEditorCommand(command, this.execute, this); + } + + dispose() { + this._disposable && this._disposable.dispose(); + } + + abstract execute(editor: TextEditor, edit: TextEditorEdit, ...args: any[]): any; +} + +export abstract class ActiveEditorCommand extends Disposable { + private _disposable: Disposable; + + constructor(command: Commands) { + super(() => this.dispose()); + this._disposable = commands.registerCommand(command, this._execute, this); + } + + dispose() { + this._disposable && this._disposable.dispose(); + } + + _execute(...args: any[]): any { + return this.execute(window.activeTextEditor, ...args); + } + + abstract execute(editor: TextEditor, ...args: any[]): any; +} \ No newline at end of file diff --git a/src/commands/commands.ts b/src/commands/commands.ts deleted file mode 100644 index c097dd8..0000000 --- a/src/commands/commands.ts +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; -import { commands, Disposable, TextEditor, TextEditorEdit, window } from 'vscode'; -import { Commands } from '../constants'; - -export abstract class Command extends Disposable { - - private _disposable: Disposable; - - constructor(command: Commands) { - super(() => this.dispose()); - this._disposable = commands.registerCommand(command, this.execute, this); - } - - dispose() { - this._disposable && this._disposable.dispose(); - } - - abstract execute(...args: any[]): any; -} - -export abstract class EditorCommand extends Disposable { - private _disposable: Disposable; - - constructor(command: Commands) { - super(() => this.dispose()); - this._disposable = commands.registerTextEditorCommand(command, this.execute, this); - } - - dispose() { - this._disposable && this._disposable.dispose(); - } - - abstract execute(editor: TextEditor, edit: TextEditorEdit, ...args: any[]): any; -} - -export abstract class ActiveEditorCommand extends Disposable { - private _disposable: Disposable; - - constructor(command: Commands) { - super(() => this.dispose()); - this._disposable = commands.registerCommand(command, this._execute, this); - } - - dispose() { - this._disposable && this._disposable.dispose(); - } - - _execute(...args: any[]): any { - return this.execute(window.activeTextEditor, ...args); - } - - abstract execute(editor: TextEditor, ...args: any[]): any; -} \ No newline at end of file diff --git a/src/commands/copyMessageToClipboard.ts b/src/commands/copyMessageToClipboard.ts index 6f94749..c6d540c 100644 --- a/src/commands/copyMessageToClipboard.ts +++ b/src/commands/copyMessageToClipboard.ts @@ -1,8 +1,7 @@ 'use strict'; import { Iterables } from '../system'; import { TextEditor, Uri, window } from 'vscode'; -import { ActiveEditorCommand } from './commands'; -import { Commands } from '../constants'; +import { ActiveEditorCommand, Commands } from '../commands'; import GitProvider, { GitUri } from '../gitProvider'; import { Logger } from '../logger'; import { copy } from 'copy-paste'; diff --git a/src/commands/copyShaToClipboard.ts b/src/commands/copyShaToClipboard.ts index ef11c56..c309ead 100644 --- a/src/commands/copyShaToClipboard.ts +++ b/src/commands/copyShaToClipboard.ts @@ -1,8 +1,7 @@ 'use strict'; import { Iterables } from '../system'; import { TextEditor, Uri, window } from 'vscode'; -import { ActiveEditorCommand } from './commands'; -import { Commands } from '../constants'; +import { ActiveEditorCommand, Commands } from '../commands'; import GitProvider, { GitUri } from '../gitProvider'; import { Logger } from '../logger'; import { copy } from 'copy-paste'; diff --git a/src/commands/diffLineWithPrevious.ts b/src/commands/diffLineWithPrevious.ts index 8b15c44..cae1efc 100644 --- a/src/commands/diffLineWithPrevious.ts +++ b/src/commands/diffLineWithPrevious.ts @@ -1,7 +1,7 @@ 'use strict'; import { commands, TextEditor, TextEditorEdit, Uri, window } from 'vscode'; -import { EditorCommand } from './commands'; -import { BuiltInCommands, Commands } from '../constants'; +import { Commands, EditorCommand } from '../commands'; +import { BuiltInCommands } from '../constants'; import GitProvider, { GitCommit, GitUri } from '../gitProvider'; import { Logger } from '../logger'; import * as path from 'path'; diff --git a/src/commands/diffLineWithWorking.ts b/src/commands/diffLineWithWorking.ts index 1211580..c383b12 100644 --- a/src/commands/diffLineWithWorking.ts +++ b/src/commands/diffLineWithWorking.ts @@ -1,7 +1,6 @@ 'use strict'; import { commands, TextEditor, TextEditorEdit, Uri, window } from 'vscode'; -import { EditorCommand } from './commands'; -import { Commands } from '../constants'; +import { Commands, EditorCommand } from '../commands'; import GitProvider, { GitCommit, GitUri } from '../gitProvider'; import { Logger } from '../logger'; diff --git a/src/commands/diffWithPrevious.ts b/src/commands/diffWithPrevious.ts index bbaed1b..fd38a4d 100644 --- a/src/commands/diffWithPrevious.ts +++ b/src/commands/diffWithPrevious.ts @@ -1,8 +1,8 @@ 'use strict'; import { Iterables } from '../system'; import { commands, Range, TextEditor, TextEditorEdit, Uri, window } from 'vscode'; -import { EditorCommand } from './commands'; -import { BuiltInCommands, Commands } from '../constants'; +import { Commands, EditorCommand } from '../commands'; +import { BuiltInCommands } from '../constants'; import GitProvider, { GitCommit, GitUri } from '../gitProvider'; import { Logger } from '../logger'; import * as moment from 'moment'; diff --git a/src/commands/diffWithWorking.ts b/src/commands/diffWithWorking.ts index e593a24..aaed896 100644 --- a/src/commands/diffWithWorking.ts +++ b/src/commands/diffWithWorking.ts @@ -1,8 +1,8 @@ 'use strict'; import { Iterables } from '../system'; import { commands, TextEditor, TextEditorEdit, Uri, window } from 'vscode'; -import { EditorCommand } from './commands'; -import { BuiltInCommands, Commands } from '../constants'; +import { Commands, EditorCommand } from '../commands'; +import { BuiltInCommands } from '../constants'; import GitProvider, { GitCommit, GitUri } from '../gitProvider'; import { Logger } from '../logger'; import * as path from 'path'; diff --git a/src/commands/showBlame.ts b/src/commands/showBlame.ts index 1c2032a..476588f 100644 --- a/src/commands/showBlame.ts +++ b/src/commands/showBlame.ts @@ -1,8 +1,7 @@ 'use strict'; import { TextEditor, TextEditorEdit, Uri, window } from 'vscode'; import BlameAnnotationController from '../blameAnnotationController'; -import { EditorCommand } from './commands'; -import { Commands } from '../constants'; +import { Commands, EditorCommand } from '../commands'; import { Logger } from '../logger'; export default class ShowBlameCommand extends EditorCommand { diff --git a/src/commands/showBlameHistory.ts b/src/commands/showBlameHistory.ts index 4fa6c54..bb3553b 100644 --- a/src/commands/showBlameHistory.ts +++ b/src/commands/showBlameHistory.ts @@ -1,7 +1,7 @@ 'use strict'; import { commands, Position, Range, TextEditor, TextEditorEdit, Uri, window } from 'vscode'; -import { EditorCommand } from './commands'; -import { BuiltInCommands, Commands } from '../constants'; +import { Commands, EditorCommand } from '../commands'; +import { BuiltInCommands } from '../constants'; import GitProvider, { GitUri } from '../gitProvider'; import { Logger } from '../logger'; diff --git a/src/commands/showFileHistory.ts b/src/commands/showFileHistory.ts index 987aef4..145bb00 100644 --- a/src/commands/showFileHistory.ts +++ b/src/commands/showFileHistory.ts @@ -1,7 +1,7 @@ 'use strict'; import { commands, Position, Range, TextEditor, TextEditorEdit, Uri, window } from 'vscode'; -import { EditorCommand } from './commands'; -import { BuiltInCommands, Commands } from '../constants'; +import { Commands, EditorCommand } from '../commands'; +import { BuiltInCommands } from '../constants'; import GitProvider, { GitUri } from '../gitProvider'; import { Logger } from '../logger'; diff --git a/src/commands/showQuickCommitDetails.ts b/src/commands/showQuickCommitDetails.ts index 7b7da65..d1c06fa 100644 --- a/src/commands/showQuickCommitDetails.ts +++ b/src/commands/showQuickCommitDetails.ts @@ -1,8 +1,7 @@ 'use strict'; import { Iterables } from '../system'; import { commands, TextEditor, Uri, window } from 'vscode'; -import { ActiveEditorCommand } from './commands'; -import { Commands } from '../constants'; +import { ActiveEditorCommand, Commands } from '../commands'; import GitProvider, { GitCommit, GitUri } from '../gitProvider'; import { Logger } from '../logger'; import { CommandQuickPickItem, FileQuickPickItem } from './quickPickItems'; diff --git a/src/commands/showQuickFileHistory.ts b/src/commands/showQuickFileHistory.ts index bac9364..ebb9173 100644 --- a/src/commands/showQuickFileHistory.ts +++ b/src/commands/showQuickFileHistory.ts @@ -1,7 +1,6 @@ 'use strict'; import { commands, TextEditor, Uri, window } from 'vscode'; -import { ActiveEditorCommand } from './commands'; -import { Commands } from '../constants'; +import { ActiveEditorCommand, Commands } from '../commands'; import GitProvider, { GitCommit, GitUri } from '../gitProvider'; import { Logger } from '../logger'; import { CommandQuickPickItem } from './quickPickItems'; diff --git a/src/commands/showQuickRepoHistory.ts b/src/commands/showQuickRepoHistory.ts index adfd49d..8e062cf 100644 --- a/src/commands/showQuickRepoHistory.ts +++ b/src/commands/showQuickRepoHistory.ts @@ -1,7 +1,6 @@ 'use strict'; import { commands, TextEditor, Uri, window } from 'vscode'; -import { ActiveEditorCommand } from './commands'; -import { Commands } from '../constants'; +import { ActiveEditorCommand, Commands } from '../commands'; import GitProvider, { GitCommit, GitUri } from '../gitProvider'; import { Logger } from '../logger'; import { CommandQuickPickItem } from './quickPickItems'; diff --git a/src/commands/toggleBlame.ts b/src/commands/toggleBlame.ts index e196d5e..aedece0 100644 --- a/src/commands/toggleBlame.ts +++ b/src/commands/toggleBlame.ts @@ -1,8 +1,7 @@ 'use strict'; import { TextEditor, TextEditorEdit, Uri, window } from 'vscode'; import BlameAnnotationController from '../blameAnnotationController'; -import { EditorCommand } from './commands'; -import { Commands } from '../constants'; +import { Commands, EditorCommand } from '../commands'; import { Logger } from '../logger'; export default class ToggleBlameCommand extends EditorCommand { diff --git a/src/commands/toggleCodeLens.ts b/src/commands/toggleCodeLens.ts index 62ed4c1..b45510b 100644 --- a/src/commands/toggleCodeLens.ts +++ b/src/commands/toggleCodeLens.ts @@ -1,7 +1,6 @@ 'use strict'; import { TextEditor, TextEditorEdit } from 'vscode'; -import { EditorCommand } from './commands'; -import { Commands } from '../constants'; +import { Commands, EditorCommand } from '../commands'; import GitProvider from '../gitProvider'; export default class ToggleCodeLensCommand extends EditorCommand { diff --git a/src/configuration.ts b/src/configuration.ts index bbf6ca2..75767e7 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -1,5 +1,5 @@ 'use strict'; -import { Commands } from './constants'; +import { Commands } from './commands'; export type BlameAnnotationStyle = 'compact' | 'expanded' | 'trailing'; export const BlameAnnotationStyle = { diff --git a/src/constants.ts b/src/constants.ts index 0693f5f..1f1fce3 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -16,24 +16,6 @@ export const BuiltInCommands = { ToggleRenderWhitespace: 'editor.action.toggleRenderWhitespace' as BuiltInCommands }; -export type Commands = 'gitlens.copyMessageToClipboard' | 'gitlens.copyShaToClipboard' | 'gitlens.diffWithPrevious' | 'gitlens.diffLineWithPrevious' | 'gitlens.diffWithWorking' | 'gitlens.diffLineWithWorking' | 'gitlens.showBlame' | 'gitlens.showBlameHistory' | 'gitlens.showFileHistory' | 'gitlens.showQuickCommitDetails' | 'gitlens.showQuickFileHistory' | 'gitlens.showQuickRepoHistory' | 'gitlens.toggleBlame' | 'gitlens.toggleCodeLens'; -export const Commands = { - CopyMessageToClipboard: 'gitlens.copyMessageToClipboard' as Commands, - CopyShaToClipboard: 'gitlens.copyShaToClipboard' as Commands, - DiffWithPrevious: 'gitlens.diffWithPrevious' as Commands, - DiffLineWithPrevious: 'gitlens.diffLineWithPrevious' as Commands, - DiffWithWorking: 'gitlens.diffWithWorking' as Commands, - DiffLineWithWorking: 'gitlens.diffLineWithWorking' as Commands, - ShowBlame: 'gitlens.showBlame' as Commands, - ShowBlameHistory: 'gitlens.showBlameHistory' as Commands, - ShowFileHistory: 'gitlens.showFileHistory' as Commands, - ShowQuickCommitDetails: 'gitlens.showQuickCommitDetails' as Commands, - ShowQuickFileHistory: 'gitlens.showQuickFileHistory' as Commands, - ShowQuickRepoHistory: 'gitlens.showQuickRepoHistory' as Commands, - ToggleBlame: 'gitlens.toggleBlame' as Commands, - ToggleCodeLens: 'gitlens.toggleCodeLens' as Commands -}; - export type DocumentSchemes = 'file' | 'gitlens-git'; export const DocumentSchemes = { File: 'file' as DocumentSchemes, diff --git a/src/gitCodeLensProvider.ts b/src/gitCodeLensProvider.ts index c8da939..77b3523 100644 --- a/src/gitCodeLensProvider.ts +++ b/src/gitCodeLensProvider.ts @@ -1,7 +1,8 @@ 'use strict'; import { Functions, Iterables, Strings } from './system'; import { CancellationToken, CodeLens, CodeLensProvider, commands, DocumentSelector, Event, EventEmitter, ExtensionContext, Position, Range, SymbolInformation, SymbolKind, TextDocument, Uri, workspace } from 'vscode'; -import { BuiltInCommands, Commands, DocumentSchemes } from './constants'; +import { Commands } from './commands'; +import { BuiltInCommands, DocumentSchemes } from './constants'; import { CodeLensCommand, CodeLensLocation, IConfig, ICodeLensLanguageLocation } from './configuration'; import GitProvider, { GitCommit, GitUri, IGitBlame, IGitBlameLines } from './gitProvider'; import { Logger } from './logger'; diff --git a/src/gitRevisionCodeLensProvider.ts b/src/gitRevisionCodeLensProvider.ts index 257581d..5bf07b0 100644 --- a/src/gitRevisionCodeLensProvider.ts +++ b/src/gitRevisionCodeLensProvider.ts @@ -1,7 +1,8 @@ 'use strict'; import { Iterables } from './system'; import { CancellationToken, CodeLens, CodeLensProvider, DocumentSelector, ExtensionContext, Range, TextDocument, Uri } from 'vscode'; -import { Commands, DocumentSchemes } from './constants'; +import { Commands } from './commands'; +import { DocumentSchemes } from './constants'; import GitProvider, { GitCommit, GitUri } from './gitProvider'; export class GitDiffWithWorkingCodeLens extends CodeLens {