-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exposed
onChanged
event on the menu registry.
From now on, both the electron and the browser based main menu factories listen `onChanged` events and updates the main menu by recreating it from scratch. Signed-off-by: Akos Kitta <kittaakos@typefox.io>
- Loading branch information
Showing
10 changed files
with
184 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
packages/core/src/browser/menu/browser-menu-contribution.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2017 TypeFox and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { injectable, inject } from 'inversify'; | ||
import { Widget } from '@phosphor/widgets'; | ||
import debounce = require('lodash.debounce'); | ||
import { ApplicationShell } from '../shell'; | ||
import { MenuModelRegistry } from '../../common'; | ||
import { FrontendApplicationContribution, FrontendApplication } from '../frontend-application'; | ||
import { BrowserMainMenuFactory, MenuBarWidget } from './browser-main-menu-factory'; | ||
|
||
@injectable() | ||
export class BrowserMenuContribution implements FrontendApplicationContribution { | ||
|
||
@inject(ApplicationShell) | ||
protected readonly shell: ApplicationShell; | ||
|
||
@inject(BrowserMainMenuFactory) | ||
protected readonly factory: BrowserMainMenuFactory; | ||
|
||
@inject(MenuModelRegistry) | ||
protected readonly menuRegistry: MenuModelRegistry; | ||
|
||
onStart(app: FrontendApplication): void { | ||
const logo = this.createLogo(); | ||
app.shell.addWidget(logo, { area: 'top' }); | ||
const menuBar = this.factory.createMenuBar(); | ||
app.shell.addWidget(menuBar, { area: 'top' }); | ||
const update = debounce(() => this.update(), 100); | ||
this.menuRegistry.onChanged(update); | ||
} | ||
|
||
get menuBar(): MenuBarWidget | undefined { | ||
return this.shell.topPanel.widgets.find(w => w instanceof MenuBarWidget) as MenuBarWidget | undefined; | ||
} | ||
|
||
protected createLogo(): Widget { | ||
const logo = new Widget(); | ||
logo.id = 'theia:icon'; | ||
logo.addClass('theia-icon'); | ||
return logo; | ||
} | ||
|
||
protected update(): void { | ||
if (this.menuBar) { | ||
this.menuBar.clearMenus(); | ||
this.factory.fillMenuBar(this.menuBar); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.