diff --git a/src/public/app/components/note_context.js b/src/public/app/components/note_context.js index 3de2565aa..5bed983c7 100644 --- a/src/public/app/components/note_context.js +++ b/src/public/app/components/note_context.js @@ -37,7 +37,9 @@ class NoteContext extends Component { return !this.noteId; } - async setNote(inputNotePath, triggerSwitchEvent = true) { + async setNote(inputNotePath, opts = {}) { + opts.triggerSwitchEvent = opts.triggerSwitchEvent !== undefined ? opts.triggerSwitchEvent : true; + const resolvedNotePath = await this.getResolvedNotePath(inputNotePath); if (!resolvedNotePath) { @@ -52,12 +54,13 @@ class NoteContext extends Component { ({noteId: this.noteId, parentNoteId: this.parentNoteId} = treeService.getNoteIdAndParentIdFromNotePath(resolvedNotePath)); this.resetViewScope(); + this.viewScope.viewMode = opts.viewMode || "default"; this.saveToRecentNotes(resolvedNotePath); protectedSessionHolder.touchProtectedSessionIfNecessary(this.note); - if (triggerSwitchEvent) { + if (opts.triggerSwitchEvent) { await this.triggerEvent('noteSwitched', { noteContext: this, notePath: this.notePath @@ -183,7 +186,8 @@ class NoteContext extends Component { mainNtxId: this.mainNtxId, notePath: this.notePath, hoistedNoteId: this.hoistedNoteId, - active: this.isActive() + active: this.isActive(), + viewMode: this.viewScope.viewMode } } @@ -224,9 +228,9 @@ class NoteContext extends Component { const noteComplement = await this.getNoteComplement(); - const sizeLimit = this.note.type === 'text' ? - options.getInt('autoReadonlySizeText') - : options.getInt('autoReadonlySizeCode'); + const sizeLimit = this.note.type === 'text' + ? options.getInt('autoReadonlySizeText') + : options.getInt('autoReadonlySizeCode'); return noteComplement.content && noteComplement.content.length > sizeLimit @@ -251,6 +255,7 @@ class NoteContext extends Component { hasNoteList() { return this.note + && this.viewScope.viewMode === 'default' && this.note.hasChildren() && ['book', 'text', 'code'].includes(this.note.type) && this.note.mime !== 'text/x-sqlite;schema=trilium' diff --git a/src/public/app/components/root_command_executor.js b/src/public/app/components/root_command_executor.js index 4a3383da3..b02cd7eb8 100644 --- a/src/public/app/components/root_command_executor.js +++ b/src/public/app/components/root_command_executor.js @@ -18,7 +18,7 @@ export default class RootCommandExecutor extends Component { async showSQLConsoleCommand() { const sqlConsoleNote = await dateNoteService.createSqlConsole(); - const noteContext = await appContext.tabManager.openContextWithNote(sqlConsoleNote.noteId, true); + const noteContext = await appContext.tabManager.openContextWithNote(sqlConsoleNote.noteId, { activate: true }); appContext.triggerEvent('focusOnDetail', {ntxId: noteContext.ntxId}); } @@ -32,7 +32,10 @@ export default class RootCommandExecutor extends Component { const activeNoteContext = appContext.tabManager.getActiveContext(); const hoistedNoteId = activeNoteContext?.hoistedNoteId || 'root'; - const noteContext = await appContext.tabManager.openContextWithNote(searchNote.noteId, true, null, hoistedNoteId); + const noteContext = await appContext.tabManager.openContextWithNote(searchNote.noteId, { + activate: true, + hoistedNoteId + }); appContext.triggerCommand('focusOnSearchDefinition', {ntxId: noteContext.ntxId}); } @@ -73,7 +76,7 @@ export default class RootCommandExecutor extends Component { } async showBackendLogCommand() { - await appContext.tabManager.openContextWithNote('_backendLog', true); + await appContext.tabManager.openContextWithNote('_backendLog', { activate: true }); } async showLaunchBarSubtreeCommand() { @@ -89,11 +92,10 @@ export default class RootCommandExecutor extends Component { } async showOptionsCommand({section}) { - await appContext.tabManager.openContextWithNote( - section || '_options', - true, - null, - '_options'); + await appContext.tabManager.openContextWithNote(section || '_options', { + activate: true, + hoistedNoteId: '_options' + }); } async showSQLConsoleHistoryCommand() { @@ -109,6 +111,17 @@ export default class RootCommandExecutor extends Component { } async showAndHoistSubtree(subtreeNoteId) { - await appContext.tabManager.openContextWithNote(subtreeNoteId, true, null, subtreeNoteId); + await appContext.tabManager.openContextWithNote(subtreeNoteId, { + activate: true, + hoistedNoteId: subtreeNoteId + }); + } + + async showNoteSourceEvent() { + const notePath = appContext.tabManager.getActiveContextNotePath(); + + if (notePath) { + await appContext.tabManager.openContextWithNote(notePath, { activate: true, viewMode: 'source' }); + } } } diff --git a/src/public/app/components/tab_manager.js b/src/public/app/components/tab_manager.js index 2cbc3f0f4..92e94b218 100644 --- a/src/public/app/components/tab_manager.js +++ b/src/public/app/components/tab_manager.js @@ -96,7 +96,13 @@ export default class TabManager extends Component { await this.tabsUpdate.allowUpdateWithoutChange(async () => { for (const tab of filteredTabs) { - await this.openContextWithNote(tab.notePath, tab.active, tab.ntxId, tab.hoistedNoteId, tab.mainNtxId); + await this.openContextWithNote(tab.notePath, { + activate: tab.active, + ntxId: tab.ntxId, + mainNtxId: tab.mainNtxId, + hoistedNoteId: tab.hoistedNoteId, + viewMode: tab.viewMode + }); } }); @@ -277,14 +283,24 @@ export default class TabManager extends Component { } } - return this.openContextWithNote(notePath, activate, null, hoistedNoteId); + return this.openContextWithNote(notePath, { activate, hoistedNoteId }); } - async openContextWithNote(notePath, activate, ntxId = null, hoistedNoteId = 'root', mainNtxId = null) { + async openContextWithNote(notePath, opts = {}) { + const activate = !!opts.activate; + const ntxId = opts.ntxId || null; + const mainNtxId = opts.mainNtxId || null; + const hoistedNoteId = opts.hoistedNoteId || 'root'; + const viewMode = opts.viewMode || "default"; + const noteContext = await this.openEmptyTab(ntxId, hoistedNoteId, mainNtxId); if (notePath) { - await noteContext.setNote(notePath, !activate); // if activate is false then send normal noteSwitched event + await noteContext.setNote(notePath, { + // if activate is false then send normal noteSwitched event + triggerSwitchEvent: !activate, + viewMode: viewMode + }); } if (activate) { @@ -310,7 +326,7 @@ export default class TabManager extends Component { // if no tab with this note has been found we'll create new tab - await this.openContextWithNote(noteId, true); + await this.openContextWithNote(noteId, { activate: true }); } async activateNoteContext(ntxId, triggerEvent = true) { diff --git a/src/public/app/layouts/desktop_layout.js b/src/public/app/layouts/desktop_layout.js index a893ca3d4..46de93ae4 100644 --- a/src/public/app/layouts/desktop_layout.js +++ b/src/public/app/layouts/desktop_layout.js @@ -46,7 +46,6 @@ import FindWidget from "../widgets/find.js"; import TocWidget from "../widgets/toc.js"; import BulkActionsDialog from "../widgets/dialogs/bulk_actions.js"; import AboutDialog from "../widgets/dialogs/about.js"; -import NoteSourceDialog from "../widgets/dialogs/note_source.js"; import HelpDialog from "../widgets/dialogs/help.js"; import RecentChangesDialog from "../widgets/dialogs/recent_changes.js"; import BackendLogDialog from "../widgets/dialogs/backend_log.js"; @@ -186,7 +185,6 @@ export default class DesktopLayout { ) .child(new BulkActionsDialog()) .child(new AboutDialog()) - .child(new NoteSourceDialog()) .child(new HelpDialog()) .child(new RecentChangesDialog()) .child(new BackendLogDialog()) diff --git a/src/public/app/menus/link_context_menu.js b/src/public/app/menus/link_context_menu.js index 8435eaf52..9e4d83dc0 100644 --- a/src/public/app/menus/link_context_menu.js +++ b/src/public/app/menus/link_context_menu.js @@ -16,7 +16,7 @@ function openContextMenu(notePath, hoistedNoteId, e) { } if (command === 'openNoteInNewTab') { - appContext.tabManager.openContextWithNote(notePath, false, null, hoistedNoteId); + appContext.tabManager.openContextWithNote(notePath, { hoistedNoteId }); } else if (command === 'openNoteInNewSplit') { const subContexts = appContext.tabManager.getActiveContext().getSubContexts(); diff --git a/src/public/app/services/frontend_script_api.js b/src/public/app/services/frontend_script_api.js index 91bd49fc0..7734abd0f 100644 --- a/src/public/app/services/frontend_script_api.js +++ b/src/public/app/services/frontend_script_api.js @@ -103,7 +103,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain this.openTabWithNote = async (notePath, activate) => { await ws.waitForMaxKnownEntityChangeId(); - await appContext.tabManager.openContextWithNote(notePath, activate); + await appContext.tabManager.openContextWithNote(notePath, { activate }); if (activate) { appContext.triggerEvent('focusAndSelectTitle'); diff --git a/src/public/app/services/hoisted_note.js b/src/public/app/services/hoisted_note.js index 6e74908ca..5263b2eb3 100644 --- a/src/public/app/services/hoisted_note.js +++ b/src/public/app/services/hoisted_note.js @@ -42,7 +42,7 @@ async function checkNoteAccess(notePath, noteContext) { const resolvedNotePath = await treeService.resolveNotePath(notePath, noteContext.hoistedNoteId); if (!resolvedNotePath) { - console.log(`Cannot activate ${notePath}`); + console.log(`Cannot activate '${notePath}'`); return false; } diff --git a/src/public/app/widgets/buttons/note_actions.js b/src/public/app/widgets/buttons/note_actions.js index 6b1c15b51..fb2c19918 100644 --- a/src/public/app/widgets/buttons/note_actions.js +++ b/src/public/app/widgets/buttons/note_actions.js @@ -27,7 +27,7 @@ const TPL = `