mirror of
https://github.com/microsoft/vscode.git
synced 2026-10-02 14:04:01 +01:00
remove root folders multi select aware and move helpr commandArgument methods to files.ts
This commit is contained in:
@@ -27,9 +27,6 @@ import { isLinux } from 'vs/base/common/platform';
|
||||
export const ADD_ROOT_FOLDER_COMMAND_ID = 'workbench.command.addRootFolder';
|
||||
export const ADD_ROOT_FOLDER_LABEL = nls.localize('addFolderToWorkspace', "Add Folder to Workspace...");
|
||||
|
||||
export const REMOVE_ROOT_FOLDER_COMMAND_ID = 'workbench.command.removeRootFolder';
|
||||
export const REMOVE_ROOT_FOLDER_LABEL = nls.localize('removeFolderFromWorkspace', "Remove Folder from Workspace");
|
||||
|
||||
export const PICK_WORKSPACE_FOLDER_COMMAND_ID = '_workbench.pickWorkspaceFolder';
|
||||
|
||||
function pickFolders(buttonLabel: string, title: string, windowService: IWindowService, contextService: IWorkspaceContextService, historyService: IHistoryService): TPromise<string[]> {
|
||||
@@ -158,14 +155,6 @@ CommandsRegistry.registerCommand({
|
||||
}
|
||||
});
|
||||
|
||||
CommandsRegistry.registerCommand({
|
||||
id: REMOVE_ROOT_FOLDER_COMMAND_ID,
|
||||
handler: (accessor, resource: URI) => {
|
||||
const workspaceEditingService = accessor.get(IWorkspaceEditingService);
|
||||
return workspaceEditingService.removeFolders([resource]);
|
||||
}
|
||||
});
|
||||
|
||||
CommandsRegistry.registerCommand(PICK_WORKSPACE_FOLDER_COMMAND_ID, function (accessor, args?: [IPickOptions, CancellationToken]) {
|
||||
const contextService = accessor.get(IWorkspaceContextService);
|
||||
const quickOpenService = accessor.get(IQuickOpenService);
|
||||
|
||||
@@ -25,7 +25,7 @@ import { ResourceContextKey } from 'vs/workbench/common/resources';
|
||||
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||
import { IFileService } from 'vs/platform/files/common/files';
|
||||
import { IListService } from 'vs/platform/list/browser/listService';
|
||||
import { getResourceForCommand } from 'vs/workbench/parts/files/electron-browser/fileCommands';
|
||||
import { getResourceForCommand } from 'vs/workbench/parts/files/browser/files';
|
||||
|
||||
if (env.isWindows) {
|
||||
registerSingleton(ITerminalService, WinTerminalService);
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import URI from 'vs/base/common/uri';
|
||||
import { IListService } from 'vs/platform/list/browser/listService';
|
||||
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { FileStat, OpenEditor } from 'vs/workbench/parts/files/common/explorerModel';
|
||||
import { toResource } from 'vs/workbench/common/editor';
|
||||
import { Tree } from 'vs/base/parts/tree/browser/treeImpl';
|
||||
|
||||
// Commands can get exeucted from a command pallete, from a context menu or from some list using a keybinding
|
||||
// To cover all these cases we need to properly compute the resource on which the command is being executed
|
||||
export function getResourceForCommand(resource: URI, listService: IListService, editorService: IWorkbenchEditorService): URI {
|
||||
if (URI.isUri(resource)) {
|
||||
return resource;
|
||||
}
|
||||
|
||||
const list = listService.lastFocusedList;
|
||||
if (list && list.isDOMFocused()) {
|
||||
const focus = list.getFocus();
|
||||
if (focus instanceof FileStat) {
|
||||
return focus.resource;
|
||||
} else if (focus instanceof OpenEditor) {
|
||||
return focus.editorInput.getResource();
|
||||
}
|
||||
}
|
||||
|
||||
return toResource(editorService.getActiveEditorInput(), { supportSideBySide: true });
|
||||
}
|
||||
|
||||
export function getResourcesForCommand(resource: URI, listService: IListService, editorService: IWorkbenchEditorService): URI[] {
|
||||
const list = listService.lastFocusedList;
|
||||
if (list && list.isDOMFocused() && list instanceof Tree) {
|
||||
const selection = list.getSelection();
|
||||
if (selection && selection.length > 1) {
|
||||
return selection.map(fs => fs.resource);
|
||||
}
|
||||
}
|
||||
|
||||
const result = getResourceForCommand(resource, listService, editorService);
|
||||
return !!result ? [result] : [];
|
||||
}
|
||||
@@ -11,13 +11,13 @@ import { revertLocalChangesCommand, acceptLocalChangesCommand, CONFLICT_RESOLUTI
|
||||
import { SyncActionDescriptor, MenuId, MenuRegistry } from 'vs/platform/actions/common/actions';
|
||||
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions';
|
||||
import { KeyMod, KeyChord, KeyCode } from 'vs/base/common/keyCodes';
|
||||
import { openWindowCommand, REVEAL_IN_OS_COMMAND_ID, COPY_PATH_COMMAND_ID, REVEAL_IN_EXPLORER_COMMAND_ID, OPEN_TO_SIDE_COMMAND_ID, REVERT_FILE_COMMAND_ID, SAVE_FILE_COMMAND_ID, SAVE_FILE_LABEL, SAVE_FILE_AS_COMMAND_ID, SAVE_FILE_AS_LABEL, SAVE_ALL_IN_GROUP_COMMAND_ID, OpenEditorsGroupContext, COMPARE_WITH_SAVED_COMMAND_ID, COMPARE_RESOURCE_COMMAND_ID, SELECT_FOR_COMPARE_COMMAND_ID, ResourceSelectedForCompareContext, REVEAL_IN_OS_LABEL, DirtyEditorContext, COMPARE_SELECTED_COMMAND_ID } from 'vs/workbench/parts/files/electron-browser/fileCommands';
|
||||
import { openWindowCommand, REVEAL_IN_OS_COMMAND_ID, COPY_PATH_COMMAND_ID, REVEAL_IN_EXPLORER_COMMAND_ID, OPEN_TO_SIDE_COMMAND_ID, REVERT_FILE_COMMAND_ID, SAVE_FILE_COMMAND_ID, SAVE_FILE_LABEL, SAVE_FILE_AS_COMMAND_ID, SAVE_FILE_AS_LABEL, SAVE_ALL_IN_GROUP_COMMAND_ID, OpenEditorsGroupContext, COMPARE_WITH_SAVED_COMMAND_ID, COMPARE_RESOURCE_COMMAND_ID, SELECT_FOR_COMPARE_COMMAND_ID, ResourceSelectedForCompareContext, REVEAL_IN_OS_LABEL, DirtyEditorContext, COMPARE_SELECTED_COMMAND_ID, REMOVE_ROOT_FOLDER_COMMAND_ID, REMOVE_ROOT_FOLDER_LABEL } from 'vs/workbench/parts/files/electron-browser/fileCommands';
|
||||
import { CommandsRegistry, ICommandHandler } from 'vs/platform/commands/common/commands';
|
||||
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||
import { isWindows, isMacintosh } from 'vs/base/common/platform';
|
||||
import { FilesExplorerFocusCondition, ExplorerRootContext, ExplorerFolderContext } from 'vs/workbench/parts/files/common/files';
|
||||
import { ADD_ROOT_FOLDER_COMMAND_ID, ADD_ROOT_FOLDER_LABEL, REMOVE_ROOT_FOLDER_COMMAND_ID, REMOVE_ROOT_FOLDER_LABEL } from 'vs/workbench/browser/actions/workspaceCommands';
|
||||
import { ADD_ROOT_FOLDER_COMMAND_ID, ADD_ROOT_FOLDER_LABEL } from 'vs/workbench/browser/actions/workspaceCommands';
|
||||
import { CLOSE_UNMODIFIED_EDITORS_COMMAND_ID, CLOSE_EDITORS_IN_GROUP_COMMAND_ID, CLOSE_EDITOR_COMMAND_ID, CLOSE_OTHER_EDITORS_IN_GROUP_COMMAND_ID } from 'vs/workbench/browser/parts/editor/editorCommands';
|
||||
import { OPEN_FOLDER_SETTINGS_COMMAND, OPEN_FOLDER_SETTINGS_LABEL } from 'vs/workbench/parts/preferences/browser/preferencesActions';
|
||||
import { AutoSaveContext } from 'vs/workbench/services/textfile/common/textfiles';
|
||||
|
||||
@@ -38,8 +38,9 @@ import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRe
|
||||
import { KeyMod, KeyCode, KeyChord } from 'vs/base/common/keyCodes';
|
||||
import { isWindows, isMacintosh } from 'vs/base/common/platform';
|
||||
import { ITextModelService } from 'vs/editor/common/services/resolverService';
|
||||
import { FileStat, OpenEditor } from 'vs/workbench/parts/files/common/explorerModel';
|
||||
import { sequence } from 'vs/base/common/async';
|
||||
import { getResourceForCommand, getResourcesForCommand } from 'vs/workbench/parts/files/browser/files';
|
||||
import { IWorkspaceEditingService } from 'vs/workbench/services/workspace/common/workspaceEditing';
|
||||
|
||||
// Commands
|
||||
|
||||
@@ -72,44 +73,14 @@ export const OpenEditorsGroupContext = new RawContextKey<boolean>('groupFocusedI
|
||||
export const DirtyEditorContext = new RawContextKey<boolean>('dirtyEditor', false);
|
||||
export const ResourceSelectedForCompareContext = new RawContextKey<boolean>('resourceSelectedForCompare', false);
|
||||
|
||||
export const REMOVE_ROOT_FOLDER_COMMAND_ID = 'workbench.command.removeRootFolder';
|
||||
export const REMOVE_ROOT_FOLDER_LABEL = nls.localize('removeFolderFromWorkspace', "Remove Folder from Workspace");
|
||||
|
||||
export const openWindowCommand = (accessor: ServicesAccessor, paths: string[], forceNewWindow: boolean) => {
|
||||
const windowsService = accessor.get(IWindowsService);
|
||||
windowsService.openWindow(paths, { forceNewWindow });
|
||||
};
|
||||
|
||||
// Commands can get exeucted from a command pallete, from a context menu or from some list using a keybinding
|
||||
// To cover all these cases we need to properly compute the resource on which the command is being executed
|
||||
export function getResourceForCommand(resource: URI, listService: IListService, editorService: IWorkbenchEditorService): URI {
|
||||
if (URI.isUri(resource)) {
|
||||
return resource;
|
||||
}
|
||||
|
||||
const list = listService.lastFocusedList;
|
||||
if (list && list.isDOMFocused()) {
|
||||
const focus = list.getFocus();
|
||||
if (focus instanceof FileStat) {
|
||||
return focus.resource;
|
||||
} else if (focus instanceof OpenEditor) {
|
||||
return focus.editorInput.getResource();
|
||||
}
|
||||
}
|
||||
|
||||
return toResource(editorService.getActiveEditorInput(), { supportSideBySide: true });
|
||||
}
|
||||
|
||||
export function getResourcesForCommand(resource: URI, listService: IListService, editorService: IWorkbenchEditorService): URI[] {
|
||||
const list = listService.lastFocusedList;
|
||||
if (list && list.isDOMFocused() && list instanceof Tree) {
|
||||
const selection = list.getSelection();
|
||||
if (selection && selection.length > 1) {
|
||||
return selection.map(fs => fs.resource);
|
||||
}
|
||||
}
|
||||
|
||||
const result = getResourceForCommand(resource, listService, editorService);
|
||||
return !!result ? [result] : [];
|
||||
}
|
||||
|
||||
function save(resource: URI, isSaveAs: boolean, editorService: IWorkbenchEditorService, fileService: IFileService, untitledEditorService: IUntitledEditorService,
|
||||
textFileService: ITextFileService, editorGroupService: IEditorGroupService): TPromise<any> {
|
||||
|
||||
@@ -542,3 +513,18 @@ CommandsRegistry.registerCommand({
|
||||
return saveAll(false, accessor.get(IWorkbenchEditorService), accessor.get(IUntitledEditorService), accessor.get(ITextFileService), accessor.get(IEditorGroupService));
|
||||
}
|
||||
});
|
||||
|
||||
CommandsRegistry.registerCommand({
|
||||
id: REMOVE_ROOT_FOLDER_COMMAND_ID,
|
||||
handler: (accessor, resource: URI) => {
|
||||
const workspaceEditingService = accessor.get(IWorkspaceEditingService);
|
||||
const contextService = accessor.get(IWorkspaceContextService);
|
||||
const workspace = contextService.getWorkspace();
|
||||
const resources = getResourcesForCommand(resource, accessor.get(IListService), accessor.get(IWorkbenchEditorService)).filter(r =>
|
||||
// Need to verify resources are workspaces since multi selection can trigger this command on some non workspace resources
|
||||
workspace.folders.some(f => f.uri.toString() === r.toString())
|
||||
);
|
||||
|
||||
return workspaceEditingService.removeFolders(resources);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -47,10 +47,10 @@ import URI from 'vs/base/common/uri';
|
||||
import { relative } from 'path';
|
||||
import { dirname } from 'vs/base/common/resources';
|
||||
import { ResourceContextKey } from 'vs/workbench/common/resources';
|
||||
import { getResourcesForCommand } from 'vs/workbench/parts/files/electron-browser/fileCommands';
|
||||
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { IFileService } from 'vs/platform/files/common/files';
|
||||
import { distinct } from 'vs/base/common/arrays';
|
||||
import { getResourcesForCommand } from 'vs/workbench/parts/files/browser/files';
|
||||
|
||||
registerSingleton(ISearchWorkbenchService, SearchWorkbenchService);
|
||||
replaceContributions();
|
||||
|
||||
Reference in New Issue
Block a user