From 0c8a07500ae75420693bfcf4301161c3e05c8beb Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Fri, 9 Aug 2019 15:44:46 +0200 Subject: [PATCH] touchbar - allow to disable/enable without restart --- .../common/relauncher.contribution.ts | 8 ---- src/vs/workbench/electron-browser/window.ts | 47 ++++++++++--------- 2 files changed, 24 insertions(+), 31 deletions(-) diff --git a/src/vs/workbench/contrib/relauncher/common/relauncher.contribution.ts b/src/vs/workbench/contrib/relauncher/common/relauncher.contribution.ts index 080e6d741e7..d3c0d4f064f 100644 --- a/src/vs/workbench/contrib/relauncher/common/relauncher.contribution.ts +++ b/src/vs/workbench/contrib/relauncher/common/relauncher.contribution.ts @@ -23,7 +23,6 @@ import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/ interface IConfiguration extends IWindowsConfiguration { update: { mode: string; }; telemetry: { enableCrashReporter: boolean }; - keyboard: { touchbar: { enabled: boolean } }; workbench: { list: { horizontalScrolling: boolean }, useExperimentalGridLayout: boolean }; debug: { console: { wordWrap: boolean } }; } @@ -36,7 +35,6 @@ export class SettingsChangeRelauncher extends Disposable implements IWorkbenchCo private clickThroughInactive: boolean; private updateMode: string; private enableCrashReporter: boolean; - private touchbarEnabled: boolean; private treeHorizontalScrolling: boolean; private useGridLayout: boolean; private debugConsoleWordWrap: boolean; @@ -112,12 +110,6 @@ export class SettingsChangeRelauncher extends Disposable implements IWorkbenchCo this.enableCrashReporter = config.telemetry.enableCrashReporter; changed = true; } - - // macOS: Touchbar config - if (isMacintosh && config.keyboard && config.keyboard.touchbar && typeof config.keyboard.touchbar.enabled === 'boolean' && config.keyboard.touchbar.enabled !== this.touchbarEnabled) { - this.touchbarEnabled = config.keyboard.touchbar.enabled; - changed = true; - } } // Notify only when changed and we are the focused window (avoids notification spam across windows) diff --git a/src/vs/workbench/electron-browser/window.ts b/src/vs/workbench/electron-browser/window.ts index 8391373c4fb..bfc7916011e 100644 --- a/src/vs/workbench/electron-browser/window.ts +++ b/src/vs/workbench/electron-browser/window.ts @@ -213,7 +213,7 @@ export class ElectronWindow extends Disposable { this._register(this.configurationService.onDidChangeConfiguration(e => { if (e.affectsConfiguration('window.zoomLevel')) { this.updateWindowZoomLevel(); - } else if (e.affectsConfiguration('keyboard.touchbar.ignored')) { + } else if (e.affectsConfiguration('keyboard.touchbar.enabled') || e.affectsConfiguration('keyboard.touchbar.ignored')) { this.updateTouchbarMenu(); } })); @@ -342,11 +342,8 @@ export class ElectronWindow extends Disposable { } private updateTouchbarMenu(): void { - if ( - !isMacintosh || // macOS only - !this.configurationService.getValue('keyboard.touchbar.enabled') // disabled via setting - ) { - return; + if (!isMacintosh) { + return; // macOS only } // Dispose old @@ -368,36 +365,40 @@ export class ElectronWindow extends Disposable { const actions: Array = []; + const disabled = this.configurationService.getValue('keyboard.touchbar.enabled') === false; + const ignoredItems = this.configurationService.getValue('keyboard.touchbar.ignored') || []; + // Fill actions into groups respecting order this.touchBarDisposables.add(createAndFillInActionBarActions(this.touchBarMenu, undefined, actions)); // Convert into command action multi array const items: ICommandAction[][] = []; let group: ICommandAction[] = []; - const ignoredItems = this.configurationService.getValue('keyboard.touchbar.ignored') || []; - for (const action of actions) { + if (!disabled) { + for (const action of actions) { + + // Command + if (action instanceof MenuItemAction) { + if (ignoredItems.indexOf(action.item.id) >= 0) { + continue; // ignored + } - // Command - if (action instanceof MenuItemAction) { - if (ignoredItems.indexOf(action.item.id) >= 0) { - continue; // ignored + group.push(action.item); } - group.push(action.item); - } + // Separator + else if (action instanceof Separator) { + if (group.length) { + items.push(group); + } - // Separator - else if (action instanceof Separator) { - if (group.length) { - items.push(group); + group = []; } - - group = []; } - } - if (group.length) { - items.push(group); + if (group.length) { + items.push(group); + } } // Only update if the actions have changed -- GitLab