mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	removed dependency on note tree widget from app context
This commit is contained in:
		| @@ -36,6 +36,7 @@ window.glob.isDesktop = utils.isDesktop; | |||||||
| window.glob.isMobile = utils.isMobile; | window.glob.isMobile = utils.isMobile; | ||||||
|  |  | ||||||
| // required for CKEditor image upload plugin | // required for CKEditor image upload plugin | ||||||
|  | // FIXME | ||||||
| window.glob.getActiveNode = () => appContext.getMainNoteTree().getActiveNode(); | window.glob.getActiveNode = () => appContext.getMainNoteTree().getActiveNode(); | ||||||
| window.glob.getHeaders = server.getHeaders; | window.glob.getHeaders = server.getHeaders; | ||||||
| window.glob.showAddLinkDialog = () => import('./dialogs/add_link.js').then(d => d.showDialog()); | window.glob.showAddLinkDialog = () => import('./dialogs/add_link.js').then(d => d.showDialog()); | ||||||
|   | |||||||
| @@ -36,6 +36,7 @@ export async function showDialog(nodes) { | |||||||
| } | } | ||||||
|  |  | ||||||
| async function moveNotesTo(notePath) { | async function moveNotesTo(notePath) { | ||||||
|  |     // FIXME | ||||||
|     const targetNode = await appContext.getMainNoteTree().getNodeFromPath(notePath); |     const targetNode = await appContext.getMainNoteTree().getNodeFromPath(notePath); | ||||||
|  |  | ||||||
|     await treeChangesService.moveToParentNote(movedNodes, targetNode); |     await treeChangesService.moveToParentNote(movedNodes, targetNode); | ||||||
|   | |||||||
| @@ -90,6 +90,7 @@ async function showTree() { | |||||||
| } | } | ||||||
|  |  | ||||||
| $detail.on("click", ".note-menu-button", async e => { | $detail.on("click", ".note-menu-button", async e => { | ||||||
|  |     // FIXME | ||||||
|     const node = appContext.getMainNoteTree().getActiveNode(); |     const node = appContext.getMainNoteTree().getActiveNode(); | ||||||
|     const branch = treeCache.getBranch(node.data.branchId); |     const branch = treeCache.getBranch(node.data.branchId); | ||||||
|     const note = await treeCache.getNote(node.data.noteId); |     const note = await treeCache.getNote(node.data.noteId); | ||||||
|   | |||||||
| @@ -1,4 +1,3 @@ | |||||||
| import NoteTreeWidget from "../widgets/note_tree.js"; |  | ||||||
| import TabContext from "./tab_context.js"; | import TabContext from "./tab_context.js"; | ||||||
| import server from "./server.js"; | import server from "./server.js"; | ||||||
| import treeCache from "./tree_cache.js"; | import treeCache from "./tree_cache.js"; | ||||||
| @@ -10,6 +9,7 @@ import utils from "./utils.js"; | |||||||
| import treeService from "./tree.js"; | import treeService from "./tree.js"; | ||||||
| import ZoomService from "./zoom.js"; | import ZoomService from "./zoom.js"; | ||||||
| import Layout from "../widgets/layout.js"; | import Layout from "../widgets/layout.js"; | ||||||
|  | import SpacedUpdate from "./spaced_update.js"; | ||||||
|  |  | ||||||
| class AppContext { | class AppContext { | ||||||
|     constructor(layout) { |     constructor(layout) { | ||||||
| @@ -17,8 +17,17 @@ class AppContext { | |||||||
|         this.components = []; |         this.components = []; | ||||||
|         /** @type {TabContext[]} */ |         /** @type {TabContext[]} */ | ||||||
|         this.tabContexts = []; |         this.tabContexts = []; | ||||||
|         this.tabsChangedTaskId = null; |  | ||||||
|         this.activeTabId = null; |         this.activeTabId = null; | ||||||
|  |  | ||||||
|  |         this.tabsUpdate = new SpacedUpdate(async () => { | ||||||
|  |             const openTabs = this.tabContexts | ||||||
|  |                 .map(tc => tc.getTabState()) | ||||||
|  |                 .filter(t => !!t); | ||||||
|  |  | ||||||
|  |             await server.put('options', { | ||||||
|  |                 openTabs: JSON.stringify(openTabs) | ||||||
|  |             }); | ||||||
|  |         }); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     async start() { |     async start() { | ||||||
| @@ -88,6 +97,7 @@ class AppContext { | |||||||
|             filteredTabs[0].active = true; |             filteredTabs[0].active = true; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         this.tabsUpdate.allowUpdateWithoutChange(() => { | ||||||
|             for (const tab of filteredTabs) { |             for (const tab of filteredTabs) { | ||||||
|                 const tabContext = this.openEmptyTab(); |                 const tabContext = this.openEmptyTab(); | ||||||
|                 tabContext.setNote(tab.notePath); |                 tabContext.setNote(tab.notePath); | ||||||
| @@ -96,10 +106,7 @@ class AppContext { | |||||||
|                     this.activateTab(tabContext.tabId); |                     this.activateTab(tabContext.tabId); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |         }); | ||||||
|         // previous opening triggered task to save tab changes but these are bogus changes (this is init) |  | ||||||
|         // so we'll cancel it |  | ||||||
|         this.clearOpenTabsTask(); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     showWidgets() { |     showWidgets() { | ||||||
| @@ -201,13 +208,6 @@ class AppContext { | |||||||
|         await tabContext.setNote(notePath); |         await tabContext.setNote(notePath); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * @return {NoteTreeWidget} |  | ||||||
|      */ |  | ||||||
|     getMainNoteTree() { |  | ||||||
|         return this.noteTreeWidget; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     getTab(newTab, state) { |     getTab(newTab, state) { | ||||||
|         if (!this.getActiveTabContext() || newTab) { |         if (!this.getActiveTabContext() || newTab) { | ||||||
|             // if it's a new tab explicitly by user then it's in background |             // if it's a new tab explicitly by user then it's in background | ||||||
| @@ -266,35 +266,8 @@ class AppContext { | |||||||
|         this.saveOpenTabs(); |         this.saveOpenTabs(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     async saveOpenTabs() { |  | ||||||
|         const openTabs = []; |  | ||||||
|  |  | ||||||
|         for (const tabContext of this.tabContexts) { |  | ||||||
|             const tabState = tabContext.getTabState(); |  | ||||||
|  |  | ||||||
|             if (tabState) { |  | ||||||
|                 openTabs.push(tabState); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         await server.put('options', { |  | ||||||
|             openTabs: JSON.stringify(openTabs) |  | ||||||
|         }); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     clearOpenTabsTask() { |  | ||||||
|         if (this.tabsChangedTaskId) { |  | ||||||
|             clearTimeout(this.tabsChangedTaskId); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     openTabsChangedListener() { |     openTabsChangedListener() { | ||||||
|         // we don't want to send too many requests with tab changes so we always schedule task to do this in 1 seconds, |         this.tabsUpdate.scheduleUpdate(); | ||||||
|         // but if there's any change in between, we cancel the old one and schedule new one |  | ||||||
|         // so effectively we kind of wait until user stopped e.g. quickly switching tabs |  | ||||||
|         this.clearOpenTabsTask(); |  | ||||||
|  |  | ||||||
|         this.tabsChangedTaskId = setTimeout(() => this.saveOpenTabs(), 1000); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     activateTab(tabId) { |     activateTab(tabId) { | ||||||
|   | |||||||
| @@ -34,7 +34,7 @@ export default class DialogEventComponent extends Component { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     async cloneNotesToListener() { |     async cloneNotesToListener() { | ||||||
|         // probably should not happen here |         // FIXME | ||||||
|         const selectedOrActiveNodes = this.appContext.getMainNoteTree().getSelectedOrActiveNodes(); |         const selectedOrActiveNodes = this.appContext.getMainNoteTree().getSelectedOrActiveNodes(); | ||||||
|  |  | ||||||
|         const noteIds = selectedOrActiveNodes.map(node => node.data.noteId); |         const noteIds = selectedOrActiveNodes.map(node => node.data.noteId); | ||||||
| @@ -44,6 +44,7 @@ export default class DialogEventComponent extends Component { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     async moveNotesToListener() { |     async moveNotesToListener() { | ||||||
|  |         // FIXME | ||||||
|         const selectedOrActiveNodes = this.appContext.getMainNoteTree().getSelectedOrActiveNodes(); |         const selectedOrActiveNodes = this.appContext.getMainNoteTree().getSelectedOrActiveNodes(); | ||||||
|  |  | ||||||
|         const d = await import("../dialogs/move_to.js"); |         const d = await import("../dialogs/move_to.js"); | ||||||
| @@ -51,6 +52,7 @@ export default class DialogEventComponent extends Component { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     async editBranchPrefixListener() { |     async editBranchPrefixListener() { | ||||||
|  |         // FIXME | ||||||
|         const node = this.appContext.getMainNoteTree().getActiveNode(); |         const node = this.appContext.getMainNoteTree().getActiveNode(); | ||||||
|  |  | ||||||
|         const editBranchPrefixDialog = await import("../dialogs/branch_prefix.js"); |         const editBranchPrefixDialog = await import("../dialogs/branch_prefix.js"); | ||||||
|   | |||||||
| @@ -78,17 +78,17 @@ export default class Entrypoints extends Component { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     toggleNoteHoistingListener() { |     toggleNoteHoistingListener() { | ||||||
|         const node = appContext.getMainNoteTree().getActiveNode(); |         const note = appContext.getActiveTabNote(); | ||||||
|  |  | ||||||
|         hoistedNoteService.getHoistedNoteId().then(async hoistedNoteId => { |         hoistedNoteService.getHoistedNoteId().then(async hoistedNoteId => { | ||||||
|             if (node.data.noteId === hoistedNoteId) { |             if (note.noteId === hoistedNoteId) { | ||||||
|                 hoistedNoteService.unhoist(); |                 hoistedNoteService.unhoist(); | ||||||
|             } |             } | ||||||
|             else { |             else { | ||||||
|                 const note = await treeCache.getNote(node.data.noteId); |                 const note = await treeCache.getNote(note.noteId); | ||||||
|  |  | ||||||
|                 if (note.type !== 'search') { |                 if (note.type !== 'search') { | ||||||
|                     hoistedNoteService.setHoistedNoteId(node.data.noteId); |                     hoistedNoteService.setHoistedNoteId(note.noteId); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         }); |         }); | ||||||
|   | |||||||
| @@ -17,6 +17,7 @@ const helpText = ` | |||||||
| </p>`; | </p>`; | ||||||
|  |  | ||||||
| async function refreshSearch() { | async function refreshSearch() { | ||||||
|  |     // FIXME | ||||||
|     const activeNode = appContext.getMainNoteTree().getActiveNode(); |     const activeNode = appContext.getMainNoteTree().getActiveNode(); | ||||||
|  |  | ||||||
|     activeNode.load(true); |     activeNode.load(true); | ||||||
|   | |||||||
| @@ -35,8 +35,6 @@ export default class NoteTreeWidget extends TabAwareWidget { | |||||||
|  |  | ||||||
|         window.glob.cutIntoNote = () => this.cutIntoNoteListener(); |         window.glob.cutIntoNote = () => this.cutIntoNoteListener(); | ||||||
|  |  | ||||||
|         this.appContext.noteTreeWidget = this; |  | ||||||
|  |  | ||||||
|         this.tree = null; |         this.tree = null; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -107,6 +107,7 @@ export default class SearchBoxWidget extends BasicWidget { | |||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         // FIXME | ||||||
|         let activeNode = appContext.getMainNoteTree().getActiveNode(); |         let activeNode = appContext.getMainNoteTree().getActiveNode(); | ||||||
|         const parentNote = await treeCache.getNote(activeNode.data.noteId); |         const parentNote = await treeCache.getNote(activeNode.data.noteId); | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user