activity bar - use IAction in more places

This commit is contained in:
Benjamin Pasero 2021-01-12 11:07:31 +01:00
parent b5b160e015
commit 7a8c7f5731
10 changed files with 109 additions and 104 deletions

View file

@ -256,7 +256,7 @@ export class ButtonWithDropdown extends Disposable implements IButton {
this.button = this._register(new Button(this.element, options));
this._register(this.button.onDidClick(e => this._onDidClick.fire(e)));
this.action = new Action('primaryAction', this.button.label, undefined, true, async () => this._onDidClick.fire(undefined));
this.action = this._register(new Action('primaryAction', this.button.label, undefined, true, async () => this._onDidClick.fire(undefined)));
this.dropdownButton = this._register(new Button(this.element, { ...options, title: false, supportIcons: true }));
this.dropdownButton.element.classList.add('monaco-dropdown-button');

View file

@ -176,7 +176,7 @@ export class ActionWithDropdownActionViewItem extends ActionViewItem {
return [this._action, ...(Array.isArray(actionsProvider) ? actionsProvider : actionsProvider.getActions())];
}
};
this.dropdownMenuActionViewItem = new DropdownMenuActionViewItem(new Action('dropdownAction', undefined), menuActionsProvider, this.contextMenuProvider, { classNames: ['dropdown', ...Codicon.dropDownButton.classNamesArray, ...(<IActionWithDropdownActionViewItemOptions>this.options).menuActionClassNames || []] });
this.dropdownMenuActionViewItem = new DropdownMenuActionViewItem(this._register(new Action('dropdownAction', undefined)), menuActionsProvider, this.contextMenuProvider, { classNames: ['dropdown', ...Codicon.dropDownButton.classNamesArray, ...(<IActionWithDropdownActionViewItemOptions>this.options).menuActionClassNames || []] });
this.dropdownMenuActionViewItem.render(this.element);
}
}

View file

@ -283,3 +283,16 @@ export class EmptySubmenuAction extends Action {
super(EmptySubmenuAction.ID, nls.localize('submenu.empty', '(empty)'), undefined, false);
}
}
export function toAction(props: { id: string, label: string, enabled?: boolean, checked?: boolean, run: Function; }): IAction {
return {
id: props.id,
label: props.label,
class: undefined,
enabled: props.enabled ?? true,
checked: props.checked ?? false,
run: async () => props.run(),
tooltip: props.label,
dispose: () => { }
};
}

View file

