From 6dfe335707c25f0e9a87600a2cbd49d606b5d6ce Mon Sep 17 00:00:00 2001 From: zadam Date: Tue, 5 May 2020 19:30:03 +0200 Subject: [PATCH] added global menu item to open new empty window + some refactoring --- src/public/app/services/app_context.js | 13 ------------- src/public/app/services/entrypoints.js | 17 +++++++++++++++++ src/public/app/services/link.js | 2 +- src/public/app/services/tab_manager.js | 8 +++++--- src/public/app/services/tree_context_menu.js | 7 ++----- src/public/app/widgets/global_menu.js | 7 ++++++- src/public/app/widgets/tab_row.js | 6 +++--- src/services/keyboard_actions.js | 8 +++++++- 8 files changed, 41 insertions(+), 27 deletions(-) diff --git a/src/public/app/services/app_context.js b/src/public/app/services/app_context.js index 75c1c820c..b71224839 100644 --- a/src/public/app/services/app_context.js +++ b/src/public/app/services/app_context.js @@ -100,19 +100,6 @@ class AppContext extends Component { getComponentByEl(el) { return $(el).closest(".component").prop('component'); } - - async openInNewWindow(notePath) { - if (utils.isElectron()) { - const {ipcRenderer} = utils.dynamicRequire('electron'); - - ipcRenderer.send('create-extra-window', {notePath}); - } - else { - const url = window.location.protocol + '//' + window.location.host + window.location.pathname + '?extra=1#' + notePath; - - window.open(url, '', 'width=1000,height=800'); - } - } } const appContext = new AppContext(window.glob.isMainWindow); diff --git a/src/public/app/services/entrypoints.js b/src/public/app/services/entrypoints.js index 80d148c7c..262bf6e19 100644 --- a/src/public/app/services/entrypoints.js +++ b/src/public/app/services/entrypoints.js @@ -182,4 +182,21 @@ export default class Entrypoints extends Component { } createTopLevelNoteCommand() { noteCreateService.createNewTopLevelNote(); } + + async openInWindowCommand({notePath}) { + if (utils.isElectron()) { + const {ipcRenderer} = utils.dynamicRequire('electron'); + + ipcRenderer.send('create-extra-window', {notePath}); + } + else { + const url = window.location.protocol + '//' + window.location.host + window.location.pathname + '?extra=1#' + notePath; + + window.open(url, '', 'width=1000,height=800'); + } + } + + async openNewWindowCommand() { + this.openInWindowCommand({notePath: ''}); + } } diff --git a/src/public/app/services/link.js b/src/public/app/services/link.js index 97732821d..9a32f3e6c 100644 --- a/src/public/app/services/link.js +++ b/src/public/app/services/link.js @@ -114,7 +114,7 @@ function newTabContextMenu(e) { y: e.pageY, items: [ {title: "Open note in new tab", command: "openNoteInNewTab", uiIcon: "arrow-up-right"}, - {title: "Open note in new window", command: "openNoteInNewWindow", uiIcon: "arrow-up-right"} + {title: "Open note in new window", command: "openNoteInNewWindow", uiIcon: "window-open"} ], selectMenuItemHandler: ({command}) => { if (command === 'openNoteInNewTab') { diff --git a/src/public/app/services/tab_manager.js b/src/public/app/services/tab_manager.js index 13efc64a7..5463e295c 100644 --- a/src/public/app/services/tab_manager.js +++ b/src/public/app/services/tab_manager.js @@ -82,7 +82,7 @@ export default class TabManager extends Component { if (filteredTabs.length === 0) { filteredTabs.push({ - notePath: 'root', + notePath: this.isMainWindow ? 'root' : '', active: true }); } @@ -196,7 +196,9 @@ export default class TabManager extends Component { async openTabWithNote(notePath, activate, tabId = null) { const tabContext = await this.openEmptyTab(tabId); - await tabContext.setNote(notePath, !activate); // if activate is false then send normal noteSwitched event + if (notePath) { + await tabContext.setNote(notePath, !activate); // if activate is false then send normal noteSwitched event + } if (activate) { this.activateTab(tabContext.tabId, false); @@ -330,7 +332,7 @@ export default class TabManager extends Component { this.removeTab(tabId); - appContext.openInNewWindow(notePath); + this.triggerCommand('openInWindow', {notePath}); } async hoistedNoteChangedEvent({hoistedNoteId}) { diff --git a/src/public/app/services/tree_context_menu.js b/src/public/app/services/tree_context_menu.js index 0478a05ff..002956ebd 100644 --- a/src/public/app/services/tree_context_menu.js +++ b/src/public/app/services/tree_context_menu.js @@ -57,7 +57,7 @@ class TreeContextMenu { return [ { title: 'Open in a new tab Ctrl+Click', command: "openInTab", uiIcon: "empty", enabled: noSelectedNotes }, - { title: 'Open in a new window', command: "openInWindow", uiIcon: "empty", enabled: noSelectedNotes }, + { title: 'Open in a new window', command: "openInWindow", uiIcon: "window-open", enabled: noSelectedNotes }, { title: 'Insert note after ', command: "insertNoteAfter", uiIcon: "plus", items: insertNoteAfterEnabled ? this.getNoteTypeItems("insertNoteAfter") : null, enabled: insertNoteAfterEnabled && noSelectedNotes }, @@ -113,9 +113,6 @@ class TreeContextMenu { if (command === 'openInTab') { appContext.tabManager.openTabWithNote(notePath); } - else if (command === 'openInWindow') { - appContext.openInNewWindow(notePath); - } else if (command === "insertNoteAfter") { const parentNoteId = this.node.data.parentNoteId; const isProtected = await treeService.getParentProtectedStatus(this.node); @@ -134,7 +131,7 @@ class TreeContextMenu { }); } else { - this.treeWidget.triggerCommand(command, {node: this.node}); + this.treeWidget.triggerCommand(command, {node: this.node, notePath: notePath}); } } } diff --git a/src/public/app/widgets/global_menu.js b/src/public/app/widgets/global_menu.js index 1cd3a2ec9..1c18b7f5d 100644 --- a/src/public/app/widgets/global_menu.js +++ b/src/public/app/widgets/global_menu.js @@ -1,5 +1,4 @@ import BasicWidget from "./basic_widget.js"; -import keyboardActionService from "../services/keyboard_actions.js"; import utils from "../services/utils.js"; import syncService from "../services/sync.js"; @@ -39,6 +38,12 @@ const TPL = ` Sync (0) + + + Open new window + + + Open Dev Tools diff --git a/src/public/app/widgets/tab_row.js b/src/public/app/widgets/tab_row.js index 7f896560b..fd89cf47a 100644 --- a/src/public/app/widgets/tab_row.js +++ b/src/public/app/widgets/tab_row.js @@ -258,9 +258,9 @@ export default class TabRowWidget extends BasicWidget { x: e.pageX, y: e.pageY, items: [ - {title: "Move this tab to a new window", command: "moveTabToNewWindow", uiIcon: "empty"}, - {title: "Close all tabs", command: "removeAllTabs", uiIcon: "empty"}, - {title: "Close all tabs except for this", command: "removeAllTabsExceptForThis", uiIcon: "empty"}, + {title: "Move this tab to a new window", command: "moveTabToNewWindow", uiIcon: "window-open"}, + {title: "Close all tabs", command: "removeAllTabs", uiIcon: "x"}, + {title: "Close all tabs except for this", command: "removeAllTabsExceptForThis", uiIcon: "x"}, ], selectMenuItemHandler: ({command}) => { this.triggerCommand(command, {tabId}); diff --git a/src/services/keyboard_actions.js b/src/services/keyboard_actions.js index 44d66586d..425df2f59 100644 --- a/src/services/keyboard_actions.js +++ b/src/services/keyboard_actions.js @@ -193,7 +193,7 @@ const DEFAULT_KEYBOARD_ACTIONS = [ { - separator: "Tabs" + separator: "Tabs & Windows" }, { actionName: "openNewTab", @@ -219,6 +219,12 @@ const DEFAULT_KEYBOARD_ACTIONS = [ description: "Activates tab on the left", scope: "window" }, + { + actionName: "openNewWindow", + defaultShortcuts: [], + description: "Open new empty window", + scope: "window" + }, {