diff --git a/src/vs/workbench/contrib/files/browser/fileActions.contribution.ts b/src/vs/workbench/contrib/files/browser/fileActions.contribution.ts index a2b85639809bd..5ebfe7c291ccc 100644 --- a/src/vs/workbench/contrib/files/browser/fileActions.contribution.ts +++ b/src/vs/workbench/contrib/files/browser/fileActions.contribution.ts @@ -4,13 +4,11 @@ *--------------------------------------------------------------------------------------------*/ import * as nls from 'vs/nls'; -import { Registry } from 'vs/platform/registry/common/platform'; -import { ToggleAutoSaveAction, FocusFilesExplorer, GlobalCompareResourcesAction, ShowActiveFileInExplorer, CompareWithClipboardAction, NEW_FILE_COMMAND_ID, NEW_FILE_LABEL, NEW_FOLDER_COMMAND_ID, NEW_FOLDER_LABEL, TRIGGER_RENAME_LABEL, MOVE_FILE_TO_TRASH_LABEL, COPY_FILE_LABEL, PASTE_FILE_LABEL, FileCopiedContext, renameHandler, moveFileToTrashHandler, copyFileHandler, pasteFileHandler, deleteFileHandler, cutFileHandler, DOWNLOAD_COMMAND_ID, openFilePreserveFocusHandler, DOWNLOAD_LABEL, ShowOpenedFileInNewWindow, UPLOAD_COMMAND_ID, UPLOAD_LABEL } from 'vs/workbench/contrib/files/browser/fileActions'; +import { ToggleAutoSaveAction, FocusFilesExplorer, GlobalCompareResourcesAction, ShowActiveFileInExplorer, CompareWithClipboardAction, NEW_FILE_COMMAND_ID, NEW_FILE_LABEL, NEW_FOLDER_COMMAND_ID, NEW_FOLDER_LABEL, TRIGGER_RENAME_LABEL, MOVE_FILE_TO_TRASH_LABEL, COPY_FILE_LABEL, PASTE_FILE_LABEL, FileCopiedContext, renameHandler, moveFileToTrashHandler, copyFileHandler, pasteFileHandler, deleteFileHandler, cutFileHandler, DOWNLOAD_COMMAND_ID, openFilePreserveFocusHandler, DOWNLOAD_LABEL, ShowOpenedFileInNewWindow, UPLOAD_COMMAND_ID, UPLOAD_LABEL, fileCategory } from 'vs/workbench/contrib/files/browser/fileActions'; import { revertLocalChangesCommand, acceptLocalChangesCommand, CONFLICT_RESOLUTION_CONTEXT } from 'vs/workbench/contrib/files/browser/editors/textFileSaveErrorHandler'; -import { SyncActionDescriptor, MenuId, MenuRegistry } from 'vs/platform/actions/common/actions'; +import { MenuId, MenuRegistry, registerAction2 } from 'vs/platform/actions/common/actions'; import { ILocalizedString } from 'vs/platform/action/common/action'; -import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions'; -import { KeyMod, KeyChord, KeyCode } from 'vs/base/common/keyCodes'; +import { KeyMod, KeyCode } from 'vs/base/common/keyCodes'; import { openWindowCommand, newWindowCommand } from 'vs/workbench/contrib/files/browser/fileCommands'; import { 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, OpenEditorsDirtyEditorContext, COMPARE_SELECTED_COMMAND_ID, REMOVE_ROOT_FOLDER_COMMAND_ID, REMOVE_ROOT_FOLDER_LABEL, SAVE_FILES_COMMAND_ID, COPY_RELATIVE_PATH_COMMAND_ID, SAVE_FILE_WITHOUT_FORMATTING_COMMAND_ID, SAVE_FILE_WITHOUT_FORMATTING_LABEL, OpenEditorsReadonlyEditorContext, OPEN_WITH_EXPLORER_COMMAND_ID, NEW_UNTITLED_FILE_COMMAND_ID, NEW_UNTITLED_FILE_LABEL, SAVE_ALL_COMMAND_ID } from 'vs/workbench/contrib/files/browser/fileConstants'; import { CommandsRegistry, ICommandHandler } from 'vs/platform/commands/common/commands'; @@ -22,7 +20,7 @@ import { CLOSE_SAVED_EDITORS_COMMAND_ID, CLOSE_EDITORS_IN_GROUP_COMMAND_ID, CLOS import { AutoSaveAfterShortDelayContext } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService'; import { WorkbenchListDoubleSelection } from 'vs/platform/list/browser/listService'; import { Schemas } from 'vs/base/common/network'; -import { DirtyWorkingCopiesContext, EmptyWorkspaceSupportContext, EnterMultiRootWorkspaceSupportContext, HasWebFileSystemAccess, WorkbenchStateContext, WorkspaceFolderCountContext, SidebarFocusContext, ActiveEditorCanRevertContext, ActiveEditorContext, ResourceContextKey, ActiveEditorAvailableEditorIdsContext } from 'vs/workbench/common/contextkeys'; +import { DirtyWorkingCopiesContext, EnterMultiRootWorkspaceSupportContext, HasWebFileSystemAccess, WorkbenchStateContext, WorkspaceFolderCountContext, SidebarFocusContext, ActiveEditorCanRevertContext, ActiveEditorContext, ResourceContextKey, ActiveEditorAvailableEditorIdsContext } from 'vs/workbench/common/contextkeys'; import { IsWebContext } from 'vs/platform/contextkey/common/contextkeys'; import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { ThemeIcon } from 'vs/platform/theme/common/themeService'; @@ -30,15 +28,13 @@ import { IExplorerService } from 'vs/workbench/contrib/files/browser/files'; import { Codicon } from 'vs/base/common/codicons'; // Contribute Global Actions -const category = { value: nls.localize('filesCategory', "File"), original: 'File' }; -const registry = Registry.as(ActionExtensions.WorkbenchActions); -registry.registerWorkbenchAction(SyncActionDescriptor.from(GlobalCompareResourcesAction), 'File: Compare Active File With...', category.value, ActiveEditorContext); -registry.registerWorkbenchAction(SyncActionDescriptor.from(FocusFilesExplorer), 'File: Focus on Files Explorer', category.value); -registry.registerWorkbenchAction(SyncActionDescriptor.from(ShowActiveFileInExplorer), 'File: Reveal Active File in Explorer View', category.value); -registry.registerWorkbenchAction(SyncActionDescriptor.from(CompareWithClipboardAction, { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KeyK, KeyCode.KeyC) }), 'File: Compare Active File with Clipboard', category.value); -registry.registerWorkbenchAction(SyncActionDescriptor.from(ToggleAutoSaveAction), 'File: Toggle Auto Save', category.value); -registry.registerWorkbenchAction(SyncActionDescriptor.from(ShowOpenedFileInNewWindow, { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KeyK, KeyCode.KeyO) }), 'File: Open Active File in New Window', category.value, EmptyWorkspaceSupportContext); +registerAction2(GlobalCompareResourcesAction); +registerAction2(FocusFilesExplorer); +registerAction2(ShowActiveFileInExplorer); +registerAction2(CompareWithClipboardAction); +registerAction2(ToggleAutoSaveAction); +registerAction2(ShowOpenedFileInNewWindow); // Commands CommandsRegistry.registerCommand('_files.windowOpen', openWindowCommand); @@ -198,18 +194,18 @@ export function appendToCommandPalette(id: string, title: ILocalizedString, cate }); } -appendToCommandPalette(COPY_PATH_COMMAND_ID, { value: nls.localize('copyPathOfActive', "Copy Path of Active File"), original: 'Copy Path of Active File' }, category); -appendToCommandPalette(COPY_RELATIVE_PATH_COMMAND_ID, { value: nls.localize('copyRelativePathOfActive', "Copy Relative Path of Active File"), original: 'Copy Relative Path of Active File' }, category); -appendToCommandPalette(SAVE_FILE_COMMAND_ID, { value: SAVE_FILE_LABEL, original: 'Save' }, category); -appendToCommandPalette(SAVE_FILE_WITHOUT_FORMATTING_COMMAND_ID, { value: SAVE_FILE_WITHOUT_FORMATTING_LABEL, original: 'Save without Formatting' }, category); -appendToCommandPalette(SAVE_ALL_IN_GROUP_COMMAND_ID, { value: nls.localize('saveAllInGroup', "Save All in Group"), original: 'Save All in Group' }, category); -appendToCommandPalette(SAVE_FILES_COMMAND_ID, { value: nls.localize('saveFiles', "Save All Files"), original: 'Save All Files' }, category); -appendToCommandPalette(REVERT_FILE_COMMAND_ID, { value: nls.localize('revert', "Revert File"), original: 'Revert File' }, category); -appendToCommandPalette(COMPARE_WITH_SAVED_COMMAND_ID, { value: nls.localize('compareActiveWithSaved', "Compare Active File with Saved"), original: 'Compare Active File with Saved' }, category); -appendToCommandPalette(SAVE_FILE_AS_COMMAND_ID, { value: SAVE_FILE_AS_LABEL, original: 'Save As...' }, category); -appendToCommandPalette(NEW_FILE_COMMAND_ID, { value: NEW_FILE_LABEL, original: 'New File' }, category, WorkspaceFolderCountContext.notEqualsTo('0')); -appendToCommandPalette(NEW_FOLDER_COMMAND_ID, { value: NEW_FOLDER_LABEL, original: 'New Folder' }, category, WorkspaceFolderCountContext.notEqualsTo('0')); -appendToCommandPalette(NEW_UNTITLED_FILE_COMMAND_ID, { value: NEW_UNTITLED_FILE_LABEL, original: 'New Untitled File' }, category); +appendToCommandPalette(COPY_PATH_COMMAND_ID, { value: nls.localize('copyPathOfActive', "Copy Path of Active File"), original: 'Copy Path of Active File' }, fileCategory); +appendToCommandPalette(COPY_RELATIVE_PATH_COMMAND_ID, { value: nls.localize('copyRelativePathOfActive', "Copy Relative Path of Active File"), original: 'Copy Relative Path of Active File' }, fileCategory); +appendToCommandPalette(SAVE_FILE_COMMAND_ID, { value: SAVE_FILE_LABEL, original: 'Save' }, fileCategory); +appendToCommandPalette(SAVE_FILE_WITHOUT_FORMATTING_COMMAND_ID, { value: SAVE_FILE_WITHOUT_FORMATTING_LABEL, original: 'Save without Formatting' }, fileCategory); +appendToCommandPalette(SAVE_ALL_IN_GROUP_COMMAND_ID, { value: nls.localize('saveAllInGroup', "Save All in Group"), original: 'Save All in Group' }, fileCategory); +appendToCommandPalette(SAVE_FILES_COMMAND_ID, { value: nls.localize('saveFiles', "Save All Files"), original: 'Save All Files' }, fileCategory); +appendToCommandPalette(REVERT_FILE_COMMAND_ID, { value: nls.localize('revert', "Revert File"), original: 'Revert File' }, fileCategory); +appendToCommandPalette(COMPARE_WITH_SAVED_COMMAND_ID, { value: nls.localize('compareActiveWithSaved', "Compare Active File with Saved"), original: 'Compare Active File with Saved' }, fileCategory); +appendToCommandPalette(SAVE_FILE_AS_COMMAND_ID, { value: SAVE_FILE_AS_LABEL, original: 'Save As...' }, fileCategory); +appendToCommandPalette(NEW_FILE_COMMAND_ID, { value: NEW_FILE_LABEL, original: 'New File' }, fileCategory, WorkspaceFolderCountContext.notEqualsTo('0')); +appendToCommandPalette(NEW_FOLDER_COMMAND_ID, { value: NEW_FOLDER_LABEL, original: 'New Folder' }, fileCategory, WorkspaceFolderCountContext.notEqualsTo('0')); +appendToCommandPalette(NEW_UNTITLED_FILE_COMMAND_ID, { value: NEW_UNTITLED_FILE_LABEL, original: 'New Untitled File' }, fileCategory); // Menu registration - open editors diff --git a/src/vs/workbench/contrib/files/browser/fileActions.ts b/src/vs/workbench/contrib/files/browser/fileActions.ts index caf9e8e896735..b1f29827fbb78 100644 --- a/src/vs/workbench/contrib/files/browser/fileActions.ts +++ b/src/vs/workbench/contrib/files/browser/fileActions.ts @@ -51,6 +51,10 @@ import { BrowserFileUpload, FileDownload } from 'vs/workbench/contrib/files/brow import { IPaneCompositePartService } from 'vs/workbench/services/panecomposite/browser/panecomposite'; import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService'; import { IPathService } from 'vs/workbench/services/path/common/pathService'; +import { Action2 } from 'vs/platform/actions/common/actions'; +import { ActiveEditorContext, EmptyWorkspaceSupportContext } from 'vs/workbench/common/contextkeys'; +import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; +import { KeyChord, KeyCode, KeyMod } from 'vs/base/common/keyCodes'; export const NEW_FILE_COMMAND_ID = 'explorer.newFile'; export const NEW_FILE_LABEL = nls.localize('newFile', "New File..."); @@ -67,6 +71,7 @@ export const UPLOAD_COMMAND_ID = 'explorer.upload'; export const UPLOAD_LABEL = nls.localize('upload', "Upload..."); const CONFIRM_DELETE_SETTING_KEY = 'explorer.confirmDelete'; const MAX_UNDO_FILE_SIZE = 5000000; // 5mb +export const fileCategory = { value: nls.localize('filesCategory', "File"), original: 'File' }; function onError(notificationService: INotificationService, error: any): void { if (error.message === 'string') { @@ -451,30 +456,34 @@ async function askForOverwrite(fileService: IFileService, dialogService: IDialog } // Global Compare with -export class GlobalCompareResourcesAction extends Action { +export class GlobalCompareResourcesAction extends Action2 { static readonly ID = 'workbench.files.action.compareFileWith'; static readonly LABEL = nls.localize('globalCompareFile', "Compare Active File With..."); - constructor( - id: string, - label: string, - @IQuickInputService private readonly quickInputService: IQuickInputService, - @IEditorService private readonly editorService: IEditorService, - @ITextModelService private readonly textModelService: ITextModelService - ) { - super(id, label); + constructor() { + super({ + id: GlobalCompareResourcesAction.ID, + title: { value: GlobalCompareResourcesAction.LABEL, original: 'Compare Active File With...' }, + f1: true, + category: fileCategory, + precondition: ActiveEditorContext + }); } - override async run(): Promise { - const activeInput = this.editorService.activeEditor; + override async run(accessor: ServicesAccessor): Promise { + const editorService = accessor.get(IEditorService); + const textModelService = accessor.get(ITextModelService); + const quickInputService = accessor.get(IQuickInputService); + + const activeInput = editorService.activeEditor; const activeResource = EditorResourceAccessor.getOriginalUri(activeInput); - if (activeResource && this.textModelService.canHandleResource(activeResource)) { - const picks = await this.quickInputService.quickAccess.pick('', { itemActivation: ItemActivation.SECOND }); + if (activeResource && textModelService.canHandleResource(activeResource)) { + const picks = await quickInputService.quickAccess.pick('', { itemActivation: ItemActivation.SECOND }); if (picks?.length === 1) { const resource = (picks[0] as unknown as { resource: unknown }).resource; - if (URI.isUri(resource) && this.textModelService.canHandleResource(resource)) { - this.editorService.openEditor({ + if (URI.isUri(resource) && textModelService.canHandleResource(resource)) { + editorService.openEditor({ original: { resource: activeResource }, modified: { resource: resource }, options: { pinned: true } @@ -485,20 +494,22 @@ export class GlobalCompareResourcesAction extends Action { } } -export class ToggleAutoSaveAction extends Action { +export class ToggleAutoSaveAction extends Action2 { static readonly ID = 'workbench.action.toggleAutoSave'; static readonly LABEL = nls.localize('toggleAutoSave', "Toggle Auto Save"); - constructor( - id: string, - label: string, - @IFilesConfigurationService private readonly filesConfigurationService: IFilesConfigurationService - ) { - super(id, label); + constructor() { + super({ + id: ToggleAutoSaveAction.ID, + title: { value: ToggleAutoSaveAction.LABEL, original: 'Toggle Auto Save' }, + f1: true, + category: fileCategory + }); } - override run(): Promise { - return this.filesConfigurationService.toggleAutoSave(); + override run(accessor: ServicesAccessor): Promise { + const filesConfigurationService = accessor.get(IFilesConfigurationService); + return filesConfigurationService.toggleAutoSave(); } } @@ -573,69 +584,79 @@ export class CloseGroupAction extends Action { } } -export class FocusFilesExplorer extends Action { +export class FocusFilesExplorer extends Action2 { static readonly ID = 'workbench.files.action.focusFilesExplorer'; static readonly LABEL = nls.localize('focusFilesExplorer', "Focus on Files Explorer"); - constructor( - id: string, - label: string, - @IPaneCompositePartService private readonly paneCompositeService: IPaneCompositePartService - ) { - super(id, label); + constructor() { + super({ + id: FocusFilesExplorer.ID, + title: { value: FocusFilesExplorer.LABEL, original: 'Focus on Files Explorer' }, + f1: true, + category: fileCategory + }); } - override async run(): Promise { - await this.paneCompositeService.openPaneComposite(VIEWLET_ID, ViewContainerLocation.Sidebar, true); + override async run(accessor: ServicesAccessor): Promise { + const paneCompositeService = accessor.get(IPaneCompositePartService); + await paneCompositeService.openPaneComposite(VIEWLET_ID, ViewContainerLocation.Sidebar, true); } } -export class ShowActiveFileInExplorer extends Action { +export class ShowActiveFileInExplorer extends Action2 { static readonly ID = 'workbench.files.action.showActiveFileInExplorer'; static readonly LABEL = nls.localize('showInExplorer', "Reveal Active File in Explorer View"); - constructor( - id: string, - label: string, - @IEditorService private readonly editorService: IEditorService, - @ICommandService private readonly commandService: ICommandService - ) { - super(id, label); + constructor() { + super({ + id: ShowActiveFileInExplorer.ID, + title: { value: ShowActiveFileInExplorer.LABEL, original: 'Reveal Active File in Explorer View' }, + f1: true, + category: fileCategory + }); } - override async run(): Promise { - const resource = EditorResourceAccessor.getOriginalUri(this.editorService.activeEditor, { supportSideBySide: SideBySideEditor.PRIMARY }); + override async run(accessor: ServicesAccessor): Promise { + const commandService = accessor.get(ICommandService); + const editorService = accessor.get(IEditorService); + const resource = EditorResourceAccessor.getOriginalUri(editorService.activeEditor, { supportSideBySide: SideBySideEditor.PRIMARY }); if (resource) { - this.commandService.executeCommand(REVEAL_IN_EXPLORER_COMMAND_ID, resource); + commandService.executeCommand(REVEAL_IN_EXPLORER_COMMAND_ID, resource); } } } -export class ShowOpenedFileInNewWindow extends Action { +export class ShowOpenedFileInNewWindow extends Action2 { static readonly ID = 'workbench.action.files.showOpenedFileInNewWindow'; static readonly LABEL = nls.localize('openFileInNewWindow', "Open Active File in New Window"); constructor( - id: string, - label: string, - @IEditorService private readonly editorService: IEditorService, - @IHostService private readonly hostService: IHostService, - @IDialogService private readonly dialogService: IDialogService, - @IFileService private readonly fileService: IFileService ) { - super(id, label); + super({ + id: ShowOpenedFileInNewWindow.ID, + title: { value: ShowOpenedFileInNewWindow.LABEL, original: 'Open Active File in New Window' }, + f1: true, + category: fileCategory, + keybinding: { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KeyK, KeyCode.KeyO), weight: KeybindingWeight.WorkbenchContrib }, + precondition: EmptyWorkspaceSupportContext + }); } - override async run(): Promise { - const fileResource = EditorResourceAccessor.getOriginalUri(this.editorService.activeEditor, { supportSideBySide: SideBySideEditor.PRIMARY }); + override async run(accessor: ServicesAccessor): Promise { + const editorService = accessor.get(IEditorService); + const hostService = accessor.get(IHostService); + const dialogService = accessor.get(IDialogService); + const fileService = accessor.get(IFileService); + + const fileResource = EditorResourceAccessor.getOriginalUri(editorService.activeEditor, { supportSideBySide: SideBySideEditor.PRIMARY }); if (fileResource) { - if (this.fileService.hasProvider(fileResource)) { - this.hostService.openWindow([{ fileUri: fileResource }], { forceNewWindow: true }); + if (fileService.hasProvider(fileResource)) { + hostService.openWindow([{ fileUri: fileResource }], { forceNewWindow: true }); } else { - this.dialogService.show(Severity.Error, nls.localize('openFileToShowInNewWindow.unsupportedschema', "The active editor must contain an openable resource.")); + dialogService.show(Severity.Error, nls.localize('openFileToShowInNewWindow.unsupportedschema', "The active editor must contain an openable resource.")); } } } @@ -718,7 +739,7 @@ function getWellFormedFileName(filename: string): string { return filename; } -export class CompareWithClipboardAction extends Action { +export class CompareWithClipboardAction extends Action2 { static readonly ID = 'workbench.files.action.compareWithClipboard'; static readonly LABEL = nls.localize('compareWithClipboard', "Compare Active File with Clipboard"); @@ -726,32 +747,34 @@ export class CompareWithClipboardAction extends Action { private registrationDisposal: IDisposable | undefined; private static SCHEME_COUNTER = 0; - constructor( - id: string, - label: string, - @IEditorService private readonly editorService: IEditorService, - @IInstantiationService private readonly instantiationService: IInstantiationService, - @ITextModelService private readonly textModelService: ITextModelService, - @IFileService private readonly fileService: IFileService - ) { - super(id, label); - - this.enabled = true; + constructor() { + super({ + id: CompareWithClipboardAction.ID, + title: { value: CompareWithClipboardAction.LABEL, original: 'Compare Active File with Clipboard' }, + f1: true, + category: fileCategory, + keybinding: { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KeyK, KeyCode.KeyC), weight: KeybindingWeight.WorkbenchContrib } + }); } - override async run(): Promise { - const resource = EditorResourceAccessor.getOriginalUri(this.editorService.activeEditor, { supportSideBySide: SideBySideEditor.PRIMARY }); + override async run(accessor: ServicesAccessor): Promise { + const editorService = accessor.get(IEditorService); + const instantiationService = accessor.get(IInstantiationService); + const textModelService = accessor.get(ITextModelService); + const fileService = accessor.get(IFileService); + + const resource = EditorResourceAccessor.getOriginalUri(editorService.activeEditor, { supportSideBySide: SideBySideEditor.PRIMARY }); const scheme = `clipboardCompare${CompareWithClipboardAction.SCHEME_COUNTER++}`; - if (resource && (this.fileService.hasProvider(resource) || resource.scheme === Schemas.untitled)) { + if (resource && (fileService.hasProvider(resource) || resource.scheme === Schemas.untitled)) { if (!this.registrationDisposal) { - const provider = this.instantiationService.createInstance(ClipboardContentProvider); - this.registrationDisposal = this.textModelService.registerTextModelContentProvider(scheme, provider); + const provider = instantiationService.createInstance(ClipboardContentProvider); + this.registrationDisposal = textModelService.registerTextModelContentProvider(scheme, provider); } const name = resources.basename(resource); const editorLabel = nls.localize('clipboardComparisonLabel', "Clipboard ↔ {0}", name); - await this.editorService.openEditor({ + await editorService.openEditor({ original: { resource: resource.with({ scheme }) }, modified: { resource: resource }, label: editorLabel, @@ -763,9 +786,7 @@ export class CompareWithClipboardAction extends Action { } } - override dispose(): void { - super.dispose(); - + dispose(): void { dispose(this.registrationDisposal); this.registrationDisposal = undefined; } diff --git a/src/vs/workbench/contrib/welcomeOverlay/browser/welcomeOverlay.ts b/src/vs/workbench/contrib/welcomeOverlay/browser/welcomeOverlay.ts index 5ad26e2f482c1..7bdc7f207c41c 100644 --- a/src/vs/workbench/contrib/welcomeOverlay/browser/welcomeOverlay.ts +++ b/src/vs/workbench/contrib/welcomeOverlay/browser/welcomeOverlay.ts @@ -5,25 +5,23 @@ import 'vs/css!./media/welcomeOverlay'; import * as dom from 'vs/base/browser/dom'; -import { Registry } from 'vs/platform/registry/common/platform'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { ShowAllCommandsAction } from 'vs/workbench/contrib/quickaccess/browser/commandsQuickAccess'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { ILayoutService } from 'vs/platform/layout/browser/layoutService'; import { localize } from 'vs/nls'; -import { Action } from 'vs/base/common/actions'; -import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actions'; import { Categories } from 'vs/platform/action/common/actionCommonCategories'; -import { SyncActionDescriptor } from 'vs/platform/actions/common/actions'; +import { Action2, registerAction2 } from 'vs/platform/actions/common/actions'; import { ICommandService } from 'vs/platform/commands/common/commands'; import { Disposable } from 'vs/base/common/lifecycle'; import { RawContextKey, IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { KeyCode } from 'vs/base/common/keyCodes'; -import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; +import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { registerThemingParticipant } from 'vs/platform/theme/common/themeService'; import { textPreformatForeground, foreground } from 'vs/platform/theme/common/colorRegistry'; import { Color } from 'vs/base/common/color'; import { Codicon } from 'vs/base/common/codicons'; +import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; const $ = dom.$; @@ -110,38 +108,49 @@ const OVERLAY_VISIBLE = new RawContextKey('interfaceOverviewVisible', f let welcomeOverlay: WelcomeOverlay; -export class WelcomeOverlayAction extends Action { +export class WelcomeOverlayAction extends Action2 { public static readonly ID = 'workbench.action.showInterfaceOverview'; public static readonly LABEL = localize('welcomeOverlay', "User Interface Overview"); constructor( - id: string, - label: string, - @IInstantiationService private readonly instantiationService: IInstantiationService ) { - super(id, label); + super({ + id: WelcomeOverlayAction.ID, + title: WelcomeOverlayAction.LABEL, + category: Categories.Help, + f1: true + }); } - public override run(): Promise { + public override run(accessor: ServicesAccessor): Promise { + const instantiationService = accessor.get(IInstantiationService); if (!welcomeOverlay) { - welcomeOverlay = this.instantiationService.createInstance(WelcomeOverlay); + welcomeOverlay = instantiationService.createInstance(WelcomeOverlay); } welcomeOverlay.show(); return Promise.resolve(); } } -export class HideWelcomeOverlayAction extends Action { +export class HideWelcomeOverlayAction extends Action2 { public static readonly ID = 'workbench.action.hideInterfaceOverview'; public static readonly LABEL = localize('hideWelcomeOverlay', "Hide Interface Overview"); - constructor( - id: string, - label: string - ) { - super(id, label); + constructor() { + super({ + id: HideWelcomeOverlayAction.ID, + title: HideWelcomeOverlayAction.LABEL, + category: Categories.Help, + f1: true, + keybinding: { + primary: KeyCode.Escape, + when: OVERLAY_VISIBLE, + weight: KeybindingWeight.WorkbenchContrib + }, + precondition: OVERLAY_VISIBLE + }); } public override run(): Promise { @@ -257,11 +266,8 @@ class WelcomeOverlay extends Disposable { } } -Registry.as(Extensions.WorkbenchActions) - .registerWorkbenchAction(SyncActionDescriptor.from(WelcomeOverlayAction), 'Help: User Interface Overview', Categories.Help.value); - -Registry.as(Extensions.WorkbenchActions) - .registerWorkbenchAction(SyncActionDescriptor.from(HideWelcomeOverlayAction, { primary: KeyCode.Escape }, OVERLAY_VISIBLE), 'Help: Hide Interface Overview', Categories.Help.value); +registerAction2(WelcomeOverlayAction); +registerAction2(HideWelcomeOverlayAction); // theming diff --git a/src/vs/workbench/contrib/welcomeWalkthrough/browser/editor/editorWalkThrough.ts b/src/vs/workbench/contrib/welcomeWalkthrough/browser/editor/editorWalkThrough.ts index 51b2b12094152..8eaf3e7322b0c 100644 --- a/src/vs/workbench/contrib/welcomeWalkthrough/browser/editor/editorWalkThrough.ts +++ b/src/vs/workbench/contrib/welcomeWalkthrough/browser/editor/editorWalkThrough.ts @@ -6,12 +6,13 @@ import 'vs/workbench/contrib/welcomeWalkthrough/browser/editor/vs_code_editor_walkthrough'; import { localize } from 'vs/nls'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; -import { Action } from 'vs/base/common/actions'; -import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; +import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { WalkThroughInput, WalkThroughInputOptions } from 'vs/workbench/contrib/welcomeWalkthrough/browser/walkThroughInput'; import { FileAccess, Schemas } from 'vs/base/common/network'; import { IEditorSerializer } from 'vs/workbench/common/editor'; import { EditorInput } from 'vs/workbench/common/editor/editorInput'; +import { Action2 } from 'vs/platform/actions/common/actions'; +import { Categories } from 'vs/platform/action/common/actionCommonCategories'; const typeId = 'workbench.editors.walkThroughInput'; const inputOptions: WalkThroughInputOptions = { @@ -25,24 +26,26 @@ const inputOptions: WalkThroughInputOptions = { telemetryFrom: 'walkThrough' }; -export class EditorWalkThroughAction extends Action { +export class EditorWalkThroughAction extends Action2 { public static readonly ID = 'workbench.action.showInteractivePlayground'; public static readonly LABEL = localize('editorWalkThrough', "Interactive Editor Playground"); - constructor( - id: string, - label: string, - @IEditorService private readonly editorService: IEditorService, - @IInstantiationService private readonly instantiationService: IInstantiationService - ) { - super(id, label); + constructor() { + super({ + id: EditorWalkThroughAction.ID, + title: EditorWalkThroughAction.LABEL, + category: Categories.Help, + f1: true + }); } - public override run(): Promise { - const input = this.instantiationService.createInstance(WalkThroughInput, inputOptions); + public override run(serviceAccessor: ServicesAccessor): Promise { + const editorService = serviceAccessor.get(IEditorService); + const instantiationService = serviceAccessor.get(IInstantiationService); + const input = instantiationService.createInstance(WalkThroughInput, inputOptions); // TODO @lramos15 adopt the resolver here - return this.editorService.openEditor(input, { pinned: true }) + return editorService.openEditor(input, { pinned: true }) .then(() => void (0)); } } diff --git a/src/vs/workbench/contrib/welcomeWalkthrough/browser/walkThrough.contribution.ts b/src/vs/workbench/contrib/welcomeWalkthrough/browser/walkThrough.contribution.ts index be550f72b6618..3995757981155 100644 --- a/src/vs/workbench/contrib/welcomeWalkthrough/browser/walkThrough.contribution.ts +++ b/src/vs/workbench/contrib/welcomeWalkthrough/browser/walkThrough.contribution.ts @@ -12,9 +12,7 @@ import { EditorWalkThroughAction, EditorWalkThroughInputSerializer } from 'vs/wo import { Registry } from 'vs/platform/registry/common/platform'; import { EditorExtensions, IEditorFactoryRegistry } from 'vs/workbench/common/editor'; import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; -import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actions'; -import { Categories } from 'vs/platform/action/common/actionCommonCategories'; -import { SyncActionDescriptor, MenuRegistry, MenuId } from 'vs/platform/actions/common/actions'; +import { MenuRegistry, MenuId, registerAction2 } from 'vs/platform/actions/common/actions'; import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions'; import { IEditorPaneRegistry, EditorPaneDescriptor } from 'vs/workbench/browser/editor'; import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle'; @@ -28,10 +26,7 @@ Registry.as(EditorExtensions.EditorPane) ), [new SyncDescriptor(WalkThroughInput)]); -Registry.as(Extensions.WorkbenchActions) - .registerWorkbenchAction( - SyncActionDescriptor.from(EditorWalkThroughAction), - 'Help: Interactive Editor Playground', Categories.Help.value); +registerAction2(EditorWalkThroughAction); Registry.as(EditorExtensions.EditorFactory).registerEditorSerializer(EditorWalkThroughInputSerializer.ID, EditorWalkThroughInputSerializer);