mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-18 09:45:36 -05:00
Adds paging support to repo/file history quick picks (wip)
This commit is contained in:
@@ -1,23 +1,29 @@
|
||||
'use strict';
|
||||
import { Iterables } from '../system';
|
||||
import { QuickPickItem, QuickPickOptions, Uri, window } from 'vscode';
|
||||
import { CancellationTokenSource, QuickPickItem, QuickPickOptions, Uri, window } from 'vscode';
|
||||
import { Commands, Keyboard } from '../commands';
|
||||
import { IGitLog } from '../gitProvider';
|
||||
import { GitUri, IGitLog } from '../gitProvider';
|
||||
import { CommitQuickPickItem } from './gitQuickPicks';
|
||||
import { CommandQuickPickItem, getQuickPickIgnoreFocusOut } from './quickPicks';
|
||||
import * as path from 'path';
|
||||
|
||||
export class FileHistoryQuickPick {
|
||||
|
||||
static async show(log: IGitLog, uri: Uri, sha: string, maxCount: number, defaultMaxCount: number, goBackCommand?: CommandQuickPickItem): Promise<CommitQuickPickItem | CommandQuickPickItem | undefined> {
|
||||
static async show(log: IGitLog, uri: Uri, sha: string, progressCancellation: CancellationTokenSource, goBackCommand?: CommandQuickPickItem): Promise<CommitQuickPickItem | CommandQuickPickItem | undefined> {
|
||||
const items = Array.from(Iterables.map(log.commits.values(), c => new CommitQuickPickItem(c))) as (CommitQuickPickItem | CommandQuickPickItem)[];
|
||||
|
||||
if (maxCount !== 0 && items.length >= defaultMaxCount) {
|
||||
if (log.truncated) {
|
||||
items.splice(0, 0, new CommandQuickPickItem({
|
||||
label: `$(sync) Show All Commits`,
|
||||
description: `\u00a0 \u2014 \u00a0\u00a0 Currently only showing the first ${defaultMaxCount} commits`,
|
||||
description: `\u00a0 \u2014 \u00a0\u00a0 Currently only showing the first ${log.maxCount} commits`,
|
||||
detail: `This may take a while`
|
||||
}, Commands.ShowQuickFileHistory, [uri, 0, goBackCommand]));
|
||||
|
||||
const last = Iterables.last(log.commits.values());
|
||||
items.push(new CommandQuickPickItem({
|
||||
label: `$(ellipsis) Show More Commits`,
|
||||
description: `\u00a0 \u2014 \u00a0\u00a0 Shows the next ${log.maxCount} commits`
|
||||
}, Commands.ShowQuickFileHistory, [new GitUri(uri, last), log.maxCount, goBackCommand]));
|
||||
}
|
||||
|
||||
// Only show the full repo option if we are the root
|
||||
@@ -28,12 +34,13 @@ export class FileHistoryQuickPick {
|
||||
detail: 'Shows the commit history of the repository'
|
||||
}, Commands.ShowQuickRepoHistory,
|
||||
[
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
new CommandQuickPickItem({
|
||||
label: `go back \u21A9`,
|
||||
description: `\u00a0 \u2014 \u00a0\u00a0 to history of \u00a0$(file-text) ${path.basename(uri.fsPath)}`
|
||||
}, Commands.ShowQuickFileHistory, [uri, maxCount, undefined, log])
|
||||
}, Commands.ShowQuickFileHistory, [uri, log.maxCount, undefined, log])
|
||||
]));
|
||||
}
|
||||
|
||||
@@ -41,10 +48,14 @@ export class FileHistoryQuickPick {
|
||||
items.splice(0, 0, goBackCommand);
|
||||
}
|
||||
|
||||
if (progressCancellation.token.isCancellationRequested) return undefined;
|
||||
|
||||
await Keyboard.instance.enterScope(['left', goBackCommand]);
|
||||
|
||||
const commit = Iterables.first(log.commits.values());
|
||||
|
||||
progressCancellation.cancel();
|
||||
|
||||
const pick = await window.showQuickPick(items, {
|
||||
matchOnDescription: true,
|
||||
matchOnDetail: true,
|
||||
|
||||
@@ -1,12 +1,38 @@
|
||||
'use strict';
|
||||
import { commands, QuickPickItem, TextEditor, Uri, workspace } from 'vscode';
|
||||
import { CancellationTokenSource, commands, QuickPickItem, QuickPickOptions, TextEditor, Uri, window, workspace } from 'vscode';
|
||||
import { Commands, openEditor } from '../commands';
|
||||
import { IAdvancedConfig } from '../configuration';
|
||||
import { Logger } from '../logger';
|
||||
|
||||
export function getQuickPickIgnoreFocusOut() {
|
||||
return !workspace.getConfiguration('gitlens').get<IAdvancedConfig>('advanced').quickPick.closeOnFocusOut;
|
||||
}
|
||||
|
||||
export function showQuickPickProgress(message: string): CancellationTokenSource {
|
||||
const cancellation = new CancellationTokenSource();
|
||||
_showQuickPickProgress(message, cancellation);
|
||||
return cancellation;
|
||||
}
|
||||
|
||||
async function _showQuickPickProgress(message: string, cancellation: CancellationTokenSource) {
|
||||
Logger.log(`showQuickPickProgress`, `show`, message);
|
||||
await window.showQuickPick(_getInfiniteCancellablePromise(cancellation), {
|
||||
placeHolder: message,
|
||||
ignoreFocusOut: getQuickPickIgnoreFocusOut()
|
||||
} as QuickPickOptions, cancellation.token);
|
||||
Logger.log(`showQuickPickProgress`, `cancel`, message);
|
||||
cancellation.cancel();
|
||||
}
|
||||
|
||||
function _getInfiniteCancellablePromise(cancellation: CancellationTokenSource) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const disposable = cancellation.token.onCancellationRequested(() => {
|
||||
disposable.dispose();
|
||||
reject();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export class CommandQuickPickItem implements QuickPickItem {
|
||||
|
||||
label: string;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
import { Iterables } from '../system';
|
||||
import { QuickPickItem, QuickPickOptions, Uri, window } from 'vscode';
|
||||
import { CancellationTokenSource, QuickPickItem, QuickPickOptions, Uri, window } from 'vscode';
|
||||
import { Commands, Keyboard } from '../commands';
|
||||
import { IGitLog } from '../gitProvider';
|
||||
import { CommitQuickPickItem } from './gitQuickPicks';
|
||||
@@ -8,23 +8,33 @@ import { CommandQuickPickItem, getQuickPickIgnoreFocusOut } from './quickPicks';
|
||||
|
||||
export class RepoHistoryQuickPick {
|
||||
|
||||
static async show(log: IGitLog, uri: Uri, maxCount: number, defaultMaxCount: number, goBackCommand?: CommandQuickPickItem): Promise<CommitQuickPickItem | CommandQuickPickItem | undefined> {
|
||||
static async show(log: IGitLog, uri: Uri, sha: string, progressCancellation: CancellationTokenSource, goBackCommand?: CommandQuickPickItem): Promise<CommitQuickPickItem | CommandQuickPickItem | undefined> {
|
||||
const items = Array.from(Iterables.map(log.commits.values(), c => new CommitQuickPickItem(c, ` \u2014 ${c.fileNames}`))) as (CommitQuickPickItem | CommandQuickPickItem)[];
|
||||
|
||||
if (maxCount !== 0 && items.length >= defaultMaxCount) {
|
||||
if (log.truncated) {
|
||||
items.splice(0, 0, new CommandQuickPickItem({
|
||||
label: `$(sync) Show All Commits`,
|
||||
description: `\u00a0 \u2014 \u00a0\u00a0 Currently only showing the first ${defaultMaxCount} commits`,
|
||||
description: `\u00a0 \u2014 \u00a0\u00a0 Currently only showing the first ${log.maxCount} commits`,
|
||||
detail: `This may take a while`
|
||||
}, Commands.ShowQuickRepoHistory, [uri, 0, goBackCommand]));
|
||||
}, Commands.ShowQuickRepoHistory, [uri, undefined, 0, goBackCommand]));
|
||||
|
||||
const last = Iterables.last(log.commits.values());
|
||||
items.push(new CommandQuickPickItem({
|
||||
label: `$(ellipsis) Show More Commits`,
|
||||
description: `\u00a0 \u2014 \u00a0\u00a0 Shows the next ${log.maxCount} commits`
|
||||
}, Commands.ShowQuickRepoHistory, [uri, last.sha, log.maxCount, goBackCommand]));
|
||||
}
|
||||
|
||||
if (goBackCommand) {
|
||||
items.splice(0, 0, goBackCommand);
|
||||
}
|
||||
|
||||
if (progressCancellation.token.isCancellationRequested) return undefined;
|
||||
|
||||
await Keyboard.instance.enterScope(['left', goBackCommand]);
|
||||
|
||||
progressCancellation.cancel();
|
||||
|
||||
const pick = await window.showQuickPick(items, {
|
||||
matchOnDescription: true,
|
||||
matchOnDetail: true,
|
||||
|
||||
Reference in New Issue
Block a user