From 9c6ebcb0eaef3016f0d99c857fb5d0a587cc82ab Mon Sep 17 00:00:00 2001 From: Matt Bierner <12821956+mjbvz@users.noreply.github.com> Date: Mon, 20 Oct 2025 16:59:48 -0700 Subject: [PATCH] Convert a few more `new Action` calls to `toAction` `toAction` is preferred as it doesn't require disposal --- src/vs/base/browser/ui/button/button.ts | 6 +- .../api/browser/mainThreadExtensionService.ts | 24 +-- .../browser/parts/titlebar/menubarControl.ts | 36 +++-- .../browser/breakpointEditorContribution.ts | 145 ++++++++---------- .../debug/browser/debugEditorActions.ts | 4 +- .../contrib/debug/browser/debugService.ts | 21 ++- .../contrib/debug/browser/debugTaskRunner.ts | 4 +- .../contrib/debug/browser/variablesView.ts | 10 +- .../contrib/remote/browser/remoteExplorer.ts | 28 ++-- .../remoteTunnel.contribution.ts | 22 ++- 10 files changed, 156 insertions(+), 144 deletions(-) diff --git a/src/vs/base/browser/ui/button/button.ts b/src/vs/base/browser/ui/button/button.ts index c0a8eec0633..1f9ea52453f 100644 --- a/src/vs/base/browser/ui/button/button.ts +++ b/src/vs/base/browser/ui/button/button.ts @@ -11,7 +11,7 @@ import { Gesture, EventType as TouchEventType } from '../../touch.js'; import { createInstantHoverDelegate, getDefaultHoverDelegate } from '../hover/hoverDelegateFactory.js'; import { IHoverDelegate } from '../hover/hoverDelegate.js'; import { renderLabelWithIcons } from '../iconLabel/iconLabels.js'; -import { Action, IAction, IActionRunner } from '../../../common/actions.js'; +import { IAction, IActionRunner, toAction } from '../../../common/actions.js'; import { Codicon } from '../../../common/codicons.js'; import { Color } from '../../../common/color.js'; import { Event as BaseEvent, Emitter } from '../../../common/event.js'; @@ -371,7 +371,7 @@ export interface IButtonWithDropdownOptions extends IButtonOptions { export class ButtonWithDropdown extends Disposable implements IButton { readonly primaryButton: Button; - private readonly action: Action; + private readonly action: IAction; readonly dropdownButton: Button; private readonly separatorContainer: HTMLDivElement; private readonly separator: HTMLDivElement; @@ -393,7 +393,7 @@ export class ButtonWithDropdown extends Disposable implements IButton { this.primaryButton = this._register(new Button(this.element, options)); this._register(this.primaryButton.onDidClick(e => this._onDidClick.fire(e))); - this.action = this._register(new Action('primaryAction', renderAsPlaintext(this.primaryButton.label), undefined, true, async () => this._onDidClick.fire(undefined))); + this.action = toAction({ id: 'primaryAction', label: renderAsPlaintext(this.primaryButton.label), run: async () => this._onDidClick.fire(undefined) }); this.separatorContainer = document.createElement('div'); this.separatorContainer.classList.add('monaco-button-dropdown-separator'); diff --git a/src/vs/workbench/api/browser/mainThreadExtensionService.ts b/src/vs/workbench/api/browser/mainThreadExtensionService.ts index 67dc8c1bbfb..20daca562a4 100644 --- a/src/vs/workbench/api/browser/mainThreadExtensionService.ts +++ b/src/vs/workbench/api/browser/mainThreadExtensionService.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { Action } from '../../../base/common/actions.js'; +import { toAction } from '../../../base/common/actions.js'; import { VSBuffer } from '../../../base/common/buffer.js'; import { CancellationToken } from '../../../base/common/cancellation.js'; import { SerializedError, transformErrorFromSerialization } from '../../../base/common/errors.js'; @@ -115,7 +115,7 @@ export class MainThreadExtensionService implements MainThreadExtensionServiceSha severity: Severity.Error, message: localize('reload window', "Cannot activate the '{0}' extension because it depends on the '{1}' extension, which is not loaded. Would you like to reload the window to load the extension?", extName, missingInstalledDependency.manifest.displayName || missingInstalledDependency.manifest.name), actions: { - primary: [new Action('reload', localize('reload', "Reload Window"), '', true, () => this._hostService.reload())] + primary: [toAction({ id: 'reload', label: localize('reload', "Reload Window"), run: () => this._hostService.reload() })] } }); } else { @@ -130,8 +130,7 @@ export class MainThreadExtensionService implements MainThreadExtensionServiceSha severity: Severity.Error, message: localize('restrictedMode', "Cannot activate the '{0}' extension because it depends on the '{1}' extension which is not supported in Restricted Mode", extName, missingInstalledDependency.manifest.displayName || missingInstalledDependency.manifest.name), actions: { - primary: [new Action('manageWorkspaceTrust', localize('manageWorkspaceTrust', "Manage Workspace Trust"), '', true, - () => this._commandService.executeCommand('workbench.trust.manage'))] + primary: [toAction({ id: 'manageWorkspaceTrust', label: localize('manageWorkspaceTrust', "Manage Workspace Trust"), run: () => this._commandService.executeCommand('workbench.trust.manage') })] } }); } else if (this._extensionEnablementService.canChangeEnablement(missingInstalledDependency)) { @@ -139,9 +138,11 @@ export class MainThreadExtensionService implements MainThreadExtensionServiceSha severity: Severity.Error, message: localize('disabledDep', "Cannot activate the '{0}' extension because it depends on the '{1}' extension which is disabled. Would you like to enable the extension and reload the window?", extName, missingInstalledDependency.manifest.displayName || missingInstalledDependency.manifest.name), actions: { - primary: [new Action('enable', localize('enable dep', "Enable and Reload"), '', true, - () => this._extensionEnablementService.setEnablement([missingInstalledDependency], enablementState === EnablementState.DisabledGlobally ? EnablementState.EnabledGlobally : EnablementState.EnabledWorkspace) - .then(() => this._hostService.reload(), e => this._notificationService.error(e)))] + primary: [toAction({ + id: 'enable', label: localize('enable dep', "Enable and Reload"), enabled: true, + run: () => this._extensionEnablementService.setEnablement([missingInstalledDependency], enablementState === EnablementState.DisabledGlobally ? EnablementState.EnabledGlobally : EnablementState.EnabledWorkspace) + .then(() => this._hostService.reload(), e => this._notificationService.error(e)) + })] } }); } else { @@ -165,9 +166,12 @@ export class MainThreadExtensionService implements MainThreadExtensionServiceSha severity: Severity.Error, message: localize('uninstalledDep', "Cannot activate the '{0}' extension because it depends on the '{1}' extension from '{2}', which is not installed. Would you like to install the extension and reload the window?", extName, dependencyExtension.displayName, dependencyExtension.publisherDisplayName), actions: { - primary: [new Action('install', localize('install missing dep', "Install and Reload"), '', true, - () => this._extensionsWorkbenchService.install(dependencyExtension) - .then(() => this._hostService.reload(), e => this._notificationService.error(e)))] + primary: [toAction({ + id: 'install', + label: localize('install missing dep', "Install and Reload"), + run: () => this._extensionsWorkbenchService.install(dependencyExtension) + .then(() => this._hostService.reload(), e => this._notificationService.error(e)) + })] } }); } else { diff --git a/src/vs/workbench/browser/parts/titlebar/menubarControl.ts b/src/vs/workbench/browser/parts/titlebar/menubarControl.ts index 07e61ab30e0..07137d30ebb 100644 --- a/src/vs/workbench/browser/parts/titlebar/menubarControl.ts +++ b/src/vs/workbench/browser/parts/titlebar/menubarControl.ts @@ -463,29 +463,37 @@ export class CustomMenubarControl extends MenubarControl { switch (state.type) { case StateType.Idle: - return new Action('update.check', localize({ key: 'checkForUpdates', comment: ['&& denotes a mnemonic'] }, "Check for &&Updates..."), undefined, true, () => - this.updateService.checkForUpdates(true)); + return toAction({ + id: 'update.check', label: localize({ key: 'checkForUpdates', comment: ['&& denotes a mnemonic'] }, "Check for &&Updates..."), enabled: true, run: () => + this.updateService.checkForUpdates(true) + }); case StateType.CheckingForUpdates: - return new Action('update.checking', localize('checkingForUpdates', "Checking for Updates..."), undefined, false); + return toAction({ id: 'update.checking', label: localize('checkingForUpdates', "Checking for Updates..."), enabled: false, run: () => { } }); case StateType.AvailableForDownload: - return new Action('update.downloadNow', localize({ key: 'download now', comment: ['&& denotes a mnemonic'] }, "D&&ownload Update"), undefined, true, () => - this.updateService.downloadUpdate()); + return toAction({ + id: 'update.downloadNow', label: localize({ key: 'download now', comment: ['&& denotes a mnemonic'] }, "D&&ownload Update"), enabled: true, run: () => + this.updateService.downloadUpdate() + }); case StateType.Downloading: - return new Action('update.downloading', localize('DownloadingUpdate', "Downloading Update..."), undefined, false); + return toAction({ id: 'update.downloading', label: localize('DownloadingUpdate', "Downloading Update..."), enabled: false, run: () => { } }); case StateType.Downloaded: - return isMacintosh ? null : new Action('update.install', localize({ key: 'installUpdate...', comment: ['&& denotes a mnemonic'] }, "Install &&Update..."), undefined, true, () => - this.updateService.applyUpdate()); + return isMacintosh ? null : toAction({ + id: 'update.install', label: localize({ key: 'installUpdate...', comment: ['&& denotes a mnemonic'] }, "Install &&Update..."), enabled: true, run: () => + this.updateService.applyUpdate() + }); case StateType.Updating: - return new Action('update.updating', localize('installingUpdate', "Installing Update..."), undefined, false); + return toAction({ id: 'update.updating', label: localize('installingUpdate', "Installing Update..."), enabled: false, run: () => { } }); case StateType.Ready: - return new Action('update.restart', localize({ key: 'restartToUpdate', comment: ['&& denotes a mnemonic'] }, "Restart to &&Update"), undefined, true, () => - this.updateService.quitAndInstall()); + return toAction({ + id: 'update.restart', label: localize({ key: 'restartToUpdate', comment: ['&& denotes a mnemonic'] }, "Restart to &&Update"), enabled: true, run: () => + this.updateService.quitAndInstall() + }); default: return null; @@ -721,8 +729,10 @@ export class CustomMenubarControl extends MenubarControl { const title = typeof action.item.title === 'string' ? action.item.title : action.item.title.mnemonicTitle ?? action.item.title.value; - webNavigationActions.push(new Action(action.id, mnemonicMenuLabel(title), action.class, action.enabled, async (event?: unknown) => { - this.commandService.executeCommand(action.id, event); + webNavigationActions.push(toAction({ + id: action.id, label: mnemonicMenuLabel(title), class: action.class, enabled: action.enabled, run: async (event?: unknown) => { + this.commandService.executeCommand(action.id, event); + } })); } } diff --git a/src/vs/workbench/contrib/debug/browser/breakpointEditorContribution.ts b/src/vs/workbench/contrib/debug/browser/breakpointEditorContribution.ts index a8f46c2e44b..aac4fe7083e 100644 --- a/src/vs/workbench/contrib/debug/browser/breakpointEditorContribution.ts +++ b/src/vs/workbench/contrib/debug/browser/breakpointEditorContribution.ts @@ -7,7 +7,7 @@ import { isSafari } from '../../../../base/browser/browser.js'; import { BrowserFeatures } from '../../../../base/browser/canIUse.js'; import * as dom from '../../../../base/browser/dom.js'; import { StandardMouseEvent } from '../../../../base/browser/mouseEvent.js'; -import { Action, IAction, Separator, SubmenuAction } from '../../../../base/common/actions.js'; +import { IAction, Separator, SubmenuAction, toAction } from '../../../../base/common/actions.js'; import { distinct } from '../../../../base/common/arrays.js'; import { RunOnceScheduler, timeout } from '../../../../base/common/async.js'; import { memoize } from '../../../../base/common/decorators.js'; @@ -406,94 +406,79 @@ export class BreakpointEditorContribution implements IBreakpointEditorContributi if (breakpoints.length === 1) { const breakpointType = breakpoints[0].logMessage ? nls.localize('logPoint', "Logpoint") : nls.localize('breakpoint', "Breakpoint"); - actions.push(new Action('debug.removeBreakpoint', nls.localize('removeBreakpoint', "Remove {0}", breakpointType), undefined, true, async () => { - await this.debugService.removeBreakpoints(breakpoints[0].getId()); + actions.push(toAction({ + id: 'debug.removeBreakpoint', label: nls.localize('removeBreakpoint', "Remove {0}", breakpointType), enabled: true, run: async () => { + await this.debugService.removeBreakpoints(breakpoints[0].getId()); + } + })); + actions.push(toAction({ + id: 'workbench.debug.action.editBreakpointAction', + label: nls.localize('editBreakpoint', "Edit {0}...", breakpointType), + enabled: true, + run: () => Promise.resolve(this.showBreakpointWidget(breakpoints[0].lineNumber, breakpoints[0].column)) + })); actions.push(toAction({ + id: `workbench.debug.viewlet.action.toggleBreakpoint`, + label: breakpoints[0].enabled ? nls.localize('disableBreakpoint', "Disable {0}", breakpointType) : nls.localize('enableBreakpoint', "Enable {0}", breakpointType), + enabled: true, + run: () => this.debugService.enableOrDisableBreakpoints(!breakpoints[0].enabled, breakpoints[0]) })); - actions.push(new Action( - 'workbench.debug.action.editBreakpointAction', - nls.localize('editBreakpoint', "Edit {0}...", breakpointType), - undefined, - true, - () => Promise.resolve(this.showBreakpointWidget(breakpoints[0].lineNumber, breakpoints[0].column)) - )); - - actions.push(new Action( - `workbench.debug.viewlet.action.toggleBreakpoint`, - breakpoints[0].enabled ? nls.localize('disableBreakpoint', "Disable {0}", breakpointType) : nls.localize('enableBreakpoint', "Enable {0}", breakpointType), - undefined, - true, - () => this.debugService.enableOrDisableBreakpoints(!breakpoints[0].enabled, breakpoints[0]) - )); } else if (breakpoints.length > 1) { const sorted = breakpoints.slice().sort((first, second) => (first.column && second.column) ? first.column - second.column : 1); - actions.push(new SubmenuAction('debug.removeBreakpoints', nls.localize('removeBreakpoints', "Remove Breakpoints"), sorted.map(bp => new Action( - 'removeInlineBreakpoint', - bp.column ? nls.localize('removeInlineBreakpointOnColumn', "Remove Inline Breakpoint on Column {0}", bp.column) : nls.localize('removeLineBreakpoint', "Remove Line Breakpoint"), - undefined, - true, - () => this.debugService.removeBreakpoints(bp.getId()) - )))); - - actions.push(new SubmenuAction('debug.editBreakpoints', nls.localize('editBreakpoints', "Edit Breakpoints"), sorted.map(bp => - new Action('editBreakpoint', - bp.column ? nls.localize('editInlineBreakpointOnColumn', "Edit Inline Breakpoint on Column {0}", bp.column) : nls.localize('editLineBreakpoint', "Edit Line Breakpoint"), - undefined, - true, - () => Promise.resolve(this.showBreakpointWidget(bp.lineNumber, bp.column)) - ) - ))); - - actions.push(new SubmenuAction('debug.enableDisableBreakpoints', nls.localize('enableDisableBreakpoints', "Enable/Disable Breakpoints"), sorted.map(bp => new Action( - bp.enabled ? 'disableColumnBreakpoint' : 'enableColumnBreakpoint', - bp.enabled ? (bp.column ? nls.localize('disableInlineColumnBreakpoint', "Disable Inline Breakpoint on Column {0}", bp.column) : nls.localize('disableBreakpointOnLine', "Disable Line Breakpoint")) + actions.push(new SubmenuAction('debug.removeBreakpoints', nls.localize('removeBreakpoints', "Remove Breakpoints"), sorted.map(bp => toAction({ + id: 'removeInlineBreakpoint', + label: bp.column ? nls.localize('removeInlineBreakpointOnColumn', "Remove Inline Breakpoint on Column {0}", bp.column) : nls.localize('removeLineBreakpoint', "Remove Line Breakpoint"), + enabled: true, + run: () => this.debugService.removeBreakpoints(bp.getId()) + })))); actions.push(new SubmenuAction('debug.editBreakpoints', nls.localize('editBreakpoints', "Edit Breakpoints"), sorted.map(bp => + toAction({ + id: 'editBreakpoint', + label: bp.column ? nls.localize('editInlineBreakpointOnColumn', "Edit Inline Breakpoint on Column {0}", bp.column) : nls.localize('editLineBreakpoint', "Edit Line Breakpoint"), + enabled: true, + run: () => Promise.resolve(this.showBreakpointWidget(bp.lineNumber, bp.column)) + }) + ))); actions.push(new SubmenuAction('debug.enableDisableBreakpoints', nls.localize('enableDisableBreakpoints', "Enable/Disable Breakpoints"), sorted.map(bp => toAction({ + id: bp.enabled ? 'disableColumnBreakpoint' : 'enableColumnBreakpoint', + label: bp.enabled ? (bp.column ? nls.localize('disableInlineColumnBreakpoint', "Disable Inline Breakpoint on Column {0}", bp.column) : nls.localize('disableBreakpointOnLine', "Disable Line Breakpoint")) : (bp.column ? nls.localize('enableBreakpoints', "Enable Inline Breakpoint on Column {0}", bp.column) : nls.localize('enableBreakpointOnLine', "Enable Line Breakpoint")), - undefined, - true, - () => this.debugService.enableOrDisableBreakpoints(!bp.enabled, bp) - )))); + enabled: true, + run: () => this.debugService.enableOrDisableBreakpoints(!bp.enabled, bp) + })))); } else { - actions.push(new Action( - 'addBreakpoint', - nls.localize('addBreakpoint', "Add Breakpoint"), - undefined, - true, - () => this.debugService.addBreakpoints(uri, [{ lineNumber, column }]) - )); - actions.push(new Action( - 'addConditionalBreakpoint', - nls.localize('addConditionalBreakpoint', "Add Conditional Breakpoint..."), - undefined, - true, - () => Promise.resolve(this.showBreakpointWidget(lineNumber, column, BreakpointWidgetContext.CONDITION)) - )); - actions.push(new Action( - 'addLogPoint', - nls.localize('addLogPoint', "Add Logpoint..."), - undefined, - true, - () => Promise.resolve(this.showBreakpointWidget(lineNumber, column, BreakpointWidgetContext.LOG_MESSAGE)) - )); - actions.push(new Action( - 'addTriggeredBreakpoint', - nls.localize('addTriggeredBreakpoint', "Add Triggered Breakpoint..."), - undefined, - true, - () => Promise.resolve(this.showBreakpointWidget(lineNumber, column, BreakpointWidgetContext.TRIGGER_POINT)) - )); + actions.push(toAction({ + id: 'addBreakpoint', + label: nls.localize('addBreakpoint', "Add Breakpoint"), + enabled: true, + run: () => this.debugService.addBreakpoints(uri, [{ lineNumber, column }]) + })); + actions.push(toAction({ + id: 'addConditionalBreakpoint', + label: nls.localize('addConditionalBreakpoint', "Add Conditional Breakpoint..."), + enabled: true, + run: () => Promise.resolve(this.showBreakpointWidget(lineNumber, column, BreakpointWidgetContext.CONDITION)) + })); + actions.push(toAction({ + id: 'addLogPoint', + label: nls.localize('addLogPoint', "Add Logpoint..."), + enabled: true, + run: () => Promise.resolve(this.showBreakpointWidget(lineNumber, column, BreakpointWidgetContext.LOG_MESSAGE)) + })); + actions.push(toAction({ + id: 'addTriggeredBreakpoint', + label: nls.localize('addTriggeredBreakpoint', "Add Triggered Breakpoint..."), + enabled: true, + run: () => Promise.resolve(this.showBreakpointWidget(lineNumber, column, BreakpointWidgetContext.TRIGGER_POINT)) + })); } if (this.debugService.state === State.Stopped) { actions.push(new Separator()); - actions.push(new Action( - 'runToLine', - nls.localize('runToLine', "Run to Line"), - undefined, - true, - () => this.debugService.runTo(uri, lineNumber).catch(onUnexpectedError) - )); - } - - return actions; + actions.push(toAction({ + id: 'runToLine', + label: nls.localize('runToLine', "Run to Line"), + enabled: true, + run: () => this.debugService.runTo(uri, lineNumber).catch(onUnexpectedError) + })); + } return actions; } private marginFreeFromNonDebugDecorations(line: number): boolean { diff --git a/src/vs/workbench/contrib/debug/browser/debugEditorActions.ts b/src/vs/workbench/contrib/debug/browser/debugEditorActions.ts index 6edaa7cb866..e196fe59530 100644 --- a/src/vs/workbench/contrib/debug/browser/debugEditorActions.ts +++ b/src/vs/workbench/contrib/debug/browser/debugEditorActions.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { getDomNodePagePosition } from '../../../../base/browser/dom.js'; -import { Action } from '../../../../base/common/actions.js'; +import { toAction } from '../../../../base/common/actions.js'; import { KeyChord, KeyCode, KeyMod } from '../../../../base/common/keyCodes.js'; import { ICodeEditor } from '../../../../editor/browser/editorBrowser.js'; import { EditorAction, IActionOptions, registerEditorAction } from '../../../../editor/browser/editorExtensions.js'; @@ -542,7 +542,7 @@ class StepIntoTargetsAction extends EditorAction { contextMenuService.showContextMenu({ getAnchor: () => ({ x, y }), getActions: () => { - return targets.map(t => new Action(`stepIntoTarget:${t.id}`, t.label, undefined, true, () => session.stepIn(frame.thread.threadId, t.id))); + return targets.map(t => toAction({ id: `stepIntoTarget:${t.id}`, label: t.label, enabled: true, run: () => session.stepIn(frame.thread.threadId, t.id) })); } }); } diff --git a/src/vs/workbench/contrib/debug/browser/debugService.ts b/src/vs/workbench/contrib/debug/browser/debugService.ts index de94395e9a6..e76162ba639 100644 --- a/src/vs/workbench/contrib/debug/browser/debugService.ts +++ b/src/vs/workbench/contrib/debug/browser/debugService.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as aria from '../../../../base/browser/ui/aria/aria.js'; -import { Action, IAction } from '../../../../base/common/actions.js'; +import { IAction, toAction } from '../../../../base/common/actions.js'; import { distinct } from '../../../../base/common/arrays.js'; import { RunOnceScheduler, raceTimeout } from '../../../../base/common/async.js'; import { CancellationTokenSource } from '../../../../base/common/cancellation.js'; @@ -572,17 +572,14 @@ export class DebugService implements IDebugService { const actionList: IAction[] = []; - actionList.push(new Action( - 'installAdditionalDebuggers', - nls.localize({ key: 'installAdditionalDebuggers', comment: ['Placeholder is the debug type, so for example "node", "python"'] }, "Install {0} Extension", resolvedConfig.type), - undefined, - true, - async () => this.commandService.executeCommand('debug.installAdditionalDebuggers', resolvedConfig?.type) - )); + actionList.push(toAction({ + id: 'installAdditionalDebuggers', + label: nls.localize({ key: 'installAdditionalDebuggers', comment: ['Placeholder is the debug type, so for example "node", "python"'] }, "Install {0} Extension", resolvedConfig.type), + enabled: true, + run: async () => this.commandService.executeCommand('debug.installAdditionalDebuggers', resolvedConfig?.type) + })); - await this.showError(message, actionList); - - return false; + await this.showError(message, actionList); return false; } if (!dbg.enabled) { @@ -1001,7 +998,7 @@ export class DebugService implements IDebugService { } private async showError(message: string, errorActions: ReadonlyArray = [], promptLaunchJson = true): Promise { - const configureAction = new Action(DEBUG_CONFIGURE_COMMAND_ID, DEBUG_CONFIGURE_LABEL, undefined, true, () => this.commandService.executeCommand(DEBUG_CONFIGURE_COMMAND_ID)); + const configureAction = toAction({ id: DEBUG_CONFIGURE_COMMAND_ID, label: DEBUG_CONFIGURE_LABEL, enabled: true, run: () => this.commandService.executeCommand(DEBUG_CONFIGURE_COMMAND_ID) }); // Don't append the standard command if id of any provided action indicates it is a command const actions = errorActions.filter((action) => action.id.endsWith('.command')).length > 0 ? errorActions : diff --git a/src/vs/workbench/contrib/debug/browser/debugTaskRunner.ts b/src/vs/workbench/contrib/debug/browser/debugTaskRunner.ts index 67e1f1bdb8f..9374887badd 100644 --- a/src/vs/workbench/contrib/debug/browser/debugTaskRunner.ts +++ b/src/vs/workbench/contrib/debug/browser/debugTaskRunner.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { Action } from '../../../../base/common/actions.js'; +import { toAction } from '../../../../base/common/actions.js'; import { disposableTimeout } from '../../../../base/common/async.js'; import { CancellationTokenSource } from '../../../../base/common/cancellation.js'; import { createErrorWithActions } from '../../../../base/common/errorMessage.js'; @@ -204,7 +204,7 @@ export class DebugTaskRunner implements IDisposable { const errorMessage = typeof taskId === 'string' ? nls.localize('DebugTaskNotFoundWithTaskId', "Could not find the task '{0}'.", taskId) : nls.localize('DebugTaskNotFound', "Could not find the specified task."); - return Promise.reject(createErrorWithActions(errorMessage, [new Action(DEBUG_CONFIGURE_COMMAND_ID, DEBUG_CONFIGURE_LABEL, undefined, true, () => this.commandService.executeCommand(DEBUG_CONFIGURE_COMMAND_ID))])); + return Promise.reject(createErrorWithActions(errorMessage, [toAction({ id: DEBUG_CONFIGURE_COMMAND_ID, label: DEBUG_CONFIGURE_LABEL, enabled: true, run: () => this.commandService.executeCommand(DEBUG_CONFIGURE_COMMAND_ID) })])); } // If a task is missing the problem matcher the promise will never complete, so we need to have a workaround #35340 diff --git a/src/vs/workbench/contrib/debug/browser/variablesView.ts b/src/vs/workbench/contrib/debug/browser/variablesView.ts index 2130f6831f5..2d5079adedb 100644 --- a/src/vs/workbench/contrib/debug/browser/variablesView.ts +++ b/src/vs/workbench/contrib/debug/browser/variablesView.ts @@ -10,7 +10,7 @@ import { IListVirtualDelegate } from '../../../../base/browser/ui/list/list.js'; import { IListAccessibilityProvider } from '../../../../base/browser/ui/list/listWidget.js'; import { AsyncDataTree, IAsyncDataTreeViewState } from '../../../../base/browser/ui/tree/asyncDataTree.js'; import { ITreeContextMenuEvent, ITreeMouseEvent, ITreeNode, ITreeRenderer } from '../../../../base/browser/ui/tree/tree.js'; -import { Action, IAction } from '../../../../base/common/actions.js'; +import { IAction, toAction } from '../../../../base/common/actions.js'; import { coalesce } from '../../../../base/common/arrays.js'; import { RunOnceScheduler } from '../../../../base/common/async.js'; import { CancellationToken, CancellationTokenSource } from '../../../../base/common/cancellation.js'; @@ -506,7 +506,9 @@ export class VisualizedVariableRenderer extends AbstractExpressionsRenderer { const { primary } = getContextMenuActions(menu, 'inline'); if (viz.original) { - const action = new Action('debugViz', localize('removeVisualizer', 'Remove Visualizer'), ThemeIcon.asClassName(Codicon.eye), true, () => this.debugService.getViewModel().setVisualizedExpression(viz.original!, undefined)); + const action = toAction({ + id: 'debugViz', label: localize('removeVisualizer', 'Remove Visualizer'), class: ThemeIcon.asClassName(Codicon.eye), run: () => this.debugService.getViewModel().setVisualizedExpression(viz.original!, undefined) + }); action.checked = true; primary.push(action); actionBar.domNode.style.display = 'initial'; @@ -592,13 +594,13 @@ export class VariablesRenderer extends AbstractExpressionsRenderer { data.elementDisposable.add(result); const originalExpression = (expression instanceof VisualizedExpression && expression.original) || expression; - const actions = result.object.map(v => new Action('debugViz', v.name, v.iconClass || 'debug-viz-icon', undefined, this.useVisualizer(v, originalExpression, cts.token))); + const actions = result.object.map(v => toAction({ id: 'debugViz', label: v.name, class: v.iconClass || 'debug-viz-icon', run: this.useVisualizer(v, originalExpression, cts.token) })); if (actions.length === 0) { // no-op } else if (actions.length === 1) { actionBar.push(actions[0], { icon: true, label: false }); } else { - actionBar.push(new Action('debugViz', localize('useVisualizer', 'Visualize Variable...'), ThemeIcon.asClassName(Codicon.eye), undefined, () => this.pickVisualizer(actions, originalExpression, data)), { icon: true, label: false }); + actionBar.push(toAction({ id: 'debugViz', label: localize('useVisualizer', 'Visualize Variable...'), class: ThemeIcon.asClassName(Codicon.eye), run: () => this.pickVisualizer(actions, originalExpression, data) }), { icon: true, label: false }); } }); } diff --git a/src/vs/workbench/contrib/remote/browser/remoteExplorer.ts b/src/vs/workbench/contrib/remote/browser/remoteExplorer.ts index 480feea12ad..7adab723887 100644 --- a/src/vs/workbench/contrib/remote/browser/remoteExplorer.ts +++ b/src/vs/workbench/contrib/remote/browser/remoteExplorer.ts @@ -34,7 +34,7 @@ import { IConfigurationRegistry, Extensions as ConfigurationExtensions } from '. import { ILogService } from '../../../../platform/log/common/log.js'; import { IWorkbenchConfigurationService } from '../../../services/configuration/common/configuration.js'; import { IRemoteAgentEnvironment } from '../../../../platform/remote/common/remoteAgentEnvironment.js'; -import { Action } from '../../../../base/common/actions.js'; +import { toAction } from '../../../../base/common/actions.js'; import { IPreferencesService } from '../../../services/preferences/common/preferences.js'; import { IStorageService, StorageScope } from '../../../../platform/storage/common/storage.js'; @@ -273,16 +273,24 @@ export class AutomaticPortForwarding extends Disposable implements IWorkbenchCon severity: Severity.Warning, actions: { primary: [ - new Action('switchBack', nls.localize('remote.autoForwardPortsSource.fallback.switchBack', "Undo"), undefined, true, async () => { - await this.configurationService.updateValue(PORT_AUTO_SOURCE_SETTING, PORT_AUTO_SOURCE_SETTING_PROCESS); - await this.configurationService.updateValue(PORT_AUTO_FALLBACK_SETTING, 0, ConfigurationTarget.WORKSPACE); - this.portListener?.dispose(); - this.portListener = undefined; + toAction({ + id: 'switchBack', + label: nls.localize('remote.autoForwardPortsSource.fallback.switchBack', "Undo"), + run: async () => { + await this.configurationService.updateValue(PORT_AUTO_SOURCE_SETTING, PORT_AUTO_SOURCE_SETTING_PROCESS); + await this.configurationService.updateValue(PORT_AUTO_FALLBACK_SETTING, 0, ConfigurationTarget.WORKSPACE); + this.portListener?.dispose(); + this.portListener = undefined; + } }), - new Action('showPortSourceSetting', nls.localize('remote.autoForwardPortsSource.fallback.showPortSourceSetting', "Show Setting"), undefined, true, async () => { - await this.preferencesService.openSettings({ - query: 'remote.autoForwardPortsSource' - }); + toAction({ + id: 'showPortSourceSetting', + label: nls.localize('remote.autoForwardPortsSource.fallback.showPortSourceSetting', "Show Setting"), + run: async () => { + await this.preferencesService.openSettings({ + query: 'remote.autoForwardPortsSource' + }); + } }) ] } diff --git a/src/vs/workbench/contrib/remoteTunnel/electron-browser/remoteTunnel.contribution.ts b/src/vs/workbench/contrib/remoteTunnel/electron-browser/remoteTunnel.contribution.ts index 5de04851541..0eaa650b9c9 100644 --- a/src/vs/workbench/contrib/remoteTunnel/electron-browser/remoteTunnel.contribution.ts +++ b/src/vs/workbench/contrib/remoteTunnel/electron-browser/remoteTunnel.contribution.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { Action } from '../../../../base/common/actions.js'; +import { toAction } from '../../../../base/common/actions.js'; import { Disposable, DisposableStore } from '../../../../base/common/lifecycle.js'; import { Schemas } from '../../../../base/common/network.js'; import { ITunnelApplicationConfig } from '../../../../base/common/product.js'; @@ -200,11 +200,15 @@ export class RemoteTunnelWorkbenchContribution extends Disposable implements IWo ), actions: { primary: [ - new Action('showExtension', localize('action.showExtension', "Show Extension"), undefined, true, () => { - return this.commandService.executeCommand('workbench.extensions.action.showExtensionsWithIds', [remoteExtension.extensionId]); + toAction({ + id: 'showExtension', label: localize('action.showExtension', "Show Extension"), run: () => { + return this.commandService.executeCommand('workbench.extensions.action.showExtensionsWithIds', [remoteExtension.extensionId]); + } }), - new Action('doNotShowAgain', localize('action.doNotShowAgain', "Do not show again"), undefined, true, () => { - this.storageService.store(REMOTE_TUNNEL_EXTENSION_RECOMMENDED_KEY, true, StorageScope.APPLICATION, StorageTarget.USER); + toAction({ + id: 'doNotShowAgain', label: localize('action.doNotShowAgain', "Do not show again"), run: () => { + this.storageService.store(REMOTE_TUNNEL_EXTENSION_RECOMMENDED_KEY, true, StorageScope.APPLICATION, StorageTarget.USER); + } }), ] } @@ -564,9 +568,11 @@ export class RemoteTunnelWorkbenchContribution extends Disposable implements IWo ), actions: { primary: [ - new Action('copyToClipboard', localize('action.copyToClipboard', "Copy Browser Link to Clipboard"), undefined, true, () => clipboardService.writeText(linkToOpen.toString(true))), - new Action('showExtension', localize('action.showExtension', "Show Extension"), undefined, true, () => { - return commandService.executeCommand('workbench.extensions.action.showExtensionsWithIds', [remoteExtension.extensionId]); + toAction({ id: 'copyToClipboard', label: localize('action.copyToClipboard', "Copy Browser Link to Clipboard"), run: () => clipboardService.writeText(linkToOpen.toString(true)) }), + toAction({ + id: 'showExtension', label: localize('action.showExtension', "Show Extension"), run: () => { + return commandService.executeCommand('workbench.extensions.action.showExtensionsWithIds', [remoteExtension.extensionId]); + } }) ] }