mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-29 17:25:20 -05:00
Refactors the quickpick menus
Consolidated lots of duplicate functionality go back navigation should be robust now
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
'use strict';
|
||||
import { Iterables } from '../system';
|
||||
import { commands, QuickPickItem, QuickPickOptions, TextEditor, TextEditorEdit, Uri, window } from 'vscode';
|
||||
import { commands, TextEditor, TextEditorEdit, Uri, window } from 'vscode';
|
||||
import { EditorCommand } from './commands';
|
||||
import { Commands } from '../constants';
|
||||
import GitProvider, { GitUri } from '../gitProvider';
|
||||
import { Logger } from '../logger';
|
||||
import { CommandQuickPickItem, CommitQuickPickItem, ShowAllCommitsQuickPickItem } from './quickPickItems';
|
||||
import * as moment from 'moment';
|
||||
import { CommandQuickPickItem } from './quickPickItems';
|
||||
import { FileCommitsQuickPick } from './quickPicks';
|
||||
|
||||
export default class ShowQuickFileHistoryCommand extends EditorCommand {
|
||||
|
||||
@@ -14,7 +13,7 @@ export default class ShowQuickFileHistoryCommand extends EditorCommand {
|
||||
super(Commands.ShowQuickFileHistory);
|
||||
}
|
||||
|
||||
async execute(editor: TextEditor, edit: TextEditorEdit, uri?: Uri, maxCount?: number) {
|
||||
async execute(editor: TextEditor, edit: TextEditorEdit, uri?: Uri, maxCount?: number, goBackCommand?: CommandQuickPickItem) {
|
||||
if (!(uri instanceof Uri)) {
|
||||
if (!editor.document) return undefined;
|
||||
uri = editor.document.uri;
|
||||
@@ -30,73 +29,21 @@ export default class ShowQuickFileHistoryCommand extends EditorCommand {
|
||||
const log = await this.git.getLogForFile(gitUri.fsPath, gitUri.sha, gitUri.repoPath, undefined, maxCount);
|
||||
if (!log) return window.showWarningMessage(`Unable to show file history. File is probably not under source control`);
|
||||
|
||||
const commits = Array.from(Iterables.map(log.commits.values(), c => new CommitQuickPickItem(c))) as QuickPickItem[];
|
||||
if (maxCount !== 0 && commits.length === this.git.config.advanced.maxQuickHistory) {
|
||||
commits.splice(0, 0, new ShowAllCommitsQuickPickItem(this.git.config.advanced.maxQuickHistory));
|
||||
}
|
||||
|
||||
commits.splice(0, 0, {
|
||||
label: `$(repo) Show Repository History`,
|
||||
command: Commands.ShowQuickRepoHistory
|
||||
} as CommandQuickPickItem);
|
||||
|
||||
const pick = await window.showQuickPick(commits, {
|
||||
matchOnDescription: true,
|
||||
matchOnDetail: true,
|
||||
placeHolder: `${Iterables.first(log.commits.values()).fileName}`
|
||||
} as QuickPickOptions);
|
||||
|
||||
let pick = await FileCommitsQuickPick.show(log, uri, maxCount, this.git.config.advanced.maxQuickHistory, goBackCommand);
|
||||
if (!pick) return undefined;
|
||||
|
||||
if (pick instanceof ShowAllCommitsQuickPickItem) {
|
||||
return commands.executeCommand(Commands.ShowQuickFileHistory, uri, 0);
|
||||
if (pick instanceof CommandQuickPickItem) {
|
||||
return pick.execute();
|
||||
}
|
||||
|
||||
if (!(pick instanceof CommitQuickPickItem)) {
|
||||
const commandPick = pick && pick as CommandQuickPickItem;
|
||||
if (commandPick) {
|
||||
return commands.executeCommand(commandPick.command, ...(commandPick.args || []));
|
||||
}
|
||||
}
|
||||
|
||||
const commitPick = pick as CommitQuickPickItem;
|
||||
const commit = commitPick.commit;
|
||||
|
||||
const items: CommandQuickPickItem[] = [
|
||||
{
|
||||
label: `$(diff) Compare with Working Tree`,
|
||||
description: `$(git-commit) ${commit.sha} \u00a0 $(git-compare) \u00a0 $(file-text) ${commit.fileName}`,
|
||||
command: Commands.DiffWithWorking,
|
||||
args: [commit.uri, commit]
|
||||
}
|
||||
];
|
||||
|
||||
if (commit.previousSha) {
|
||||
items.push({
|
||||
label: `$(diff) Compare with Previous Commit`,
|
||||
description: `$(git-commit) ${commit.previousSha} \u00a0 $(git-compare) \u00a0 $(git-commit) ${commit.sha}`,
|
||||
command: Commands.DiffWithPrevious,
|
||||
args: [commit.uri, commit]
|
||||
});
|
||||
}
|
||||
|
||||
items.push({
|
||||
label: `go back \u21A9`,
|
||||
description: null,
|
||||
command: Commands.ShowQuickFileHistory,
|
||||
args: [uri, maxCount]
|
||||
} as CommandQuickPickItem);
|
||||
|
||||
const commandPick = await window.showQuickPick(items, {
|
||||
matchOnDescription: true,
|
||||
placeHolder: `${commit.fileName} \u2022 ${commit.sha} \u2022 ${commit.author}, ${moment(commit.date).fromNow()} \u2022 ${commit.message}`
|
||||
} as QuickPickOptions);
|
||||
|
||||
if (commandPick) {
|
||||
return commands.executeCommand(commandPick.command, ...(commandPick.args || []));
|
||||
}
|
||||
|
||||
return undefined;
|
||||
return commands.executeCommand(Commands.ShowQuickCommitDetails,
|
||||
new GitUri(pick.commit.uri, pick.commit),
|
||||
pick.commit.sha, pick.commit,
|
||||
new CommandQuickPickItem({
|
||||
label: `go back \u21A9`,
|
||||
description: null
|
||||
}, Commands.ShowQuickFileHistory, [uri, maxCount, goBackCommand]),
|
||||
{ showFileHistory: false });
|
||||
}
|
||||
catch (ex) {
|
||||
Logger.error('[GitLens.ShowQuickFileHistoryCommand]', 'getLogLocations', ex);
|
||||
|
||||
Reference in New Issue
Block a user