Skip to content

Commit a08c424

Browse files
authored
add context menu option to delete untracked files (#815)
1 parent 2b685a3 commit a08c424

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

src/commandsAndMenu.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export namespace CommandIDs {
7878
// Context menu commands
7979
export const gitFileDiff = 'git:context-diff';
8080
export const gitFileDiscard = 'git:context-discard';
81+
export const gitFileDelete = 'git:context-delete';
8182
export const gitFileOpen = 'git:context-open';
8283
export const gitFileUnstage = 'git:context-unstage';
8384
export const gitFileStage = 'git:context-stage';
@@ -478,6 +479,36 @@ export function addCommands(
478479
}
479480
});
480481

482+
commands.addCommand(CommandIDs.gitFileDelete, {
483+
label: 'Delete',
484+
caption: 'Delete this file',
485+
execute: async args => {
486+
const file: Git.IStatusFile = args as any;
487+
488+
const result = await showDialog({
489+
title: 'Delete File',
490+
body: (
491+
<span>
492+
Are you sure you want to permanently delete
493+
<b>{file.to}</b>? This action cannot be undone.
494+
</span>
495+
),
496+
buttons: [Dialog.cancelButton(), Dialog.warnButton({ label: 'Delete' })]
497+
});
498+
if (result.button.accept) {
499+
try {
500+
await app.commands.execute('docmanager:delete-file', {
501+
path: model.getRelativeFilePath(file.to)
502+
});
503+
} catch (reason) {
504+
showErrorMessage(`Deleting ${file.to} failed.`, reason, [
505+
Dialog.warnButton({ label: 'DISMISS' })
506+
]);
507+
}
508+
}
509+
}
510+
});
511+
481512
commands.addCommand(CommandIDs.gitFileDiscard, {
482513
label: 'Discard',
483514
caption: 'Discard recent changes of selected file',

src/components/FileList.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
8484
commands.push(
8585
CommandIDs.gitFileTrack,
8686
CommandIDs.gitIgnore,
87-
CommandIDs.gitIgnoreExtension
87+
CommandIDs.gitIgnoreExtension,
88+
CommandIDs.gitFileDelete
8889
);
8990
break;
9091
case 'staged':
@@ -125,7 +126,11 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
125126
const commands = [CommandIDs.gitFileOpen];
126127
switch (selectedFile.status) {
127128
case 'untracked':
128-
commands.push(CommandIDs.gitIgnore, CommandIDs.gitIgnoreExtension);
129+
commands.push(
130+
CommandIDs.gitIgnore,
131+
CommandIDs.gitIgnoreExtension,
132+
CommandIDs.gitFileDelete
133+
);
129134
break;
130135
default:
131136
commands.push(CommandIDs.gitFileDiscard, CommandIDs.gitFileDiff);

0 commit comments

Comments
 (0)