提交 f6703e50 编写于 作者: B Benjamin Pasero

debt - group context keys in one place

上级 cdbe7bff
......@@ -8,7 +8,7 @@ import { Disposable } from 'vs/base/common/lifecycle';
import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { InputFocusedContext } from 'vs/platform/contextkey/common/contextkeys';
import { IWindowConfiguration, IWindowService } from 'vs/platform/windows/common/windows';
import { ActiveEditorContext, EditorsVisibleContext, TextCompareEditorVisibleContext, TextCompareEditorActiveContext, ActiveEditorGroupEmptyContext, MultipleEditorGroupsContext, TEXT_DIFF_EDITOR_ID, SplitEditorsVertically } from 'vs/workbench/common/editor';
import { ActiveEditorContext, EditorsVisibleContext, TextCompareEditorVisibleContext, TextCompareEditorActiveContext, ActiveEditorGroupEmptyContext, MultipleEditorGroupsContext, TEXT_DIFF_EDITOR_ID, SplitEditorsVertically, InEditorZenModeContext } from 'vs/workbench/common/editor';
import { IsMacContext, IsLinuxContext, IsWindowsContext, HasMacNativeTabsContext, IsDevelopmentContext, SupportsWorkspacesContext, SupportsOpenFileFolderContext, WorkbenchStateContext, WorkspaceFolderCountContext } from 'vs/workbench/common/contextkeys';
import { trackFocus, addDisposableListener, EventType } from 'vs/base/browser/dom';
import { preferredSideBySideGroupDirection, GroupDirection, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
......@@ -17,18 +17,28 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { WorkbenchState, IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { EditorGroupsServiceImpl } from 'vs/workbench/browser/parts/editor/editor';
import { SidebarVisibleContext } from 'vs/workbench/common/viewlet';
import { IPartService, Parts } from 'vs/workbench/services/part/common/partService';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
export class WorkbenchContextKeysHandler extends Disposable {
private inputFocusedContext: IContextKey<boolean>;
private activeEditorContext: IContextKey<string | null>;
private editorsVisibleContext: IContextKey<boolean>;
private textCompareEditorVisibleContext: IContextKey<boolean>;
private textCompareEditorActiveContext: IContextKey<boolean>;
private activeEditorGroupEmpty: IContextKey<boolean>;
private multipleEditorGroupsContext: IContextKey<boolean>;
private splitEditorsVerticallyContext: IContextKey<boolean>;
private workbenchStateContext: IContextKey<string>;
private workspaceFolderCountContext: IContextKey<number>;
private splitEditorsVerticallyContext: IContextKey<boolean>;
private inZenModeContext: IContextKey<boolean>;
private sideBarVisibleContext: IContextKey<boolean>;
constructor(
@IContextKeyService private contextKeyService: IContextKeyService,
......@@ -37,7 +47,9 @@ export class WorkbenchContextKeysHandler extends Disposable {
@IEnvironmentService private environmentService: IEnvironmentService,
@IWindowService private windowService: IWindowService,
@IEditorService private editorService: IEditorService,
@IEditorGroupsService private editorGroupService: EditorGroupsServiceImpl
@IEditorGroupsService private editorGroupService: EditorGroupsServiceImpl,
@IPartService private partService: IPartService,
@IViewletService private viewletService: IViewletService
) {
super();
......@@ -63,6 +75,11 @@ export class WorkbenchContextKeysHandler extends Disposable {
this.updateSplitEditorsVerticallyContext();
}
}));
this._register(this.partService.onZenModeChange(enabled => this.inZenModeContext.set(enabled)));
this._register(this.viewletService.onDidViewletClose(() => this.updateSideBarContextKeys()));
this._register(this.viewletService.onDidViewletOpen(() => this.updateSideBarContextKeys()));
}
private initContextKeys(): void {
......@@ -105,6 +122,12 @@ export class WorkbenchContextKeysHandler extends Disposable {
// Editor Layout
this.splitEditorsVerticallyContext = SplitEditorsVertically.bindTo(this.contextKeyService);
this.updateSplitEditorsVerticallyContext();
// Zen Mode
this.inZenModeContext = InEditorZenModeContext.bindTo(this.contextKeyService);
// Sidebar
this.sideBarVisibleContext = SidebarVisibleContext.bindTo(this.contextKeyService);
}
private updateEditorContextKeys(): void {
......@@ -178,4 +201,8 @@ export class WorkbenchContextKeysHandler extends Disposable {
case WorkbenchState.WORKSPACE: return 'workspace';
}
}
private updateSideBarContextKeys(): void {
this.sideBarVisibleContext.set(this.partService.isVisible(Parts.SIDEBAR_PART));
}
}
\ No newline at end of file
......@@ -19,7 +19,7 @@ import { Registry } from 'vs/platform/registry/common/platform';
import { isWindows, isLinux, isMacintosh, language } from 'vs/base/common/platform';
import { IResourceInput } from 'vs/platform/editor/common/editor';
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
import { IEditorInputFactoryRegistry, Extensions as EditorExtensions, IUntitledResourceInput, IResourceDiffInput, InEditorZenModeContext } from 'vs/workbench/common/editor';
import { IEditorInputFactoryRegistry, Extensions as EditorExtensions, IUntitledResourceInput, IResourceDiffInput } from 'vs/workbench/common/editor';
import { ActivitybarPart } from 'vs/workbench/browser/parts/activitybar/activitybarPart';
import { SidebarPart } from 'vs/workbench/browser/parts/sidebar/sidebarPart';
import { PanelPart } from 'vs/workbench/browser/parts/panel/panelPart';
......@@ -40,7 +40,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
import { IJSONEditingService } from 'vs/workbench/services/configuration/common/jsonEditing';
import { ContextKeyService } from 'vs/platform/contextkey/browser/contextKeyService';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IActivityService } from 'vs/workbench/services/activity/common/activity';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { IFileService } from 'vs/platform/files/common/files';
......@@ -111,7 +111,6 @@ import { WorkbenchThemeService } from 'vs/workbench/services/themes/browser/work
import { IProductService } from 'vs/platform/product/common/product';
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility';
import { WorkbenchContextKeysHandler } from 'vs/workbench/browser/contextkeys';
import { SidebarVisibleContext } from 'vs/workbench/common/viewlet';
// import@node
import { BackupFileService, InMemoryBackupFileService } from 'vs/workbench/services/backup/node/backupFileService';
......@@ -202,7 +201,6 @@ export class Workbench extends Disposable implements IPartService {
private editorService: EditorService;
private editorGroupService: IEditorGroupsService;
private contextViewService: ContextViewService;
private contextKeyService: IContextKeyService;
private keybindingService: IKeybindingService;
private backupFileService: IBackupFileService;
private notificationService: NotificationService;
......@@ -225,8 +223,6 @@ export class Workbench extends Disposable implements IPartService {
private notificationsToasts: NotificationsToasts;
private fontAliasing: FontAliasingOption;
private inZenModeContext: IContextKey<boolean>;
private sideBarVisibleContext: IContextKey<boolean>;
constructor(
private container: HTMLElement,
......@@ -335,8 +331,6 @@ export class Workbench extends Disposable implements IPartService {
// Context Keys
this._register(this.instantiationService.createInstance(WorkbenchContextKeysHandler));
this.inZenModeContext = InEditorZenModeContext.bindTo(this.contextKeyService);
this.sideBarVisibleContext = SidebarVisibleContext.bindTo(this.contextKeyService);
// Register Listeners
this.registerListeners();
......@@ -494,8 +488,7 @@ export class Workbench extends Disposable implements IPartService {
serviceCollection.set(IStatusbarService, this.statusbarPart);
// Context Keys
this.contextKeyService = this.instantiationService.createInstance(ContextKeyService);
serviceCollection.set(IContextKeyService, this.contextKeyService);
serviceCollection.set(IContextKeyService, new SyncDescriptor(ContextKeyService));
// Keybindings
this.keybindingService = this.instantiationService.createInstance(WorkbenchKeybindingService, window);
......@@ -696,8 +689,6 @@ export class Workbench extends Disposable implements IPartService {
// Restore Sidebar
let viewletIdToRestore: string | undefined;
if (!this.state.sideBar.hidden) {
this.sideBarVisibleContext.set(true);
if (this.shouldRestoreLastOpenedViewlet()) {
viewletIdToRestore = this.storageService.get(SidebarPart.activeViewletSettingsKey, StorageScope.WORKSPACE);
}
......@@ -1055,6 +1046,9 @@ export class Workbench extends Disposable implements IPartService {
private readonly _onTitleBarVisibilityChange: Emitter<void> = this._register(new Emitter<void>());
get onTitleBarVisibilityChange(): Event<void> { return this._onTitleBarVisibilityChange.event; }
private readonly _onZenMode: Emitter<boolean> = this._register(new Emitter<boolean>());
get onZenModeChange(): Event<boolean> { return this._onZenMode.event; }
get onEditorLayout(): Event<IDimension> { return this.editorPart.onDidLayout; }
private workbenchGrid: Grid<View> | WorkbenchLayout;
......@@ -1346,8 +1340,6 @@ export class Workbench extends Disposable implements IPartService {
toggleFullScreen = this.state.zenMode.transitionedToFullScreen && isFullscreen();
}
this.inZenModeContext.set(this.state.zenMode.active);
if (!skipLayout) {
this.layout();
}
......@@ -1355,6 +1347,9 @@ export class Workbench extends Disposable implements IPartService {
if (toggleFullScreen) {
this.windowService.toggleFullScreen();
}
// Event
this._onZenMode.fire(this.state.zenMode.active);
}
private setStatusBarHidden(hidden: boolean, skipLayout?: boolean): void {
......@@ -1601,7 +1596,6 @@ export class Workbench extends Disposable implements IPartService {
setSideBarHidden(hidden: boolean, skipLayout?: boolean): void {
this.state.sideBar.hidden = hidden;
this.sideBarVisibleContext.set(!hidden);
// Adjust CSS
if (hidden) {
......
......@@ -49,6 +49,11 @@ export interface IPartService {
*/
onTitleBarVisibilityChange: Event<void>;
/**
* Emits when the zen mode is enabled or disabled.
*/
onZenModeChange: Event<boolean>;
/**
* Emits when the editor part's layout changes.
*/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册