[beast/ebeast] EBEAST: menus.js: define main application menus
- From: Tim Janik <timj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [beast/ebeast] EBEAST: menus.js: define main application menus
- Date: Tue, 7 Mar 2017 22:48:22 +0000 (UTC)
commit b3ec135a0e3666062d3d819dacb31434583630e2
Author: Tim Janik <timj gnu org>
Date: Tue Mar 7 02:03:35 2017 +0100
EBEAST: menus.js: define main application menus
Signed-off-by: Tim Janik <timj gnu org>
ebeast/index.html | 4 ++-
ebeast/menus.js | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 59 insertions(+), 1 deletions(-)
---
diff --git a/ebeast/index.html b/ebeast/index.html
index 481df07..be07eef 100644
--- a/ebeast/index.html
+++ b/ebeast/index.html
@@ -9,10 +9,12 @@
'use strict';
const Electron = require ('electron').remote;
const Bse = require ('./v8bse/v8bse.node');
+ 0 + Bse; // FIXME 'unused' warnings
const Mithril = require ('mithril');
window.$ = window.jQuery = require ('jquery');
const Dialogs = require ('./assets/dialogs.js');
- "" + Bse; // FIXME 'unused' warnings
+ const Menus = require ('./menus.js');
+ 0 + Menus; // FIXME 'unused' warnings
const App = {
show_about: true,
__proto__ : Electron.app
diff --git a/ebeast/menus.js b/ebeast/menus.js
new file mode 100644
index 0000000..0237f0f
--- /dev/null
+++ b/ebeast/menus.js
@@ -0,0 +1,56 @@
+'use strict';
+
+// == Application Menu ==
+const file_menu = [
+ { label: 'Open...', role: 'open-file', accelerator: 'Ctrl+O', },
+ { label: 'Quit', role: 'quit-app', accelerator: 'Shift+Ctrl+Q', },
+];
+const view_menu = [
+ { label: 'Toggle Fullscreen', role: 'toggle-fulscreen', accelerator: 'F11', },
+ { label: 'Toggle Developer Tools', role: 'toggle-devtools', accelerator: 'Shift+Ctrl+I', },
+];
+const menubar_menus = [
+ { label: '&File', submenu: file_menu, accelerator: 'Alt+F' },
+ { label: '&View', submenu: view_menu, accelerator: 'Alt+W' },
+];
+
+// add 'click' handlers to menu templates
+function assign_click (item, func) {
+ if (Array.isArray (item)) {
+ for (let i = 0; i < item.length; i++)
+ assign_click (item[i], func);
+ } else if (item.submenu !== undefined) {
+ assign_click (item.submenu, func);
+ } else if (item.click === undefined)
+ item.click = func;
+}
+
+// assign global app menu
+assign_click (menubar_menus, (menuitem, _focusedBrowserWindow, _event) => {
+ app_command (menuitem.role, menuitem.data);
+});
+Electron.Menu.setApplicationMenu (Electron.Menu.buildFromTemplate (menubar_menus));
+
+// handle menu activations
+function app_command (role, _data) {
+ const BrowserWindow = Electron.getCurrentWindow(); // http://electron.atom.io/docs/api/browser-window/
+ const WebContents = BrowserWindow.webContents; // http://electron.atom.io/docs/api/web-contents/
+ switch (role) {
+ case 'toggle-devtools':
+ WebContents.toggleDevTools();
+ break;
+ case 'toggle-fulscreen':
+ BrowserWindow.setFullScreen (!BrowserWindow.isFullScreen());
+ break;
+ case 'quit-app':
+ Electron.app.quit();
+ return false;
+ case 'open-file':
+ Electron.dialog.showOpenDialog ({
+ properties: ['openFile', 'openDirectory', 'multiSelections'],
+ }, (result) => {
+ console.log ('open-file: ' + result);
+ });
+ break;
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]