@ -4,11 +4,11 @@
*--------------------------------------------------------------------------------------------*/
import 'vs/css!./media/activityaction';
import * as nls from 'vs/nls';
import * as DOM from 'vs/base/browser/dom';
import { localize } from 'vs/nls';
import { EventType, addDisposableListener, EventHelper } from 'vs/base/browser/dom';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { EventType as TouchEventType, GestureEvent } from 'vs/base/browser/touch';
import { Action, IAction, Separator, SubmenuAction } from 'vs/base/common/actions';
import { Action, IAction, Separator, SubmenuAction, toAction } from 'vs/base/common/actions';
import { KeyCode } from 'vs/base/common/keyCodes';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { IMenuService, MenuId, IMenu, registerAction2, Action2, IAction2Options } from 'vs/platform/actions/common/actions';
@ -127,21 +127,21 @@ class MenuActivityActionViewItem extends ActivityActionViewItem {
// Context menus are triggered on mouse down so that an item can be picked
// and executed with releasing the mouse over it
this._register(DOM.addDisposableListener(this.container, DOM.EventType.MOUSE_DOWN, (e: MouseEvent) => {
DOM.EventHelper.stop(e, true);
this._register(addDisposableListener(this.container, EventType.MOUSE_DOWN, (e: MouseEvent) => {
EventHelper.stop(e, true);
this.showContextMenu(e);
}));
this._register(DOM.addDisposableListener(this.container, DOM.EventType.KEY_UP, (e: KeyboardEvent) => {
this._register(addDisposableListener(this.container, EventType.KEY_UP, (e: KeyboardEvent) => {
let event = new StandardKeyboardEvent(e);
if (event.equals(KeyCode.Enter) || event.equals(KeyCode.Space)) {
DOM.EventHelper.stop(e, true);
EventHelper.stop(e, true);
this.showContextMenu();
}
}));
this._register(DOM.addDisposableListener(this.container, TouchEventType.Tap, (e: GestureEvent) => {
DOM.EventHelper.stop(e, true);
this._register(addDisposableListener(this.container, TouchEventType.Tap, (e: GestureEvent) => {
EventHelper.stop(e, true);
this.showContextMenu();
}));
}
@ -206,7 +206,7 @@ export class HomeActivityActionViewItem extends MenuActivityActionViewItem {
const actions = [];
// Go Home
actions.push(disposables.add(new Action('goHome', nls.localize('goHome', "Go Home"), undefined, true, async () => window.location.href = this.goHomeHref)));
actions.push(toAction({ id: 'goHome', label: localize('goHome', "Go Home"), run: () => window.location.href = this.goHomeHref }));
// Contributed
const contributedActions = await super.resolveMainMenuActions(homeMenu, disposables);
@ -222,9 +222,7 @@ export class HomeActivityActionViewItem extends MenuActivityActionViewItem {
const actions = await super.resolveContextMenuActions(disposables);
actions.unshift(...[
new Action('hideHomeButton', nls.localize('hideHomeButton', "Hide Home Button"), undefined, true, async () => {
this.storageService.store(HomeActivityActionViewItem.HOME_BAR_VISIBILITY_PREFERENCE, false, StorageScope.GLOBAL, StorageTarget.USER);
}),
toAction({ id: 'hideHomeButton', label: localize('hideHomeButton', "Hide Home Button"), run: () => this.storageService.store(HomeActivityActionViewItem.HOME_BAR_VISIBILITY_PREFERENCE, false, StorageScope.GLOBAL, StorageTarget.USER) }),
new Separator()
]);
@ -285,11 +283,11 @@ export class AccountsActivityActionViewItem extends MenuActivityActionViewItem {
if (sessionInfo.sessions) {
Object.keys(sessionInfo.sessions).forEach(accountName => {
const manageExtensionsAction = disposables.add(new Action(`configureSessions${accountName}`, nls.localize('manageTrustedExtensions', "Manage Trusted Extensions"), '', true, () => {
const manageExtensionsAction = disposables.add(new Action(`configureSessions${accountName}`, localize('manageTrustedExtensions', "Manage Trusted Extensions"), '', true, () => {
return this.authenticationService.manageTrustedExtensionsForAccount(sessionInfo.providerId, accountName);
}));
const signOutAction = disposables.add(new Action('signOut', nls.localize('signOut', "Sign Out"), '', true, () => {
const signOutAction = disposables.add(new Action('signOut', localize('signOut', "Sign Out"), '', true, () => {
return this.authenticationService.signOutOfAccount(sessionInfo.providerId, accountName);
}));
@ -304,7 +302,7 @@ export class AccountsActivityActionViewItem extends MenuActivityActionViewItem {
menus.push(providerSubMenu);
});
} else {
const providerUnavailableAction = disposables.add(new Action('providerUnavailable', nls.localize('authProviderUnavailable', '{0} is currently unavailable', providerDisplayName)));
const providerUnavailableAction = disposables.add(new Action('providerUnavailable', localize('authProviderUnavailable', '{0} is currently unavailable', providerDisplayName)));
menus.push(providerUnavailableAction);
}
});
@ -328,9 +326,7 @@ export class AccountsActivityActionViewItem extends MenuActivityActionViewItem {
const actions = await super.resolveContextMenuActions(disposables);
actions.unshift(...[
new Action('hideAccounts', nls.localize('hideAccounts', "Hide Accounts"), undefined, true, async () => {
this.storageService.store(AccountsActivityActionViewItem.ACCOUNTS_VISIBILITY_PREFERENCE_KEY, false, StorageScope.GLOBAL, StorageTarget.USER);
}),
toAction({ id: 'hideAccounts', label: localize('hideAccounts', "Hide Accounts"), run: () => this.storageService.store(AccountsActivityActionViewItem.ACCOUNTS_VISIBILITY_PREFERENCE_KEY, false, StorageScope.GLOBAL, StorageTarget.USER) }),
new Separator()
]);
@ -404,7 +400,7 @@ registerAction2(
constructor() {
super({
id: 'workbench.action.previousSideBarView',
title: { value: nls.localize('previousSideBarView', "Previous Side Bar View"), original: 'Previous Side Bar View' },
title: { value: localize('previousSideBarView', "Previous Side Bar View"), original: 'Previous Side Bar View' },
category: CATEGORIES.View,
f1: true
}, -1);
@ -417,7 +413,7 @@ registerAction2(
constructor() {
super({
id: 'workbench.action.nextSideBarView',
title: { value: nls.localize('nextSideBarView', "Next Side Bar View"), original: 'Next Side Bar View' },
title: { value: localize('nextSideBarView', "Next Side Bar View"), original: 'Next Side Bar View' },
category: CATEGORIES.View,
f1: true
}, 1);

View file

@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import 'vs/css!./media/activitybarpart';
import * as nls from 'vs/nls';
import { localize } from 'vs/nls';
import { ActionsOrientation, ActionBar } from 'vs/base/browser/ui/actionbar/actionbar';
import { GLOBAL_ACTIVITY_ID, IActivity, ACCOUNTS_ACTIVITY_ID } from 'vs/workbench/common/activity';
import { Part } from 'vs/workbench/browser/part';
@ -35,7 +35,7 @@ import { getMenuBarVisibility } from 'vs/platform/windows/common/windows';
import { isNative, isWeb } from 'vs/base/common/platform';
import { Before2D } from 'vs/workbench/browser/dnd';
import { Codicon, iconRegistry } from 'vs/base/common/codicons';
import { Action, IAction, Separator } from 'vs/base/common/actions';
import { IAction, Separator, toAction } from 'vs/base/common/actions';
import { Event } from 'vs/base/common/event';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { KeyCode } from 'vs/base/common/keyCodes';
@ -69,9 +69,6 @@ interface ICachedViewContainer {
views?: { when?: string; }[];
}
const settingsViewBarIcon = registerIcon('settings-view-bar-icon', Codicon.settingsGear, nls.localize('settingsViewBarIcon', 'Settings icon in the view bar.'));
const accountsViewBarIcon = registerIcon('accounts-view-bar-icon', Codicon.account, nls.localize('accountsViewBarIcon', 'Accounts icon in the view bar.'));
export class ActivitybarPart extends Part implements IActivityBarService {
declare readonly _serviceBrand: undefined;
@ -81,6 +78,9 @@ export class ActivitybarPart extends Part implements IActivityBarService {
private static readonly ACTION_HEIGHT = 48;
private static readonly ACCOUNTS_ACTION_INDEX = 0;
private static readonly GEAR_ICON = registerIcon('settings-view-bar-icon', Codicon.settingsGear, localize('settingsViewBarIcon', "Settings icon in the view bar."));
private static readonly ACCOUNTS_ICON = registerIcon('accounts-view-bar-icon', Codicon.account, localize('accountsViewBarIcon', "Accounts icon in the view bar."));
//#region IView
readonly minimumWidth: number = 48;
@ -164,7 +164,7 @@ export class ActivitybarPart extends Part implements IActivityBarService {
openComposite: compositeId => this.viewsService.openViewContainer(compositeId, true),
getActivityAction: compositeId => this.getCompositeActions(compositeId).activityAction,
getCompositePinnedAction: compositeId => this.getCompositeActions(compositeId).pinnedAction,
getOnCompositeClickAction: compositeId => new Action(compositeId, '', '', true, () => this.viewsService.isViewContainerVisible(compositeId) ? Promise.resolve(this.viewsService.closeViewContainer(compositeId)) : this.viewsService.openViewContainer(compositeId)),
getOnCompositeClickAction: compositeId => toAction({ id: compositeId, label: '', run: async () => this.viewsService.isViewContainerVisible(compositeId) ? this.viewsService.closeViewContainer(compositeId) : this.viewsService.openViewContainer(compositeId) }),
fillExtraContextMenuActions: actions => {
// Home
@ -172,9 +172,9 @@ export class ActivitybarPart extends Part implements IActivityBarService {
if (this.homeBarContainer) {
topActions.push({
id: 'toggleHomeBarAction',
label: nls.localize('homeButton', "Home Button"),
label: localize('homeButton', "Home Button"),
class: undefined,
tooltip: nls.localize('homeButton', "Home Button"),
tooltip: localize('homeButton', "Home Button"),
checked: this.homeBarVisibilityPreference,
enabled: true,
run: async () => this.homeBarVisibilityPreference = !this.homeBarVisibilityPreference,
@ -187,9 +187,9 @@ export class ActivitybarPart extends Part implements IActivityBarService {
if (menuBarVisibility === 'compact' || (menuBarVisibility === 'hidden' && isWeb)) {
topActions.push({
id: 'toggleMenuVisibility',
label: nls.localize('menu', "Menu"),
label: localize('menu', "Menu"),
class: undefined,
tooltip: nls.localize('menu', "Menu"),
tooltip: localize('menu', "Menu"),
checked: menuBarVisibility === 'compact',
enabled: true,
run: async () => this.layoutService.toggleMenuBar(),
@ -205,9 +205,9 @@ export class ActivitybarPart extends Part implements IActivityBarService {
actions.push(new Separator());
actions.push({
id: 'toggleAccountsVisibility',
label: nls.localize('accounts', "Accounts"),
label: localize('accounts', "Accounts"),
class: undefined,
tooltip: nls.localize('accounts', "Accounts"),
tooltip: localize('accounts', "Accounts"),
checked: this.accountsVisibilityPreference,
enabled: true,
run: async () => this.accountsVisibilityPreference = !this.accountsVisibilityPreference,
@ -220,13 +220,7 @@ export class ActivitybarPart extends Part implements IActivityBarService {
actions.push(this.instantiationService.createInstance(ToggleSidebarPositionAction, ToggleSidebarPositionAction.ID, ToggleSidebarPositionAction.getLabel(this.layoutService)));
// Toggle Activity Bar
actions.push(new Action(
ToggleActivityBarVisibilityAction.ID,
nls.localize('hideActivitBar', "Hide Activity Bar"),
undefined,
true,
async () => { this.instantiationService.invokeFunction(accessor => new ToggleActivityBarVisibilityAction().run(accessor)); }
));
actions.push(toAction({ id: ToggleActivityBarVisibilityAction.ID, label: localize('hideActivitBar', "Hide Activity Bar"), run: async () => this.instantiationService.invokeFunction(accessor => new ToggleActivityBarVisibilityAction().run(accessor)) }));
},
getContextMenuActionsForComposite: compositeId => this.getContextMenuActionsForComposite(compositeId),
getDefaultCompositeId: () => this.viewDescriptorService.getDefaultViewContainer(this.location)!.id,
@ -242,24 +236,20 @@ export class ActivitybarPart extends Part implements IActivityBarService {
}));
}
private getContextMenuActionsForComposite(compositeId: string): Action[] {
const actions = [];
private getContextMenuActionsForComposite(compositeId: string): IAction[] {
const actions: IAction[] = [];
const viewContainer = this.viewDescriptorService.getViewContainerById(compositeId)!;
const defaultLocation = this.viewDescriptorService.getDefaultViewContainerLocation(viewContainer)!;
if (defaultLocation !== this.viewDescriptorService.getViewContainerLocation(viewContainer)) {
actions.push(new Action('resetLocationAction', nls.localize('resetLocation', "Reset Location"), undefined, true, async () => {
this.viewDescriptorService.moveViewContainerToLocation(viewContainer, defaultLocation);
}));
actions.push(toAction({ id: 'resetLocationAction', label: localize('resetLocation', "Reset Location"), run: () => this.viewDescriptorService.moveViewContainerToLocation(viewContainer, defaultLocation) }));
} else {
const viewContainerModel = this.viewDescriptorService.getViewContainerModel(viewContainer);
if (viewContainerModel.allViewDescriptors.length === 1) {
const viewToReset = viewContainerModel.allViewDescriptors[0];
const defaultContainer = this.viewDescriptorService.getDefaultContainerById(viewToReset.id)!;
if (defaultContainer !== viewContainer) {
actions.push(new Action('resetLocationAction', nls.localize('resetLocation', "Reset Location"), undefined, true, async () => {
this.viewDescriptorService.moveViewsToContainer([viewToReset], defaultContainer);
}));
actions.push(toAction({ id: 'resetLocationAction', label: localize('resetLocation', "Reset Location"), run: () => this.viewDescriptorService.moveViewsToContainer([viewToReset], defaultContainer) }));
}
}
}
@ -575,14 +565,14 @@ export class ActivitybarPart extends Part implements IActivityBarService {
private createHomeBar(href: string, icon: Codicon): void {
this.homeBarContainer = document.createElement('div');
this.homeBarContainer.setAttribute('aria-label', nls.localize('homeIndicator', "Home"));
this.homeBarContainer.setAttribute('aria-label', localize('homeIndicator', "Home"));
this.homeBarContainer.setAttribute('role', 'toolbar');
this.homeBarContainer.classList.add('home-bar');
this.homeBar = this._register(new ActionBar(this.homeBarContainer, {
actionViewItemProvider: action => this.instantiationService.createInstance(HomeActivityActionViewItem, href, action as ActivityAction, () => this.compositeBar.getContextMenuActions(), (theme: IColorTheme) => this.getActivitybarItemColors(theme)),
orientation: ActionsOrientation.VERTICAL,
ariaLabel: nls.localize('home', "Home"),
ariaLabel: localize('home', "Home"),
animated: false,
preventLoopNavigation: true,
ignoreOrientationForPreviousAndNextKey: true
@ -594,7 +584,7 @@ export class ActivitybarPart extends Part implements IActivityBarService {
this.homeBar.push(this._register(new ActivityAction({
id: 'workbench.actions.home',
name: nls.localize('home', "Home"),
name: localize('home', "Home"),
cssClass: icon.classNames
})));
@ -616,7 +606,7 @@ export class ActivitybarPart extends Part implements IActivityBarService {
throw new Error(`No view item for action '${action.id}'`);
},
orientation: ActionsOrientation.VERTICAL,
ariaLabel: nls.localize('manage', "Manage"),
ariaLabel: localize('manage', "Manage"),
animated: false,
preventLoopNavigation: true,
ignoreOrientationForPreviousAndNextKey: true
@ -624,15 +614,15 @@ export class ActivitybarPart extends Part implements IActivityBarService {
this.globalActivityAction = this._register(new ActivityAction({
id: 'workbench.actions.manage',
name: nls.localize('manage', "Manage"),
cssClass: ThemeIcon.asClassName(settingsViewBarIcon)
name: localize('manage', "Manage"),
cssClass: ThemeIcon.asClassName(ActivitybarPart.GEAR_ICON)
}));
if (this.accountsVisibilityPreference) {
this.accountsActivityAction = this._register(new ActivityAction({
id: 'workbench.actions.accounts',
name: nls.localize('accounts', "Accounts"),
cssClass: ThemeIcon.asClassName(accountsViewBarIcon)
name: localize('accounts', "Accounts"),
cssClass: ThemeIcon.asClassName(ActivitybarPart.ACCOUNTS_ICON)
}));
this.globalActivityActionBar.push(this.accountsActivityAction, { index: ActivitybarPart.ACCOUNTS_ACTION_INDEX });
@ -649,7 +639,7 @@ export class ActivitybarPart extends Part implements IActivityBarService {
} else {
this.accountsActivityAction = this._register(new ActivityAction({
id: 'workbench.actions.accounts',
name: nls.localize('accounts', "Accounts"),
name: localize('accounts', "Accounts"),
cssClass: Codicon.account.classNames
}));
this.globalActivityActionBar.push(this.accountsActivityAction, { index: ActivitybarPart.ACCOUNTS_ACTION_INDEX });
@ -1088,7 +1078,7 @@ class FocusActivityBarAction extends Action2 {
constructor() {
super({
id: 'workbench.action.focusActivityBar',
title: { value: nls.localize('focusActivityBar', "Focus Activity Bar"), original: 'Focus Activity Bar' },
title: { value: localize('focusActivityBar', "Focus Activity Bar"), original: 'Focus Activity Bar' },
category: CATEGORIES.View,
f1: true
});

View file

@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import * as nls from 'vs/nls';
import { Action, IAction } from 'vs/base/common/actions';
import { IAction, toAction } from 'vs/base/common/actions';
import { illegalArgument } from 'vs/base/common/errors';
import * as arrays from 'vs/base/common/arrays';
import { IDisposable, toDisposable } from 'vs/base/common/lifecycle';
@ -149,10 +149,10 @@ export interface ICompositeBarOptions {
readonly preventLoopNavigation?: boolean;
getActivityAction: (compositeId: string) => ActivityAction;
getCompositePinnedAction: (compositeId: string) => Action;
getOnCompositeClickAction: (compositeId: string) => Action;
getCompositePinnedAction: (compositeId: string) => IAction;
getOnCompositeClickAction: (compositeId: string) => IAction;
fillExtraContextMenuActions: (actions: IAction[]) => void;
getContextMenuActionsForComposite: (compositeId: string) => Action[];
getContextMenuActionsForComposite: (compositeId: string) => IAction[];
openComposite: (compositeId: string) => Promise<IComposite | null>;
getDefaultCompositeId: () => string;
hidePart: () => void;
@ -208,15 +208,15 @@ export class CompositeBar extends Widget implements ICompositeBar {
create(parent: HTMLElement): HTMLElement {
const actionBarDiv = parent.appendChild($('.composite-bar'));
this.compositeSwitcherBar = this._register(new ActionBar(actionBarDiv, {
actionViewItemProvider: (action: IAction) => {
actionViewItemProvider: action => {
if (action instanceof CompositeOverflowActivityAction) {
return this.compositeOverflowActionViewItem;
}
const item = this.model.findItem(action.id);
return item && this.instantiationService.createInstance(
CompositeActionViewItem, action as ActivityAction, item.pinnedAction,
(compositeId: string) => this.options.getContextMenuActionsForComposite(compositeId),
() => this.getContextMenuActions() as Action[],
compositeId => this.options.getContextMenuActionsForComposite(compositeId),
() => this.getContextMenuActions(),
this.options.colors,
this.options.icon,
this.options.dndHandler,
@ -596,7 +596,7 @@ export class CompositeBar extends Widget implements ICompositeBar {
this.compositeOverflowAction,
() => this.getOverflowingComposites(),
() => this.model.activeItem ? this.model.activeItem.id : undefined,
(compositeId: string) => {
compositeId => {
const item = this.model.findItem(compositeId);
return item?.activity[0]?.badge;
},
@ -633,7 +633,7 @@ export class CompositeBar extends Widget implements ICompositeBar {
getContextMenuActions(): IAction[] {
const actions: IAction[] = this.model.visibleItems
.map(({ id, name, activityAction }) => (<IAction>{
.map(({ id, name, activityAction }) => (toAction({
id,
label: this.getAction(id).label || name || id,
checked: this.isPinned(id),
@ -645,7 +645,7 @@ export class CompositeBar extends Widget implements ICompositeBar {
this.pin(id, true);
}
}
}));
})));
this.options.fillExtraContextMenuActions(actions);
@ -655,7 +655,7 @@ export class CompositeBar extends Widget implements ICompositeBar {
interface ICompositeBarModelItem extends ICompositeBarItem {
activityAction: ActivityAction;
pinnedAction: Action;
pinnedAction: IAction;
activity: ICompositeActivity[];
}

View file

@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import * as nls from 'vs/nls';
import { Action, Separator } from 'vs/base/common/actions';
import { Action, IAction, Separator } from 'vs/base/common/actions';
import * as dom from 'vs/base/browser/dom';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { dispose, toDisposable, MutableDisposable } from 'vs/base/common/lifecycle';
@ -374,14 +374,14 @@ export class CompositeOverflowActivityAction extends ActivityAction {
}
export class CompositeOverflowActivityActionViewItem extends ActivityActionViewItem {
private actions: Action[] = [];
private actions: IAction[] = [];
constructor(
action: ActivityAction,
private getOverflowingComposites: () => { id: string, name?: string }[],
private getActiveCompositeId: () => string | undefined,
private getBadge: (compositeId: string) => IBadge,
private getCompositeOpenAction: (compositeId: string) => Action,
private getCompositeOpenAction: (compositeId: string) => IAction,
colors: (theme: IColorTheme) => ICompositeBarColors,
@IContextMenuService private readonly contextMenuService: IContextMenuService,
@IThemeService themeService: IThemeService
@ -404,7 +404,7 @@ export class CompositeOverflowActivityActionViewItem extends ActivityActionViewI
});
}
private getActions(): Action[] {
private getActions(): IAction[] {
return this.getOverflowingComposites().map(composite => {
const action = this.getCompositeOpenAction(composite.id);
action.checked = this.getActiveCompositeId() === action.id;
@ -457,9 +457,9 @@ export class CompositeActionViewItem extends ActivityActionViewItem {
constructor(
private compositeActivityAction: ActivityAction,
private toggleCompositePinnedAction: Action,
private compositeContextMenuActionsProvider: (compositeId: string) => ReadonlyArray<Action>,
private contextMenuActionsProvider: () => ReadonlyArray<Action>,
private toggleCompositePinnedAction: IAction,
private compositeContextMenuActionsProvider: (compositeId: string) => IAction[],
private contextMenuActionsProvider: () => IAction[],
colors: (theme: IColorTheme) => ICompositeBarColors,
icon: boolean,
private dndHandler: ICompositeDragAndDrop,
@ -606,7 +606,7 @@ export class CompositeActionViewItem extends ActivityActionViewItem {
}
private showContextMenu(container: HTMLElement): void {
const actions: Action[] = [this.toggleCompositePinnedAction];
const actions: IAction[] = [this.toggleCompositePinnedAction];
const compositeContextMenuActions = this.compositeContextMenuActionsProvider(this.activity.id);
if (compositeContextMenuActions.length) {

View file

@ -611,7 +611,7 @@ export class StatusbarPart extends Part implements IStatusbarService {
}
private getContextMenuActions(event: StandardMouseEvent): IAction[] {
const actions: Action[] = [];
const actions: IAction[] = [];
// Provide an action to hide the status bar at last
actions.push(this.instantiationService.createInstance(ToggleStatusbarVisibilityAction, ToggleStatusbarVisibilityAction.ID, nls.localize('hideStatusBar', "Hide Status Bar")));

View file

@ -3,12 +3,12 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as nls from 'vs/nls';
import { localize } from 'vs/nls';
import { toErrorMessage } from 'vs/base/common/errorMessage';
import { isFunction, assertIsDefined } from 'vs/base/common/types';
import { isValidBasename } from 'vs/base/common/extpath';
import { basename } from 'vs/base/common/resources';
import { Action } from 'vs/base/common/actions';
import { toAction } from 'vs/base/common/actions';
import { VIEWLET_ID, TEXT_FILE_EDITOR_ID } from 'vs/workbench/contrib/files/common/files';
import { ITextFileService, TextFileOperationError, TextFileOperationResult } from 'vs/workbench/services/textfile/common/textfiles';
import { BaseTextEditor } from 'vs/workbench/browser/parts/editor/textEditor';
@ -97,7 +97,7 @@ export class TextFileEditor extends BaseTextEditor {
}
getTitle(): string {
return this.input ? this.input.getName() : nls.localize('textFileEditor', "Text File Editor");
return this.input ? this.input.getName() : localize('textFileEditor', "Text File Editor");
}
get input(): FileEditorInput | undefined {
@ -169,22 +169,24 @@ export class TextFileEditor extends BaseTextEditor {
if ((<FileOperationError>error).fileOperationResult === FileOperationResult.FILE_IS_DIRECTORY) {
this.openAsFolder(input);
throw new Error(nls.localize('openFolderError', "File is a directory"));
throw new Error(localize('openFolderError', "File is a directory"));
}
// Offer to create a file from the error if we have a file not found and the name is valid
if ((<FileOperationError>error).fileOperationResult === FileOperationResult.FILE_NOT_FOUND && isValidBasename(basename(input.preferredResource))) {
throw createErrorWithActions(toErrorMessage(error), {
actions: [
new Action('workbench.files.action.createMissingFile', nls.localize('createFile', "Create File"), undefined, true, async () => {
await this.textFileService.create(input.preferredResource);
toAction({
id: 'workbench.files.action.createMissingFile', label: localize('createFile', "Create File"), run: async () => {
await this.textFileService.create(input.preferredResource);
return this.editorService.openEditor({
resource: input.preferredResource,
options: {
pinned: true // new file gets pinned by default
}
});
return this.editorService.openEditor({
resource: input.preferredResource,
options: {
pinned: true // new file gets pinned by default
}
});
}
})
]
});

View file

@ -3,13 +3,13 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as nls from 'vs/nls';
import { localize } from 'vs/nls';
import { TextFileEditor } from 'vs/workbench/contrib/files/browser/editors/textFileEditor';
import { FileEditorInput } from 'vs/workbench/contrib/files/common/editors/fileEditorInput';
import { EditorOptions } from 'vs/workbench/common/editor';
import { FileOperationError, FileOperationResult, IFileService, MIN_MAX_MEMORY_SIZE_MB, FALLBACK_MAX_MEMORY_SIZE_MB } from 'vs/platform/files/common/files';
import { createErrorWithActions } from 'vs/base/common/errorsWithActions';
import { Action } from 'vs/base/common/actions';
import { toAction } from 'vs/base/common/actions';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
@ -56,18 +56,22 @@ export class NativeTextFileEditor extends TextFileEditor {
if ((<FileOperationError>error).fileOperationResult === FileOperationResult.FILE_EXCEEDS_MEMORY_LIMIT) {
const memoryLimit = Math.max(MIN_MAX_MEMORY_SIZE_MB, +this.textResourceConfigurationService.getValue<number>(undefined, 'files.maxMemoryForLargeFilesMB') || FALLBACK_MAX_MEMORY_SIZE_MB);
throw createErrorWithActions(nls.localize('fileTooLargeForHeapError', "To open a file of this size, you need to restart and allow it to use more memory"), {
throw createErrorWithActions(localize('fileTooLargeForHeapError', "To open a file of this size, you need to restart and allow it to use more memory"), {
actions: [
new Action('workbench.window.action.relaunchWithIncreasedMemoryLimit', nls.localize('relaunchWithIncreasedMemoryLimit', "Restart with {0} MB", memoryLimit), undefined, true, () => {
return this.nativeHostService.relaunch({
addArgs: [
`--max-memory=${memoryLimit}`
]
});
toAction({
id: 'workbench.window.action.relaunchWithIncreasedMemoryLimit', label: localize('relaunchWithIncreasedMemoryLimit', "Restart with {0} MB", memoryLimit), run: () => {
return this.nativeHostService.relaunch({
addArgs: [
`--max-memory=${memoryLimit}`
]
});
}
}),
toAction({
id: 'workbench.window.action.configureMemoryLimit', label: localize('configureMemoryLimit', 'Configure Memory Limit'), run: () => {
return this.preferencesService.openGlobalSettings(undefined, { query: 'files.maxMemoryForLargeFilesMB' });
}
}),
new Action('workbench.window.action.configureMemoryLimit', nls.localize('configureMemoryLimit', 'Configure Memory Limit'), undefined, true, () => {
return this.preferencesService.openGlobalSettings(undefined, { query: 'files.maxMemoryForLargeFilesMB' });
})
]
});
}