Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
protected async doDiscard(repository: Repository, change: GitFileChange) {
// Allow deletion, only iff the same file is not yet in the Git index.
if (await this.git.lsFiles(repository, change.uri, { errorUnmatch: true })) {
if (await this.confirm(change.uri)) {
try {
await this.git.unstage(repository, change.uri, { treeish: 'HEAD', reset: 'working-tree' });
} catch (error) {
this.gitErrorHandler.handleError(error);
}
}
} else {
await this.commandService.executeCommand(WorkspaceCommands.FILE_DELETE.id, new URI(change.uri));
}
}
protected async doDiscard(repository: Repository, change: GitFileChange) {
// Allow deletion, only iff the same file is not yet in the Git index.
if (await this.git.lsFiles(repository, change.uri, { errorUnmatch: true })) {
if (await this.confirm(change.uri)) {
try {
await this.git.unstage(repository, change.uri, { treeish: 'HEAD', reset: 'working-tree' });
} catch (error) {
this.gitErrorHandler.handleError(error);
}
}
} else {
await this.commandService.executeCommand(WorkspaceCommands.FILE_DELETE.id, new URI(change.uri));
}
if (this.listContainer) {
this.listContainer.focus();
}
}
const { repository } = this;
const status = this.getStatus();
if (!(status && status.changes.some(change => change.uri === uri))) {
return;
}
// Allow deletion, only iff the same file is not yet in the Git index.
if (await this.git.lsFiles(repository, uri, { errorUnmatch: true })) {
if (await this.confirm(uri)) {
try {
await this.git.unstage(repository, uri, { treeish: 'HEAD', reset: 'working-tree' });
} catch (error) {
this.gitErrorHandler.handleError(error);
}
}
} else {
await this.commands.executeCommand(WorkspaceCommands.FILE_DELETE.id, new URI(uri));
}
}
protected async buildWorkspaceId(workspace: FileStat, roots: FileStat[]): Promise {
const homeDir = await this.getUserHomeDir();
const untitledWorkspace = getTemporaryWorkspaceFileUri(new URI(homeDir));
if (untitledWorkspace.toString() === workspace.uri) {
// if workspace is temporary
// then let create a storage path for each set of workspace roots
const rootsStr = roots.map(root => root.uri).sort().join(',');
return crypto.createHash('md5').update(rootsStr).digest('hex');
} else {
const uri = new URI(workspace.uri);
let displayName = uri.displayName;
if ((!workspace || !workspace.isDirectory) && (displayName.endsWith(`.${THEIA_EXT}`) || displayName.endsWith(`.${VSCODE_EXT}`))) {
displayName = displayName.slice(0, displayName.lastIndexOf('.'));
}
return crypto.createHash('md5').update(uri.toString()).digest('hex');
}
// registry.registerMenuAction([CONTEXT_MENU_PATH, CUT_MENU_GROUP], {
// commandId: Commands.FILE_CUT
// });
registry.registerMenuAction(NavigatorContextMenu.CLIPBOARD, {
commandId: CommonCommands.COPY.id
});
registry.registerMenuAction(NavigatorContextMenu.CLIPBOARD, {
commandId: CommonCommands.PASTE.id
});
registry.registerMenuAction(NavigatorContextMenu.MOVE, {
commandId: WorkspaceCommands.FILE_RENAME.id
});
registry.registerMenuAction(NavigatorContextMenu.MOVE, {
commandId: WorkspaceCommands.FILE_DELETE.id
});
registry.registerMenuAction(NavigatorContextMenu.NEW, {
commandId: WorkspaceCommands.NEW_FILE.id
});
registry.registerMenuAction(NavigatorContextMenu.NEW, {
commandId: WorkspaceCommands.NEW_FOLDER.id
});
registry.registerMenuAction(NavigatorContextMenu.DIFF, {
commandId: WorkspaceCommands.FILE_COMPARE.id
});
}
}
registerMenus(registry: MenuModelRegistry) {
registry.registerMenuAction(NavigatorContextMenu.OPEN, {
commandId: WorkspaceCommands.FILE_OPEN.id
});
registry.registerSubmenu(NavigatorContextMenu.OPEN_WITH, 'Open With');
this.openerService.getOpeners().then(openers => {
for (const opener of openers) {
const openWithCommand = WorkspaceCommands.FILE_OPEN_WITH(opener);
registry.registerMenuAction(NavigatorContextMenu.OPEN_WITH, {
commandId: openWithCommand.id
});
}
});
// registry.registerMenuAction([CONTEXT_MENU_PATH, CUT_MENU_GROUP], {
// commandId: Commands.FILE_CUT
// });
registry.registerMenuAction(NavigatorContextMenu.CLIPBOARD, {
commandId: CommonCommands.COPY.id
registerKeybindings(registry: KeybindingRegistry): void {
super.registerKeybindings(registry);
registry.registerKeybinding({
command: FileNavigatorCommands.REVEAL_IN_NAVIGATOR.id,
keybinding: 'alt+r'
});
registry.registerKeybinding({
command: WorkspaceCommands.FILE_DELETE.id,
keybinding: 'del',
context: NavigatorKeybindingContexts.navigatorActive
});
if (isOSX) {
registry.registerKeybinding({
command: WorkspaceCommands.FILE_DELETE.id,
keybinding: 'cmd+backspace',
context: NavigatorKeybindingContexts.navigatorActive
});
}
registry.registerKeybinding({
command: WorkspaceCommands.FILE_RENAME.id,
keybinding: 'f2',
context: NavigatorKeybindingContexts.navigatorActive
});
registry.registerKeybinding({
command: FileNavigatorCommands.TOGGLE_HIDDEN_FILES.id,
keybinding: 'ctrlcmd+i',
context: NavigatorKeybindingContexts.navigatorActive
});
registerKeybindings(registry: KeybindingRegistry): void {
super.registerKeybindings(registry);
registry.registerKeybinding({
command: FileNavigatorCommands.REVEAL_IN_NAVIGATOR.id,
keybinding: 'alt+r'
});
registry.registerKeybinding({
command: WorkspaceCommands.FILE_DELETE.id,
keybinding: 'del',
context: NavigatorKeybindingContexts.navigatorActive
});
if (isOSX) {
registry.registerKeybinding({
command: WorkspaceCommands.FILE_DELETE.id,
keybinding: 'cmd+backspace',
context: NavigatorKeybindingContexts.navigatorActive
});
}
registry.registerKeybinding({
command: WorkspaceCommands.FILE_RENAME.id,
keybinding: 'f2',
context: NavigatorKeybindingContexts.navigatorActive
});
execute: () => commands.executeCommand(WorkspaceCommands.OPEN_FOLDER.id)
});
protected doOpenFolder(): void {
this.commandService.executeCommand(WorkspaceCommands.OPEN_FOLDER.id);
}