mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-16 09:35:40 -05:00
Refactors quick pick lists
This commit is contained in:
69
src/quickPicks/quickPicks.ts
Normal file
69
src/quickPicks/quickPicks.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
'use strict';
|
||||
import { commands, QuickPickItem, TextEditor, Uri, window, workspace } from 'vscode';
|
||||
import { Commands } from '../commands';
|
||||
import { IAdvancedConfig } from '../configuration';
|
||||
import { BuiltInCommands } from '../constants';
|
||||
|
||||
export function getQuickPickIgnoreFocusOut() {
|
||||
return !workspace.getConfiguration('gitlens').get<IAdvancedConfig>('advanced').quickPick.closeOnFocusOut;
|
||||
}
|
||||
|
||||
export async function openEditor(uri: Uri, pinned: boolean = false) {
|
||||
try {
|
||||
if (pinned) return await commands.executeCommand(BuiltInCommands.Open, uri);
|
||||
|
||||
const document = await workspace.openTextDocument(uri);
|
||||
return window.showTextDocument(document, (window.activeTextEditor && window.activeTextEditor.viewColumn) || 1, true);
|
||||
}
|
||||
catch (ex) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export class CommandQuickPickItem implements QuickPickItem {
|
||||
|
||||
label: string;
|
||||
description: string;
|
||||
detail: string;
|
||||
|
||||
constructor(item: QuickPickItem, protected command: Commands, protected args?: any[]) {
|
||||
Object.assign(this, item);
|
||||
}
|
||||
|
||||
execute(): Thenable<{}> {
|
||||
return commands.executeCommand(this.command, ...(this.args || []));
|
||||
}
|
||||
}
|
||||
|
||||
export class OpenFileCommandQuickPickItem extends CommandQuickPickItem {
|
||||
|
||||
constructor(public uri: Uri, item: QuickPickItem) {
|
||||
super(item, undefined, undefined);
|
||||
}
|
||||
|
||||
async execute(): Promise<{}> {
|
||||
return this.preview();
|
||||
}
|
||||
|
||||
async open(): Promise<TextEditor | undefined> {
|
||||
return openEditor(this.uri);
|
||||
}
|
||||
|
||||
async preview(): Promise<{}> {
|
||||
return openEditor(this.uri, true);
|
||||
}
|
||||
}
|
||||
|
||||
export class OpenFilesCommandQuickPickItem extends CommandQuickPickItem {
|
||||
|
||||
constructor(public uris: Uri[], item: QuickPickItem) {
|
||||
super(item, undefined, undefined);
|
||||
}
|
||||
|
||||
async execute(): Promise<{}> {
|
||||
for (const uri of this.uris) {
|
||||
openEditor(uri);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user