mirror of
https://github.com/zadam/trilium.git
synced 2025-06-05 01:18:44 +02:00
refactored TabContext => NoteContext
This commit is contained in:
parent
274cf7312c
commit
79a85a0aa7
@ -20,7 +20,7 @@ export async function showDialog() {
|
||||
return false;
|
||||
}
|
||||
|
||||
appContext.tabManager.getActiveNoteContext().setNote(suggestion.notePath);
|
||||
appContext.tabManager.getActiveContext().setNote(suggestion.notePath);
|
||||
});
|
||||
|
||||
// if you open the Jump To dialog soon after using it previously it can often mean that you
|
||||
|
@ -27,7 +27,7 @@ export async function showDialog() {
|
||||
}
|
||||
|
||||
$dialog.on('shown.bs.modal', () => {
|
||||
const note = appContext.tabManager.getActiveTabNote();
|
||||
const note = appContext.tabManager.getActiveContextNote();
|
||||
|
||||
linkMapService = new LinkMapService(note, $linkMapContainer, getOptions());
|
||||
linkMapService.render();
|
||||
|
@ -29,7 +29,7 @@ async function convertMarkdownToHtml(text) {
|
||||
}
|
||||
|
||||
export async function importMarkdownInline() {
|
||||
if (appContext.tabManager.getActiveTabNoteType() !== 'text') {
|
||||
if (appContext.tabManager.getActiveContextNoteType() !== 'text') {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -58,4 +58,4 @@ $importButton.on('click', sendForm);
|
||||
|
||||
$dialog.on('shown.bs.modal', () => $importTextarea.trigger('focus'));
|
||||
|
||||
utils.bindElShortcut($dialog, 'ctrl+return', sendForm);
|
||||
utils.bindElShortcut($dialog, 'ctrl+return', sendForm);
|
||||
|
@ -12,7 +12,7 @@ const $okButton = $("#note-info-ok-button");
|
||||
export async function showDialog() {
|
||||
utils.openDialog($dialog);
|
||||
|
||||
const activeNoteContext = appContext.tabManager.getActiveNoteContext();
|
||||
const activeNoteContext = appContext.tabManager.getActiveContext();
|
||||
const {note} = activeNoteContext;
|
||||
const noteComplement = await activeNoteContext.getNoteComplement();
|
||||
|
||||
|
@ -27,7 +27,7 @@ let note;
|
||||
let noteRevisionId;
|
||||
|
||||
export async function showCurrentNoteRevisions() {
|
||||
await showNoteRevisionsDialog(appContext.tabManager.getActiveTabNoteId());
|
||||
await showNoteRevisionsDialog(appContext.tabManager.getActiveContextNoteId());
|
||||
}
|
||||
|
||||
export async function showNoteRevisionsDialog(noteId, noteRevisionId) {
|
||||
@ -41,7 +41,7 @@ async function loadNoteRevisions(noteId, noteRevId) {
|
||||
$content.empty();
|
||||
$titleButtons.empty();
|
||||
|
||||
note = appContext.tabManager.getActiveTabNote();
|
||||
note = appContext.tabManager.getActiveContextNote();
|
||||
revisionItems = await server.get(`notes/${noteId}/revisions`);
|
||||
|
||||
for (const item of revisionItems) {
|
||||
|
@ -7,7 +7,7 @@ const $noteSource = $("#note-source");
|
||||
export async function showDialog() {
|
||||
utils.openDialog($dialog);
|
||||
|
||||
const noteCompletement = await appContext.tabManager.getActiveNoteContext().getNoteComplement();
|
||||
const noteCompletement = await appContext.tabManager.getActiveContext().getNoteComplement();
|
||||
|
||||
$noteSource.text(formatHtml(noteCompletement.content));
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ export async function showDialog(ancestorNoteId) {
|
||||
|
||||
await froca.reloadNotes([change.noteId]);
|
||||
|
||||
appContext.tabManager.getActiveNoteContext().setNote(change.noteId);
|
||||
appContext.tabManager.getActiveContext().setNote(change.noteId);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -5,7 +5,7 @@ import TitleBarButtonsWidget from "../widgets/title_bar_buttons.js";
|
||||
import StandardTopWidget from "../widgets/standard_top_widget.js";
|
||||
import SidePaneContainer from "../widgets/containers/side_pane_container.js";
|
||||
import NoteTreeWidget from "../widgets/note_tree.js";
|
||||
import TabCachingWidget from "../widgets/tab_caching_widget.js";
|
||||
import NoteContextCachingWidget from "../widgets/note_context_caching_widget.js";
|
||||
import NotePathsWidget from "../widgets/note_paths.js";
|
||||
import NoteTitleWidget from "../widgets/note_title.js";
|
||||
import OwnedAttributeListWidget from "../widgets/type_property_widgets/owned_attribute_list.js";
|
||||
|
@ -161,7 +161,7 @@ $(window).on('hashchange', function() {
|
||||
return;
|
||||
}
|
||||
|
||||
appContext.tabManager.switchToTab(ntxId, notePath);
|
||||
appContext.tabManager.switchToNoteContext(ntxId, notePath);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -74,17 +74,17 @@ export default class Entrypoints extends Component {
|
||||
|
||||
await ws.waitForMaxKnownEntityChangeId();
|
||||
|
||||
const hoistedNoteId = appContext.tabManager.getActiveNoteContext()
|
||||
? appContext.tabManager.getActiveNoteContext().hoistedNoteId
|
||||
const hoistedNoteId = appContext.tabManager.getActiveContext()
|
||||
? appContext.tabManager.getActiveContext().hoistedNoteId
|
||||
: 'root';
|
||||
|
||||
await appContext.tabManager.openTabWithNote(note.noteId, true, null, hoistedNoteId);
|
||||
await appContext.tabManager.openContextWithNote(note.noteId, true, null, hoistedNoteId);
|
||||
|
||||
appContext.triggerEvent('focusAndSelectTitle');
|
||||
}
|
||||
|
||||
async toggleNoteHoistingCommand() {
|
||||
const noteContext = appContext.tabManager.getActiveNoteContext();
|
||||
const noteContext = appContext.tabManager.getActiveContext();
|
||||
|
||||
if (noteContext.note.noteId === noteContext.hoistedNoteId) {
|
||||
await noteContext.unhoist();
|
||||
@ -95,7 +95,7 @@ export default class Entrypoints extends Component {
|
||||
}
|
||||
|
||||
async hoistNoteCommand({noteId}) {
|
||||
const noteContext = appContext.tabManager.getActiveNoteContext();
|
||||
const noteContext = appContext.tabManager.getActiveContext();
|
||||
|
||||
if (noteContext.hoistedNoteId !== noteId) {
|
||||
await noteContext.setHoistedNoteId(noteId);
|
||||
@ -103,7 +103,7 @@ export default class Entrypoints extends Component {
|
||||
}
|
||||
|
||||
async unhoistCommand() {
|
||||
const activeNoteContext = appContext.tabManager.getActiveNoteContext();
|
||||
const activeNoteContext = appContext.tabManager.getActiveContext();
|
||||
|
||||
if (activeNoteContext) {
|
||||
activeNoteContext.unhoist();
|
||||
@ -194,7 +194,7 @@ export default class Entrypoints extends Component {
|
||||
}
|
||||
|
||||
async runActiveNoteCommand() {
|
||||
const noteContext = appContext.tabManager.getActiveNoteContext();
|
||||
const noteContext = appContext.tabManager.getActiveContext();
|
||||
const note = noteContext.note;
|
||||
|
||||
// ctrl+enter is also used elsewhere so make sure we're running only when appropriate
|
||||
@ -220,7 +220,7 @@ export default class Entrypoints extends Component {
|
||||
$(".tooltip").removeClass("show");
|
||||
}
|
||||
|
||||
tabNoteSwitchedEvent() {
|
||||
noteSwitchedEvent() {
|
||||
this.hideAllTooltips();
|
||||
}
|
||||
|
||||
|
@ -10,8 +10,8 @@ import searchService from './search.js';
|
||||
import CollapsibleWidget from '../widgets/collapsible_widget.js';
|
||||
import ws from "./ws.js";
|
||||
import appContext from "./app_context.js";
|
||||
import TabAwareWidget from "../widgets/tab_aware_widget.js";
|
||||
import TabCachingWidget from "../widgets/tab_caching_widget.js";
|
||||
import NoteContextAwareWidget from "../widgets/note_context_aware_widget.js";
|
||||
import NoteContextCachingWidget from "../widgets/note_context_caching_widget.js";
|
||||
import BasicWidget from "../widgets/basic_widget.js";
|
||||
|
||||
/**
|
||||
@ -39,11 +39,11 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
|
||||
/** @property {CollapsibleWidget} */
|
||||
this.CollapsibleWidget = CollapsibleWidget;
|
||||
|
||||
/** @property {TabAwareWidget} */
|
||||
this.TabAwareWidget = TabAwareWidget;
|
||||
/** @property {NoteContextAwareWidget} */
|
||||
this.TabAwareWidget = NoteContextAwareWidget;
|
||||
|
||||
/** @property {TabCachingWidget} */
|
||||
this.TabCachingWidget = TabCachingWidget;
|
||||
/** @property {NoteContextCachingWidget} */
|
||||
this.TabCachingWidget = NoteContextCachingWidget;
|
||||
|
||||
/** @property {BasicWidget} */
|
||||
this.BasicWidget = BasicWidget;
|
||||
@ -56,7 +56,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
this.activateNote = async notePath => {
|
||||
await appContext.tabManager.getActiveNoteContext().setNote(notePath);
|
||||
await appContext.tabManager.getActiveContext().setNote(notePath);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -68,7 +68,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
|
||||
this.activateNewNote = async notePath => {
|
||||
await ws.waitForMaxKnownEntityChangeId();
|
||||
|
||||
await appContext.tabManager.getActiveNoteContext().setNote(notePath);
|
||||
await appContext.tabManager.getActiveContext().setNote(notePath);
|
||||
appContext.triggerEvent('focusAndSelectTitle');
|
||||
};
|
||||
|
||||
@ -82,7 +82,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
|
||||
this.openTabWithNote = async (notePath, activate) => {
|
||||
await ws.waitForMaxKnownEntityChangeId();
|
||||
|
||||
await appContext.tabManager.openTabWithNote(notePath, activate);
|
||||
await appContext.tabManager.openContextWithNote(notePath, activate);
|
||||
|
||||
if (activate) {
|
||||
appContext.triggerEvent('focusAndSelectTitle');
|
||||
@ -313,7 +313,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
|
||||
* @method
|
||||
* @returns {NoteShort} active note (loaded into right pane)
|
||||
*/
|
||||
this.getActiveTabNote = () => appContext.tabManager.getActiveTabNote();
|
||||
this.getActiveTabNote = () => appContext.tabManager.getActiveContextNote();
|
||||
|
||||
/**
|
||||
* See https://ckeditor.com/docs/ckeditor5/latest/api/module_core_editor_editor-Editor.html for a documentation on the returned instance.
|
||||
@ -327,7 +327,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
|
||||
* @method
|
||||
* @returns {Promise<string|null>} returns note path of active note or null if there isn't active note
|
||||
*/
|
||||
this.getActiveTabNotePath = () => appContext.tabManager.getActiveTabNotePath();
|
||||
this.getActiveTabNotePath = () => appContext.tabManager.getActiveContextNotePath();
|
||||
|
||||
/**
|
||||
* @method
|
||||
@ -340,7 +340,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
|
||||
* @method
|
||||
*/
|
||||
this.protectActiveNote = async () => {
|
||||
const activeNote = appContext.tabManager.getActiveTabNote();
|
||||
const activeNote = appContext.tabManager.getActiveContextNote();
|
||||
|
||||
await protectedSessionService.protectNote(activeNote.noteId, true, false);
|
||||
};
|
||||
@ -406,7 +406,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
|
||||
* @return {Promise}
|
||||
*/
|
||||
this.setHoistedNoteId = (noteId) => {
|
||||
const activeNoteContext = appContext.tabManager.getActiveNoteContext();
|
||||
const activeNoteContext = appContext.tabManager.getActiveContext();
|
||||
|
||||
if (activeNoteContext) {
|
||||
activeNoteContext.setHoistedNoteId(noteId);
|
||||
|
@ -16,7 +16,7 @@ function setupGlobs() {
|
||||
window.glob.getHeaders = server.getHeaders;
|
||||
|
||||
// required for ESLint plugin and CKEditor
|
||||
window.glob.getActiveTabNote = () => appContext.tabManager.getActiveTabNote();
|
||||
window.glob.getActiveTabNote = () => appContext.tabManager.getActiveContextNote();
|
||||
window.glob.requireLibrary = libraryLoader.requireLibrary;
|
||||
window.glob.ESLINT = libraryLoader.ESLINT;
|
||||
window.glob.appContext = appContext; // for debugging
|
||||
|
@ -2,13 +2,13 @@ import appContext from "./app_context.js";
|
||||
import treeService from "./tree.js";
|
||||
|
||||
function getHoistedNoteId() {
|
||||
const activeNoteContext = appContext.tabManager.getActiveNoteContext();
|
||||
const activeNoteContext = appContext.tabManager.getActiveContext();
|
||||
|
||||
return activeNoteContext ? activeNoteContext.hoistedNoteId : 'root';
|
||||
}
|
||||
|
||||
async function unhoist() {
|
||||
const activeNoteContext = appContext.tabManager.getActiveNoteContext();
|
||||
const activeNoteContext = appContext.tabManager.getActiveContext();
|
||||
|
||||
if (activeNoteContext) {
|
||||
await activeNoteContext.unhoist();
|
||||
|
@ -64,7 +64,7 @@ ws.subscribeToMessages(async message => {
|
||||
toastService.showPersistent(toast);
|
||||
|
||||
if (message.result.importedNoteId) {
|
||||
await appContext.tabManager.getActiveNoteContext().setNote(message.result.importedNoteId);
|
||||
await appContext.tabManager.getActiveContext().setNote(message.result.importedNoteId);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -43,7 +43,7 @@ getActionsForScope("window").then(actions => {
|
||||
server.get('keyboard-shortcuts-for-notes').then(shortcutForNotes => {
|
||||
for (const shortcut in shortcutForNotes) {
|
||||
utils.bindGlobalShortcut(shortcut, async () => {
|
||||
appContext.tabManager.getActiveNoteContext().setNote(shortcutForNotes[shortcut]);
|
||||
appContext.tabManager.getActiveContext().setNote(shortcutForNotes[shortcut]);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -85,11 +85,11 @@ function goToLink(e) {
|
||||
|
||||
const noteContext = ntxId
|
||||
? appContext.tabManager.getNoteContextById(ntxId)
|
||||
: appContext.tabManager.getActiveNoteContext();
|
||||
: appContext.tabManager.getActiveContext();
|
||||
|
||||
noteContext.setNote(notePath).then(() => {
|
||||
if (noteContext !== appContext.tabManager.getActiveNoteContext()) {
|
||||
appContext.tabManager.activateTab(noteContext.ntxId);
|
||||
if (noteContext !== appContext.tabManager.getActiveContext()) {
|
||||
appContext.tabManager.activateNoteContext(noteContext.ntxId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ export default class MainTreeExecutors extends Component {
|
||||
}
|
||||
|
||||
async createNoteIntoCommand() {
|
||||
const activeNoteContext = appContext.tabManager.getActiveNoteContext();
|
||||
const activeNoteContext = appContext.tabManager.getActiveContext();
|
||||
|
||||
if (!activeNoteContext) {
|
||||
return;
|
||||
|
@ -31,7 +31,7 @@ async function autocompleteSourceForCKEditor(queryText) {
|
||||
}
|
||||
|
||||
async function autocompleteSource(term, cb, options = {}) {
|
||||
const activeNoteId = appContext.tabManager.getActiveTabNoteId();
|
||||
const activeNoteId = appContext.tabManager.getActiveContextNoteId();
|
||||
|
||||
let results = await server.get('autocomplete'
|
||||
+ '?query=' + encodeURIComponent(term)
|
||||
|
@ -20,7 +20,7 @@ class NoteContext extends Component {
|
||||
}
|
||||
|
||||
setEmpty() {
|
||||
this.triggerEvent('tabNoteSwitched', {
|
||||
this.triggerEvent('noteSwitched', {
|
||||
noteContext: this,
|
||||
notePath: this.notePath
|
||||
});
|
||||
@ -48,7 +48,7 @@ class NoteContext extends Component {
|
||||
protectedSessionHolder.touchProtectedSessionIfNecessary(this.note);
|
||||
|
||||
if (triggerSwitchEvent) {
|
||||
await this.triggerEvent('tabNoteSwitched', {
|
||||
await this.triggerEvent('noteSwitched', {
|
||||
noteContext: this,
|
||||
notePath: this.notePath
|
||||
});
|
||||
@ -180,7 +180,7 @@ class NoteContext extends Component {
|
||||
this.noteId = null;
|
||||
this.notePath = null;
|
||||
|
||||
this.triggerEvent('tabNoteSwitched', {
|
||||
this.triggerEvent('noteSwitched', {
|
||||
noteContext: this,
|
||||
notePath: this.notePath
|
||||
});
|
@ -20,7 +20,7 @@ async function createNote(parentNotePath, options = {}) {
|
||||
options.isProtected = false;
|
||||
}
|
||||
|
||||
if (appContext.tabManager.getActiveTabNoteType() !== 'text') {
|
||||
if (appContext.tabManager.getActiveContextNoteType() !== 'text') {
|
||||
options.saveSelection = false;
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ async function createNote(parentNotePath, options = {}) {
|
||||
await ws.waitForMaxKnownEntityChangeId();
|
||||
|
||||
if (options.activate) {
|
||||
const activeNoteContext = appContext.tabManager.getActiveNoteContext();
|
||||
const activeNoteContext = appContext.tabManager.getActiveContext();
|
||||
await activeNoteContext.setNote(`${parentNotePath}/${note.noteId}`);
|
||||
|
||||
if (options.focus === 'title') {
|
||||
@ -90,7 +90,7 @@ async function duplicateSubtree(noteId, parentNotePath) {
|
||||
|
||||
await ws.waitForMaxKnownEntityChangeId();
|
||||
|
||||
const activeNoteContext = appContext.tabManager.getActiveNoteContext();
|
||||
const activeNoteContext = appContext.tabManager.getActiveContext();
|
||||
activeNoteContext.setNote(`${parentNotePath}/${note.noteId}`);
|
||||
|
||||
const origNote = await froca.getNote(noteId);
|
||||
|
@ -35,7 +35,7 @@ export default class RootCommandExecutor extends Component {
|
||||
}
|
||||
|
||||
async editBranchPrefixCommand() {
|
||||
const notePath = appContext.tabManager.getActiveTabNotePath();
|
||||
const notePath = appContext.tabManager.getActiveContextNotePath();
|
||||
|
||||
if (notePath) {
|
||||
const editBranchPrefixDialog = await import("../dialogs/branch_prefix.js");
|
||||
@ -64,7 +64,7 @@ export default class RootCommandExecutor extends Component {
|
||||
async showSQLConsoleCommand() {
|
||||
const sqlConsoleNote = await dateNoteService.createSqlConsole();
|
||||
|
||||
const noteContext = await appContext.tabManager.openTabWithNote(sqlConsoleNote.noteId, true);
|
||||
const noteContext = await appContext.tabManager.openContextWithNote(sqlConsoleNote.noteId, true);
|
||||
|
||||
appContext.triggerEvent('focusOnDetail', {ntxId: noteContext.ntxId});
|
||||
}
|
||||
@ -72,7 +72,7 @@ export default class RootCommandExecutor extends Component {
|
||||
async searchNotesCommand({searchString, ancestorNoteId}) {
|
||||
const searchNote = await dateNoteService.createSearchNote({searchString, ancestorNoteId});
|
||||
|
||||
const noteContext = await appContext.tabManager.openTabWithNote(searchNote.noteId, true);
|
||||
const noteContext = await appContext.tabManager.openContextWithNote(searchNote.noteId, true);
|
||||
|
||||
appContext.triggerCommand('focusOnSearchDefinition', {ntxId: noteContext.ntxId});
|
||||
}
|
||||
@ -88,7 +88,7 @@ export default class RootCommandExecutor extends Component {
|
||||
}
|
||||
|
||||
openNoteExternallyCommand() {
|
||||
const noteId = appContext.tabManager.getActiveTabNoteId();
|
||||
const noteId = appContext.tabManager.getActiveContextNoteId();
|
||||
|
||||
if (noteId) {
|
||||
openService.openNoteExternally(noteId);
|
||||
|
@ -4,7 +4,7 @@ const REQUEST_LOGGING_ENABLED = false;
|
||||
|
||||
async function getHeaders(headers) {
|
||||
const appContext = (await import('./app_context.js')).default;
|
||||
const activeNoteContext = appContext.tabManager ? appContext.tabManager.getActiveNoteContext() : null;
|
||||
const activeNoteContext = appContext.tabManager ? appContext.tabManager.getActiveContext() : null;
|
||||
|
||||
// headers need to be lowercase because node.js automatically converts them to lower case
|
||||
// also avoiding using underscores instead of dashes since nginx filters them out by default
|
||||
|
@ -5,7 +5,7 @@ import options from "./options.js";
|
||||
import froca from "./froca.js";
|
||||
import treeService from "./tree.js";
|
||||
import utils from "./utils.js";
|
||||
import NoteContext from "./tab_context.js";
|
||||
import NoteContext from "./note_context.js";
|
||||
import appContext from "./app_context.js";
|
||||
|
||||
export default class TabManager extends Component {
|
||||
@ -104,12 +104,12 @@ export default class TabManager extends Component {
|
||||
|
||||
await this.tabsUpdate.allowUpdateWithoutChange(async () => {
|
||||
for (const tab of filteredTabs) {
|
||||
await this.openTabWithNote(tab.notePath, tab.active, tab.ntxId, tab.hoistedNoteId, tab.mainNtxId);
|
||||
await this.openContextWithNote(tab.notePath, tab.active, tab.ntxId, tab.hoistedNoteId, tab.mainNtxId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
tabNoteSwitchedEvent({noteContext}) {
|
||||
noteSwitchedEvent({noteContext}) {
|
||||
if (noteContext.isActive()) {
|
||||
this.setCurrentNotePathToHash();
|
||||
}
|
||||
@ -118,7 +118,7 @@ export default class TabManager extends Component {
|
||||
}
|
||||
|
||||
setCurrentNotePathToHash() {
|
||||
const activeNoteContext = this.getActiveNoteContext();
|
||||
const activeNoteContext = this.getActiveContext();
|
||||
|
||||
if (window.history.length === 0 // first history entry
|
||||
|| (activeNoteContext && activeNoteContext.notePath !== treeService.getHashValueFromAddress()[0])) {
|
||||
@ -155,50 +155,50 @@ export default class TabManager extends Component {
|
||||
}
|
||||
|
||||
/** @returns {NoteContext} */
|
||||
getActiveNoteContext() {
|
||||
getActiveContext() {
|
||||
return this.activeTabId
|
||||
? this.getNoteContextById(this.activeTabId)
|
||||
: null;
|
||||
}
|
||||
|
||||
/** @returns {string|null} */
|
||||
getActiveTabNotePath() {
|
||||
const activeContext = this.getActiveNoteContext();
|
||||
getActiveContextNotePath() {
|
||||
const activeContext = this.getActiveContext();
|
||||
return activeContext ? activeContext.notePath : null;
|
||||
}
|
||||
|
||||
/** @return {NoteShort} */
|
||||
getActiveTabNote() {
|
||||
const activeContext = this.getActiveNoteContext();
|
||||
getActiveContextNote() {
|
||||
const activeContext = this.getActiveContext();
|
||||
return activeContext ? activeContext.note : null;
|
||||
}
|
||||
|
||||
/** @return {string|null} */
|
||||
getActiveTabNoteId() {
|
||||
const activeNote = this.getActiveTabNote();
|
||||
getActiveContextNoteId() {
|
||||
const activeNote = this.getActiveContextNote();
|
||||
|
||||
return activeNote ? activeNote.noteId : null;
|
||||
}
|
||||
|
||||
/** @return {string|null} */
|
||||
getActiveTabNoteType() {
|
||||
const activeNote = this.getActiveTabNote();
|
||||
getActiveContextNoteType() {
|
||||
const activeNote = this.getActiveContextNote();
|
||||
|
||||
return activeNote ? activeNote.type : null;
|
||||
}
|
||||
|
||||
async switchToTab(ntxId, notePath) {
|
||||
async switchToNoteContext(ntxId, notePath) {
|
||||
const noteContext = this.noteContexts.find(nc => nc.ntxId === ntxId)
|
||||
|| await this.openEmptyTab();
|
||||
|
||||
this.activateTab(noteContext.ntxId);
|
||||
this.activateNoteContext(noteContext.ntxId);
|
||||
await noteContext.setNote(notePath);
|
||||
}
|
||||
|
||||
async openAndActivateEmptyTab() {
|
||||
const noteContext = await this.openEmptyTab();
|
||||
|
||||
await this.activateTab(noteContext.ntxId);
|
||||
await this.activateNoteContext(noteContext.ntxId);
|
||||
|
||||
await noteContext.setEmpty();
|
||||
}
|
||||
@ -214,7 +214,7 @@ export default class TabManager extends Component {
|
||||
|
||||
this.child(noteContext);
|
||||
|
||||
await this.triggerEvent('newTabOpened', {noteContext});
|
||||
await this.triggerEvent('newNoteContextCreated', {noteContext});
|
||||
|
||||
return noteContext;
|
||||
}
|
||||
@ -223,7 +223,7 @@ export default class TabManager extends Component {
|
||||
* If the requested notePath is within current note hoisting scope then keep the note hoisting also for the new tab.
|
||||
*/
|
||||
async openTabWithNoteWithHoisting(notePath) {
|
||||
const noteContext = this.getActiveNoteContext();
|
||||
const noteContext = this.getActiveContext();
|
||||
let hoistedNoteId = 'root';
|
||||
|
||||
if (noteContext) {
|
||||
@ -234,10 +234,10 @@ export default class TabManager extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
return this.openTabWithNote(notePath, false, null, hoistedNoteId);
|
||||
return this.openContextWithNote(notePath, false, null, hoistedNoteId);
|
||||
}
|
||||
|
||||
async openTabWithNote(notePath, activate, ntxId, hoistedNoteId = 'root', mainNtxId = null) {
|
||||
async openContextWithNote(notePath, activate, ntxId, hoistedNoteId = 'root', mainNtxId = null) {
|
||||
const noteContext = await this.openEmptyTab(ntxId, hoistedNoteId, mainNtxId);
|
||||
|
||||
if (notePath) {
|
||||
@ -245,9 +245,9 @@ export default class TabManager extends Component {
|
||||
}
|
||||
|
||||
if (activate) {
|
||||
this.activateTab(noteContext.ntxId, false);
|
||||
this.activateNoteContext(noteContext.ntxId, false);
|
||||
|
||||
await this.triggerEvent('tabNoteSwitchedAndActivated', {
|
||||
await this.triggerEvent('noteSwitchedAndActivated', {
|
||||
noteContext,
|
||||
notePath: noteContext.notePath // resolved note path
|
||||
});
|
||||
@ -259,7 +259,7 @@ export default class TabManager extends Component {
|
||||
async activateOrOpenNote(noteId) {
|
||||
for (const noteContext of this.getNoteContexts()) {
|
||||
if (noteContext.note && noteContext.note.noteId === noteId) {
|
||||
this.activateTab(noteContext.ntxId);
|
||||
this.activateNoteContext(noteContext.ntxId);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -267,10 +267,10 @@ export default class TabManager extends Component {
|
||||
|
||||
// if no tab with this note has been found we'll create new tab
|
||||
|
||||
await this.openTabWithNote(noteId, true);
|
||||
await this.openContextWithNote(noteId, true);
|
||||
}
|
||||
|
||||
activateTab(ntxId, triggerEvent = true) {
|
||||
activateNoteContext(ntxId, triggerEvent = true) {
|
||||
if (ntxId === this.activeTabId) {
|
||||
return;
|
||||
}
|
||||
@ -288,7 +288,7 @@ export default class TabManager extends Component {
|
||||
this.setCurrentNotePathToHash();
|
||||
}
|
||||
|
||||
async removeTab(ntxId) {
|
||||
async removeNoteContext(ntxId) {
|
||||
const mainNoteContextToRemove = this.getNoteContextById(ntxId).getMainNoteContext();
|
||||
|
||||
// close dangling autocompletes after closing the tab
|
||||
@ -314,7 +314,7 @@ export default class TabManager extends Component {
|
||||
|
||||
this.children = this.children.filter(nc => !ntxIdsToRemove.includes(nc.ntxId));
|
||||
|
||||
this.triggerEvent('tabRemoved', {ntxIds: ntxIdsToRemove});
|
||||
this.triggerEvent('noteContextRemoved', {ntxIds: ntxIdsToRemove});
|
||||
|
||||
this.tabsUpdate.scheduleUpdate();
|
||||
}
|
||||
@ -335,18 +335,18 @@ export default class TabManager extends Component {
|
||||
const oldIdx = this.mainNoteContexts.findIndex(nc => nc.ntxId === this.activeTabId);
|
||||
const newActiveTabId = this.mainNoteContexts[oldIdx === this.noteContexts.length - 1 ? 0 : oldIdx + 1].ntxId;
|
||||
|
||||
this.activateTab(newActiveTabId);
|
||||
this.activateNoteContext(newActiveTabId);
|
||||
}
|
||||
|
||||
activatePreviousTabCommand() {
|
||||
const oldIdx = this.mainNoteContexts.findIndex(nc => nc.ntxId === this.activeTabId);
|
||||
const newActiveTabId = this.mainNoteContexts[oldIdx === 0 ? this.noteContexts.length - 1 : oldIdx - 1].ntxId;
|
||||
|
||||
this.activateTab(newActiveTabId);
|
||||
this.activateNoteContext(newActiveTabId);
|
||||
}
|
||||
|
||||
closeActiveTabCommand() {
|
||||
this.removeTab(this.activeTabId);
|
||||
this.removeNoteContext(this.activeTabId);
|
||||
}
|
||||
|
||||
beforeUnloadEvent() {
|
||||
@ -361,14 +361,14 @@ export default class TabManager extends Component {
|
||||
|
||||
async removeAllTabsCommand() {
|
||||
for (const ntxIdToRemove of this.noteContexts.map(nc => nc.ntxId)) {
|
||||
await this.removeTab(ntxIdToRemove);
|
||||
await this.removeNoteContext(ntxIdToRemove);
|
||||
}
|
||||
}
|
||||
|
||||
async removeAllTabsExceptForThisCommand({ntxId}) {
|
||||
for (const ntxIdToRemove of this.noteContexts.map(nc => nc.ntxId)) {
|
||||
if (ntxIdToRemove !== ntxId) {
|
||||
await this.removeTab(ntxIdToRemove);
|
||||
await this.removeNoteContext(ntxIdToRemove);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -376,7 +376,7 @@ export default class TabManager extends Component {
|
||||
moveTabToNewWindowCommand({ntxId}) {
|
||||
const {notePath, hoistedNoteId} = this.getNoteContextById(ntxId);
|
||||
|
||||
this.removeTab(ntxId);
|
||||
this.removeNoteContext(ntxId);
|
||||
|
||||
this.triggerCommand('openInWindow', {notePath, hoistedNoteId});
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ class TreeContextMenu {
|
||||
const note = await froca.getNote(this.node.data.noteId);
|
||||
const branch = froca.getBranch(this.node.data.branchId);
|
||||
const isNotRoot = note.noteId !== 'root';
|
||||
const isHoisted = note.noteId === appContext.tabManager.getActiveNoteContext().hoistedNoteId;
|
||||
const isHoisted = note.noteId === appContext.tabManager.getActiveContext().hoistedNoteId;
|
||||
const parentNote = isNotRoot ? await froca.getNote(branch.parentNoteId) : null;
|
||||
|
||||
// some actions don't support multi-note so they are disabled when notes are selected
|
||||
|
@ -5,7 +5,7 @@ import linkService from "../../services/link.js";
|
||||
import attributeAutocompleteService from "../../services/attribute_autocomplete.js";
|
||||
import noteAutocompleteService from "../../services/note_autocomplete.js";
|
||||
import promotedAttributeDefinitionParser from '../../services/promoted_attribute_definition_parser.js';
|
||||
import TabAwareWidget from "../tab_aware_widget.js";
|
||||
import NoteContextAwareWidget from "../note_context_aware_widget.js";
|
||||
import SpacedUpdate from "../../services/spaced_update.js";
|
||||
import utils from "../../services/utils.js";
|
||||
|
||||
@ -222,7 +222,7 @@ const ATTR_HELP = {
|
||||
}
|
||||
};
|
||||
|
||||
export default class AttributeDetailWidget extends TabAwareWidget {
|
||||
export default class AttributeDetailWidget extends NoteContextAwareWidget {
|
||||
async refresh() {
|
||||
// switching note/tab should close the widget
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import TabAwareWidget from "../tab_aware_widget.js";
|
||||
import NoteContextAwareWidget from "../note_context_aware_widget.js";
|
||||
import noteAutocompleteService from "../../services/note_autocomplete.js";
|
||||
import server from "../../services/server.js";
|
||||
import contextMenuService from "../../services/context_menu.js";
|
||||
@ -176,7 +176,7 @@ const editorConfig = {
|
||||
mention: mentionSetup
|
||||
};
|
||||
|
||||
export default class AttributeEditorWidget extends TabAwareWidget {
|
||||
export default class AttributeEditorWidget extends NoteContextAwareWidget {
|
||||
constructor(attributeDetailWidget) {
|
||||
super();
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import TabAwareWidget from "./tab_aware_widget.js";
|
||||
import NoteContextAwareWidget from "./note_context_aware_widget.js";
|
||||
import options from "../services/options.js";
|
||||
|
||||
const WIDGET_TPL = `
|
||||
@ -29,7 +29,7 @@ const WIDGET_TPL = `
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
export default class CollapsibleWidget extends TabAwareWidget {
|
||||
export default class CollapsibleWidget extends NoteContextAwareWidget {
|
||||
get widgetTitle() { return "Untitled widget"; }
|
||||
|
||||
get headerActions() { return []; }
|
||||
|
@ -56,7 +56,7 @@ export default class CalendarWidget extends CollapsibleWidget {
|
||||
const note = await dateNoteService.getDateNote(date);
|
||||
|
||||
if (note) {
|
||||
appContext.tabManager.getActiveNoteContext().setNote(note.noteId);
|
||||
appContext.tabManager.getActiveContext().setNote(note.noteId);
|
||||
}
|
||||
else {
|
||||
alert("Cannot find day note");
|
||||
|
@ -1,4 +1,4 @@
|
||||
import TabAwareWidget from "../tab_aware_widget.js";
|
||||
import NoteContextAwareWidget from "../note_context_aware_widget.js";
|
||||
|
||||
const TPL = `
|
||||
<div class="section-container">
|
||||
@ -57,7 +57,7 @@ const TPL = `
|
||||
<div class="section-body-container"></div>
|
||||
</div>`;
|
||||
|
||||
export default class CollapsibleSectionContainer extends TabAwareWidget {
|
||||
export default class CollapsibleSectionContainer extends NoteContextAwareWidget {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
|
@ -14,14 +14,14 @@ export default class PaneContainer extends FlexContainer {
|
||||
this.css('flex-grow', '1');
|
||||
}
|
||||
|
||||
async newTabOpenedEvent({noteContext}) {
|
||||
async newNoteContextCreatedEvent({noteContext}) {
|
||||
const widget = this.widgetFactory();
|
||||
|
||||
const $renderedWidget = widget.render();
|
||||
|
||||
$renderedWidget.attr("data-tab-id", noteContext.ntxId);
|
||||
|
||||
$renderedWidget.on('click', () => appContext.tabManager.activateTab(noteContext.ntxId));
|
||||
$renderedWidget.on('click', () => appContext.tabManager.activateNoteContext(noteContext.ntxId));
|
||||
|
||||
this.$widget.append($renderedWidget);
|
||||
|
||||
@ -35,9 +35,9 @@ export default class PaneContainer extends FlexContainer {
|
||||
}
|
||||
|
||||
async openNewPaneCommand() {
|
||||
const noteContext = await appContext.tabManager.openEmptyTab(null, 'root', appContext.tabManager.getActiveNoteContext().ntxId);
|
||||
const noteContext = await appContext.tabManager.openEmptyTab(null, 'root', appContext.tabManager.getActiveContext().ntxId);
|
||||
|
||||
await appContext.tabManager.activateTab(noteContext.ntxId);
|
||||
await appContext.tabManager.activateNoteContext(noteContext.ntxId);
|
||||
|
||||
await noteContext.setEmpty();
|
||||
}
|
||||
@ -49,7 +49,7 @@ export default class PaneContainer extends FlexContainer {
|
||||
toggleInt(show) {} // not needed
|
||||
|
||||
toggleExt(show) {
|
||||
const activeTabId = appContext.tabManager.getActiveNoteContext().getMainNoteContext().ntxId;
|
||||
const activeTabId = appContext.tabManager.getActiveContext().getMainNoteContext().ntxId;
|
||||
|
||||
for (const ntxId in this.widgets) {
|
||||
const noteContext = appContext.tabManager.getNoteContextById(ntxId);
|
||||
@ -69,7 +69,7 @@ export default class PaneContainer extends FlexContainer {
|
||||
* activation further note switches are always propagated to the tabs.
|
||||
*/
|
||||
handleEventInChildren(name, data) {
|
||||
if (['tabNoteSwitched', 'tabNoteSwitchedAndActivated'].includes(name)) {
|
||||
if (['noteSwitched', 'noteSwitchedAndActivated'].includes(name)) {
|
||||
// this event is propagated only to the widgets of a particular tab
|
||||
const widget = this.widgets[data.noteContext.ntxId];
|
||||
|
||||
@ -79,7 +79,7 @@ export default class PaneContainer extends FlexContainer {
|
||||
|
||||
const promises = [];
|
||||
|
||||
if (appContext.tabManager.getActiveNoteContext().getMainNoteContext() === data.noteContext.getMainNoteContext()) {
|
||||
if (appContext.tabManager.getActiveContext().getMainNoteContext() === data.noteContext.getMainNoteContext()) {
|
||||
promises.push(widget.handleEvent('activeTabChanged', data));
|
||||
}
|
||||
|
||||
@ -95,14 +95,14 @@ export default class PaneContainer extends FlexContainer {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (subNoteContext === data.noteContext && (subWidget.hasBeenAlreadyShown || name === 'tabNoteSwitchedAndActivated')) {
|
||||
if (subNoteContext === data.noteContext && (subWidget.hasBeenAlreadyShown || name === 'noteSwitchedAndActivated')) {
|
||||
subWidget.hasBeenAlreadyShown = true;
|
||||
|
||||
promises.push(widget.handleEvent('tabNoteSwitched', data));
|
||||
promises.push(widget.handleEvent('noteSwitched', data));
|
||||
}
|
||||
}
|
||||
|
||||
if (name === 'tabNoteSwitchedAndActivated') {
|
||||
if (name === 'noteSwitchedAndActivated') {
|
||||
this.toggleExt(true);
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ export default class RootContainer extends FlexContainer {
|
||||
|
||||
refresh() {
|
||||
this.$widget.removeClass(); // remove all classes
|
||||
const note = appContext.tabManager.getActiveTabNote();
|
||||
const note = appContext.tabManager.getActiveContextNote();
|
||||
|
||||
if (note) {
|
||||
this.$widget.addClass(note.getCssClass());
|
||||
@ -41,7 +41,7 @@ export default class RootContainer extends FlexContainer {
|
||||
this.setZenMode(!this.isZenModeActive);
|
||||
}
|
||||
|
||||
tabNoteSwitchedEvent() {
|
||||
noteSwitchedEvent() {
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
@ -49,7 +49,7 @@ export default class RootContainer extends FlexContainer {
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
tabNoteSwitchedAndActivatedEvent() {
|
||||
noteSwitchedAndActivatedEvent() {
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ export default class ScrollingContainer extends Container {
|
||||
this.css('height: 100%; overflow: auto;');
|
||||
}
|
||||
|
||||
async tabNoteSwitchedEvent({noteContext, notePath}) {
|
||||
async noteSwitchedEvent({noteContext, notePath}) {
|
||||
// if notePath does not match then the noteContext has been switched to another note in the mean time
|
||||
if (noteContext.notePath === notePath) {
|
||||
this.$widget.scrollTop(0);
|
||||
|
@ -13,7 +13,7 @@ class MobileDetailMenuWidget extends BasicWidget {
|
||||
this.overflowing();
|
||||
|
||||
this.$widget.on("click", async e => {
|
||||
const note = appContext.tabManager.getActiveTabNote();
|
||||
const note = appContext.tabManager.getActiveContextNote();
|
||||
|
||||
contextMenu.show({
|
||||
x: e.pageX,
|
||||
@ -26,10 +26,10 @@ class MobileDetailMenuWidget extends BasicWidget {
|
||||
],
|
||||
selectMenuItemHandler: async ({command}) => {
|
||||
if (command === "insertChildNote") {
|
||||
noteCreateService.createNote(appContext.tabManager.getActiveTabNotePath());
|
||||
noteCreateService.createNote(appContext.tabManager.getActiveContextNotePath());
|
||||
}
|
||||
else if (command === "delete") {
|
||||
const notePath = appContext.tabManager.getActiveTabNotePath();
|
||||
const notePath = appContext.tabManager.getActiveContextNotePath();
|
||||
const branchId = await treeService.getBranchIdFromNotePath(notePath);
|
||||
|
||||
if (!branchId) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import TabAwareWidget from "./tab_aware_widget.js";
|
||||
import NoteContextAwareWidget from "./note_context_aware_widget.js";
|
||||
import protectedSessionService from "../services/protected_session.js";
|
||||
import utils from "../services/utils.js";
|
||||
|
||||
@ -100,7 +100,7 @@ const TPL = `
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
export default class NoteActionsWidget extends TabAwareWidget {
|
||||
export default class NoteActionsWidget extends NoteContextAwareWidget {
|
||||
doRender() {
|
||||
this.$widget = $(TPL);
|
||||
this.overflowing();
|
||||
|
@ -1,7 +1,7 @@
|
||||
import BasicWidget from "./basic_widget.js";
|
||||
import appContext from "../services/app_context.js";
|
||||
|
||||
export default class TabAwareWidget extends BasicWidget {
|
||||
export default class NoteContextAwareWidget extends BasicWidget {
|
||||
isTab(ntxId) {
|
||||
if (Array.isArray(ntxId)) {
|
||||
return this.noteContext && ntxId.includes(this.noteContext.ntxId);
|
||||
@ -59,7 +59,7 @@ export default class TabAwareWidget extends BasicWidget {
|
||||
|
||||
async refreshWithNote(note) {}
|
||||
|
||||
async tabNoteSwitchedEvent({noteContext, notePath}) {
|
||||
async noteSwitchedEvent({noteContext, notePath}) {
|
||||
// if notePath does not match then the noteContext has been switched to another note in the mean time
|
||||
if (noteContext.notePath === notePath) {
|
||||
await this.noteSwitched();
|
||||
@ -81,7 +81,7 @@ export default class TabAwareWidget extends BasicWidget {
|
||||
}
|
||||
|
||||
// when note is both switched and activated, this should not produce double refresh
|
||||
async tabNoteSwitchedAndActivatedEvent({noteContext, notePath}) {
|
||||
async noteSwitchedAndActivatedEvent({noteContext, notePath}) {
|
||||
this.noteContext = noteContext;
|
||||
|
||||
// if notePath does not match then the noteContext has been switched to another note in the mean time
|
||||
@ -107,7 +107,7 @@ export default class TabAwareWidget extends BasicWidget {
|
||||
|
||||
async lazyLoadedEvent() {
|
||||
if (!this.noteContext) { // has not been loaded yet
|
||||
this.noteContext = appContext.tabManager.getActiveNoteContext();
|
||||
this.noteContext = appContext.tabManager.getActiveContext();
|
||||
}
|
||||
|
||||
await this.refresh();
|
@ -1,7 +1,7 @@
|
||||
import TabAwareWidget from "./tab_aware_widget.js";
|
||||
import NoteContextAwareWidget from "./note_context_aware_widget.js";
|
||||
import keyboardActionsService from "../services/keyboard_actions.js";
|
||||
|
||||
export default class TabCachingWidget extends TabAwareWidget {
|
||||
export default class NoteContextCachingWidget extends NoteContextAwareWidget {
|
||||
constructor(widgetFactory) {
|
||||
super();
|
||||
|
||||
@ -13,7 +13,7 @@ export default class TabCachingWidget extends TabAwareWidget {
|
||||
return this.$widget = $(`<div class="marker" style="display: none;">`);
|
||||
}
|
||||
|
||||
async newTabOpenedEvent({noteContext}) {
|
||||
async newNoteContextCreatedEvent({noteContext}) {
|
||||
const {ntxId} = noteContext;
|
||||
|
||||
if (this.widgets[ntxId]) {
|
||||
@ -34,7 +34,7 @@ export default class TabCachingWidget extends TabAwareWidget {
|
||||
this.child(this.widgets[ntxId]); // add as child only once it is ready (rendered with noteContext)
|
||||
}
|
||||
|
||||
tabRemovedEvent({ntxIds}) {
|
||||
noteContextRemovedEvent({ntxIds}) {
|
||||
for (const ntxId of ntxIds) {
|
||||
const widget = this.widgets[ntxId];
|
||||
|
||||
@ -65,7 +65,7 @@ export default class TabCachingWidget extends TabAwareWidget {
|
||||
* activation further note switches are always propagated to the tabs.
|
||||
*/
|
||||
handleEventInChildren(name, data) {
|
||||
if (['tabNoteSwitched', 'tabNoteSwitchedAndActivated'].includes(name)) {
|
||||
if (['noteSwitched', 'noteSwitchedAndActivated'].includes(name)) {
|
||||
// this event is propagated only to the widgets of a particular tab
|
||||
let widget = this.widgets[data.noteContext.ntxId];
|
||||
|
||||
@ -73,10 +73,10 @@ export default class TabCachingWidget extends TabAwareWidget {
|
||||
widget = this.widgets[data.noteContext.mainNtxId];
|
||||
}
|
||||
|
||||
if (widget && (widget.hasBeenAlreadyShown || name === 'tabNoteSwitchedAndActivated')) {
|
||||
if (widget && (widget.hasBeenAlreadyShown || name === 'noteSwitchedAndActivated')) {
|
||||
widget.hasBeenAlreadyShown = true;
|
||||
|
||||
return widget.handleEvent('tabNoteSwitched', data);
|
||||
return widget.handleEvent('noteSwitched', data);
|
||||
}
|
||||
else {
|
||||
return Promise.resolve();
|
@ -1,4 +1,4 @@
|
||||
import TabAwareWidget from "./tab_aware_widget.js";
|
||||
import NoteContextAwareWidget from "./note_context_aware_widget.js";
|
||||
import utils from "../services/utils.js";
|
||||
import protectedSessionHolder from "../services/protected_session_holder.js";
|
||||
import SpacedUpdate from "../services/spaced_update.js";
|
||||
@ -48,7 +48,7 @@ const typeWidgetClasses = {
|
||||
'book': BookTypeWidget
|
||||
};
|
||||
|
||||
export default class NoteDetailWidget extends TabAwareWidget {
|
||||
export default class NoteDetailWidget extends NoteContextAwareWidget {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
@ -82,7 +82,7 @@ export default class NoteDetailWidget extends TabAwareWidget {
|
||||
this.$widget.on("dragleave", e => e.preventDefault());
|
||||
|
||||
this.$widget.on("drop", async e => {
|
||||
const activeNote = appContext.tabManager.getActiveTabNote();
|
||||
const activeNote = appContext.tabManager.getActiveContextNote();
|
||||
|
||||
if (!activeNote) {
|
||||
return;
|
||||
@ -122,7 +122,7 @@ export default class NoteDetailWidget extends TabAwareWidget {
|
||||
await typeWidget.handleEvent('setNoteContext', {noteContext: this.noteContext});
|
||||
|
||||
// this is happening in update() so note has been already set and we need to reflect this
|
||||
await typeWidget.handleEvent('tabNoteSwitched', {
|
||||
await typeWidget.handleEvent('noteSwitched', {
|
||||
noteContext: this.noteContext,
|
||||
notePath: this.noteContext.notePath
|
||||
});
|
||||
@ -291,14 +291,14 @@ export default class NoteDetailWidget extends TabAwareWidget {
|
||||
}
|
||||
|
||||
async cutIntoNoteCommand() {
|
||||
const note = appContext.tabManager.getActiveTabNote();
|
||||
const note = appContext.tabManager.getActiveContextNote();
|
||||
|
||||
if (!note) {
|
||||
return;
|
||||
}
|
||||
|
||||
// without await as this otherwise causes deadlock through component mutex
|
||||
noteCreateService.createNote(appContext.tabManager.getActiveTabNotePath(), {
|
||||
noteCreateService.createNote(appContext.tabManager.getActiveContextNotePath(), {
|
||||
isProtected: note.isProtected,
|
||||
saveSelection: true
|
||||
});
|
||||
|
@ -1,4 +1,4 @@
|
||||
import TabAwareWidget from "./tab_aware_widget.js";
|
||||
import NoteContextAwareWidget from "./note_context_aware_widget.js";
|
||||
import attributeService from "../services/attributes.js";
|
||||
|
||||
const TPL = `
|
||||
@ -75,7 +75,7 @@ const TPL = `
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
export default class NoteIconWidget extends TabAwareWidget {
|
||||
export default class NoteIconWidget extends NoteContextAwareWidget {
|
||||
doRender() {
|
||||
this.$widget = $(TPL);
|
||||
this.overflowing();
|
||||
|
@ -1,4 +1,4 @@
|
||||
import TabAwareWidget from "./tab_aware_widget.js";
|
||||
import NoteContextAwareWidget from "./note_context_aware_widget.js";
|
||||
import NoteListRenderer from "../services/note_list_renderer.js";
|
||||
|
||||
const TPL = `
|
||||
@ -20,7 +20,7 @@ const TPL = `
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
export default class NoteListWidget extends TabAwareWidget {
|
||||
export default class NoteListWidget extends NoteContextAwareWidget {
|
||||
isEnabled() {
|
||||
return super.isEnabled()
|
||||
&& ['book', 'text', 'code'].includes(this.note.type)
|
||||
|
@ -1,4 +1,4 @@
|
||||
import TabAwareWidget from "./tab_aware_widget.js";
|
||||
import NoteContextAwareWidget from "./note_context_aware_widget.js";
|
||||
import treeService from "../services/tree.js";
|
||||
import linkService from "../services/link.js";
|
||||
|
||||
@ -36,7 +36,7 @@ const TPL = `
|
||||
</ul>
|
||||
</div>`;
|
||||
|
||||
export default class NotePathsWidget extends TabAwareWidget {
|
||||
export default class NotePathsWidget extends NoteContextAwareWidget {
|
||||
doRender() {
|
||||
this.$widget = $(TPL);
|
||||
this.overflowing();
|
||||
|
@ -1,4 +1,4 @@
|
||||
import TabAwareWidget from "./tab_aware_widget.js";
|
||||
import NoteContextAwareWidget from "./note_context_aware_widget.js";
|
||||
import utils from "../services/utils.js";
|
||||
import protectedSessionHolder from "../services/protected_session_holder.js";
|
||||
import server from "../services/server.js";
|
||||
@ -27,7 +27,7 @@ const TPL = `
|
||||
<input autocomplete="off" value="" placeholder="type note's title here..." class="note-title" tabindex="100">
|
||||
</div>`;
|
||||
|
||||
export default class NoteTitleWidget extends TabAwareWidget {
|
||||
export default class NoteTitleWidget extends NoteContextAwareWidget {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
|
@ -5,7 +5,7 @@ import contextMenu from "../services/context_menu.js";
|
||||
import froca from "../services/froca.js";
|
||||
import branchService from "../services/branches.js";
|
||||
import ws from "../services/ws.js";
|
||||
import TabAwareWidget from "./tab_aware_widget.js";
|
||||
import NoteContextAwareWidget from "./note_context_aware_widget.js";
|
||||
import server from "../services/server.js";
|
||||
import noteCreateService from "../services/note_create.js";
|
||||
import toastService from "../services/toast.js";
|
||||
@ -197,7 +197,7 @@ const TPL = `
|
||||
|
||||
const MAX_SEARCH_RESULTS_IN_TREE = 100;
|
||||
|
||||
export default class NoteTreeWidget extends TabAwareWidget {
|
||||
export default class NoteTreeWidget extends NoteContextAwareWidget {
|
||||
constructor(treeName) {
|
||||
super();
|
||||
|
||||
@ -395,7 +395,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
||||
|
||||
const notePath = treeService.getNotePath(data.node);
|
||||
|
||||
const activeNoteContext = appContext.tabManager.getActiveNoteContext();
|
||||
const activeNoteContext = appContext.tabManager.getActiveContext();
|
||||
await activeNoteContext.setNote(notePath);
|
||||
|
||||
if (utils.isMobile()) {
|
||||
@ -525,7 +525,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
||||
}
|
||||
|
||||
const note = await froca.getNote(node.data.noteId);
|
||||
const activeNoteContext = appContext.tabManager.getActiveNoteContext();
|
||||
const activeNoteContext = appContext.tabManager.getActiveContext();
|
||||
|
||||
const $span = $(node.span);
|
||||
|
||||
@ -810,7 +810,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
||||
}
|
||||
|
||||
async scrollToActiveNoteEvent() {
|
||||
const activeContext = appContext.tabManager.getActiveNoteContext();
|
||||
const activeContext = appContext.tabManager.getActiveContext();
|
||||
|
||||
if (activeContext && activeContext.notePath) {
|
||||
this.tree.$container.focus();
|
||||
@ -1162,7 +1162,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
||||
// this should be done by NoteContext / TabManager and note tree should only listen to
|
||||
// changes in active note and just set the "active" state
|
||||
// We don't await since that can bring up infinite cycles when e.g. custom widget does some backend requests which wait for max sync ID processed
|
||||
appContext.tabManager.getActiveNoteContext().setNote(nextNotePath).then(() => {
|
||||
appContext.tabManager.getActiveContext().setNote(nextNotePath).then(() => {
|
||||
const newActiveNode = this.getActiveNode();
|
||||
|
||||
// return focus if the previously active node was also focused
|
||||
|
@ -1,6 +1,6 @@
|
||||
import server from '../services/server.js';
|
||||
import mimeTypesService from '../services/mime_types.js';
|
||||
import TabAwareWidget from "./tab_aware_widget.js";
|
||||
import NoteContextAwareWidget from "./note_context_aware_widget.js";
|
||||
|
||||
const NOTE_TYPES = [
|
||||
{ type: "file", title: "File", selectable: false },
|
||||
@ -31,7 +31,7 @@ const TPL = `
|
||||
</div>
|
||||
`;
|
||||
|
||||
export default class NoteTypeWidget extends TabAwareWidget {
|
||||
export default class NoteTypeWidget extends NoteContextAwareWidget {
|
||||
doRender() {
|
||||
this.$widget = $(TPL);
|
||||
this.overflowing();
|
||||
|
@ -1,4 +1,4 @@
|
||||
import TabAwareWidget from "./tab_aware_widget.js";
|
||||
import NoteContextAwareWidget from "./note_context_aware_widget.js";
|
||||
import server from "../services/server.js";
|
||||
import fileWatcher from "../services/file_watcher.js";
|
||||
|
||||
@ -19,7 +19,7 @@ const TPL = `
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
export default class NoteUpdateStatusWidget extends TabAwareWidget {
|
||||
export default class NoteUpdateStatusWidget extends NoteContextAwareWidget {
|
||||
isEnabled() {
|
||||
return super.isEnabled()
|
||||
&& !!fileWatcher.getFileModificationStatus(this.noteId);
|
||||
|
@ -98,13 +98,13 @@ export default class QuickSearchWidget extends BasicWidget {
|
||||
|
||||
if (!e.target || e.target.nodeName !== 'A') {
|
||||
// click on the link is handled by link handling but we want the whole item clickable
|
||||
appContext.tabManager.getActiveNoteContext().setNote(note.noteId);
|
||||
appContext.tabManager.getActiveContext().setNote(note.noteId);
|
||||
}
|
||||
});
|
||||
utils.bindElShortcut($link, 'return', () => {
|
||||
this.$dropdownToggle.dropdown("hide");
|
||||
|
||||
appContext.tabManager.getActiveNoteContext().setNote(note.noteId);
|
||||
appContext.tabManager.getActiveContext().setNote(note.noteId);
|
||||
});
|
||||
|
||||
this.$dropdownMenu.append($link);
|
||||
@ -131,7 +131,7 @@ export default class QuickSearchWidget extends BasicWidget {
|
||||
async showInFullSearch() {
|
||||
const searchNote = await dateNotesService.createSearchNote({searchString: this.$searchString.val()});
|
||||
|
||||
await appContext.tabManager.getActiveNoteContext().setNote(searchNote.noteId);
|
||||
await appContext.tabManager.getActiveContext().setNote(searchNote.noteId);
|
||||
}
|
||||
|
||||
quickSearchEvent() {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import TabAwareWidget from "./tab_aware_widget.js";
|
||||
import NoteContextAwareWidget from "./note_context_aware_widget.js";
|
||||
import NoteListRenderer from "../services/note_list_renderer.js";
|
||||
|
||||
const TPL = `
|
||||
@ -33,7 +33,7 @@ const TPL = `
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
export default class SearchResultWidget extends TabAwareWidget {
|
||||
export default class SearchResultWidget extends NoteContextAwareWidget {
|
||||
isEnabled() {
|
||||
return super.isEnabled()
|
||||
&& this.note.type === 'search';
|
||||
|
@ -1,7 +1,7 @@
|
||||
import linkService from "../services/link.js";
|
||||
import server from "../services/server.js";
|
||||
import froca from "../services/froca.js";
|
||||
import TabAwareWidget from "./tab_aware_widget.js";
|
||||
import NoteContextAwareWidget from "./note_context_aware_widget.js";
|
||||
import options from "../services/options.js";
|
||||
|
||||
const TPL = `
|
||||
@ -39,7 +39,7 @@ const TPL = `
|
||||
</div>
|
||||
`;
|
||||
|
||||
export default class SimilarNotesWidget extends TabAwareWidget {
|
||||
export default class SimilarNotesWidget extends NoteContextAwareWidget {
|
||||
isEnabled() {
|
||||
return super.isEnabled()
|
||||
&& this.note.type !== 'search'
|
||||
|
@ -1,4 +1,4 @@
|
||||
import TabAwareWidget from "./tab_aware_widget.js";
|
||||
import NoteContextAwareWidget from "./note_context_aware_widget.js";
|
||||
|
||||
const TPL = `
|
||||
<div class="sql-result-widget">
|
||||
@ -11,7 +11,7 @@ const TPL = `
|
||||
<div class="sql-console-result-container"></div>
|
||||
</div>`;
|
||||
|
||||
export default class SqlResultWidget extends TabAwareWidget {
|
||||
export default class SqlResultWidget extends NoteContextAwareWidget {
|
||||
isEnabled() {
|
||||
return this.note
|
||||
&& this.note.mime === 'text/x-sqlite;schema=trilium'
|
||||
|
@ -1,4 +1,4 @@
|
||||
import TabAwareWidget from "./tab_aware_widget.js";
|
||||
import NoteContextAwareWidget from "./note_context_aware_widget.js";
|
||||
import treeService from "../services/tree.js";
|
||||
import linkService from "../services/link.js";
|
||||
import hoistedNoteService from "../services/hoisted_note.js";
|
||||
@ -33,7 +33,7 @@ const TPL = `
|
||||
<span class="sql-table-schemas"></span>
|
||||
</div>`;
|
||||
|
||||
export default class SqlTableSchemasWidget extends TabAwareWidget {
|
||||
export default class SqlTableSchemasWidget extends NoteContextAwareWidget {
|
||||
isEnabled() {
|
||||
return this.note
|
||||
&& this.note.mime === 'text/x-sqlite;schema=trilium'
|
||||
|
@ -409,13 +409,13 @@ export default class TabRowWidget extends BasicWidget {
|
||||
closeActiveTabCommand({$el}) {
|
||||
const ntxId = $el.closest(".note-tab").attr('data-tab-id');
|
||||
|
||||
appContext.tabManager.removeTab(ntxId);
|
||||
appContext.tabManager.removeNoteContext(ntxId);
|
||||
}
|
||||
|
||||
setTabCloseEvent($tab) {
|
||||
$tab.on('mousedown', e => {
|
||||
if (e.which === 2) {
|
||||
appContext.tabManager.removeTab($tab.attr('data-tab-id'));
|
||||
appContext.tabManager.removeNoteContext($tab.attr('data-tab-id'));
|
||||
|
||||
return true; // event has been handled
|
||||
}
|
||||
@ -427,7 +427,7 @@ export default class TabRowWidget extends BasicWidget {
|
||||
}
|
||||
|
||||
activeTabChangedEvent() {
|
||||
let activeNoteContext = appContext.tabManager.getActiveNoteContext();
|
||||
let activeNoteContext = appContext.tabManager.getActiveContext();
|
||||
|
||||
if (!activeNoteContext) {
|
||||
return;
|
||||
@ -444,7 +444,7 @@ export default class TabRowWidget extends BasicWidget {
|
||||
if (tabEl) tabEl.setAttribute('active', '');
|
||||
}
|
||||
|
||||
newTabOpenedEvent({noteContext}) {
|
||||
newNoteContextCreatedEvent({noteContext}) {
|
||||
if (!noteContext.mainNtxId) {
|
||||
this.addTab(noteContext.ntxId);
|
||||
}
|
||||
@ -478,7 +478,7 @@ export default class TabRowWidget extends BasicWidget {
|
||||
return $tab.attr('data-tab-id');
|
||||
}
|
||||
|
||||
tabRemovedEvent({ntxIds}) {
|
||||
noteContextRemovedEvent({ntxIds}) {
|
||||
for (const ntxId of ntxIds) {
|
||||
this.removeTab(ntxId);
|
||||
}
|
||||
@ -517,7 +517,7 @@ export default class TabRowWidget extends BasicWidget {
|
||||
this.draggabillies.push(draggabilly);
|
||||
|
||||
draggabilly.on('pointerDown', _ => {
|
||||
appContext.tabManager.activateTab(tabEl.getAttribute('data-tab-id'));
|
||||
appContext.tabManager.activateNoteContext(tabEl.getAttribute('data-tab-id'));
|
||||
});
|
||||
|
||||
draggabilly.on('dragStart', _ => {
|
||||
@ -611,13 +611,13 @@ export default class TabRowWidget extends BasicWidget {
|
||||
return closestIndex;
|
||||
};
|
||||
|
||||
tabNoteSwitchedAndActivatedEvent({noteContext}) {
|
||||
noteSwitchedAndActivatedEvent({noteContext}) {
|
||||
this.activeTabChangedEvent();
|
||||
|
||||
this.updateTabById(noteContext.mainNtxId || noteContext.ntxId);
|
||||
}
|
||||
|
||||
tabNoteSwitchedEvent({noteContext}) {
|
||||
noteSwitchedEvent({noteContext}) {
|
||||
this.updateTabById(noteContext.mainNtxId || noteContext.ntxId);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import server from "../../services/server.js";
|
||||
import TabAwareWidget from "../tab_aware_widget.js";
|
||||
import NoteContextAwareWidget from "../note_context_aware_widget.js";
|
||||
import toastService from "../../services/toast.js";
|
||||
import openService from "../../services/open.js";
|
||||
import utils from "../../services/utils.js";
|
||||
@ -54,7 +54,7 @@ const TPL = `
|
||||
</table>
|
||||
</div>`;
|
||||
|
||||
export default class FilePropertiesWidget extends TabAwareWidget {
|
||||
export default class FilePropertiesWidget extends NoteContextAwareWidget {
|
||||
static getType() { return "file"; }
|
||||
|
||||
isEnabled() {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import server from "../../services/server.js";
|
||||
import TabAwareWidget from "../tab_aware_widget.js";
|
||||
import NoteContextAwareWidget from "../note_context_aware_widget.js";
|
||||
import toastService from "../../services/toast.js";
|
||||
import openService from "../../services/open.js";
|
||||
import utils from "../../services/utils.js";
|
||||
@ -36,7 +36,7 @@ const TPL = `
|
||||
<input type="file" class="image-upload-new-revision-input" style="display: none">
|
||||
</div>`;
|
||||
|
||||
export default class ImagePropertiesWidget extends TabAwareWidget {
|
||||
export default class ImagePropertiesWidget extends NoteContextAwareWidget {
|
||||
static getType() { return "image"; }
|
||||
|
||||
isEnabled() {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import TabAwareWidget from "../tab_aware_widget.js";
|
||||
import NoteContextAwareWidget from "../note_context_aware_widget.js";
|
||||
import AttributeDetailWidget from "../attribute_widgets/attribute_detail.js";
|
||||
import attributeRenderer from "../../services/attribute_renderer.js";
|
||||
|
||||
@ -20,7 +20,7 @@ const TPL = `
|
||||
<div class="inherited-attributes-container"></div>
|
||||
</div>`;
|
||||
|
||||
export default class InheritedAttributesWidget extends TabAwareWidget {
|
||||
export default class InheritedAttributesWidget extends NoteContextAwareWidget {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import TabAwareWidget from "../tab_aware_widget.js";
|
||||
import NoteContextAwareWidget from "../note_context_aware_widget.js";
|
||||
|
||||
const TPL = `
|
||||
<div class="note-properties-widget">
|
||||
@ -14,7 +14,7 @@ const TPL = `
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
export default class NotePropertiesWidget extends TabAwareWidget {
|
||||
export default class NotePropertiesWidget extends NoteContextAwareWidget {
|
||||
static getType() { return "note-properties"; }
|
||||
|
||||
isEnabled() {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import TabAwareWidget from "../tab_aware_widget.js";
|
||||
import NoteContextAwareWidget from "../note_context_aware_widget.js";
|
||||
import AttributeDetailWidget from "../attribute_widgets/attribute_detail.js";
|
||||
import AttributeEditorWidget from "../attribute_widgets/attribute_editor.js";
|
||||
|
||||
@ -21,7 +21,7 @@ const TPL = `
|
||||
</div>
|
||||
`;
|
||||
|
||||
export default class OwnedAttributeListWidget extends TabAwareWidget {
|
||||
export default class OwnedAttributeListWidget extends NoteContextAwareWidget {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
|
@ -2,7 +2,7 @@ import server from "../../services/server.js";
|
||||
import ws from "../../services/ws.js";
|
||||
import treeService from "../../services/tree.js";
|
||||
import noteAutocompleteService from "../../services/note_autocomplete.js";
|
||||
import TabAwareWidget from "../tab_aware_widget.js";
|
||||
import NoteContextAwareWidget from "../note_context_aware_widget.js";
|
||||
|
||||
const TPL = `
|
||||
<div>
|
||||
@ -34,7 +34,7 @@ const TPL = `
|
||||
</div>
|
||||
`;
|
||||
|
||||
export default class PromotedAttributesWidget extends TabAwareWidget {
|
||||
export default class PromotedAttributesWidget extends NoteContextAwareWidget {
|
||||
doRender() {
|
||||
this.$widget = $(TPL);
|
||||
this.overflowing();
|
||||
|
@ -1,5 +1,5 @@
|
||||
import server from "../../services/server.js";
|
||||
import TabAwareWidget from "../tab_aware_widget.js";
|
||||
import NoteContextAwareWidget from "../note_context_aware_widget.js";
|
||||
import froca from "../../services/froca.js";
|
||||
import ws from "../../services/ws.js";
|
||||
import toastService from "../../services/toast.js";
|
||||
@ -199,7 +199,7 @@ for (const clazz of [
|
||||
ACTION_CLASSES[clazz.actionName] = clazz;
|
||||
}
|
||||
|
||||
export default class SearchDefinitionWidget extends TabAwareWidget {
|
||||
export default class SearchDefinitionWidget extends NoteContextAwareWidget {
|
||||
static getType() { return "search"; }
|
||||
|
||||
isEnabled() {
|
||||
|
@ -23,7 +23,7 @@ export default class AbstractTextTypeWidget extends TypeWidget {
|
||||
const noteId = this.getNoteIdFromImage(imgSrc);
|
||||
|
||||
if (noteId) {
|
||||
appContext.tabManager.getActiveNoteContext().setNote(noteId);
|
||||
appContext.tabManager.getActiveContext().setNote(noteId);
|
||||
} else {
|
||||
window.open(imgSrc, '_blank');
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ export default class EmptyTypeWidget extends TypeWidget {
|
||||
return false;
|
||||
}
|
||||
|
||||
appContext.tabManager.getActiveNoteContext().setNote(suggestion.notePath);
|
||||
appContext.tabManager.getActiveContext().setNote(suggestion.notePath);
|
||||
});
|
||||
|
||||
noteAutocompleteService.showRecentNotes(this.$autoComplete);
|
||||
|
@ -1,6 +1,6 @@
|
||||
import TabAwareWidget from "../tab_aware_widget.js";
|
||||
import NoteContextAwareWidget from "../note_context_aware_widget.js";
|
||||
|
||||
export default class TypeWidget extends TabAwareWidget {
|
||||
export default class TypeWidget extends NoteContextAwareWidget {
|
||||
// for overriding
|
||||
static getType() {}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user