@ -1,211 +0,0 @@ | |||
'use strict'; | |||
import { commands, QuickPickItem, TextEditor, Uri, window, workspace } from 'vscode'; | |||
import { Commands } from '../commands'; | |||
import { BuiltInCommands } from '../constants'; | |||
import { GitCommit, GitFileStatus, GitFileStatusItem, GitLogCommit, GitUri } from '../gitProvider'; | |||
import * as moment from 'moment'; | |||
import * as path from 'path'; | |||
const statusOcticonsMap = { | |||
'?': '$(diff-ignored)', | |||
A: '$(diff-added)', | |||
C: '$(diff-added)', | |||
D: '$(diff-removed)', | |||
M: '$(diff-modified)', | |||
R: '$(diff-renamed)', | |||
U: '$(question)' | |||
}; | |||
function getStatusIcon(status: GitFileStatus, missing: string = '\u00a0\u00a0\u00a0\u00a0'): string { | |||
return statusOcticonsMap[status] || missing; | |||
} | |||
export interface PartialQuickPickItem { | |||
label?: string; | |||
description?: string; | |||
detail?: string; | |||
} | |||
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 OpenFilesCommandQuickPickItem extends CommandQuickPickItem { | |||
constructor(public fileNames: string[], public repoPath: string, item: QuickPickItem) { | |||
super(item, undefined, undefined); | |||
} | |||
getUri(fileName: string) { | |||
return Uri.file(path.resolve(this.repoPath, fileName)); | |||
} | |||
async execute(): Promise<{}> { | |||
for (const fileName of this.fileNames) { | |||
this.open(fileName); | |||
} | |||
return undefined; | |||
} | |||
async open(fileName: string): Promise<TextEditor | undefined> { | |||
try { | |||
const uri = this.getUri(fileName); | |||
const document = await workspace.openTextDocument(uri); | |||
return window.showTextDocument(document, 1, true); | |||
} | |||
catch (ex) { | |||
return undefined; | |||
} | |||
} | |||
} | |||
export class OpenCommitFilesCommandQuickPickItem extends OpenFilesCommandQuickPickItem { | |||
constructor(commit: GitLogCommit, item?: PartialQuickPickItem) { | |||
const repoPath = commit.repoPath; | |||
item = { | |||
...{ | |||
label: `$(file-symlink-file) Open Files`, | |||
description: undefined, | |||
detail: `Opens all of the files in commit $(git-commit) ${commit.sha}` | |||
}, | |||
...item | |||
}; | |||
super(commit.fileStatuses.map(_ => _.fileName), repoPath, item as QuickPickItem); | |||
} | |||
} | |||
export class OpenStatusFilesCommandQuickPickItem extends OpenFilesCommandQuickPickItem { | |||
constructor(statuses: GitFileStatusItem[], item?: PartialQuickPickItem) { | |||
const repoPath = statuses.length && statuses[0].repoPath; | |||
const fileNames = statuses.map(_ => _.fileName); | |||
item = { | |||
...{ | |||
label: `$(file-symlink-file) Open Files`, | |||
description: undefined, | |||
detail: `Opens all of the changed files in the repository` | |||
}, | |||
...item | |||
}; | |||
super(fileNames, repoPath, item as QuickPickItem); | |||
} | |||
} | |||
export class OpenFileCommandQuickPickItem extends CommandQuickPickItem { | |||
constructor(public fileName: string, public repoPath: string, item: QuickPickItem) { | |||
super(item, undefined, undefined); | |||
} | |||
getUri() { | |||
return Uri.file(path.resolve(this.repoPath, this.fileName)); | |||
} | |||
async execute(): Promise<{}> { | |||
try { | |||
const uri = this.getUri(); | |||
return await commands.executeCommand(BuiltInCommands.Open, uri); | |||
} | |||
catch (ex) { | |||
return undefined; | |||
} | |||
} | |||
} | |||
export class OpenCommitFileCommandQuickPickItem extends OpenFileCommandQuickPickItem { | |||
constructor(commit: GitCommit, item?: PartialQuickPickItem) { | |||
item = { | |||
...{ | |||
label: `$(file-symlink-file) Open File`, | |||
description: `\u00a0 \u2014 \u00a0\u00a0 ${commit.getFormattedPath()}` | |||
}, | |||
...item | |||
}; | |||
super(commit.fileName, commit.repoPath, item as QuickPickItem); | |||
} | |||
} | |||
export class OpenStatusFileCommandQuickPickItem extends OpenFileCommandQuickPickItem { | |||
constructor(status: GitFileStatusItem, item?: PartialQuickPickItem) { | |||
let directory = path.dirname(status.fileName); | |||
if (!directory || directory === '.') { | |||
directory = undefined; | |||
} | |||
const icon = getStatusIcon(status.status); | |||
item = { | |||
...{ | |||
label: `${status.staged ? '$(check)' : '\u00a0\u00a0\u00a0'}\u00a0\u00a0${icon}\u00a0\u00a0\u00a0${path.basename(status.fileName)}`, | |||
description: directory | |||
}, | |||
...item | |||
}; | |||
super(status.fileName, status.repoPath, item as QuickPickItem); | |||
} | |||
} | |||
export class CommitQuickPickItem implements QuickPickItem { | |||
label: string; | |||
description: string; | |||
detail: string; | |||
constructor(public commit: GitCommit, descriptionSuffix: string = '') { | |||
this.label = `${commit.author}, ${moment(commit.date).fromNow()}`; | |||
this.description = `\u00a0 \u2014 \u00a0\u00a0 $(git-commit) ${commit.sha}${descriptionSuffix}`; | |||
this.detail = commit.message; | |||
} | |||
} | |||
export class FileQuickPickItem implements QuickPickItem { | |||
label: string; | |||
description: string; | |||
detail: string; | |||
sha: string; | |||
uri: GitUri; | |||
constructor(commit: GitCommit, public fileName: string, public status: GitFileStatus) { | |||
const icon = getStatusIcon(status); | |||
this.label = `${icon} ${path.basename(fileName)}`; | |||
let directory = path.dirname(fileName); | |||
if (!directory || directory === '.') { | |||
directory = undefined; | |||
} | |||
this.description = directory; | |||
this.sha = commit.sha; | |||
this.uri = GitUri.fromUri(Uri.file(path.resolve(commit.repoPath, fileName))); | |||
} | |||
async preview(): Promise<{}> { | |||
try { | |||
return await commands.executeCommand(BuiltInCommands.Open, this.uri); | |||
} | |||
catch (ex) { | |||
return undefined; | |||
} | |||
} | |||
} |
@ -1,231 +0,0 @@ | |||
'use strict'; | |||
import { Iterables } from '../system'; | |||
import { QuickPickOptions, Uri, window, workspace } from 'vscode'; | |||
import { IAdvancedConfig } from '../configuration'; | |||
import { Commands } from '../commands'; | |||
import GitProvider, { GitCommit, GitFileStatusItem, GitLogCommit, GitUri, IGitLog } from '../gitProvider'; | |||
import { CommandQuickPickItem, CommitQuickPickItem, FileQuickPickItem, OpenCommitFileCommandQuickPickItem, OpenStatusFileCommandQuickPickItem, OpenCommitFilesCommandQuickPickItem, OpenStatusFilesCommandQuickPickItem } from './quickPickItems'; | |||
import * as moment from 'moment'; | |||
import * as path from 'path'; | |||
function getQuickPickIgnoreFocusOut() { | |||
return !workspace.getConfiguration('gitlens').get<IAdvancedConfig>('advanced').quickPick.closeOnFocusOut; | |||
} | |||
export class CommitQuickPick { | |||
static async show(git: GitProvider, commit: GitCommit, workingFileName: string, uri: Uri, currentCommand?: CommandQuickPickItem, goBackCommand?: CommandQuickPickItem, options: { showFileHistory?: boolean } = {}): Promise<CommandQuickPickItem | undefined> { | |||
const items: CommandQuickPickItem[] = []; | |||
const workingName = (workingFileName && path.basename(workingFileName)) || path.basename(commit.fileName); | |||
const isUncommitted = commit.isUncommitted; | |||
if (isUncommitted) { | |||
// Since we can't trust the previous sha on an uncommitted commit, find the last commit for this file | |||
const log = await git.getLogForFile(commit.uri.fsPath, undefined, undefined, undefined, 2); | |||
if (!log) return undefined; | |||
commit = Iterables.first(log.commits.values()); | |||
} | |||
if (commit.previousSha) { | |||
items.push(new CommandQuickPickItem({ | |||
label: `$(git-compare) Compare with Previous Commit`, | |||
description: `\u00a0 \u2014 \u00a0\u00a0 $(git-commit) ${commit.previousSha} \u00a0 $(git-compare) \u00a0 $(git-commit) ${commit.sha}` | |||
}, Commands.DiffWithPrevious, [commit.uri, commit])); | |||
} | |||
items.push(new CommandQuickPickItem({ | |||
label: `$(git-compare) Compare with Working Tree`, | |||
description: `\u00a0 \u2014 \u00a0\u00a0 $(git-commit) ${commit.sha} \u00a0 $(git-compare) \u00a0 $(file-text) ${workingName}` | |||
}, Commands.DiffWithWorking, [uri, commit])); | |||
items.push(new OpenCommitFileCommandQuickPickItem(commit)); | |||
items.push(new CommandQuickPickItem({ | |||
label: `$(clippy) Copy Commit Sha to Clipboard`, | |||
description: `\u00a0 \u2014 \u00a0\u00a0 $(git-commit) ${commit.sha}` | |||
}, Commands.CopyShaToClipboard, [uri, commit.sha])); | |||
items.push(new CommandQuickPickItem({ | |||
label: `$(clippy) Copy Commit Message to Clipboard`, | |||
description: `\u00a0 \u2014 \u00a0\u00a0 $(git-commit) ${commit.message}` | |||
}, Commands.CopyMessageToClipboard, [uri, commit.sha, commit.message])); | |||
items.push(new CommandQuickPickItem({ | |||
label: `$(diff) Show Changed Files`, | |||
description: undefined, //`\u00a0 \u2014 \u00a0\u00a0 $(git-commit) ${commit.sha}`, | |||
detail: `Shows all of the changed files in commit $(git-commit) ${commit.sha}` | |||
}, Commands.ShowQuickCommitDetails, [new GitUri(commit.uri, commit), commit.sha, undefined, currentCommand])); | |||
if (options.showFileHistory) { | |||
if (workingFileName) { | |||
items.push(new CommandQuickPickItem({ | |||
label: `$(history) Show File History`, | |||
description: undefined, //`\u00a0 \u2014 \u00a0\u00a0 ${path.basename(commit.fileName)}`, | |||
detail: `Shows the commit history of the file, starting at the most recent commit` | |||
}, Commands.ShowQuickFileHistory, [commit.uri, undefined, undefined, currentCommand])); | |||
} | |||
items.push(new CommandQuickPickItem({ | |||
label: `$(history) Show Previous File History`, | |||
description: undefined, //`\u00a0 \u2014 \u00a0\u00a0 ${path.basename(commit.fileName)}`, | |||
detail: `Shows the previous commit history of the file, starting at $(git-commit) ${commit.sha}` | |||
}, Commands.ShowQuickFileHistory, [new GitUri(commit.uri, commit), undefined, undefined, currentCommand])); | |||
} | |||
if (goBackCommand) { | |||
items.splice(0, 0, goBackCommand); | |||
} | |||
return await window.showQuickPick(items, { | |||
matchOnDescription: true, | |||
placeHolder: `${commit.getFormattedPath()} \u2022 ${isUncommitted ? 'Uncommitted \u21E8 ' : '' }${commit.sha} \u2022 ${commit.author}, ${moment(commit.date).fromNow()} \u2022 ${commit.message}`, | |||
ignoreFocusOut: getQuickPickIgnoreFocusOut() | |||
} as QuickPickOptions); | |||
} | |||
} | |||
export class CommitFilesQuickPick { | |||
static async show(commit: GitLogCommit, uri: Uri, goBackCommand?: CommandQuickPickItem): Promise<FileQuickPickItem | CommandQuickPickItem | undefined> { | |||
const items: (FileQuickPickItem | CommandQuickPickItem)[] = commit.fileStatuses.map(fs => new FileQuickPickItem(commit, fs.fileName, fs.status)); | |||
items.splice(0, 0, new OpenCommitFilesCommandQuickPickItem(commit)); | |||
items.splice(1, 0, new CommandQuickPickItem({ | |||
label: `$(clippy) Copy Commit Sha to Clipboard`, | |||
description: `\u00a0 \u2014 \u00a0\u00a0 $(git-commit) ${commit.sha}` | |||
}, Commands.CopyShaToClipboard, [uri, commit.sha])); | |||
items.splice(2, 0, new CommandQuickPickItem({ | |||
label: `$(clippy) Copy Commit Message to Clipboard`, | |||
description: `\u00a0 \u2014 \u00a0\u00a0 $(git-commit) ${commit.message}` | |||
}, Commands.CopyMessageToClipboard, [uri, commit.sha, commit.message])); | |||
if (goBackCommand) { | |||
items.splice(0, 0, goBackCommand); | |||
} | |||
const result = await window.showQuickPick(items, { | |||
matchOnDescription: true, | |||
matchOnDetail: true, | |||
placeHolder: `${commit.sha} \u2022 ${commit.author}, ${moment(commit.date).fromNow()} \u2022 ${commit.message}`, | |||
ignoreFocusOut: getQuickPickIgnoreFocusOut() | |||
// onDidSelectItem: (item: QuickPickItem) => { | |||
// if (item instanceof FileQuickPickItem) { | |||
// item.preview(); | |||
// } | |||
// } | |||
} as QuickPickOptions); | |||
return result; | |||
} | |||
} | |||
export class FileCommitsQuickPick { | |||
static async show(log: IGitLog, uri: Uri, maxCount: number, defaultMaxCount: number, 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) { | |||
items.splice(0, 0, new CommandQuickPickItem({ | |||
label: `$(sync) Show All Commits`, | |||
description: `\u00a0 \u2014 \u00a0\u00a0 Currently only showing the first ${defaultMaxCount} commits`, | |||
detail: `This may take a while` | |||
}, Commands.ShowQuickFileHistory, [uri, 0, undefined, goBackCommand])); | |||
} | |||
// Only show the full repo option if we are the root | |||
if (!goBackCommand) { | |||
items.splice(0, 0, new CommandQuickPickItem({ | |||
label: `$(repo) Show Repository History`, | |||
description: null, | |||
detail: 'Shows the commit history of the repository' | |||
}, Commands.ShowQuickRepoHistory, [undefined, undefined, undefined, new CommandQuickPickItem({ | |||
label: `go back \u21A9`, | |||
description: null | |||
}, Commands.ShowQuickFileHistory, [uri, maxCount])])); | |||
} | |||
if (goBackCommand) { | |||
items.splice(0, 0, goBackCommand); | |||
} | |||
const commit = Iterables.first(log.commits.values()); | |||
return await window.showQuickPick(items, { | |||
matchOnDescription: true, | |||
matchOnDetail: true, | |||
placeHolder: commit.getFormattedPath(), | |||
ignoreFocusOut: getQuickPickIgnoreFocusOut() | |||
} as QuickPickOptions); | |||
} | |||
} | |||
export class RepoCommitsQuickPick { | |||
static async show(log: IGitLog, uri: Uri, maxCount: number, defaultMaxCount: number, goBackCommand?: CommandQuickPickItem): Promise<CommitQuickPickItem | CommandQuickPickItem | undefined> { | |||
const items = Array.from(Iterables.map(log.commits.values(), c => new CommitQuickPickItem(c, ` \u2014 ${c.fileName}`))) as (CommitQuickPickItem | CommandQuickPickItem)[]; | |||
if (maxCount !== 0 && items.length >= defaultMaxCount) { | |||
items.splice(0, 0, new CommandQuickPickItem({ | |||
label: `$(sync) Show All Commits`, | |||
description: `\u00a0 \u2014 \u00a0\u00a0 Currently only showing the first ${defaultMaxCount} commits`, | |||
detail: `This may take a while` | |||
}, Commands.ShowQuickRepoHistory, [uri, 0, undefined, goBackCommand])); | |||
} | |||
if (goBackCommand) { | |||
items.splice(0, 0, goBackCommand); | |||
} | |||
return await window.showQuickPick(items, { | |||
matchOnDescription: true, | |||
matchOnDetail: true, | |||
placeHolder: 'Search by commit message, filename, or sha', | |||
ignoreFocusOut: getQuickPickIgnoreFocusOut() | |||
} as QuickPickOptions); | |||
} | |||
} | |||
export class RepoStatusesQuickPick { | |||
static async show(statuses: GitFileStatusItem[], goBackCommand?: CommandQuickPickItem): Promise<CommitQuickPickItem | CommandQuickPickItem | undefined> { | |||
// Sort the status by staged and then filename | |||
statuses.sort((a, b) => (a.staged ? -1 : 1) - (b.staged ? -1 : 1) || a.fileName.localeCompare(b.fileName)); | |||
const items = Array.from(Iterables.map(statuses, s => new OpenStatusFileCommandQuickPickItem(s))) as (OpenStatusFileCommandQuickPickItem | CommandQuickPickItem)[]; | |||
if (statuses.some(_ => _.staged)) { | |||
const index = statuses.findIndex(_ => !_.staged); | |||
if (index > -1) { | |||
items.splice(index, 0, new OpenStatusFilesCommandQuickPickItem(statuses.filter(_ => _.status !== 'D' && !_.staged), { | |||
label: `$(file-symlink-file) Open Unstaged Files`, | |||
description: undefined, | |||
detail: `Opens all of the unstaged files in the repository` | |||
})); | |||
items.splice(0, 0, new OpenStatusFilesCommandQuickPickItem(statuses.filter(_ => _.status !== 'D' && _.staged), { | |||
label: `$(file-symlink-file) Open Staged Files`, | |||
description: undefined, | |||
detail: `Opens all of the staged files in the repository` | |||
})); | |||
} | |||
} | |||
if (statuses.length) { | |||
items.splice(0, 0, new OpenStatusFilesCommandQuickPickItem(statuses.filter(_ => _.status !== 'D'))); | |||
} | |||
if (goBackCommand) { | |||
items.splice(0, 0, goBackCommand); | |||
} | |||
return await window.showQuickPick(items, { | |||
matchOnDescription: true, | |||
placeHolder: statuses.length ? 'Repository has changes' : 'Repository has no changes', | |||
ignoreFocusOut: getQuickPickIgnoreFocusOut() | |||
} as QuickPickOptions); | |||
} | |||
} |
@ -0,0 +1,146 @@ | |||
'use strict'; | |||
import { Iterables } from '../system'; | |||
import { QuickPickItem, QuickPickOptions, Uri, window } from 'vscode'; | |||
import { Commands } from '../commands'; | |||
import GitProvider, { GitCommit, GitLogCommit, GitUri } from '../gitProvider'; | |||
import { CommitWithFileStatusQuickPickItem } from './gitQuickPicks'; | |||
import { CommandQuickPickItem, getQuickPickIgnoreFocusOut, OpenFileCommandQuickPickItem, OpenFilesCommandQuickPickItem } from './quickPicks'; | |||
import * as moment from 'moment'; | |||
import * as path from 'path'; | |||
export { CommandQuickPickItem, CommitWithFileStatusQuickPickItem }; | |||
export class OpenCommitFileCommandQuickPickItem extends OpenFileCommandQuickPickItem { | |||
constructor(commit: GitCommit, item?: QuickPickItem) { | |||
const uri = Uri.file(path.resolve(commit.repoPath, commit.fileName)); | |||
super(uri, item || { | |||
label: `$(file-symlink-file) Open Working Tree File`, | |||
description: `\u00a0 \u2014 \u00a0\u00a0 ${commit.getFormattedPath()}` | |||
}); | |||
} | |||
} | |||
export class OpenCommitFilesCommandQuickPickItem extends OpenFilesCommandQuickPickItem { | |||
constructor(commit: GitLogCommit, item?: QuickPickItem) { | |||
const repoPath = commit.repoPath; | |||
const uris = commit.fileStatuses.map(_ => Uri.file(path.resolve(repoPath, _.fileName))); | |||
super(uris, item || { | |||
label: `$(file-symlink-file) Open Working Tree Files`, | |||
description: undefined, | |||
detail: `Opens all of the files in commit $(git-commit) ${commit.sha}` | |||
}); | |||
} | |||
} | |||
export class CommitDetailsQuickPick { | |||
static async show(commit: GitLogCommit, uri: Uri, goBackCommand?: CommandQuickPickItem): Promise<CommitWithFileStatusQuickPickItem | CommandQuickPickItem | undefined> { | |||
const items: (CommitWithFileStatusQuickPickItem | CommandQuickPickItem)[] = commit.fileStatuses.map(fs => new CommitWithFileStatusQuickPickItem(commit, fs.fileName, fs.status)); | |||
items.splice(0, 0, new CommandQuickPickItem({ | |||
label: `$(clippy) Copy Commit Sha to Clipboard`, | |||
description: `\u00a0 \u2014 \u00a0\u00a0 $(git-commit) ${commit.sha}` | |||
}, Commands.CopyShaToClipboard, [uri, commit.sha])); | |||
items.splice(1, 0, new CommandQuickPickItem({ | |||
label: `$(clippy) Copy Commit Message to Clipboard`, | |||
description: `\u00a0 \u2014 \u00a0\u00a0 $(git-commit) ${commit.message}` | |||
}, Commands.CopyMessageToClipboard, [uri, commit.sha, commit.message])); | |||
items.splice(2, 0, new OpenCommitFilesCommandQuickPickItem(commit)); | |||
if (goBackCommand) { | |||
items.splice(0, 0, goBackCommand); | |||
} | |||
const result = await window.showQuickPick(items, { | |||
matchOnDescription: true, | |||
matchOnDetail: true, | |||
placeHolder: `${commit.sha} \u2022 ${commit.author}, ${moment(commit.date).fromNow()} \u2022 ${commit.message}`, | |||
ignoreFocusOut: getQuickPickIgnoreFocusOut() | |||
// onDidSelectItem: (item: QuickPickItem) => { | |||
// if (item instanceof FileQuickPickItem) { | |||
// item.preview(); | |||
// } | |||
// } | |||
} as QuickPickOptions); | |||
return result; | |||
} | |||
} | |||
export class CommitFileDetailsQuickPick { | |||
static async show(git: GitProvider, commit: GitCommit, workingFileName: string, uri: Uri, currentCommand?: CommandQuickPickItem, goBackCommand?: CommandQuickPickItem, options: { showFileHistory?: boolean } = {}): Promise<CommandQuickPickItem | undefined> { | |||
const items: CommandQuickPickItem[] = []; | |||
const workingName = (workingFileName && path.basename(workingFileName)) || path.basename(commit.fileName); | |||
const isUncommitted = commit.isUncommitted; | |||
if (isUncommitted) { | |||
// Since we can't trust the previous sha on an uncommitted commit, find the last commit for this file | |||
const log = await git.getLogForFile(commit.uri.fsPath, undefined, undefined, undefined, 2); | |||
if (!log) return undefined; | |||
commit = Iterables.first(log.commits.values()); | |||
} | |||
if (commit.previousSha) { | |||
items.push(new CommandQuickPickItem({ | |||
label: `$(git-compare) Compare with Previous Commit`, | |||
description: `\u00a0 \u2014 \u00a0\u00a0 $(git-commit) ${commit.previousSha} \u00a0 $(git-compare) \u00a0 $(git-commit) ${commit.sha}` | |||
}, Commands.DiffWithPrevious, [commit.uri, commit])); | |||
} | |||
items.push(new CommandQuickPickItem({ | |||
label: `$(git-compare) Compare with Working Tree`, | |||
description: `\u00a0 \u2014 \u00a0\u00a0 $(git-commit) ${commit.sha} \u00a0 $(git-compare) \u00a0 $(file-text) ${workingName}` | |||
}, Commands.DiffWithWorking, [uri, commit])); | |||
items.push(new CommandQuickPickItem({ | |||
label: `$(diff) Show Changed Files`, | |||
description: undefined, //`\u00a0 \u2014 \u00a0\u00a0 $(git-commit) ${commit.sha}`, | |||
detail: `Shows all of the changed files in commit $(git-commit) ${commit.sha}` | |||
}, Commands.ShowQuickCommitDetails, [new GitUri(commit.uri, commit), commit.sha, undefined, currentCommand])); | |||
items.push(new CommandQuickPickItem({ | |||
label: `$(clippy) Copy Commit Sha to Clipboard`, | |||
description: `\u00a0 \u2014 \u00a0\u00a0 $(git-commit) ${commit.sha}` | |||
}, Commands.CopyShaToClipboard, [uri, commit.sha])); | |||
items.push(new CommandQuickPickItem({ | |||
label: `$(clippy) Copy Commit Message to Clipboard`, | |||
description: `\u00a0 \u2014 \u00a0\u00a0 $(git-commit) ${commit.message}` | |||
}, Commands.CopyMessageToClipboard, [uri, commit.sha, commit.message])); | |||
items.push(new OpenCommitFileCommandQuickPickItem(commit)); | |||
if (options.showFileHistory) { | |||
if (workingFileName) { | |||
items.push(new CommandQuickPickItem({ | |||
label: `$(history) Show File History`, | |||
description: undefined, //`\u00a0 \u2014 \u00a0\u00a0 ${path.basename(commit.fileName)}`, | |||
detail: `Shows the commit history of the file, starting at the most recent commit` | |||
}, Commands.ShowQuickFileHistory, [commit.uri, undefined, undefined, currentCommand])); | |||
} | |||
items.push(new CommandQuickPickItem({ | |||
label: `$(history) Show Previous File History`, | |||
description: undefined, //`\u00a0 \u2014 \u00a0\u00a0 ${path.basename(commit.fileName)}`, | |||
detail: `Shows the previous commit history of the file, starting at $(git-commit) ${commit.sha}` | |||
}, Commands.ShowQuickFileHistory, [new GitUri(commit.uri, commit), undefined, undefined, currentCommand])); | |||
} | |||
if (goBackCommand) { | |||
items.splice(0, 0, goBackCommand); | |||
} | |||
return await window.showQuickPick(items, { | |||
matchOnDescription: true, | |||
placeHolder: `${commit.getFormattedPath()} \u2022 ${isUncommitted ? 'Uncommitted \u21E8 ' : '' }${commit.sha} \u2022 ${commit.author}, ${moment(commit.date).fromNow()} \u2022 ${commit.message}`, | |||
ignoreFocusOut: getQuickPickIgnoreFocusOut() | |||
} as QuickPickOptions); | |||
} | |||
} |
@ -0,0 +1,49 @@ | |||
'use strict'; | |||
import { Iterables } from '../system'; | |||
import { QuickPickOptions, Uri, window } from 'vscode'; | |||
import { Commands } from '../commands'; | |||
import { IGitLog } from '../gitProvider'; | |||
import { CommitQuickPickItem } from './gitQuickPicks'; | |||
import { CommandQuickPickItem, getQuickPickIgnoreFocusOut } from './quickPicks'; | |||
export { CommandQuickPickItem, CommitQuickPickItem }; | |||
export class FileHistoryQuickPick { | |||
static async show(log: IGitLog, uri: Uri, maxCount: number, defaultMaxCount: number, 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) { | |||
items.splice(0, 0, new CommandQuickPickItem({ | |||
label: `$(sync) Show All Commits`, | |||
description: `\u00a0 \u2014 \u00a0\u00a0 Currently only showing the first ${defaultMaxCount} commits`, | |||
detail: `This may take a while` | |||
}, Commands.ShowQuickFileHistory, [uri, 0, undefined, goBackCommand])); | |||
} | |||
// Only show the full repo option if we are the root | |||
if (!goBackCommand) { | |||
items.splice(0, 0, new CommandQuickPickItem({ | |||
label: `$(repo) Show Repository History`, | |||
description: null, | |||
detail: 'Shows the commit history of the repository' | |||
}, Commands.ShowQuickRepoHistory, [undefined, undefined, undefined, new CommandQuickPickItem({ | |||
label: `go back \u21A9`, | |||
description: null | |||
}, Commands.ShowQuickFileHistory, [uri, maxCount])])); | |||
} | |||
if (goBackCommand) { | |||
items.splice(0, 0, goBackCommand); | |||
} | |||
const commit = Iterables.first(log.commits.values()); | |||
return await window.showQuickPick(items, { | |||
matchOnDescription: true, | |||
matchOnDetail: true, | |||
placeHolder: commit.getFormattedPath(), | |||
ignoreFocusOut: getQuickPickIgnoreFocusOut() | |||
} as QuickPickOptions); | |||
} | |||
} |
@ -0,0 +1,48 @@ | |||
'use strict'; | |||
import { QuickPickItem, Uri } from 'vscode'; | |||
import { getGitStatusIcon, GitCommit, GitFileStatus, GitUri } from '../gitProvider'; | |||
import { openEditor } from './quickPicks'; | |||
import * as moment from 'moment'; | |||
import * as path from 'path'; | |||
export class CommitQuickPickItem implements QuickPickItem { | |||
label: string; | |||
description: string; | |||
detail: string; | |||
constructor(public commit: GitCommit, descriptionSuffix: string = '') { | |||
this.label = `${commit.author}, ${moment(commit.date).fromNow()}`; | |||
this.description = `\u00a0 \u2014 \u00a0\u00a0 $(git-commit) ${commit.sha}${descriptionSuffix}`; | |||
this.detail = commit.message; | |||
} | |||
} | |||
export class CommitWithFileStatusQuickPickItem implements QuickPickItem { | |||
label: string; | |||
description: string; | |||
detail: string; | |||
sha: string; | |||
uri: GitUri; | |||
constructor(commit: GitCommit, public fileName: string, public status: GitFileStatus) { | |||
const icon = getGitStatusIcon(status); | |||
this.label = `\u00a0\u00a0\u00a0\u00a0${icon}\u00a0\u00a0 ${path.basename(fileName)}`; | |||
let directory = path.dirname(fileName); | |||
if (!directory || directory === '.') { | |||
directory = undefined; | |||
} | |||
this.description = directory; | |||
this.sha = commit.sha; | |||
this.uri = GitUri.fromUri(Uri.file(path.resolve(commit.repoPath, fileName))); | |||
} | |||
async preview(): Promise<{}> { | |||
return openEditor(this.uri, true); | |||
} | |||
} |
@ -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; | |||
} | |||
} |
@ -0,0 +1,35 @@ | |||
'use strict'; | |||
import { Iterables } from '../system'; | |||
import { QuickPickOptions, Uri, window } from 'vscode'; | |||
import { Commands } from '../commands'; | |||
import { IGitLog } from '../gitProvider'; | |||
import { CommitQuickPickItem } from './gitQuickPicks'; | |||
import { CommandQuickPickItem, getQuickPickIgnoreFocusOut } from './quickPicks'; | |||
export { CommandQuickPickItem, CommitQuickPickItem }; | |||
export class RepoHistoryQuickPick { | |||
static async show(log: IGitLog, uri: Uri, maxCount: number, defaultMaxCount: number, goBackCommand?: CommandQuickPickItem): Promise<CommitQuickPickItem | CommandQuickPickItem | undefined> { | |||
const items = Array.from(Iterables.map(log.commits.values(), c => new CommitQuickPickItem(c, ` \u2014 ${c.fileName}`))) as (CommitQuickPickItem | CommandQuickPickItem)[]; | |||
if (maxCount !== 0 && items.length >= defaultMaxCount) { | |||
items.splice(0, 0, new CommandQuickPickItem({ | |||
label: `$(sync) Show All Commits`, | |||
description: `\u00a0 \u2014 \u00a0\u00a0 Currently only showing the first ${defaultMaxCount} commits`, | |||
detail: `This may take a while` | |||
}, Commands.ShowQuickRepoHistory, [uri, 0, undefined, goBackCommand])); | |||
} | |||
if (goBackCommand) { | |||
items.splice(0, 0, goBackCommand); | |||
} | |||
return await window.showQuickPick(items, { | |||
matchOnDescription: true, | |||
matchOnDetail: true, | |||
placeHolder: 'Search by commit message, filename, or sha', | |||
ignoreFocusOut: getQuickPickIgnoreFocusOut() | |||
} as QuickPickOptions); | |||
} | |||
} |
@ -0,0 +1,81 @@ | |||
'use strict'; | |||
import { Iterables } from '../system'; | |||
import { QuickPickItem, QuickPickOptions, Uri, window } from 'vscode'; | |||
import { getGitStatusIcon, GitFileStatusItem } from '../gitProvider'; | |||
import { CommandQuickPickItem, getQuickPickIgnoreFocusOut, OpenFileCommandQuickPickItem, OpenFilesCommandQuickPickItem } from './quickPicks'; | |||
import * as path from 'path'; | |||
export { CommandQuickPickItem }; | |||
export class OpenStatusFileCommandQuickPickItem extends OpenFileCommandQuickPickItem { | |||
constructor(status: GitFileStatusItem, item?: QuickPickItem) { | |||
const uri = Uri.file(path.resolve(status.repoPath, status.fileName)); | |||
const icon = getGitStatusIcon(status.status); | |||
let directory = path.dirname(status.fileName); | |||
if (!directory || directory === '.') { | |||
directory = undefined; | |||
} | |||
super(uri, item || { | |||
label: `${status.staged ? '$(check)' : '\u00a0\u00a0\u00a0'}\u00a0\u00a0${icon}\u00a0\u00a0\u00a0${path.basename(status.fileName)}`, | |||
description: directory | |||
}); | |||
} | |||
} | |||
export class OpenStatusFilesCommandQuickPickItem extends OpenFilesCommandQuickPickItem { | |||
constructor(statuses: GitFileStatusItem[], item?: QuickPickItem) { | |||
const repoPath = statuses.length && statuses[0].repoPath; | |||
const uris = statuses.map(_ => Uri.file(path.resolve(repoPath, _.fileName))); | |||
super(uris, item || { | |||
label: `$(file-symlink-file) Open Files`, | |||
description: undefined, | |||
detail: `Opens all of the changed files in the repository` | |||
}); | |||
} | |||
} | |||
export class RepoStatusQuickPick { | |||
static async show(statuses: GitFileStatusItem[], goBackCommand?: CommandQuickPickItem): Promise<OpenStatusFileCommandQuickPickItem | OpenStatusFilesCommandQuickPickItem | CommandQuickPickItem | undefined> { | |||
// Sort the status by staged and then filename | |||
statuses.sort((a, b) => (a.staged ? -1 : 1) - (b.staged ? -1 : 1) || a.fileName.localeCompare(b.fileName)); | |||
const items = Array.from(Iterables.map(statuses, s => new OpenStatusFileCommandQuickPickItem(s))) as (OpenStatusFileCommandQuickPickItem | OpenStatusFilesCommandQuickPickItem | CommandQuickPickItem)[]; | |||
if (statuses.some(_ => _.staged)) { | |||
const index = statuses.findIndex(_ => !_.staged); | |||
if (index > -1) { | |||
items.splice(index, 0, new OpenStatusFilesCommandQuickPickItem(statuses.filter(_ => _.status !== 'D' && !_.staged), { | |||
label: `$(file-symlink-file) Open Unstaged Files`, | |||
description: undefined, | |||
detail: `Opens all of the unstaged files in the repository` | |||
})); | |||
items.splice(0, 0, new OpenStatusFilesCommandQuickPickItem(statuses.filter(_ => _.status !== 'D' && _.staged), { | |||
label: `$(file-symlink-file) Open Staged Files`, | |||
description: undefined, | |||
detail: `Opens all of the staged files in the repository` | |||
})); | |||
} | |||
} | |||
if (statuses.length) { | |||
items.splice(0, 0, new OpenStatusFilesCommandQuickPickItem(statuses.filter(_ => _.status !== 'D'))); | |||
} | |||
if (goBackCommand) { | |||
items.splice(0, 0, goBackCommand); | |||
} | |||
return await window.showQuickPick(items, { | |||
matchOnDescription: true, | |||
placeHolder: statuses.length ? 'Repository has changes' : 'Repository has no changes', | |||
ignoreFocusOut: getQuickPickIgnoreFocusOut() | |||
} as QuickPickOptions); | |||
} | |||
} |