Skip to content

Commit 1823344

Browse files
authored
Merge pull request #634 from CodinGame/vscode-trimming-customization
feat: add extra context keys for customization
2 parents a89716d + 6c1274b commit 1823344

1 file changed

Lines changed: 135 additions & 0 deletions

File tree

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Jean-Damien Thevenoux <jean-damien.thevenoux@codingame.com>
3+
Date: Tue, 10 Jun 2025 19:02:16 +0200
4+
Subject: [PATCH] feat: add a context key to enable further customization
5+
6+
---
7+
src/vs/workbench/browser/actions/windowActions.ts | 15 ++++++++++-----
8+
src/vs/workbench/browser/contextkeys.ts | 5 ++++-
9+
src/vs/workbench/common/contextkeys.ts | 2 ++
10+
.../files/browser/fileActions.contribution.ts | 6 +++---
11+
4 files changed, 19 insertions(+), 9 deletions(-)
12+
13+
diff --git a/src/vs/workbench/browser/actions/windowActions.ts b/src/vs/workbench/browser/actions/windowActions.ts
14+
index 2fb9c8edbb3..c2084859922 100644
15+
--- a/src/vs/workbench/browser/actions/windowActions.ts
16+
+++ b/src/vs/workbench/browser/actions/windowActions.ts
17+
@@ -8,7 +8,7 @@ import { IWindowOpenable } from '../../../platform/window/common/window.js';
18+
import { IDialogService } from '../../../platform/dialogs/common/dialogs.js';
19+
import { MenuRegistry, MenuId, Action2, registerAction2, IAction2Options } from '../../../platform/actions/common/actions.js';
20+
import { KeyChord, KeyCode, KeyMod } from '../../../base/common/keyCodes.js';
21+
-import { IsMainWindowFullscreenContext } from '../../common/contextkeys.js';
22+
+import { IsMainWindowFullscreenContext, IsSandboxWorkspaceContext } from '../../common/contextkeys.js';
23+
import { IsMacNativeContext, IsDevelopmentContext, IsWebContext, IsIOSContext } from '../../../platform/contextkey/common/contextkeys.js';
24+
import { Categories } from '../../../platform/action/common/actionCommonCategories.js';
25+
import { KeybindingsRegistry, KeybindingWeight } from '../../../platform/keybinding/common/keybindingsRegistry.js';
26+
@@ -247,10 +247,12 @@ export class OpenRecentAction extends BaseOpenRecentAction {
27+
primary: KeyMod.CtrlCmd | KeyCode.KeyR,
28+
mac: { primary: KeyMod.WinCtrl | KeyCode.KeyR }
29+
},
30+
+ precondition: IsSandboxWorkspaceContext.toNegated(),
31+
menu: {
32+
id: MenuId.MenubarRecentMenu,
33+
group: 'y_more',
34+
- order: 1
35+
+ order: 1,
36+
+ when: IsSandboxWorkspaceContext.toNegated()
37+
}
38+
});
39+
}
40+
@@ -378,10 +380,12 @@ class NewWindowAction extends Action2 {
41+
primary: isWeb ? (isWindows ? KeyChord(KeyMod.CtrlCmd | KeyCode.KeyK, KeyMod.Shift | KeyCode.KeyN) : KeyMod.CtrlCmd | KeyMod.Alt | KeyMod.Shift | KeyCode.KeyN) : KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KeyN,
42+
secondary: isWeb ? [KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KeyN] : undefined
43+
},
44+
+ precondition: IsSandboxWorkspaceContext.toNegated(),
45+
menu: {
46+
id: MenuId.MenubarFileMenu,
47+
group: '1_new',
48+
- order: 3
49+
+ order: 3,
50+
+ when: IsSandboxWorkspaceContext.toNegated()
51+
}
52+
});
53+
}
54+
@@ -461,12 +465,13 @@ MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
55+
toggled: ContextKeyExpr.notEquals('config.window.confirmBeforeClose', 'never')
56+
},
57+
order: 1,
58+
- when: IsWebContext
59+
+ when: ContextKeyExpr.and(IsSandboxWorkspaceContext.toNegated(), IsWebContext)
60+
});
61+
62+
MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
63+
title: localize({ key: 'miOpenRecent', comment: ['&& denotes a mnemonic'] }, "Open &&Recent"),
64+
submenu: MenuId.MenubarRecentMenu,
65+
group: '2_open',
66+
- order: 4
67+
+ order: 4,
68+
+ when: IsSandboxWorkspaceContext.toNegated()
69+
});
70+
diff --git a/src/vs/workbench/browser/contextkeys.ts b/src/vs/workbench/browser/contextkeys.ts
71+
index 840174189ee..c6a076d0295 100644
72+
--- a/src/vs/workbench/browser/contextkeys.ts
73+
+++ b/src/vs/workbench/browser/contextkeys.ts
74+
@@ -7,7 +7,7 @@ import { Event } from '../../base/common/event.js';
75+
import { Disposable, DisposableStore } from '../../base/common/lifecycle.js';
76+
import { IContextKeyService, IContextKey, setConstant as setConstantContextKey } from '../../platform/contextkey/common/contextkey.js';
77+
import { InputFocusedContext, IsMacContext, IsLinuxContext, IsWindowsContext, IsWebContext, IsMacNativeContext, IsDevelopmentContext, IsIOSContext, ProductQualityContext, IsMobileContext } from '../../platform/contextkey/common/contextkeys.js';
78+
-import { SplitEditorsVertically, InEditorZenModeContext, AuxiliaryBarVisibleContext, SideBarVisibleContext, PanelAlignmentContext, PanelMaximizedContext, PanelVisibleContext, EmbedderIdentifierContext, EditorTabsVisibleContext, IsMainEditorCenteredLayoutContext, MainEditorAreaVisibleContext, DirtyWorkingCopiesContext, EmptyWorkspaceSupportContext, EnterMultiRootWorkspaceSupportContext, HasWebFileSystemAccess, IsMainWindowFullscreenContext, OpenFolderWorkspaceSupportContext, RemoteNameContext, VirtualWorkspaceContext, WorkbenchStateContext, WorkspaceFolderCountContext, PanelPositionContext, TemporaryWorkspaceContext, TitleBarVisibleContext, TitleBarStyleContext, IsAuxiliaryWindowFocusedContext, ActiveEditorGroupEmptyContext, ActiveEditorGroupIndexContext, ActiveEditorGroupLastContext, ActiveEditorGroupLockedContext, MultipleEditorGroupsContext, EditorsVisibleContext } from '../common/contextkeys.js';
79+
+import { SplitEditorsVertically, InEditorZenModeContext, AuxiliaryBarVisibleContext, SideBarVisibleContext, PanelAlignmentContext, PanelMaximizedContext, PanelVisibleContext, EmbedderIdentifierContext, EditorTabsVisibleContext, IsMainEditorCenteredLayoutContext, MainEditorAreaVisibleContext, DirtyWorkingCopiesContext, EmptyWorkspaceSupportContext, EnterMultiRootWorkspaceSupportContext, HasWebFileSystemAccess, IsMainWindowFullscreenContext, OpenFolderWorkspaceSupportContext, RemoteNameContext, VirtualWorkspaceContext, WorkbenchStateContext, WorkspaceFolderCountContext, PanelPositionContext, TemporaryWorkspaceContext, TitleBarVisibleContext, TitleBarStyleContext, IsAuxiliaryWindowFocusedContext, ActiveEditorGroupEmptyContext, ActiveEditorGroupIndexContext, ActiveEditorGroupLastContext, ActiveEditorGroupLockedContext, MultipleEditorGroupsContext, EditorsVisibleContext, IsSandboxWorkspaceContext } from '../common/contextkeys.js';
80+
import { trackFocus, addDisposableListener, EventType, onDidRegisterWindow, getActiveWindow, isEditableElement } from '../../base/browser/dom.js';
81+
import { preferredSideBySideGroupDirection, GroupDirection, IEditorGroupsService } from '../services/editor/common/editorGroupsService.js';
82+
import { IConfigurationService } from '../../platform/configuration/common/configuration.js';
83+
@@ -197,6 +197,9 @@ export class WorkbenchContextKeysHandler extends Disposable {
84+
this.auxiliaryBarVisibleContext = AuxiliaryBarVisibleContext.bindTo(this.contextKeyService);
85+
this.auxiliaryBarVisibleContext.set(this.layoutService.isVisible(Parts.AUXILIARYBAR_PART));
86+
87+
+ // Environment
88+
+ IsSandboxWorkspaceContext.bindTo(this.contextKeyService);
89+
+
90+
this.registerListeners();
91+
}
92+
93+
diff --git a/src/vs/workbench/common/contextkeys.ts b/src/vs/workbench/common/contextkeys.ts
94+
index 548fe41ac89..4c1ec4b3f87 100644
95+
--- a/src/vs/workbench/common/contextkeys.ts
96+
+++ b/src/vs/workbench/common/contextkeys.ts
97+
@@ -40,6 +40,8 @@ export const HasWebFileSystemAccess = new RawContextKey<boolean>('hasWebFileSyst
98+
99+
export const EmbedderIdentifierContext = new RawContextKey<string | undefined>('embedderIdentifier', undefined, localize('embedderIdentifier', 'The identifier of the embedder according to the product service, if one is defined'));
100+
101+
+export const IsSandboxWorkspaceContext = new RawContextKey<boolean>('isSandboxWorkspace', false, true);
102+
+
103+
//#endregion
104+
105+
106+
diff --git a/src/vs/workbench/contrib/files/browser/fileActions.contribution.ts b/src/vs/workbench/contrib/files/browser/fileActions.contribution.ts
107+
index 6cd04336cfb..d9469ae6123 100644
108+
--- a/src/vs/workbench/contrib/files/browser/fileActions.contribution.ts
109+
+++ b/src/vs/workbench/contrib/files/browser/fileActions.contribution.ts
110+
@@ -20,7 +20,7 @@ import { CLOSE_SAVED_EDITORS_COMMAND_ID, CLOSE_EDITORS_IN_GROUP_COMMAND_ID, CLOS
111+
import { AutoSaveAfterShortDelayContext } from '../../../services/filesConfiguration/common/filesConfigurationService.js';
112+
import { WorkbenchListDoubleSelection } from '../../../../platform/list/browser/listService.js';
113+
import { Schemas } from '../../../../base/common/network.js';
114+
-import { DirtyWorkingCopiesContext, EnterMultiRootWorkspaceSupportContext, HasWebFileSystemAccess, WorkbenchStateContext, WorkspaceFolderCountContext, SidebarFocusContext, ActiveEditorCanRevertContext, ActiveEditorContext, ResourceContextKey, ActiveEditorAvailableEditorIdsContext, MultipleEditorsSelectedInGroupContext, TwoEditorsSelectedInGroupContext, SelectedEditorsInGroupFileOrUntitledResourceContextKey } from '../../../common/contextkeys.js';
115+
+import { DirtyWorkingCopiesContext, EnterMultiRootWorkspaceSupportContext, HasWebFileSystemAccess, WorkbenchStateContext, WorkspaceFolderCountContext, SidebarFocusContext, ActiveEditorCanRevertContext, ActiveEditorContext, ResourceContextKey, ActiveEditorAvailableEditorIdsContext, MultipleEditorsSelectedInGroupContext, TwoEditorsSelectedInGroupContext, SelectedEditorsInGroupFileOrUntitledResourceContextKey, IsSandboxWorkspaceContext } from '../../../common/contextkeys.js';
116+
import { IsWebContext } from '../../../../platform/contextkey/common/contextkeys.js';
117+
import { ServicesAccessor } from '../../../../platform/instantiation/common/instantiation.js';
118+
import { ThemeIcon } from '../../../../base/common/themables.js';
119+
@@ -571,14 +571,14 @@ MenuRegistry.appendMenuItem(MenuId.ExplorerContext, ({
120+
id: DOWNLOAD_COMMAND_ID,
121+
title: DOWNLOAD_LABEL
122+
},
123+
- when: ContextKeyExpr.or(
124+
+ when: ContextKeyExpr.and(IsSandboxWorkspaceContext.toNegated(), ContextKeyExpr.or(
125+
// native: for any remote resource
126+
ContextKeyExpr.and(IsWebContext.toNegated(), ResourceContextKey.Scheme.notEqualsTo(Schemas.file)),
127+
// web: for any files
128+
ContextKeyExpr.and(IsWebContext, ExplorerFolderContext.toNegated(), ExplorerRootContext.toNegated()),
129+
// web: for any folders if file system API support is provided
130+
ContextKeyExpr.and(IsWebContext, HasWebFileSystemAccess)
131+
- )
132+
+ ))
133+
}));
134+
135+
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, ({

0 commit comments

Comments
 (0)