From bed7bdfd00adf08c805c9d2af1fc832280d89dff Mon Sep 17 00:00:00 2001 From: zadam Date: Sun, 7 Feb 2021 21:27:09 +0100 Subject: [PATCH] "move to new window" respects note hoisting of original tab --- src/public/app/services/entrypoints.js | 10 +++++++--- src/public/app/services/hoisted_note.js | 2 +- src/public/app/services/link.js | 2 +- src/public/app/services/tab_context.js | 4 ++++ src/public/app/services/tab_manager.js | 12 ++++++++---- src/public/app/widgets/tab_row.js | 10 ++++++++++ src/routes/index.js | 3 ++- src/services/window.js | 6 +++--- src/views/desktop.ejs | 3 ++- 9 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/public/app/services/entrypoints.js b/src/public/app/services/entrypoints.js index 4633bc300..aef68b430 100644 --- a/src/public/app/services/entrypoints.js +++ b/src/public/app/services/entrypoints.js @@ -184,11 +184,15 @@ export default class Entrypoints extends Component { createTopLevelNoteCommand() { noteCreateService.createNewTopLevelNote(); } - async openInWindowCommand({notePath}) { + async openInWindowCommand({notePath, hoistedNoteId}) { + if (!hoistedNoteId) { + hoistedNoteId = 'root'; + } + if (utils.isElectron()) { const {ipcRenderer} = utils.dynamicRequire('electron'); - ipcRenderer.send('create-extra-window', {notePath}); + ipcRenderer.send('create-extra-window', {notePath, hoistedNoteId}); } else { const url = window.location.protocol + '//' + window.location.host + window.location.pathname + '?extra=1#' + notePath; @@ -198,7 +202,7 @@ export default class Entrypoints extends Component { } async openNewWindowCommand() { - this.openInWindowCommand({notePath: ''}); + this.openInWindowCommand({notePath: '', hoistedNoteId: 'root'}); } async runActiveNoteCommand() { diff --git a/src/public/app/services/hoisted_note.js b/src/public/app/services/hoisted_note.js index 953e8ae31..fffd5d4ab 100644 --- a/src/public/app/services/hoisted_note.js +++ b/src/public/app/services/hoisted_note.js @@ -39,7 +39,7 @@ async function checkNoteAccess(notePath, tabContext) { if (hoistedNoteId !== 'root' && !resolvedNotePath.includes(hoistedNoteId)) { const confirmDialog = await import('../dialogs/confirm.js'); -console.trace("HI!", hoistedNoteId, notePath); + if (!await confirmDialog.confirm("Requested note is outside of hoisted note subtree and you must unhoist to access the note. Do you want to proceed with unhoisting?")) { return false; } diff --git a/src/public/app/services/link.js b/src/public/app/services/link.js index 7f8a2f1ac..ceaf73ab2 100644 --- a/src/public/app/services/link.js +++ b/src/public/app/services/link.js @@ -130,7 +130,7 @@ function linkContextMenu(e) { appContext.tabManager.openTabWithNoteWithHoisting(notePath); } else if (command === 'openNoteInNewWindow') { - appContext.triggerCommand('openInWindow', {notePath}); + appContext.triggerCommand('openInWindow', {notePath, hoistedNoteId: 'root'}); } } }); diff --git a/src/public/app/services/tab_context.js b/src/public/app/services/tab_context.js index fd3b81bdc..80d4eaed3 100644 --- a/src/public/app/services/tab_context.js +++ b/src/public/app/services/tab_context.js @@ -145,6 +145,10 @@ class TabContext extends Component { } async setHoistedNoteId(noteIdToHoist) { + if (this.notePathArray && !this.notePathArray.includes(noteIdToHoist)) { + await this.setNote(noteIdToHoist); + } + this.hoistedNoteId = noteIdToHoist; await this.triggerEvent('hoistedNoteChanged', { diff --git a/src/public/app/services/tab_manager.js b/src/public/app/services/tab_manager.js index 44af32da1..b1782dc5f 100644 --- a/src/public/app/services/tab_manager.js +++ b/src/public/app/services/tab_manager.js @@ -58,7 +58,8 @@ export default class TabManager extends Component { else { tabsToOpen.push({ notePath: notePath, - active: true + active: true, + hoistedNoteId: glob.extraHoistedNoteId || 'root' }); } } @@ -83,7 +84,8 @@ export default class TabManager extends Component { if (filteredTabs.length === 0) { filteredTabs.push({ notePath: this.isMainWindow ? 'root' : '', - active: true + active: true, + extraHoistedNoteId: glob.extraHoistedNoteId || 'root' }); } @@ -91,6 +93,8 @@ export default class TabManager extends Component { filteredTabs[0].active = true; } + console.log("filteredTabs", filteredTabs); + await this.tabsUpdate.allowUpdateWithoutChange(async () => { for (const tab of filteredTabs) { await this.openTabWithNote(tab.notePath, tab.active, tab.tabId, tab.hoistedNoteId); @@ -348,11 +352,11 @@ export default class TabManager extends Component { } moveTabToNewWindowCommand({tabId}) { - const notePath = this.getTabContextById(tabId).notePath; + const {notePath, hoistedNoteId} = this.getTabContextById(tabId); this.removeTab(tabId); - this.triggerCommand('openInWindow', {notePath}); + this.triggerCommand('openInWindow', {notePath, hoistedNoteId}); } hoistedNoteChangedEvent() { diff --git a/src/public/app/widgets/tab_row.js b/src/public/app/widgets/tab_row.js index 1991125a4..2382e3bdc 100644 --- a/src/public/app/widgets/tab_row.js +++ b/src/public/app/widgets/tab_row.js @@ -680,4 +680,14 @@ export default class TabRowWidget extends BasicWidget { this.updateTab($tab, tabContext.note); } } + + hoistedNoteChangedEvent({tabId}) { + const $tab = this.getTabById(tabId); + + if ($tab) { + const tabContext = appContext.tabManager.getTabContextById(tabId); + + this.updateTab($tab, tabContext.note); + } + } } diff --git a/src/routes/index.js b/src/routes/index.js index ec0485f6b..1f47b305e 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -27,7 +27,8 @@ function index(req, res) { instanceName: config.General ? config.General.instanceName : null, appCssNoteIds: getAppCssNoteIds(), isDev: env.isDev(), - isMainWindow: !req.query.extra + isMainWindow: !req.query.extra, + extraHoistedNoteId: req.query.extraHoistedNoteId }); } diff --git a/src/services/window.js b/src/services/window.js index d2670eec3..b4fc797bc 100644 --- a/src/services/window.js +++ b/src/services/window.js @@ -15,7 +15,7 @@ let mainWindow; /** @type {Electron.BrowserWindow} */ let setupWindow; -async function createExtraWindow(notePath) { +async function createExtraWindow(notePath, hoistedNoteId = 'root') { const {BrowserWindow} = require('electron'); const win = new BrowserWindow({ width: 1000, @@ -31,11 +31,11 @@ async function createExtraWindow(notePath) { }); win.setMenuBarVisibility(false); - win.loadURL('http://127.0.0.1:' + await port + '/?extra=1#' + notePath); + win.loadURL('http://127.0.0.1:' + await port + '/?extra=1&extraHoistedNoteId=' + hoistedNoteId + '#' + notePath); } ipcMain.on('create-extra-window', (event, arg) => { - createExtraWindow(arg.notePath); + createExtraWindow(arg.notePath, arg.hoistedNoteId); }); async function createMainWindow() { diff --git a/src/views/desktop.ejs b/src/views/desktop.ejs index 631c9ff2a..9b99a76cd 100644 --- a/src/views/desktop.ejs +++ b/src/views/desktop.ejs @@ -51,7 +51,8 @@ csrfToken: '<%= csrfToken %>', isDev: <%= isDev %>, appCssNoteIds: <%- JSON.stringify(appCssNoteIds) %>, - isMainWindow: <%= isMainWindow %> + isMainWindow: <%= isMainWindow %>, + extraHoistedNoteId: '<%= extraHoistedNoteId %>', };