diff options
author | Andrew Dolgov <[email protected]> | 2019-03-15 07:47:06 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2019-03-15 07:47:06 +0300 |
commit | feac4e7d5335556b13a1eb04866e59076d33588e (patch) | |
tree | 88578c6d32d225352faa46ebca40f0bb09647d05 | |
parent | 774bbc4cf46f378820c23f7eda0bc77b323d941b (diff) |
add MRU menu
-rwxr-xr-x | app.js | 56 | ||||
-rwxr-xr-x | reader.js | 97 |
2 files changed, 94 insertions, 59 deletions
@@ -5,22 +5,6 @@ const {app, BrowserWindow, Menu} = require('electron'); // be closed automatically when the JavaScript object is garbage collected. let mainWindow; -function openFileDialog() { - const { dialog } = require('electron') - - const result = dialog.showOpenDialog(mainWindow, - { - properties: ['openFile'], - filters: [ - { name: 'Comic Archives', extensions: ['cbz', 'zip'] } - ], - }); - - if (result && result[0]) { - mainWindow.webContents.send("open-file", result[0]); - } -} - function createWindow() { // Create the browser window. mainWindow = new BrowserWindow({ @@ -36,46 +20,44 @@ function createWindow() { const menu = Menu.buildFromTemplate([ { - label: 'File', + label: '&File', + id: 'M-FILE', submenu: [ - {label: 'Open...', accelerator: 'Ctrl+O', click: () => { openFileDialog(); }}, - {id: 'F-CLOSE', label: 'Close', click: () => { mainWindow.webContents.send("close-file"); }}, - {type: 'separator'}, - {label: 'Exit', click: () => { app.quit(); }} + // filled at runtime ] }, { - label: 'Location', + label: '&Location', submenu: [ - {id: 'F-GO', label: 'Go to...', accelerator: 'Ctrl+G', click: () => { mainWindow.webContents.send("open-location"); }}, - {id: 'F-SYNC', label: 'Sync to last page read', click: () => { mainWindow.webContents.send("sync-to-last"); }}, + {id: 'F-GO', label: '&Go to...', accelerator: 'Ctrl+G', click: () => { mainWindow.webContents.send("open-location"); }}, + {id: 'F-SYNC', label: '&Sync to last page read', click: () => { mainWindow.webContents.send("sync-to-last"); }}, {type: 'separator'}, - {id: 'F-CLEAR', label: 'Clear last read', click: () => { mainWindow.webContents.send("clear-last-read"); }}, - {id: 'F-MARK', label: 'Mark as read', accelerator: 'Ctrl+M', click: () => { mainWindow.webContents.send("mark-as-read"); }}, + {id: 'F-CLEAR', label: '&Clear last read', click: () => { mainWindow.webContents.send("clear-last-read"); }}, + {id: 'F-MARK', label: '&Mark as read', accelerator: 'Ctrl+M', click: () => { mainWindow.webContents.send("mark-as-read"); }}, ] }, { - label: 'Reading', + label: '&Reading', submenu: [ - {id: 'F-FIT', label: 'Fit to width', type: 'checkbox', click: () => { mainWindow.webContents.send("fit-to-width"); }}, + {id: 'F-FIT', label: 'Fit to &width', type: 'checkbox', accelerator: 'Alt+W', click: () => { mainWindow.webContents.send("fit-to-width"); }}, {type: 'separator'}, - {id: 'F-SINGLE', label: 'Single column', type: 'checkbox', click: () => { mainWindow.webContents.send("single-column"); }}, - {id: 'F-FLIP', label: 'Mirror (manga mode)', type: 'checkbox', click: () => { mainWindow.webContents.send("flip-columns"); }}, + {id: 'F-SINGLE', label: '&Single column', type: 'checkbox', accelerator: 'Alt+S', click: () => { mainWindow.webContents.send("single-column"); }}, + {id: 'F-FLIP', label: '&Mirror (manga mode)', type: 'checkbox', accelerator: 'Alt+M', click: () => { mainWindow.webContents.send("flip-columns"); }}, {type: 'separator'}, - {id: 'F-ZOOM-IN', label: 'Zoom in', accelerator: 'Ctrl++', click: () => { mainWindow.webContents.send("zoom-in"); }}, - {id: 'F-ZOOM-OUT', label: 'Zoom out', accelerator: 'Ctrl+-', click: () => { mainWindow.webContents.send("zoom-out"); }}, - {id: 'F-ZOOM-RESET', label: 'Reset zoom', accelerator: 'Ctrl+0', click: () => { mainWindow.webContents.send("zoom-reset"); }}, + {id: 'F-ZOOM-IN', label: 'Zoom &in', accelerator: 'Ctrl+=', click: () => { mainWindow.webContents.send("zoom-in"); }}, + {id: 'F-ZOOM-OUT', label: 'Zoom &out', accelerator: 'Ctrl+-', click: () => { mainWindow.webContents.send("zoom-out"); }}, + {id: 'F-ZOOM-RESET', label: '&Reset zoom', accelerator: 'Ctrl+0', click: () => { mainWindow.webContents.send("zoom-reset"); }}, ] }, { - label: 'Tools', + label: '&Tools', submenu: [ - {label: 'Options', click: () => { mainWindow.webContents.send("open-settings"); }}, - {label: 'Toggle fullscreen', accelerator: 'F11', click: () => { mainWindow.setFullScreen(!mainWindow.isFullScreen()); }}, + {label: '&Options', accelerator: 'Ctrl+Shift+O', click: () => { mainWindow.webContents.send("open-settings"); }}, + {label: 'Toggle &fullscreen', accelerator: 'F11', role: 'toggleFullScreen' }, {type: 'separator'}, - {label: 'Developer tools', accelerator: 'F12', click: () => { mainWindow.webContents.openDevTools(); }}, + {label: '&Developer tools', accelerator: 'F12', role: 'toggleDevTools' }, ] }, ]); @@ -187,9 +187,9 @@ function Model() { return self._mruList(); }, write: function (file) { - self.mruList().splice(5); + self.mruList().splice(4); - if (self._mruList().length == 0 || self._mruList()[self._mruList().length - 1] != file) { + if (!self._mruList().find((f) => { return file == f })) { self._mruList.push(file); require('electron').remote.app.addRecentDocument(file); @@ -199,6 +199,11 @@ function Model() { } }); + self.mruClear = function() { + self._mruList.removeAll(); + localforage.setItem("TTC:MRU-LIST", self._mruList()); + }; + self._fitToWidth = ko.observable(false); self.fitToWidth = ko.computed({ @@ -266,10 +271,57 @@ function Model() { remote.getCurrentWindow().setProgressBar(progress/100); }); - /* self._updateMruMenu = ko.computed(function() { + self.openFileDialog = function() { + const { remote } = require('electron'); + const { dialog } = remote; + + const result = dialog.showOpenDialog(remote.getCurrentWindow(), + { + properties: ['openFile'], + filters: [ + { name: 'Comic Archives', extensions: ['cbz', 'zip'] } + ], + }); + + if (result && result[0]) { + self.openFile(result[0]); + } + }; + + self._updateMruMenu = ko.computed(function() { const { remote } = require('electron'); const { Menu, MenuItem } = remote; - }); */ + + const file = Menu.getApplicationMenu().getMenuItemById('M-FILE'); + + if (file != null) { + const menu = file.submenu; + + menu.clear(); + menu.append(new MenuItem({label: '&Open...', accelerator: 'Ctrl+O', + click: () => { self.openFileDialog(); }})); + menu.append(new MenuItem({id: 'F-CLOSE', label: '&Close', + click: () => { self.closeFile(); }})); + menu.append(new MenuItem({type: 'separator'})); + + const mruList = self.mruList(); + + if (mruList.length > 0) { + for (let i = 0; i < mruList.length; i++) { + const file = mruList[i]; + + menu.append(new MenuItem({label: "&" + (i+1) + ". " + file, + click: () => { self.openFile(file); }})); + } + + menu.append(new MenuItem({label: '&Clear recent files', + click: () => { self.mruClear(); }})); + menu.append(new MenuItem({type: 'separator'})); + } + + menu.append(new MenuItem({label: 'E&xit', role: 'quit'})); + } + }); self._updateMenu = ko.computed(function() { const enabled = self.fileName() != ""; @@ -277,25 +329,26 @@ function Model() { const menu = remote.Menu.getApplicationMenu(); $.each(menu.items, (i,g) => { - $.each(g.submenu.items, (i,m) => { - if (m.id && m.id.indexOf("F-") == 0) { - m.enabled = enabled; - - switch (m.id) { - case "F-FIT": - m.checked = self.fitToWidth(); - break; - case "F-SINGLE": - m.checked = self.singleColumn(); - break; - case "F-FLIP": - m.checked = self.flipColumns(); - break; - case "F-SYNC": - m.enabled = self.syncAccount() != ""; + if (g.submenu != null) + $.each(g.submenu.items, (i,m) => { + if (m.id && m.id.indexOf("F-") == 0) { + m.enabled = enabled; + + switch (m.id) { + case "F-FIT": + m.checked = self.fitToWidth(); + break; + case "F-SINGLE": + m.checked = self.singleColumn(); + break; + case "F-FLIP": + m.checked = self.flipColumns(); + break; + case "F-SYNC": + m.enabled = self.syncAccount() != ""; + } } - } - }); + }); }); }); |