Skip to content

Commit

Permalink
register to core preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
ChayaLau committed Aug 24, 2021
1 parent d0892bc commit 4547b21
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions packages/core/src/browser/shell/application-shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,17 @@ export class ApplicationShell extends Widget {
protected init(): void {
this.initSidebarVisibleKeyContext();
this.initFocusKeyContexts();

if (!environment.electron.is()) {
this.corePreferences.ready.then(() => {
this.setTopPanelVisibily(this.corePreferences['window.menuBarVisibility']);
});
this.corePreferences.onPreferenceChanged(preference => {
if (preference.preferenceName === 'window.menuBarVisibility') {
this.setTopPanelVisibily(preference.newValue);
}
});
}
}

protected initSidebarVisibleKeyContext(): void {
Expand Down Expand Up @@ -282,6 +293,11 @@ export class ApplicationShell extends Widget {
this.activeChanged.connect(updateFocusContextKeys);
}

protected setTopPanelVisibily(preference: string): void {
const hiddenPreferences = ['compact', 'hidden'];
this.topPanel.setHidden(hiddenPreferences.includes(preference));
}

protected onBeforeAttach(msg: Message): void {
document.addEventListener('p-dragenter', this, true);
document.addEventListener('p-dragover', this, true);
Expand Down Expand Up @@ -496,22 +512,7 @@ export class ApplicationShell extends Widget {
protected createTopPanel(): Panel {
const topPanel = new Panel();
topPanel.id = 'theia-top-panel';
topPanel.setHidden(true);

// Hide top panel when the `menuBarVisibility` preference changes.
if (!environment.electron.is()) {
this.corePreferences.onPreferenceChanged(preference => {
if (preference.preferenceName === 'window.menuBarVisibility') {
const hiddenPreferences = ['compact', 'hidden'];
const hiddenNew = hiddenPreferences.includes(preference.newValue);
const hiddenOld = preference.oldValue ? hiddenPreferences.includes(preference.oldValue) : true;

if (preference.oldValue === undefined || (hiddenNew && !hiddenOld) || (!hiddenNew && hiddenOld)) {
topPanel.setHidden(hiddenNew);
}
}
});
}
topPanel.hide();
return topPanel;
}

Expand Down

0 comments on commit 4547b21

Please sign in to comment.