Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
added global menu item to open new empty window + some refactoring
zadam6dfe335707c2
diff --git a/src/public/app/services/app_context.js b/src/public/app/services/app_context.jsindex 75c1c820ca..b712248396 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.jsindex 80d148c7c0..262bf6e19c 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.jsindex 97732821dd..9a32f3e6cd 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.jsindex 13efc64a7a..5463e295c7 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.jsindex 0478a05ffe..002956ebde 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 <kbd>Ctrl+Click</kbd>', 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 <kbd data-command="createNoteAfter"></kbd>', 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.jsindex 1cd3a2ec9e..1c18b7f5dd 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 (<span id="outstanding-syncs-count">0</span>)</a>+ <a class="dropdown-item" data-trigger-command="openNewWindow">+ <span class="bx bx-window-open"></span>+ Open new window+ <kbd data-command="openNewWindow"></kbd>+ </a>+<a class="dropdown-item open-dev-tools-button" data-trigger-command="openDevTools"><span class="bx bx-terminal"></span>Open Dev Toolsdiff --git a/src/public/app/widgets/tab_row.js b/src/public/app/widgets/tab_row.jsindex 7f896560b9..fd89cf47a8 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.jsindex 44d66586d5..425df2f593 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"+ },{