From 8e34708a1fc24e86da438b1da32503d77f5c8281 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Sat, 19 Feb 2022 19:24:57 +0100 Subject: [PATCH] explorer - add "Open Recent" to web serverless empty explorer --- .../browser/actions/windowActions.ts | 4 +- .../browser/parts/titlebar/menubarControl.ts | 3 +- .../contrib/files/browser/explorerViewlet.ts | 64 ++++++++++++++++--- .../contrib/watermark/browser/watermark.ts | 3 +- .../browser/gettingStarted.ts | 5 +- .../parts/titlebar/menubarControl.ts | 3 +- 6 files changed, 66 insertions(+), 16 deletions(-) diff --git a/src/vs/workbench/browser/actions/windowActions.ts b/src/vs/workbench/browser/actions/windowActions.ts index 528678530bb6c..69b1ef95f2dab 100644 --- a/src/vs/workbench/browser/actions/windowActions.ts +++ b/src/vs/workbench/browser/actions/windowActions.ts @@ -232,9 +232,11 @@ abstract class BaseOpenRecentAction extends Action2 { export class OpenRecentAction extends BaseOpenRecentAction { + static ID = 'workbench.action.openRecent'; + constructor() { super({ - id: 'workbench.action.openRecent', + id: OpenRecentAction.ID, title: { value: localize('openRecent', "Open Recent..."), mnemonicTitle: localize({ key: 'miMore', comment: ['&& denotes a mnemonic'] }, "&&More..."), diff --git a/src/vs/workbench/browser/parts/titlebar/menubarControl.ts b/src/vs/workbench/browser/parts/titlebar/menubarControl.ts index 3d75dfa9686c0..fd8c91724bfb6 100644 --- a/src/vs/workbench/browser/parts/titlebar/menubarControl.ts +++ b/src/vs/workbench/browser/parts/titlebar/menubarControl.ts @@ -39,6 +39,7 @@ import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegis import { IsMacNativeContext, IsWebContext } from 'vs/platform/contextkey/common/contextkeys'; import { ICommandService } from 'vs/platform/commands/common/commands'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; +import { OpenRecentAction } from 'vs/workbench/browser/actions/windowActions'; export type IOpenRecentAction = IAction & { uri: URI; remoteAuthority?: string }; @@ -592,7 +593,7 @@ export class CustomMenubarControl extends MenubarControl { private insertActionsBefore(nextAction: IAction, target: IAction[]): void { switch (nextAction.id) { - case 'workbench.action.openRecent': + case OpenRecentAction.ID: target.push(...this.getOpenRecentActions()); break; diff --git a/src/vs/workbench/contrib/files/browser/explorerViewlet.ts b/src/vs/workbench/contrib/files/browser/explorerViewlet.ts index c74af0f3b9d2d..e1fe01aeb71d0 100644 --- a/src/vs/workbench/contrib/files/browser/explorerViewlet.ts +++ b/src/vs/workbench/contrib/files/browser/explorerViewlet.ts @@ -29,9 +29,10 @@ import { KeyChord, KeyMod, KeyCode } from 'vs/base/common/keyCodes'; import { Registry } from 'vs/platform/registry/common/platform'; import { IProgressService, ProgressLocation } from 'vs/platform/progress/common/progress'; import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; -import { WorkbenchStateContext, RemoteNameContext } from 'vs/workbench/common/contextkeys'; +import { WorkbenchStateContext, RemoteNameContext, OpenFolderWorkspaceSupportContext } from 'vs/workbench/common/contextkeys'; import { IsIOSContext, IsWebContext } from 'vs/platform/contextkey/common/contextkeys'; import { AddRootFolderAction, OpenFolderAction, OpenFileFolderAction } from 'vs/workbench/browser/actions/workspaceActions'; +import { OpenRecentAction } from 'vs/workbench/browser/actions/windowActions'; import { isMacintosh, isWeb } from 'vs/base/common/platform'; import { Codicon } from 'vs/base/common/codicons'; import { registerIcon } from 'vs/platform/theme/common/iconRegistry'; @@ -282,19 +283,38 @@ export const VIEW_CONTAINER: ViewContainer = viewContainerRegistry.registerViewC const openFolder = localize('openFolder', "Open Folder"); const addAFolder = localize('addAFolder', "add a folder"); +const openRecent = localize('openRecent', "Open Recent"); const addRootFolderButton = `[${openFolder}](command:${AddRootFolderAction.ID})`; const addAFolderButton = `[${addAFolder}](command:${AddRootFolderAction.ID})`; - -const commandId = (isMacintosh && !isWeb) ? OpenFileFolderAction.ID : OpenFolderAction.ID; -const openFolderButton = `[${openFolder}](command:${commandId})`; - +const openFolderButton = `[${openFolder}](command:${(isMacintosh && !isWeb) ? OpenFileFolderAction.ID : OpenFolderAction.ID})`; +const openRecentButton = `[${openRecent}](command:${OpenRecentAction.ID})`; const viewsRegistry = Registry.as(Extensions.ViewsRegistry); viewsRegistry.registerViewWelcomeContent(EmptyView.ID, { content: localize({ key: 'noWorkspaceHelp', comment: ['Please do not translate the word "commmand", it is part of our internal syntax which must not change'] }, "You have not yet added a folder to the workspace.\n{0}", addRootFolderButton), - when: ContextKeyExpr.and(WorkbenchStateContext.isEqualTo('workspace'), IsIOSContext.toNegated()), + when: ContextKeyExpr.and( + // inside a .code-workspace + WorkbenchStateContext.isEqualTo('workspace'), + // but not on iOS (TODO@isidorn why?) + IsIOSContext.toNegated(), + // unless we cannot enter or open workspaces (e.g. web serverless) + OpenFolderWorkspaceSupportContext + ), + group: ViewContentGroups.Open, + order: 1 +}); + +viewsRegistry.registerViewWelcomeContent(EmptyView.ID, { + content: localize({ key: 'noFolderHelpWeb', comment: ['Please do not translate the word "commmand", it is part of our internal syntax which must not change'] }, + "You have not yet opened a folder.\n{0}\n{1}", addRootFolderButton, openRecentButton), + when: ContextKeyExpr.and( + // inside a .code-workspace + WorkbenchStateContext.isEqualTo('workspace'), + // we cannot enter workspaces (e.g. web serverless) + OpenFolderWorkspaceSupportContext.toNegated() + ), group: ViewContentGroups.Open, order: 1 }); @@ -302,15 +322,30 @@ viewsRegistry.registerViewWelcomeContent(EmptyView.ID, { viewsRegistry.registerViewWelcomeContent(EmptyView.ID, { content: localize({ key: 'remoteNoFolderHelp', comment: ['Please do not translate the word "commmand", it is part of our internal syntax which must not change'] }, "Connected to remote.\n{0}", openFolderButton), - when: ContextKeyExpr.and(WorkbenchStateContext.notEqualsTo('workspace'), RemoteNameContext.notEqualsTo(''), IsWebContext.toNegated()), + when: ContextKeyExpr.and( + // not inside a .code-workspace + WorkbenchStateContext.notEqualsTo('workspace'), + // connected to a remote + RemoteNameContext.notEqualsTo(''), + // but not in web + IsWebContext.toNegated()), group: ViewContentGroups.Open, order: 1 }); viewsRegistry.registerViewWelcomeContent(EmptyView.ID, { content: localize({ key: 'noFolderButEditorsHelp', comment: ['Please do not translate the word "commmand", it is part of our internal syntax which must not change'] }, - "You have not yet opened a folder.\n{0}\nOpening a folder will close all currently open editors. To keep them open, {0} instead.", openFolderButton, addAFolderButton), - when: ContextKeyExpr.and(ContextKeyExpr.has('editorIsOpen'), ContextKeyExpr.or(ContextKeyExpr.and(WorkbenchStateContext.notEqualsTo('workspace'), RemoteNameContext.isEqualTo('')), ContextKeyExpr.and(WorkbenchStateContext.notEqualsTo('workspace'), IsWebContext))), + "You have not yet opened a folder.\n{0}\nOpening a folder will close all currently open editors. To keep them open, {1} instead.", openFolderButton, addAFolderButton), + when: ContextKeyExpr.and( + // editors are opened + ContextKeyExpr.has('editorIsOpen'), + ContextKeyExpr.or( + // not inside a .code-workspace and local + ContextKeyExpr.and(WorkbenchStateContext.notEqualsTo('workspace'), RemoteNameContext.isEqualTo('')), + // not inside a .code-workspace and web + ContextKeyExpr.and(WorkbenchStateContext.notEqualsTo('workspace'), IsWebContext) + ) + ), group: ViewContentGroups.Open, order: 1 }); @@ -318,7 +353,16 @@ viewsRegistry.registerViewWelcomeContent(EmptyView.ID, { viewsRegistry.registerViewWelcomeContent(EmptyView.ID, { content: localize({ key: 'noFolderHelp', comment: ['Please do not translate the word "commmand", it is part of our internal syntax which must not change'] }, "You have not yet opened a folder.\n{0}", openFolderButton), - when: ContextKeyExpr.and(ContextKeyExpr.has('editorIsOpen')?.negate(), ContextKeyExpr.or(ContextKeyExpr.and(WorkbenchStateContext.notEqualsTo('workspace'), RemoteNameContext.isEqualTo('')), ContextKeyExpr.and(WorkbenchStateContext.notEqualsTo('workspace'), IsWebContext))), + when: ContextKeyExpr.and( + // no editor is open + ContextKeyExpr.has('editorIsOpen')?.negate(), + ContextKeyExpr.or( + // not inside a .code-workspace and local + ContextKeyExpr.and(WorkbenchStateContext.notEqualsTo('workspace'), RemoteNameContext.isEqualTo('')), + // not inside a .code-workspace and web + ContextKeyExpr.and(WorkbenchStateContext.notEqualsTo('workspace'), IsWebContext) + ) + ), group: ViewContentGroups.Open, order: 1 }); diff --git a/src/vs/workbench/contrib/watermark/browser/watermark.ts b/src/vs/workbench/contrib/watermark/browser/watermark.ts index 703edf4b757dd..d7f8e8d49caf0 100644 --- a/src/vs/workbench/contrib/watermark/browser/watermark.ts +++ b/src/vs/workbench/contrib/watermark/browser/watermark.ts @@ -16,6 +16,7 @@ import { IWorkbenchContribution, IWorkbenchContributionsRegistry, Extensions as import { ILifecycleService, LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { OpenFolderAction, OpenFileFolderAction, OpenFileAction } from 'vs/workbench/browser/actions/workspaceActions'; +import { OpenRecentAction } from 'vs/workbench/browser/actions/windowActions'; import { ShowAllCommandsAction } from 'vs/workbench/contrib/quickaccess/browser/commandsQuickAccess'; import { Parts, IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService'; import { FindInFilesActionId } from 'vs/workbench/contrib/search/common/constants'; @@ -47,7 +48,7 @@ const quickAccess: WatermarkEntry = { text: nls.localize('watermark.quickAccess' const openFileNonMacOnly: WatermarkEntry = { text: nls.localize('watermark.openFile', "Open File"), id: OpenFileAction.ID, mac: false }; const openFolderNonMacOnly: WatermarkEntry = { text: nls.localize('watermark.openFolder', "Open Folder"), id: OpenFolderAction.ID, mac: false }; const openFileOrFolderMacOnly: WatermarkEntry = { text: nls.localize('watermark.openFileFolder', "Open File or Folder"), id: OpenFileFolderAction.ID, mac: true }; -const openRecent: WatermarkEntry = { text: nls.localize('watermark.openRecent', "Open Recent"), id: 'workbench.action.openRecent' }; +const openRecent: WatermarkEntry = { text: nls.localize('watermark.openRecent', "Open Recent"), id: OpenRecentAction.ID }; const newUntitledFile: WatermarkEntry = { text: nls.localize('watermark.newUntitledFile', "New Untitled File"), id: NEW_UNTITLED_FILE_COMMAND_ID }; const newUntitledFileMacOnly: WatermarkEntry = Object.assign({ mac: true }, newUntitledFile); const findInFiles: WatermarkEntry = { text: nls.localize('watermark.findInFiles', "Find in Files"), id: FindInFilesActionId }; diff --git a/src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStarted.ts b/src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStarted.ts index 66cd179289902..fdc12e99399a1 100644 --- a/src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStarted.ts +++ b/src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStarted.ts @@ -71,6 +71,7 @@ import { getTelemetryLevel } from 'vs/platform/telemetry/common/telemetryUtils'; import { WorkbenchStateContext } from 'vs/workbench/common/contextkeys'; import { IsIOSContext } from 'vs/platform/contextkey/common/contextkeys'; import { AddRootFolderAction } from 'vs/workbench/browser/actions/workspaceActions'; +import { OpenRecentAction } from 'vs/workbench/browser/actions/windowActions'; import { Checkbox } from 'vs/base/browser/ui/checkbox/checkbox'; import { Codicon } from 'vs/base/common/codicons'; import { restoreWalkthroughsConfigurationKey, RestoreWalkthroughsConfigurationValue } from 'vs/workbench/contrib/welcomePage/browser/welcomePage'; @@ -347,7 +348,7 @@ export class GettingStartedPage extends EditorPane { break; } case 'showMoreRecents': { - this.commandService.executeCommand('workbench.action.openRecent'); + this.commandService.executeCommand(OpenRecentAction.ID); break; } case 'seeAllWalkthroughs': { @@ -1100,7 +1101,7 @@ export class GettingStartedPage extends EditorPane { $('button.button-link', { 'x-dispatch': 'showMoreRecents', - title: localize('show more recents', "Show All Recent Folders {0}", this.getKeybindingLabel('workbench.action.openRecent')) + title: localize('show more recents', "Show All Recent Folders {0}", this.getKeybindingLabel(OpenRecentAction.ID)) }, 'More...')), renderElement: renderRecent, contextService: this.contextService diff --git a/src/vs/workbench/electron-sandbox/parts/titlebar/menubarControl.ts b/src/vs/workbench/electron-sandbox/parts/titlebar/menubarControl.ts index b95f18d9e93e4..a2a5bb55453e9 100644 --- a/src/vs/workbench/electron-sandbox/parts/titlebar/menubarControl.ts +++ b/src/vs/workbench/electron-sandbox/parts/titlebar/menubarControl.ts @@ -24,6 +24,7 @@ import { INativeHostService } from 'vs/platform/native/electron-sandbox/native'; import { IHostService } from 'vs/workbench/services/host/browser/host'; import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences'; import { ICommandService } from 'vs/platform/commands/common/commands'; +import { OpenRecentAction } from 'vs/workbench/browser/actions/windowActions'; export class NativeMenubarControl extends MenubarControl { @@ -138,7 +139,7 @@ export class NativeMenubarControl extends MenubarControl { menuToDispose.dispose(); } else { - if (menuItem.id === 'workbench.action.openRecent') { + if (menuItem.id === OpenRecentAction.ID) { const actions = this.getOpenRecentActions().map(this.transformOpenRecentAction); menuToPopulate.items.push(...actions); }