mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-14 12:08:33 -05:00
Adds Open Files command to commit files quick pick
Adds Open File command to commit quick pick
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import { commands, QuickPickItem, Uri } from 'vscode';
|
import { commands, QuickPickItem, TextEditor, Uri, window, workspace } from 'vscode';
|
||||||
import { Commands } from '../constants';
|
import { BuiltInCommands, Commands } from '../constants';
|
||||||
import { GitCommit, GitUri } from '../gitProvider';
|
import { GitCommit, GitUri } from '../gitProvider';
|
||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
@@ -10,15 +10,70 @@ export class CommandQuickPickItem implements QuickPickItem {
|
|||||||
description: string;
|
description: string;
|
||||||
detail: string;
|
detail: string;
|
||||||
|
|
||||||
constructor(item: QuickPickItem, public command: Commands, public args?: any[]) {
|
constructor(item: QuickPickItem, protected command: Commands, protected args?: any[]) {
|
||||||
Object.assign(this, item);
|
Object.assign(this, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
execute() {
|
execute(): Thenable<{}> {
|
||||||
return commands.executeCommand(this.command, ...(this.args || []));
|
return commands.executeCommand(this.command, ...(this.args || []));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class OpenFilesCommandQuickPickItem extends CommandQuickPickItem {
|
||||||
|
label: string;
|
||||||
|
description: string;
|
||||||
|
detail: string;
|
||||||
|
|
||||||
|
constructor(private commit: GitCommit, private fileNames?: string[]) {
|
||||||
|
super({
|
||||||
|
label: `$(file-symlink-file) Open Files`,
|
||||||
|
description: `\u00a0 \u2014 \u00a0\u00a0 $(file-text) ${commit.fileName}`,
|
||||||
|
detail: `Opens all the files in commit $(git-commit) ${commit.sha}`
|
||||||
|
}, undefined, undefined);
|
||||||
|
|
||||||
|
if (!this.fileNames) {
|
||||||
|
this.fileNames = commit.fileName.split(', ').filter(_ => !!_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async execute(): Promise<{}> {
|
||||||
|
const repoPath = this.commit.repoPath;
|
||||||
|
for (const file of this.fileNames) {
|
||||||
|
try {
|
||||||
|
const uri = Uri.file(path.resolve(repoPath, file));
|
||||||
|
const document = await workspace.openTextDocument(uri);
|
||||||
|
await window.showTextDocument(document, 1, true);
|
||||||
|
}
|
||||||
|
catch (ex) { }
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class OpenFileCommandQuickPickItem extends CommandQuickPickItem {
|
||||||
|
label: string;
|
||||||
|
description: string;
|
||||||
|
detail: string;
|
||||||
|
|
||||||
|
constructor(private commit: GitCommit) {
|
||||||
|
super({
|
||||||
|
label: `$(file-symlink-file) Open File`,
|
||||||
|
description: `\u00a0 \u2014 \u00a0\u00a0 $(file-text) ${commit.fileName}`
|
||||||
|
}, undefined, undefined);
|
||||||
|
}
|
||||||
|
|
||||||
|
async execute(): Promise<{}> {
|
||||||
|
const repoPath = this.commit.repoPath;
|
||||||
|
try {
|
||||||
|
const file = path.resolve(repoPath, this.commit.fileName);
|
||||||
|
return await commands.executeCommand(BuiltInCommands.Open, Uri.file(file));
|
||||||
|
}
|
||||||
|
catch (ex) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export class CommitQuickPickItem implements QuickPickItem {
|
export class CommitQuickPickItem implements QuickPickItem {
|
||||||
|
|
||||||
label: string;
|
label: string;
|
||||||
@@ -47,4 +102,29 @@ export class FileQuickPickItem implements QuickPickItem {
|
|||||||
this.sha = commit.sha;
|
this.sha = commit.sha;
|
||||||
this.uri = GitUri.fromUri(Uri.file(path.resolve(commit.repoPath, fileName)));
|
this.uri = GitUri.fromUri(Uri.file(path.resolve(commit.repoPath, fileName)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async open(): Promise<TextEditor | undefined> {
|
||||||
|
let document = workspace.textDocuments.find(_ => _.fileName === this.uri.fsPath);
|
||||||
|
const existing = !!document;
|
||||||
|
try {
|
||||||
|
if (!document) {
|
||||||
|
document = await workspace.openTextDocument(this.uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
const editor = await window.showTextDocument(document, 1, true);
|
||||||
|
return existing ? undefined : editor;
|
||||||
|
}
|
||||||
|
catch (ex) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async preview(): Promise<{}> {
|
||||||
|
try {
|
||||||
|
return await commands.executeCommand(BuiltInCommands.Open, this.uri);
|
||||||
|
}
|
||||||
|
catch (ex) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@ import { QuickPickOptions, Uri, window, workspace } from 'vscode';
|
|||||||
import { IAdvancedConfig } from '../configuration';
|
import { IAdvancedConfig } from '../configuration';
|
||||||
import { Commands } from '../constants';
|
import { Commands } from '../constants';
|
||||||
import { GitCommit, GitUri, IGitLog } from '../gitProvider';
|
import { GitCommit, GitUri, IGitLog } from '../gitProvider';
|
||||||
import { CommandQuickPickItem, CommitQuickPickItem, FileQuickPickItem } from './quickPickItems';
|
import { CommandQuickPickItem, CommitQuickPickItem, FileQuickPickItem, OpenFileCommandQuickPickItem, OpenFilesCommandQuickPickItem } from './quickPickItems';
|
||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
@@ -29,6 +29,8 @@ export class CommitQuickPick {
|
|||||||
description: `\u00a0 \u2014 \u00a0\u00a0 $(git-commit) ${commit.sha} \u00a0 $(git-compare) \u00a0 $(file-text) ${workingFileName || commit.fileName}`
|
description: `\u00a0 \u2014 \u00a0\u00a0 $(git-commit) ${commit.sha} \u00a0 $(git-compare) \u00a0 $(file-text) ${workingFileName || commit.fileName}`
|
||||||
}, Commands.DiffWithWorking, [uri, commit]));
|
}, Commands.DiffWithWorking, [uri, commit]));
|
||||||
|
|
||||||
|
items.push(new OpenFileCommandQuickPickItem(commit));
|
||||||
|
|
||||||
items.push(new CommandQuickPickItem({
|
items.push(new CommandQuickPickItem({
|
||||||
label: `$(clippy) Copy Commit Sha to Clipboard`,
|
label: `$(clippy) Copy Commit Sha to Clipboard`,
|
||||||
description: `\u00a0 \u2014 \u00a0\u00a0 $(git-commit) ${commit.sha}`
|
description: `\u00a0 \u2014 \u00a0\u00a0 $(git-commit) ${commit.sha}`
|
||||||
@@ -78,21 +80,28 @@ export class CommitQuickPick {
|
|||||||
export class CommitFilesQuickPick {
|
export class CommitFilesQuickPick {
|
||||||
|
|
||||||
static async show(commit: GitCommit, uri: Uri, goBackCommand?: CommandQuickPickItem): Promise<FileQuickPickItem | CommandQuickPickItem | undefined> {
|
static async show(commit: GitCommit, uri: Uri, goBackCommand?: CommandQuickPickItem): Promise<FileQuickPickItem | CommandQuickPickItem | undefined> {
|
||||||
const items: (FileQuickPickItem | CommandQuickPickItem)[] = commit.fileName
|
const fileNames = commit.fileName.split(', ').filter(_ => !!_);
|
||||||
.split(', ')
|
const items: (FileQuickPickItem | CommandQuickPickItem)[] = fileNames.map(f => new FileQuickPickItem(commit, f));
|
||||||
.filter(_ => !!_)
|
|
||||||
.map(f => new FileQuickPickItem(commit, f));
|
items.splice(0, 0, new OpenFilesCommandQuickPickItem(commit, fileNames));
|
||||||
|
|
||||||
if (goBackCommand) {
|
if (goBackCommand) {
|
||||||
items.splice(0, 0, goBackCommand);
|
items.splice(0, 0, goBackCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await window.showQuickPick(items, {
|
const result = await window.showQuickPick(items, {
|
||||||
matchOnDescription: true,
|
matchOnDescription: true,
|
||||||
matchOnDetail: true,
|
matchOnDetail: true,
|
||||||
placeHolder: `${commit.sha} \u2022 ${commit.author}, ${moment(commit.date).fromNow()} \u2022 ${commit.message}`,
|
placeHolder: `${commit.sha} \u2022 ${commit.author}, ${moment(commit.date).fromNow()} \u2022 ${commit.message}`,
|
||||||
ignoreFocusOut: getQuickPickIgnoreFocusOut()
|
ignoreFocusOut: getQuickPickIgnoreFocusOut()
|
||||||
|
// onDidSelectItem: (item: QuickPickItem) => {
|
||||||
|
// if (item instanceof FileQuickPickItem) {
|
||||||
|
// item.preview();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
} as QuickPickOptions);
|
} as QuickPickOptions);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,13 +2,14 @@
|
|||||||
|
|
||||||
export const RepoPath = 'repoPath';
|
export const RepoPath = 'repoPath';
|
||||||
|
|
||||||
export type BuiltInCommands = 'cursorMove' | 'editor.action.showReferences' | 'editor.action.toggleRenderWhitespace' | 'editorScroll' | 'revealLine' | 'vscode.diff' | 'vscode.executeDocumentSymbolProvider' | 'vscode.executeCodeLensProvider' | 'setContext';
|
export type BuiltInCommands = 'cursorMove' | 'editor.action.showReferences' | 'editor.action.toggleRenderWhitespace' | 'editorScroll' | 'revealLine' | 'setContext' | 'vscode.diff' | 'vscode.executeDocumentSymbolProvider' | 'vscode.executeCodeLensProvider' | 'vscode.open';
|
||||||
export const BuiltInCommands = {
|
export const BuiltInCommands = {
|
||||||
CursorMove: 'cursorMove' as BuiltInCommands,
|
CursorMove: 'cursorMove' as BuiltInCommands,
|
||||||
Diff: 'vscode.diff' as BuiltInCommands,
|
Diff: 'vscode.diff' as BuiltInCommands,
|
||||||
EditorScroll: 'editorScroll' as BuiltInCommands,
|
EditorScroll: 'editorScroll' as BuiltInCommands,
|
||||||
ExecuteDocumentSymbolProvider: 'vscode.executeDocumentSymbolProvider' as BuiltInCommands,
|
ExecuteDocumentSymbolProvider: 'vscode.executeDocumentSymbolProvider' as BuiltInCommands,
|
||||||
ExecuteCodeLensProvider: 'vscode.executeCodeLensProvider' as BuiltInCommands,
|
ExecuteCodeLensProvider: 'vscode.executeCodeLensProvider' as BuiltInCommands,
|
||||||
|
Open: 'vscode.open' as BuiltInCommands,
|
||||||
RevealLine: 'revealLine' as BuiltInCommands,
|
RevealLine: 'revealLine' as BuiltInCommands,
|
||||||
SetContext: 'setContext' as BuiltInCommands,
|
SetContext: 'setContext' as BuiltInCommands,
|
||||||
ShowReferences: 'editor.action.showReferences' as BuiltInCommands,
|
ShowReferences: 'editor.action.showReferences' as BuiltInCommands,
|
||||||
|
|||||||
Reference in New Issue
Block a user