"move to new window" respects note hoisting of original tab

This commit is contained in:
zadam 2021-02-07 21:27:09 +01:00
parent cd5be59413
commit bed7bdfd00
9 changed files with 38 additions and 14 deletions

View File

@ -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() {

View File

@ -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;
}

View File

@ -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'});
}
}
});

View File

@ -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', {

View File

@ -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() {

View File

@ -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);
}
}
}

View File

@ -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
});
}

View File

@ -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() {

View File

@ -51,7 +51,8 @@
csrfToken: '<%= csrfToken %>',
isDev: <%= isDev %>,
appCssNoteIds: <%- JSON.stringify(appCssNoteIds) %>,
isMainWindow: <%= isMainWindow %>
isMainWindow: <%= isMainWindow %>,
extraHoistedNoteId: '<%= extraHoistedNoteId %>',
};
</script>