debt - convert all workspace actions to action2
This commit is contained in:
parent
6c4f2129ee
commit
a3cbe52139
3 changed files with 129 additions and 130 deletions
|
@ -3,18 +3,17 @@
|
|||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { Action } from 'vs/base/common/actions';
|
||||
import { localize } from 'vs/nls';
|
||||
import { ITelemetryData } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { IWorkspaceContextService, WorkbenchState, IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
|
||||
import { IWorkspaceEditingService } from 'vs/workbench/services/workspaces/common/workspaceEditing';
|
||||
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { ICommandService, CommandsRegistry } from 'vs/platform/commands/common/commands';
|
||||
import { ICommandService } from 'vs/platform/commands/common/commands';
|
||||
import { ADD_ROOT_FOLDER_COMMAND_ID, ADD_ROOT_FOLDER_LABEL, PICK_WORKSPACE_FOLDER_COMMAND_ID } from 'vs/workbench/browser/actions/workspaceCommands';
|
||||
import { IDialogService, IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
|
||||
import { MenuRegistry, MenuId, Action2, registerAction2, ILocalizedString } from 'vs/platform/actions/common/actions';
|
||||
import { EmptyWorkspaceSupportContext, WorkbenchStateContext, WorkspaceFolderCountContext } from 'vs/workbench/browser/contextkeys';
|
||||
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
|
||||
import Severity from 'vs/base/common/severity';
|
||||
import { IHostService } from 'vs/workbench/services/host/browser/host';
|
||||
import { KeyChord, KeyCode, KeyMod } from 'vs/base/common/keyCodes';
|
||||
|
@ -22,82 +21,111 @@ import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
|
|||
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
|
||||
import { IWorkspacesService, hasWorkspaceFileExtension } from 'vs/platform/workspaces/common/workspaces';
|
||||
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||
import { IsMacNativeContext } from 'vs/platform/contextkey/common/contextkeys';
|
||||
|
||||
const workspacesCategory: ILocalizedString = { value: localize('workspaces', "Workspaces"), original: 'Workspaces' };
|
||||
const fileCategory = { value: localize('filesCategory', "File"), original: 'File' };
|
||||
|
||||
export class OpenFileAction extends Action {
|
||||
export class OpenFileAction extends Action2 {
|
||||
|
||||
static readonly ID = 'workbench.action.files.openFile';
|
||||
static readonly LABEL = localize('openFile', "Open File...");
|
||||
|
||||
constructor(
|
||||
id: string,
|
||||
label: string,
|
||||
@IFileDialogService private readonly dialogService: IFileDialogService
|
||||
) {
|
||||
super(id, label);
|
||||
constructor() {
|
||||
super({
|
||||
id: OpenFileAction.ID,
|
||||
title: { value: localize('openFile', "Open File..."), original: 'Open File...' },
|
||||
category: fileCategory,
|
||||
f1: true,
|
||||
precondition: IsMacNativeContext.toNegated(),
|
||||
keybinding: {
|
||||
weight: KeybindingWeight.WorkbenchContrib,
|
||||
when: IsMacNativeContext.toNegated(),
|
||||
primary: KeyMod.CtrlCmd | KeyCode.KEY_O
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
override run(event?: unknown, data?: ITelemetryData): Promise<void> {
|
||||
return this.dialogService.pickFileAndOpen({ forceNewWindow: false, telemetryExtraData: data });
|
||||
override async run(accessor: ServicesAccessor, data?: ITelemetryData): Promise<void> {
|
||||
const fileDialogService = accessor.get(IFileDialogService);
|
||||
|
||||
return fileDialogService.pickFileAndOpen({ forceNewWindow: false, telemetryExtraData: data });
|
||||
}
|
||||
}
|
||||
|
||||
export class OpenFolderAction extends Action {
|
||||
export class OpenFolderAction extends Action2 {
|
||||
|
||||
static readonly ID = 'workbench.action.files.openFolder';
|
||||
static readonly LABEL = localize('openFolder', "Open Folder...");
|
||||
|
||||
constructor(
|
||||
id: string,
|
||||
label: string,
|
||||
@IFileDialogService private readonly dialogService: IFileDialogService
|
||||
) {
|
||||
super(id, label);
|
||||
constructor() {
|
||||
super({
|
||||
id: OpenFolderAction.ID,
|
||||
title: { value: localize('openFolder', "Open Folder..."), original: 'Open Folder...' },
|
||||
category: fileCategory,
|
||||
f1: true,
|
||||
precondition: IsMacNativeContext.toNegated(),
|
||||
keybinding: {
|
||||
weight: KeybindingWeight.WorkbenchContrib,
|
||||
when: IsMacNativeContext.toNegated(),
|
||||
primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_O)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
override run(event?: unknown, data?: ITelemetryData): Promise<void> {
|
||||
return this.dialogService.pickFolderAndOpen({ forceNewWindow: false, telemetryExtraData: data });
|
||||
override async run(accessor: ServicesAccessor, data?: ITelemetryData): Promise<void> {
|
||||
const fileDialogService = accessor.get(IFileDialogService);
|
||||
|
||||
return fileDialogService.pickFolderAndOpen({ forceNewWindow: false, telemetryExtraData: data });
|
||||
}
|
||||
}
|
||||
|
||||
export class OpenFileFolderAction extends Action {
|
||||
export class OpenFileFolderAction extends Action2 {
|
||||
|
||||
static readonly ID = 'workbench.action.files.openFileFolder';
|
||||
static readonly LABEL = localize('openFileFolder', "Open...");
|
||||
static readonly LABEL: ILocalizedString = { value: localize('openFileFolder', "Open..."), original: 'Open...' };
|
||||
|
||||
constructor(
|
||||
id: string,
|
||||
label: string,
|
||||
@IFileDialogService private readonly dialogService: IFileDialogService
|
||||
) {
|
||||
super(id, label);
|
||||
constructor() {
|
||||
super({
|
||||
id: OpenFileFolderAction.ID,
|
||||
title: OpenFileFolderAction.LABEL,
|
||||
category: fileCategory,
|
||||
f1: true,
|
||||
precondition: IsMacNativeContext,
|
||||
keybinding: {
|
||||
weight: KeybindingWeight.WorkbenchContrib,
|
||||
when: IsMacNativeContext,
|
||||
primary: KeyMod.CtrlCmd | KeyCode.KEY_O
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
override run(event?: unknown, data?: ITelemetryData): Promise<void> {
|
||||
return this.dialogService.pickFileFolderAndOpen({ forceNewWindow: false, telemetryExtraData: data });
|
||||
override async run(accessor: ServicesAccessor, data?: ITelemetryData): Promise<void> {
|
||||
const fileDialogService = accessor.get(IFileDialogService);
|
||||
|
||||
return fileDialogService.pickFileFolderAndOpen({ forceNewWindow: false, telemetryExtraData: data });
|
||||
}
|
||||
}
|
||||
|
||||
export class OpenWorkspaceAction extends Action {
|
||||
class OpenWorkspaceAction extends Action2 {
|
||||
|
||||
static readonly ID = 'workbench.action.openWorkspace';
|
||||
static readonly LABEL = localize('openWorkspaceAction', "Open Workspace...");
|
||||
|
||||
constructor(
|
||||
id: string,
|
||||
label: string,
|
||||
@IFileDialogService private readonly dialogService: IFileDialogService
|
||||
) {
|
||||
super(id, label);
|
||||
constructor() {
|
||||
super({
|
||||
id: OpenWorkspaceAction.ID,
|
||||
title: { value: localize('openWorkspaceAction', "Open Workspace..."), original: 'Open Workspace...' },
|
||||
category: fileCategory,
|
||||
f1: true
|
||||
});
|
||||
}
|
||||
|
||||
override run(event?: unknown, data?: ITelemetryData): Promise<void> {
|
||||
return this.dialogService.pickWorkspaceAndOpen({ telemetryExtraData: data });
|
||||
override async run(accessor: ServicesAccessor, data?: ITelemetryData): Promise<void> {
|
||||
const fileDialogService = accessor.get(IFileDialogService);
|
||||
|
||||
return fileDialogService.pickWorkspaceAndOpen({ telemetryExtraData: data });
|
||||
}
|
||||
}
|
||||
|
||||
export class CloseWorkspaceAction extends Action2 {
|
||||
class CloseWorkspaceAction extends Action2 {
|
||||
|
||||
static readonly ID = 'workbench.action.closeFolder';
|
||||
|
||||
|
@ -130,26 +158,27 @@ export class CloseWorkspaceAction extends Action2 {
|
|||
}
|
||||
}
|
||||
|
||||
export class OpenWorkspaceConfigFileAction extends Action {
|
||||
class OpenWorkspaceConfigFileAction extends Action2 {
|
||||
|
||||
static readonly ID = 'workbench.action.openWorkspaceConfigFile';
|
||||
static readonly LABEL = localize('openWorkspaceConfigFile', "Open Workspace Configuration File");
|
||||
|
||||
constructor(
|
||||
id: string,
|
||||
label: string,
|
||||
@IWorkspaceContextService private readonly workspaceContextService: IWorkspaceContextService,
|
||||
@IEditorService private readonly editorService: IEditorService
|
||||
) {
|
||||
super(id, label);
|
||||
|
||||
this.enabled = !!this.workspaceContextService.getWorkspace().configuration;
|
||||
constructor() {
|
||||
super({
|
||||
id: OpenWorkspaceConfigFileAction.ID,
|
||||
title: { value: localize('openWorkspaceConfigFile', "Open Workspace Configuration File"), original: 'Open Workspace Configuration File' },
|
||||
category: workspacesCategory,
|
||||
f1: true,
|
||||
precondition: WorkbenchStateContext.isEqualTo('workspace')
|
||||
});
|
||||
}
|
||||
|
||||
override async run(): Promise<void> {
|
||||
const configuration = this.workspaceContextService.getWorkspace().configuration;
|
||||
override async run(accessor: ServicesAccessor): Promise<void> {
|
||||
const contextService = accessor.get(IWorkspaceContextService);
|
||||
const editorService = accessor.get(IEditorService);
|
||||
|
||||
const configuration = contextService.getWorkspace().configuration;
|
||||
if (configuration) {
|
||||
await this.editorService.openEditor({ resource: configuration, options: { pinned: true } });
|
||||
await editorService.openEditor({ resource: configuration, options: { pinned: true } });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -267,16 +296,17 @@ class DuplicateWorkspaceInNewWindowAction extends Action2 {
|
|||
|
||||
registerAction2(AddRootFolderAction);
|
||||
registerAction2(RemoveRootFolderAction);
|
||||
registerAction2(OpenFileAction);
|
||||
registerAction2(OpenFolderAction);
|
||||
registerAction2(OpenFileFolderAction);
|
||||
registerAction2(OpenWorkspaceAction);
|
||||
registerAction2(OpenWorkspaceConfigFileAction);
|
||||
registerAction2(CloseWorkspaceAction);
|
||||
registerAction2(SaveWorkspaceAsAction);
|
||||
registerAction2(DuplicateWorkspaceInNewWindowAction);
|
||||
|
||||
// --- Menu Registration
|
||||
|
||||
CommandsRegistry.registerCommand(OpenWorkspaceConfigFileAction.ID, serviceAccessor => {
|
||||
serviceAccessor.get(IInstantiationService).createInstance(OpenWorkspaceConfigFileAction, OpenWorkspaceConfigFileAction.ID, OpenWorkspaceConfigFileAction.LABEL).run();
|
||||
});
|
||||
|
||||
MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
|
||||
group: '3_workspace',
|
||||
command: {
|
||||
|
@ -306,13 +336,43 @@ MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
|
|||
when: EmptyWorkspaceSupportContext
|
||||
});
|
||||
|
||||
MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
|
||||
MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
|
||||
group: '2_open',
|
||||
command: {
|
||||
id: OpenWorkspaceConfigFileAction.ID,
|
||||
title: { value: OpenWorkspaceConfigFileAction.LABEL, original: 'Open Workspace Configuration File' },
|
||||
category: workspacesCategory
|
||||
id: OpenFileAction.ID,
|
||||
title: localize({ key: 'miOpenFile', comment: ['&& denotes a mnemonic'] }, "&&Open File...")
|
||||
},
|
||||
when: WorkbenchStateContext.isEqualTo('workspace')
|
||||
order: 1,
|
||||
when: IsMacNativeContext.toNegated()
|
||||
});
|
||||
|
||||
MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
|
||||
group: '2_open',
|
||||
command: {
|
||||
id: OpenFolderAction.ID,
|
||||
title: localize({ key: 'miOpenFolder', comment: ['&& denotes a mnemonic'] }, "Open &&Folder...")
|
||||
},
|
||||
order: 2,
|
||||
when: IsMacNativeContext.toNegated()
|
||||
});
|
||||
|
||||
MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
|
||||
group: '2_open',
|
||||
command: {
|
||||
id: OpenFileFolderAction.ID,
|
||||
title: localize({ key: 'miOpen', comment: ['&& denotes a mnemonic'] }, "&&Open...")
|
||||
},
|
||||
order: 1,
|
||||
when: IsMacNativeContext
|
||||
});
|
||||
|
||||
MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
|
||||
group: '2_open',
|
||||
command: {
|
||||
id: OpenWorkspaceAction.ID,
|
||||
title: localize({ key: 'miOpenWorkspace', comment: ['&& denotes a mnemonic'] }, "Open Wor&&kspace...")
|
||||
},
|
||||
order: 3
|
||||
});
|
||||
|
||||
MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
|
||||
|
|
|
@ -14,7 +14,6 @@ import { openWindowCommand, COPY_PATH_COMMAND_ID, REVEAL_IN_EXPLORER_COMMAND_ID,
|
|||
import { CommandsRegistry, ICommandHandler } from 'vs/platform/commands/common/commands';
|
||||
import { ContextKeyExpr, ContextKeyExpression } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||
import { isMacintosh, isWeb } from 'vs/base/common/platform';
|
||||
import { FilesExplorerFocusCondition, ExplorerRootContext, ExplorerFolderContext, ExplorerResourceNotReadonlyContext, ExplorerResourceCut, ExplorerResourceMoveableToTrash, ExplorerViewletVisibleContext, ExplorerResourceAvailableEditorIdsContext } from 'vs/workbench/contrib/files/common/files';
|
||||
import { ADD_ROOT_FOLDER_COMMAND_ID, ADD_ROOT_FOLDER_LABEL } from 'vs/workbench/browser/actions/workspaceCommands';
|
||||
import { CLOSE_SAVED_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';
|
||||
|
@ -25,7 +24,6 @@ import { Schemas } from 'vs/base/common/network';
|
|||
import { DirtyWorkingCopiesContext, EmptyWorkspaceSupportContext, HasWebFileSystemAccess, WorkspaceFolderCountContext } from 'vs/workbench/browser/contextkeys';
|
||||
import { IsWebContext } from 'vs/platform/contextkey/common/contextkeys';
|
||||
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { OpenFileFolderAction, OpenFileAction, OpenFolderAction, OpenWorkspaceAction } from 'vs/workbench/browser/actions/workspaceActions';
|
||||
import { ActiveEditorCanRevertContext, ActiveEditorContext } from 'vs/workbench/common/editor';
|
||||
import { SidebarFocusContext } from 'vs/workbench/common/viewlet';
|
||||
import { ThemeIcon } from 'vs/platform/theme/common/themeService';
|
||||
|
@ -43,17 +41,6 @@ registry.registerWorkbenchAction(SyncActionDescriptor.from(CompareWithClipboardA
|
|||
registry.registerWorkbenchAction(SyncActionDescriptor.from(ToggleAutoSaveAction), 'File: Toggle Auto Save', category.value);
|
||||
registry.registerWorkbenchAction(SyncActionDescriptor.from(ShowOpenedFileInNewWindow, { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyCode.KEY_O) }), 'File: Open Active File in New Window', category.value, EmptyWorkspaceSupportContext);
|
||||
|
||||
const workspacesCategory = nls.localize('workspaces', "Workspaces");
|
||||
registry.registerWorkbenchAction(SyncActionDescriptor.from(OpenWorkspaceAction), 'Workspaces: Open Workspace...', workspacesCategory);
|
||||
|
||||
const fileCategory = nls.localize('file', "File");
|
||||
if (isMacintosh && !isWeb) {
|
||||
registry.registerWorkbenchAction(SyncActionDescriptor.from(OpenFileFolderAction, { primary: KeyMod.CtrlCmd | KeyCode.KEY_O }), 'File: Open...', fileCategory);
|
||||
} else {
|
||||
registry.registerWorkbenchAction(SyncActionDescriptor.from(OpenFileAction, { primary: KeyMod.CtrlCmd | KeyCode.KEY_O }), 'File: Open File...', fileCategory);
|
||||
registry.registerWorkbenchAction(SyncActionDescriptor.from(OpenFolderAction, { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_O) }), 'File: Open Folder...', fileCategory);
|
||||
}
|
||||
|
||||
// Commands
|
||||
CommandsRegistry.registerCommand('_files.windowOpen', openWindowCommand);
|
||||
CommandsRegistry.registerCommand('_files.newWindow', newWindowCommand);
|
||||
|
@ -635,44 +622,6 @@ MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
|
|||
order: 3
|
||||
});
|
||||
|
||||
if (isMacintosh && !isWeb) {
|
||||
MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
|
||||
group: '2_open',
|
||||
command: {
|
||||
id: OpenFileFolderAction.ID,
|
||||
title: nls.localize({ key: 'miOpen', comment: ['&& denotes a mnemonic'] }, "&&Open...")
|
||||
},
|
||||
order: 1
|
||||
});
|
||||
} else {
|
||||
MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
|
||||
group: '2_open',
|
||||
command: {
|
||||
id: OpenFileAction.ID,
|
||||
title: nls.localize({ key: 'miOpenFile', comment: ['&& denotes a mnemonic'] }, "&&Open File...")
|
||||
},
|
||||
order: 1
|
||||
});
|
||||
|
||||
MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
|
||||
group: '2_open',
|
||||
command: {
|
||||
id: OpenFolderAction.ID,
|
||||
title: nls.localize({ key: 'miOpenFolder', comment: ['&& denotes a mnemonic'] }, "Open &&Folder...")
|
||||
},
|
||||
order: 2
|
||||
});
|
||||
}
|
||||
|
||||
MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
|
||||
group: '2_open',
|
||||
command: {
|
||||
id: OpenWorkspaceAction.ID,
|
||||
title: nls.localize({ key: 'miOpenWorkspace', comment: ['&& denotes a mnemonic'] }, "Open Wor&&kspace...")
|
||||
},
|
||||
order: 3
|
||||
});
|
||||
|
||||
MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
|
||||
group: '5_autosave',
|
||||
command: {
|
||||
|
|
|
@ -10,7 +10,7 @@ import { MessageType } from 'vs/base/browser/ui/inputbox/inputBox';
|
|||
import { IIdentityProvider } from 'vs/base/browser/ui/list/list';
|
||||
import { Orientation } from 'vs/base/browser/ui/sash/sash';
|
||||
import { ITreeContextMenuEvent, ITreeElement } from 'vs/base/browser/ui/tree/tree';
|
||||
import { ActionRunner, IAction } from 'vs/base/common/actions';
|
||||
import { IAction } from 'vs/base/common/actions';
|
||||
import { Delayer } from 'vs/base/common/async';
|
||||
import { Color, RGBA } from 'vs/base/common/color';
|
||||
import * as errors from 'vs/base/common/errors';
|
||||
|
@ -1659,20 +1659,10 @@ export class SearchView extends ViewPane {
|
|||
const textEl = dom.append(this.searchWithoutFolderMessageElement,
|
||||
$('p', undefined, nls.localize('searchWithoutFolder', "You have not opened or specified a folder. Only open files are currently searched - ")));
|
||||
|
||||
const actionRunner = this.messageDisposables.add(new ActionRunner());
|
||||
const openFolderButton = this.messageDisposables.add(new SearchLinkButton(
|
||||
nls.localize('openFolder', "Open Folder"),
|
||||
() => {
|
||||
const action = env.isMacintosh ?
|
||||
this.instantiationService.createInstance(OpenFileFolderAction, OpenFileFolderAction.ID, OpenFileFolderAction.LABEL) :
|
||||
this.instantiationService.createInstance(OpenFolderAction, OpenFolderAction.ID, OpenFolderAction.LABEL);
|
||||
|
||||
actionRunner.run(action).then(() => {
|
||||
action.dispose();
|
||||
}, err => {
|
||||
action.dispose();
|
||||
errors.onUnexpectedError(err);
|
||||
});
|
||||
this.commandService.executeCommand(env.isMacintosh && env.isNative ? OpenFileFolderAction.ID : OpenFolderAction.ID).catch(err => errors.onUnexpectedError(err));
|
||||
}));
|
||||
dom.append(textEl, openFolderButton.element);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue