Skip to content

Commit 704bf0f

Browse files
author
Benjamin Pasero
committed
contextkey - add web to statically defined ones
1 parent d1c1e27 commit 704bf0f

10 files changed

Lines changed: 29 additions & 33 deletions

File tree

src/vs/platform/contextkey/common/contextkey.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66
import { Event } from 'vs/base/common/event';
77
import { isFalsyOrWhitespace } from 'vs/base/common/strings';
88
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
9-
import { isMacintosh, isLinux, isWindows } from 'vs/base/common/platform';
9+
import { isMacintosh, isLinux, isWindows, isWeb } from 'vs/base/common/platform';
1010

1111
const STATIC_VALUES = new Map<string, boolean>();
1212
STATIC_VALUES.set('false', false);
1313
STATIC_VALUES.set('true', true);
1414
STATIC_VALUES.set('isMac', isMacintosh);
1515
STATIC_VALUES.set('isLinux', isLinux);
1616
STATIC_VALUES.set('isWindows', isWindows);
17+
STATIC_VALUES.set('isWeb', isWeb);
18+
STATIC_VALUES.set('isMacNative', isMacintosh && !isWeb);
1719

1820
export const enum ContextKeyExprType {
1921
False = 0,

src/vs/platform/contextkey/common/contextkeys.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { RawContextKey } from 'vs/platform/contextkey/common/contextkey';
7+
import { isMacintosh, isLinux, isWindows, isWeb } from 'vs/base/common/platform';
8+
9+
export const IsMacContext = new RawContextKey<boolean>('isMac', isMacintosh);
10+
export const IsLinuxContext = new RawContextKey<boolean>('isLinux', isLinux);
11+
export const IsWindowsContext = new RawContextKey<boolean>('isWindows', isWindows);
12+
13+
export const IsWebContext = new RawContextKey<boolean>('isWeb', isWeb);
14+
export const IsMacNativeContext = new RawContextKey<boolean>('isMacNative', isMacintosh && !isWeb);
15+
16+
export const IsDevelopmentContext = new RawContextKey<boolean>('isDevelopment', false);
717

818
export const InputFocusedContextKey = 'inputFocus';
919
export const InputFocusedContext = new RawContextKey<boolean>(InputFocusedContextKey, false);
10-
11-
export const FalseContext = new RawContextKey<boolean>('__false', false);

src/vs/workbench/browser/actions/layoutActions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { KeyMod, KeyCode, KeyChord } from 'vs/base/common/keyCodes';
1818
import { DisposableStore } from 'vs/base/common/lifecycle';
1919
import { getMenuBarVisibility } from 'vs/platform/windows/common/windows';
2020
import { isWindows, isLinux, isWeb } from 'vs/base/common/platform';
21-
import { IsMacNativeContext } from 'vs/workbench/browser/contextkeys';
21+
import { IsMacNativeContext } from 'vs/platform/contextkey/common/contextkeys';
2222
import { KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
2323
import { InEditorZenModeContext, IsCenteredLayoutContext, EditorAreaVisibleContext } from 'vs/workbench/common/editor';
2424
import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';

src/vs/workbench/browser/actions/windowActions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
1212
import { SyncActionDescriptor, MenuRegistry, MenuId } from 'vs/platform/actions/common/actions';
1313
import { Registry } from 'vs/platform/registry/common/platform';
1414
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
15-
import { IsFullscreenContext, IsDevelopmentContext, IsMacNativeContext } from 'vs/workbench/browser/contextkeys';
15+
import { IsFullscreenContext } from 'vs/workbench/browser/contextkeys';
16+
import { IsMacNativeContext, IsDevelopmentContext } from 'vs/platform/contextkey/common/contextkeys';
1617
import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actions';
1718
import { KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
1819
import { IQuickInputButton, IQuickInputService, IQuickPickSeparator } from 'vs/platform/quickinput/common/quickInput';

src/vs/workbench/browser/contextkeys.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
import { Event } from 'vs/base/common/event';
77
import { Disposable } from 'vs/base/common/lifecycle';
88
import { IContextKeyService, IContextKey, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
9-
import { InputFocusedContext } from 'vs/platform/contextkey/common/contextkeys';
10-
import { IWindowsConfiguration } from 'vs/platform/windows/common/windows';
9+
import { InputFocusedContext, IsMacContext, IsLinuxContext, IsWindowsContext, IsWebContext, IsMacNativeContext, IsDevelopmentContext } from 'vs/platform/contextkey/common/contextkeys';
1110
import { ActiveEditorContext, EditorsVisibleContext, TextCompareEditorVisibleContext, TextCompareEditorActiveContext, ActiveEditorGroupEmptyContext, MultipleEditorGroupsContext, TEXT_DIFF_EDITOR_ID, SplitEditorsVertically, InEditorZenModeContext, IsCenteredLayoutContext, ActiveEditorGroupIndexContext, ActiveEditorGroupLastContext, ActiveEditorIsReadonlyContext, EditorAreaVisibleContext, DirtyWorkingCopiesContext } from 'vs/workbench/common/editor';
1211
import { trackFocus, addDisposableListener, EventType } from 'vs/base/browser/dom';
1312
import { preferredSideBySideGroupDirection, GroupDirection, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
@@ -18,27 +17,15 @@ import { WorkbenchState, IWorkspaceContextService } from 'vs/platform/workspace/
1817
import { SideBarVisibleContext } from 'vs/workbench/common/viewlet';
1918
import { IWorkbenchLayoutService, Parts, positionToString } from 'vs/workbench/services/layout/browser/layoutService';
2019
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
21-
import { isMacintosh, isLinux, isWindows, isWeb } from 'vs/base/common/platform';
2220
import { PanelPositionContext } from 'vs/workbench/common/panel';
2321
import { getRemoteName } from 'vs/platform/remote/common/remoteHosts';
2422
import { IWorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService';
2523

26-
export const IsMacContext = new RawContextKey<boolean>('isMac', isMacintosh);
27-
export const IsLinuxContext = new RawContextKey<boolean>('isLinux', isLinux);
28-
export const IsWindowsContext = new RawContextKey<boolean>('isWindows', isWindows);
29-
30-
export const IsWebContext = new RawContextKey<boolean>('isWeb', isWeb);
31-
export const IsMacNativeContext = new RawContextKey<boolean>('isMacNative', isMacintosh && !isWeb);
32-
3324
export const Deprecated_RemoteAuthorityContext = new RawContextKey<string>('remoteAuthority', '');
3425

3526
export const RemoteNameContext = new RawContextKey<string>('remoteName', '');
3627
export const RemoteConnectionState = new RawContextKey<'' | 'initializing' | 'disconnected' | 'connected'>('remoteConnectionState', '');
3728

38-
export const HasMacNativeTabsContext = new RawContextKey<boolean>('hasMacNativeTabs', false);
39-
40-
export const IsDevelopmentContext = new RawContextKey<boolean>('isDevelopment', false);
41-
4229
export const WorkbenchStateContext = new RawContextKey<string>('workbenchState', undefined);
4330

4431
export const WorkspaceFolderCountContext = new RawContextKey<number>('workspaceFolderCount', 0);
@@ -98,10 +85,6 @@ export class WorkbenchContextKeysHandler extends Disposable {
9885

9986
RemoteNameContext.bindTo(this.contextKeyService).set(getRemoteName(this.environmentService.configuration.remoteAuthority) || '');
10087

101-
// macOS Native Tabs
102-
const windowConfig = this.configurationService.getValue<IWindowsConfiguration>();
103-
HasMacNativeTabsContext.bindTo(this.contextKeyService).set(windowConfig?.window?.nativeTabs);
104-
10588
// Development
10689
IsDevelopmentContext.bindTo(this.contextKeyService).set(!this.environmentService.isBuilt || this.environmentService.isExtensionDevelopment);
10790

src/vs/workbench/contrib/files/browser/explorerViewlet.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ import { KeyChord, KeyMod, KeyCode } from 'vs/base/common/keyCodes';
3434
import { Registry } from 'vs/platform/registry/common/platform';
3535
import { IProgressService, ProgressLocation } from 'vs/platform/progress/common/progress';
3636
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
37-
import { WorkbenchStateContext, RemoteNameContext, IsWebContext } from 'vs/workbench/browser/contextkeys';
37+
import { WorkbenchStateContext, RemoteNameContext } from 'vs/workbench/browser/contextkeys';
38+
import { IsWebContext } from 'vs/platform/contextkey/common/contextkeys';
3839
import { AddRootFolderAction, OpenFolderAction, OpenFileFolderAction } from 'vs/workbench/browser/actions/workspaceActions';
3940
import { isMacintosh } from 'vs/base/common/platform';
4041

src/vs/workbench/contrib/files/browser/fileActions.contribution.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import { AutoSaveAfterShortDelayContext } from 'vs/workbench/services/filesConfi
2222
import { ResourceContextKey } from 'vs/workbench/common/resources';
2323
import { WorkbenchListDoubleSelection } from 'vs/platform/list/browser/listService';
2424
import { Schemas } from 'vs/base/common/network';
25-
import { WorkspaceFolderCountContext, IsWebContext } from 'vs/workbench/browser/contextkeys';
25+
import { WorkspaceFolderCountContext } from 'vs/workbench/browser/contextkeys';
26+
import { IsWebContext } from 'vs/platform/contextkey/common/contextkeys';
2627
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
2728
import { OpenFileFolderAction, OpenFileAction, OpenFolderAction, OpenWorkspaceAction } from 'vs/workbench/browser/actions/workspaceActions';
2829
import { ActiveEditorIsReadonlyContext, DirtyWorkingCopiesContext, ActiveEditorContext } from 'vs/workbench/common/editor';

src/vs/workbench/contrib/preferences/browser/preferences.contribution.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
2020
import { Registry } from 'vs/platform/registry/common/platform';
2121
import { REMOTE_HOST_SCHEME } from 'vs/platform/remote/common/remoteHosts';
2222
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
23-
import { IsMacNativeContext, RemoteNameContext, WorkbenchStateContext } from 'vs/workbench/browser/contextkeys';
23+
import { RemoteNameContext, WorkbenchStateContext } from 'vs/workbench/browser/contextkeys';
24+
import { IsMacNativeContext } from 'vs/platform/contextkey/common/contextkeys';
2425
import { EditorDescriptor, Extensions as EditorExtensions, IEditorRegistry } from 'vs/workbench/browser/editor';
2526
import { Extensions, IWorkbenchActionRegistry } from 'vs/workbench/common/actions';
2627
import { Extensions as WorkbenchExtensions, IWorkbenchContribution, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions';

src/vs/workbench/contrib/update/browser/update.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/
2222
import { ReleaseNotesManager } from './releaseNotesEditor';
2323
import { isWindows } from 'vs/base/common/platform';
2424
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
25-
import { RawContextKey, IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
25+
import { RawContextKey, IContextKey, IContextKeyService, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
2626
import { MenuRegistry, MenuId } from 'vs/platform/actions/common/actions';
2727
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
28-
import { FalseContext } from 'vs/platform/contextkey/common/contextkeys';
2928
import { ShowCurrentReleaseNotesActionId, CheckForVSCodeUpdateActionId } from 'vs/workbench/contrib/update/common/update';
3029
import { IHostService } from 'vs/workbench/services/host/browser/host';
3130
import { IProductService } from 'vs/platform/product/common/productService';
@@ -417,7 +416,7 @@ export class UpdateContribution extends Disposable implements IWorkbenchContribu
417416
command: {
418417
id: 'update.checking',
419418
title: nls.localize('checkingForUpdates', "Checking for Updates..."),
420-
precondition: FalseContext
419+
precondition: ContextKeyExpr.false()
421420
},
422421
when: CONTEXT_UPDATE_STATE.isEqualTo(StateType.CheckingForUpdates)
423422
});
@@ -438,7 +437,7 @@ export class UpdateContribution extends Disposable implements IWorkbenchContribu
438437
command: {
439438
id: 'update.downloading',
440439
title: nls.localize('DownloadingUpdate', "Downloading Update..."),
441-
precondition: FalseContext
440+
precondition: ContextKeyExpr.false()
442441
},
443442
when: CONTEXT_UPDATE_STATE.isEqualTo(StateType.Downloading)
444443
});
@@ -459,7 +458,7 @@ export class UpdateContribution extends Disposable implements IWorkbenchContribu
459458
command: {
460459
id: 'update.updating',
461460
title: nls.localize('installingUpdate', "Installing Update..."),
462-
precondition: FalseContext
461+
precondition: ContextKeyExpr.false()
463462
},
464463
when: CONTEXT_UPDATE_STATE.isEqualTo(StateType.Updating)
465464
});

src/vs/workbench/electron-browser/desktop.contribution.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
1717
import { KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
1818
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
1919
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
20-
import { IsMacContext, HasMacNativeTabsContext, IsDevelopmentContext } from 'vs/workbench/browser/contextkeys';
20+
import { IsDevelopmentContext, IsMacContext } from 'vs/platform/contextkey/common/contextkeys';
2121
import { NoEditorsVisibleContext, SingleEditorGroupsContext } from 'vs/workbench/common/editor';
2222
import { IElectronService } from 'vs/platform/electron/node/electron';
2323
import { IJSONContributionRegistry, Extensions as JSONExtensions } from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
@@ -82,7 +82,7 @@ import { IJSONSchema } from 'vs/base/common/jsonSchema';
8282

8383
MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
8484
command,
85-
when: HasMacNativeTabsContext
85+
when: ContextKeyExpr.equals('config.window.nativeTabs', 'true')
8686
});
8787
});
8888
}

0 commit comments

Comments
 (0)