提交 9aaeb198 编写于 作者: N NKumar2 提交者: Bugra Cuhadaroglu

Registering and handling commad

上级 2bad7de4
......@@ -211,6 +211,11 @@
"command": "git.showOutput",
"title": "%command.showOutput%",
"category": "Git"
},
{
"command": "git.ignore",
"title": "%command.ignore%",
"category": "Git"
}
],
"menus": {
......@@ -525,6 +530,11 @@
"command": "git.stage",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == workingTree",
"group": "inline"
},
{
"command": "git.ignore",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == workingTree",
"group": "1_modification@3"
}
],
"editor/title": [
......
......@@ -29,6 +29,7 @@
"command.sync": "Sync",
"command.publish": "Publish Branch",
"command.showOutput": "Show Git Output",
"command.ignore": "Ignore",
"config.enabled": "Whether git is enabled",
"config.path": "Path to the git executable",
"config.autorefresh": "Whether auto refreshing is enabled",
......
......@@ -879,6 +879,18 @@ export class CommandCenter {
this.outputChannel.show();
}
@command('git.ignore')
async ignore(...resourceStates: SourceControlResourceState[]): Promise<void> {
const resources = resourceStates
.filter(s => s instanceof Resource) as Resource[];
if (!resources.length) {
return;
}
await this.model.ignore(resources);
}
private createCommand(id: string, key: string, method: Function, skipModelCheck: boolean): (...args: any[]) => any {
const result = (...args) => {
if (!skipModelCheck && !this.model) {
......
......@@ -17,6 +17,8 @@ const timeout = (millis: number) => new Promise(c => setTimeout(c, millis));
const localize = nls.loadMessageBundle();
const iconsRootPath = path.join(path.dirname(__dirname), 'resources', 'icons');
const ignoreFileName = '.gitignore';
function getIconUri(iconName: string, theme: string): Uri {
return Uri.file(path.join(iconsRootPath, theme, `${iconName}.svg`));
}
......@@ -211,7 +213,8 @@ export enum Operation {
Show = 1 << 13,
Stage = 1 << 14,
GetCommitTemplate = 1 << 15,
DeleteBranch = 1 << 16
DeleteBranch = 1 << 16,
Ignore = 1 << 17
}
// function getOperationName(operation: Operation): string {
......@@ -525,6 +528,23 @@ export class Model implements Disposable {
return await this.run(Operation.GetCommitTemplate, async () => this.repository.getCommitTemplate());
}
async ignore(files: Resource[]): Promise<void> {
const newLineChar = '\n';
return await this.run(Operation.Ignore, async () => {
const ignoreFile = `${this.repository.root}${path.sep}${ignoreFileName}`;
let textToAppend = files
.map(file => path.relative(this.repository.root, file.resourceUri.fsPath).replace(/\\/g, '/'))
.join(newLineChar);
// Append in new line.
textToAppend = newLineChar + textToAppend;
createOrAppendFile(ignoreFile, textToAppend);
});
}
private async run<T>(operation: Operation, runOperation: () => Promise<T> = () => Promise.resolve<any>(null)): Promise<T> {
const run = async () => {
this._operations = this._operations.start(operation);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册