mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-16 10:58:34 -05:00
Refactors commands to utilize a common base
This commit is contained in:
@@ -44,15 +44,19 @@ export abstract class Command extends Disposable {
|
|||||||
|
|
||||||
private _disposable: Disposable;
|
private _disposable: Disposable;
|
||||||
|
|
||||||
constructor(command: Commands) {
|
constructor(protected command: Commands) {
|
||||||
super(() => this.dispose());
|
super(() => this.dispose());
|
||||||
this._disposable = commands.registerCommand(command, this.execute, this);
|
this._disposable = commands.registerCommand(command, this._execute, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
this._disposable && this._disposable.dispose();
|
this._disposable && this._disposable.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected _execute(...args: any[]): any {
|
||||||
|
return this.execute(...args);
|
||||||
|
}
|
||||||
|
|
||||||
abstract execute(...args: any[]): any;
|
abstract execute(...args: any[]): any;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,33 +64,30 @@ export abstract class EditorCommand extends Disposable {
|
|||||||
|
|
||||||
private _disposable: Disposable;
|
private _disposable: Disposable;
|
||||||
|
|
||||||
constructor(command: Commands) {
|
constructor(public readonly command: Commands) {
|
||||||
super(() => this.dispose());
|
super(() => this.dispose());
|
||||||
this._disposable = commands.registerTextEditorCommand(command, this.execute, this);
|
this._disposable = commands.registerTextEditorCommand(command, this._execute, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
this._disposable && this._disposable.dispose();
|
this._disposable && this._disposable.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _execute(editor: TextEditor, edit: TextEditorEdit, ...args: any[]): any {
|
||||||
|
return this.execute(editor, edit, ...args);
|
||||||
|
}
|
||||||
|
|
||||||
abstract execute(editor: TextEditor, edit: TextEditorEdit, ...args: any[]): any;
|
abstract execute(editor: TextEditor, edit: TextEditorEdit, ...args: any[]): any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export abstract class ActiveEditorCommand extends Disposable {
|
export abstract class ActiveEditorCommand extends Command {
|
||||||
|
|
||||||
private _disposable: Disposable;
|
constructor(public readonly command: Commands) {
|
||||||
|
super(command);
|
||||||
constructor(command: Commands) {
|
|
||||||
super(() => this.dispose());
|
|
||||||
this._disposable = commands.registerCommand(command, this._execute, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
protected _execute(...args: any[]): any {
|
||||||
this._disposable && this._disposable.dispose();
|
return super._execute(window.activeTextEditor, ...args);
|
||||||
}
|
|
||||||
|
|
||||||
_execute(...args: any[]): any {
|
|
||||||
return this.execute(window.activeTextEditor, ...args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract execute(editor: TextEditor, ...args: any[]): any;
|
abstract execute(editor: TextEditor, ...args: any[]): any;
|
||||||
@@ -99,16 +100,16 @@ export function getLastCommand() {
|
|||||||
|
|
||||||
export abstract class ActiveEditorCachedCommand extends ActiveEditorCommand {
|
export abstract class ActiveEditorCachedCommand extends ActiveEditorCommand {
|
||||||
|
|
||||||
constructor(private command: Commands) {
|
constructor(public readonly command: Commands) {
|
||||||
super(command);
|
super(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
_execute(...args: any[]): any {
|
protected _execute(...args: any[]): any {
|
||||||
lastCommand = {
|
lastCommand = {
|
||||||
command: this.command,
|
command: this.command,
|
||||||
args: args
|
args: args
|
||||||
};
|
};
|
||||||
return this.execute(window.activeTextEditor, ...args);
|
return super._execute(...args);
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract execute(editor: TextEditor, ...args: any[]): any;
|
abstract execute(editor: TextEditor, ...args: any[]): any;
|
||||||
|
|||||||
Reference in New Issue
Block a user