mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-14 10:03:15 -05:00
69 lines
1.9 KiB
TypeScript
69 lines
1.9 KiB
TypeScript
'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;
|
|
}
|
|
} |