diff --git a/package.json b/package.json index d6dbc74..473cb67 100644 --- a/package.json +++ b/package.json @@ -419,6 +419,11 @@ "category": "GitLens" }, { + "command": "gitlens.showLastQuickPick", + "title": "Show Last Opened Quick Pick", + "category": "GitLens" + }, + { "command": "gitlens.showQuickCommitDetails", "title": "Show Commit Details", "category": "GitLens" @@ -515,6 +520,10 @@ "when": "gitlens:enabled" }, { + "command": "gitlens.showLastQuickPick", + "when": "gitlens:enabled" + }, + { "command": "gitlens.showQuickCommitDetails", "when": "gitlens:enabled && gitlens:isBlameable" }, @@ -695,6 +704,12 @@ "when": "editorTextFocus && gitlens:enabled && gitlens:canToggleCodeLens" }, { + "command": "gitlens.showLastQuickPick", + "key": "alt+-", + "mac": "alt+-", + "when": "gitlens:enabled" + }, + { "command": "gitlens.showQuickFileHistory", "key": "alt+h", "mac": "alt+h", diff --git a/src/commands.ts b/src/commands.ts index 6a6f151..0b79f92 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -2,30 +2,31 @@ import { commands } from 'vscode'; import { BuiltInCommands } from './constants'; -export { Keyboard, KeyboardScope, KeyMapping, KeyNoopCommand, Keys } from './commands/keyboard'; +export * from './commands/keyboard'; -export { ActiveEditorCommand, Command, Commands, EditorCommand, openEditor } from './commands/commands'; -export { CloseUnchangedFilesCommand } from './commands/closeUnchangedFiles'; -export { CopyMessageToClipboardCommand } from './commands/copyMessageToClipboard'; -export { CopyShaToClipboardCommand } from './commands/copyShaToClipboard'; -export { DiffDirectoryCommand } from './commands/diffDirectory'; -export { DiffLineWithPreviousCommand } from './commands/diffLineWithPrevious'; -export { DiffLineWithWorkingCommand } from './commands/diffLineWithWorking'; -export { DiffWithBranchCommand } from './commands/diffWithBranch'; -export { DiffWithNextCommand } from './commands/diffWithNext'; -export { DiffWithPreviousCommand } from './commands/diffWithPrevious'; -export { DiffWithWorkingCommand } from './commands/diffWithWorking'; -export { OpenChangedFilesCommand } from './commands/openChangedFiles'; -export { ShowBlameCommand } from './commands/showBlame'; -export { ShowBlameHistoryCommand } from './commands/showBlameHistory'; -export { ShowFileHistoryCommand } from './commands/showFileHistory'; -export { ShowQuickCommitDetailsCommand } from './commands/showQuickCommitDetails'; -export { ShowQuickCommitFileDetailsCommand } from './commands/showQuickCommitFileDetails'; -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 * from './commands/commands'; +export * from './commands/closeUnchangedFiles'; +export * from './commands/copyMessageToClipboard'; +export * from './commands/copyShaToClipboard'; +export * from './commands/diffDirectory'; +export * from './commands/diffLineWithPrevious'; +export * from './commands/diffLineWithWorking'; +export * from './commands/diffWithBranch'; +export * from './commands/diffWithNext'; +export * from './commands/diffWithPrevious'; +export * from './commands/diffWithWorking'; +export * from './commands/openChangedFiles'; +export * from './commands/showBlame'; +export * from './commands/showBlameHistory'; +export * from './commands/showFileHistory'; +export * from './commands/showLastQuickPick'; +export * from './commands/showQuickCommitDetails'; +export * from './commands/showQuickCommitFileDetails'; +export * from './commands/showQuickFileHistory'; +export * from './commands/showQuickRepoHistory'; +export * from './commands/showQuickRepoStatus'; +export * from './commands/toggleBlame'; +export * from './commands/toggleCodeLens'; export type CommandContext = 'gitlens:canToggleCodeLens' | 'gitlens:enabled' | 'gitlens:isBlameable' | 'gitlens:key'; export const CommandContext = { diff --git a/src/commands/commands.ts b/src/commands/commands.ts index 254719c..3ff6124 100644 --- a/src/commands/commands.ts +++ b/src/commands/commands.ts @@ -2,7 +2,7 @@ import { commands, Disposable, TextEditor, TextEditorEdit, Uri, window, workspace } from 'vscode'; import { BuiltInCommands } from '../constants'; -export type Commands = 'gitlens.closeUnchangedFiles' | 'gitlens.copyMessageToClipboard' | 'gitlens.copyShaToClipboard' | 'gitlens.diffDirectory' | 'gitlens.diffWithBranch' | 'gitlens.diffWithNext' | 'gitlens.diffWithPrevious' | 'gitlens.diffLineWithPrevious' | 'gitlens.diffWithWorking' | 'gitlens.diffLineWithWorking' | 'gitlens.openChangedFiles' | 'gitlens.showBlame' | 'gitlens.showBlameHistory' | 'gitlens.showFileHistory' | 'gitlens.showQuickCommitDetails' | 'gitlens.showQuickCommitFileDetails' | 'gitlens.showQuickFileHistory' | 'gitlens.showQuickRepoHistory' | 'gitlens.showQuickRepoStatus' | 'gitlens.toggleBlame' | 'gitlens.toggleCodeLens'; +export type Commands = 'gitlens.closeUnchangedFiles' | 'gitlens.copyMessageToClipboard' | 'gitlens.copyShaToClipboard' | 'gitlens.diffDirectory' | 'gitlens.diffWithBranch' | 'gitlens.diffWithNext' | 'gitlens.diffWithPrevious' | 'gitlens.diffLineWithPrevious' | 'gitlens.diffWithWorking' | 'gitlens.diffLineWithWorking' | 'gitlens.openChangedFiles' | 'gitlens.showBlame' | 'gitlens.showBlameHistory' | 'gitlens.showFileHistory' | 'gitlens.showLastQuickPick' | 'gitlens.showQuickCommitDetails' | 'gitlens.showQuickCommitFileDetails' | 'gitlens.showQuickFileHistory' | 'gitlens.showQuickRepoHistory' | 'gitlens.showQuickRepoStatus' | 'gitlens.toggleBlame' | 'gitlens.toggleCodeLens'; export const Commands = { CloseUnchangedFiles: 'gitlens.closeUnchangedFiles' as Commands, CopyMessageToClipboard: 'gitlens.copyMessageToClipboard' as Commands, @@ -18,6 +18,7 @@ export const Commands = { ShowBlame: 'gitlens.showBlame' as Commands, ShowBlameHistory: 'gitlens.showBlameHistory' as Commands, ShowFileHistory: 'gitlens.showFileHistory' as Commands, + ShowLastQuickPick: 'gitlens.showLastQuickPick' as Commands, ShowQuickCommitDetails: 'gitlens.showQuickCommitDetails' as Commands, ShowQuickCommitFileDetails: 'gitlens.showQuickCommitFileDetails' as Commands, ShowQuickFileHistory: 'gitlens.showQuickFileHistory' as Commands, @@ -44,6 +45,7 @@ export abstract class Command extends Disposable { } export abstract class EditorCommand extends Disposable { + private _disposable: Disposable; constructor(command: Commands) { @@ -59,6 +61,7 @@ export abstract class EditorCommand extends Disposable { } export abstract class ActiveEditorCommand extends Disposable { + private _disposable: Disposable; constructor(command: Commands) { @@ -77,6 +80,28 @@ export abstract class ActiveEditorCommand extends Disposable { abstract execute(editor: TextEditor, ...args: any[]): any; } +let lastCommand: { command: string, args: any[] } = undefined; +export function getLastCommand() { + return lastCommand; +} + +export abstract class ActiveEditorCachedCommand extends ActiveEditorCommand { + + constructor(private command: Commands) { + super(command); + } + + _execute(...args: any[]): any { + lastCommand = { + command: this.command, + args: args + }; + return this.execute(window.activeTextEditor, ...args); + } + + abstract execute(editor: TextEditor, ...args: any[]): any; +} + export async function openEditor(uri: Uri, pinned: boolean = false) { try { if (!pinned) return await commands.executeCommand(BuiltInCommands.Open, uri); diff --git a/src/commands/showLastQuickPick.ts b/src/commands/showLastQuickPick.ts new file mode 100644 index 0000000..b1f2734 --- /dev/null +++ b/src/commands/showLastQuickPick.ts @@ -0,0 +1,24 @@ +'use strict'; +import { commands, window } from 'vscode'; +import { Command, Commands, getLastCommand } from './commands'; +import { Logger } from '../logger'; + +export class ShowLastQuickPickCommand extends Command { + + constructor() { + super(Commands.ShowLastQuickPick); + } + + async execute() { + const command = getLastCommand(); + if (!command) return undefined; + + try { + return commands.executeCommand(command.command, ...command.args); + } + catch (ex) { + Logger.error('[GitLens.ShowLastQuickPickCommand]', ex); + return window.showErrorMessage(`Unable to show last quick pick. See output channel for more details`); + } + } +} \ No newline at end of file diff --git a/src/commands/showQuickCommitDetails.ts b/src/commands/showQuickCommitDetails.ts index 7336658..7de35e1 100644 --- a/src/commands/showQuickCommitDetails.ts +++ b/src/commands/showQuickCommitDetails.ts @@ -1,12 +1,12 @@ 'use strict'; import { commands, TextEditor, Uri, window } from 'vscode'; -import { ActiveEditorCommand, Commands } from './commands'; +import { ActiveEditorCachedCommand, Commands } from './commands'; import { GitCommit, GitLogCommit, GitService, GitUri, IGitLog } from '../gitService'; import { Logger } from '../logger'; import { CommandQuickPickItem, CommitDetailsQuickPick, CommitWithFileStatusQuickPickItem } from '../quickPicks'; import * as path from 'path'; -export class ShowQuickCommitDetailsCommand extends ActiveEditorCommand { +export class ShowQuickCommitDetailsCommand extends ActiveEditorCachedCommand { constructor(private git: GitService, private repoPath: string) { super(Commands.ShowQuickCommitDetails); diff --git a/src/commands/showQuickCommitFileDetails.ts b/src/commands/showQuickCommitFileDetails.ts index b14ed07..98b4871 100644 --- a/src/commands/showQuickCommitFileDetails.ts +++ b/src/commands/showQuickCommitFileDetails.ts @@ -1,12 +1,12 @@ 'use strict'; import { TextEditor, Uri, window } from 'vscode'; -import { ActiveEditorCommand, Commands } from './commands'; +import { ActiveEditorCachedCommand, Commands } from './commands'; import { GitCommit, GitLogCommit, GitService, GitUri, IGitLog } from '../gitService'; import { Logger } from '../logger'; import { CommandQuickPickItem, CommitFileDetailsQuickPick } from '../quickPicks'; import * as path from 'path'; -export class ShowQuickCommitFileDetailsCommand extends ActiveEditorCommand { +export class ShowQuickCommitFileDetailsCommand extends ActiveEditorCachedCommand { constructor(private git: GitService) { super(Commands.ShowQuickCommitFileDetails); diff --git a/src/commands/showQuickFileHistory.ts b/src/commands/showQuickFileHistory.ts index ac9f7d0..2eed1a6 100644 --- a/src/commands/showQuickFileHistory.ts +++ b/src/commands/showQuickFileHistory.ts @@ -1,12 +1,12 @@ 'use strict'; import { commands, Range, TextEditor, Uri, window } from 'vscode'; -import { ActiveEditorCommand, Commands } from '../commands'; +import { ActiveEditorCachedCommand, Commands } from '../commands'; import { GitService, GitUri, IGitLog } from '../gitService'; import { Logger } from '../logger'; import { CommandQuickPickItem, FileHistoryQuickPick } from '../quickPicks'; import * as path from 'path'; -export class ShowQuickFileHistoryCommand extends ActiveEditorCommand { +export class ShowQuickFileHistoryCommand extends ActiveEditorCachedCommand { constructor(private git: GitService) { super(Commands.ShowQuickFileHistory); diff --git a/src/commands/showQuickRepoHistory.ts b/src/commands/showQuickRepoHistory.ts index ff631fe..1c1b8fb 100644 --- a/src/commands/showQuickRepoHistory.ts +++ b/src/commands/showQuickRepoHistory.ts @@ -1,11 +1,11 @@ 'use strict'; import { commands, TextEditor, Uri, window } from 'vscode'; -import { ActiveEditorCommand, Commands } from '../commands'; +import { ActiveEditorCachedCommand, Commands } from '../commands'; import { GitService, GitUri, IGitLog } from '../gitService'; import { Logger } from '../logger'; import { CommandQuickPickItem, RepoHistoryQuickPick } from '../quickPicks'; -export class ShowQuickRepoHistoryCommand extends ActiveEditorCommand { +export class ShowQuickRepoHistoryCommand extends ActiveEditorCachedCommand { constructor(private git: GitService, private repoPath: string) { super(Commands.ShowQuickRepoHistory); diff --git a/src/commands/showQuickRepoStatus.ts b/src/commands/showQuickRepoStatus.ts index 18a3fd4..01e4eb9 100644 --- a/src/commands/showQuickRepoStatus.ts +++ b/src/commands/showQuickRepoStatus.ts @@ -1,11 +1,11 @@ 'use strict'; import { TextEditor, Uri, window } from 'vscode'; -import { ActiveEditorCommand, Commands } from './commands'; +import { ActiveEditorCachedCommand, Commands } from './commands'; import { GitService } from '../gitService'; import { Logger } from '../logger'; import { CommandQuickPickItem, RepoStatusQuickPick } from '../quickPicks'; -export class ShowQuickRepoStatusCommand extends ActiveEditorCommand { +export class ShowQuickRepoStatusCommand extends ActiveEditorCachedCommand { constructor(private git: GitService, private repoPath: string) { super(Commands.ShowQuickRepoStatus); diff --git a/src/extension.ts b/src/extension.ts index 4357ecd..5cb011b 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -10,7 +10,7 @@ import { CopyMessageToClipboardCommand, CopyShaToClipboardCommand } from './comm import { DiffDirectoryCommand, DiffLineWithPreviousCommand, DiffLineWithWorkingCommand, DiffWithBranchCommand, DiffWithNextCommand, DiffWithPreviousCommand, DiffWithWorkingCommand} from './commands'; import { ShowBlameCommand, ToggleBlameCommand } from './commands'; import { ShowBlameHistoryCommand, ShowFileHistoryCommand } from './commands'; -import { ShowQuickCommitDetailsCommand, ShowQuickCommitFileDetailsCommand, ShowQuickFileHistoryCommand, ShowQuickRepoHistoryCommand, ShowQuickRepoStatusCommand} from './commands'; +import { ShowLastQuickPickCommand, ShowQuickCommitDetailsCommand, ShowQuickCommitFileDetailsCommand, ShowQuickFileHistoryCommand, ShowQuickRepoHistoryCommand, ShowQuickRepoStatusCommand} from './commands'; import { ToggleCodeLensCommand } from './commands'; import { Keyboard } from './commands'; import { IAdvancedConfig, IBlameConfig } from './configuration'; @@ -103,6 +103,7 @@ export async function activate(context: ExtensionContext) { context.subscriptions.push(new ToggleBlameCommand(annotationController)); context.subscriptions.push(new ShowBlameHistoryCommand(git)); context.subscriptions.push(new ShowFileHistoryCommand(git)); + context.subscriptions.push(new ShowLastQuickPickCommand()); context.subscriptions.push(new ShowQuickCommitDetailsCommand(git, repoPath)); context.subscriptions.push(new ShowQuickCommitFileDetailsCommand(git)); context.subscriptions.push(new ShowQuickFileHistoryCommand(git));