mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 05:28:59 +01:00 
			
		
		
		
	wip
This commit is contained in:
		
							parent
							
								
									3ab2b41e8c
								
							
						
					
					
						commit
						95d1952896
					
				@ -69,9 +69,7 @@ export default class Entrypoints extends Component {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        await treeService.expandToNote(note.noteId);
 | 
					        await treeService.expandToNote(note.noteId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const tabContext = appContext.tabManager.openEmptyTab();
 | 
					        const tabContext = await appContext.tabManager.openTabWithNote(note.noteId, true);
 | 
				
			||||||
        appContext.tabManager.activateTab(tabContext.tabId);
 | 
					 | 
				
			||||||
        await tabContext.setNote(note.noteId);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        appContext.triggerCommand('focusAndSelectTitle');
 | 
					        appContext.triggerCommand('focusAndSelectTitle');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -77,8 +77,7 @@ function goToLink(e) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    if (notePath) {
 | 
					    if (notePath) {
 | 
				
			||||||
        if ((e.which === 1 && e.ctrlKey) || e.which === 2) {
 | 
					        if ((e.which === 1 && e.ctrlKey) || e.which === 2) {
 | 
				
			||||||
            const tabContext = appContext.tabManager.openEmptyTab();
 | 
					            appContext.tabManager.openTabWithNote(notePath);
 | 
				
			||||||
            tabContext.setNote(notePath);
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        else if (e.which === 1) {
 | 
					        else if (e.which === 1) {
 | 
				
			||||||
            const activeTabContext = appContext.tabManager.getActiveTabContext();
 | 
					            const activeTabContext = appContext.tabManager.getActiveTabContext();
 | 
				
			||||||
@ -118,8 +117,7 @@ function newTabContextMenu(e) {
 | 
				
			|||||||
        ],
 | 
					        ],
 | 
				
			||||||
        selectMenuItemHandler: ({command}) => {
 | 
					        selectMenuItemHandler: ({command}) => {
 | 
				
			||||||
            if (command === 'openNoteInNewTab') {
 | 
					            if (command === 'openNoteInNewTab') {
 | 
				
			||||||
                const tabContext = appContext.tabManager.openEmptyTab();
 | 
					                appContext.tabManager.openTabWithNote(notePath);
 | 
				
			||||||
                tabContext.setNote(notePath);
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
@ -139,8 +137,7 @@ $(document).on('mousedown', '.note-detail-text a', function (e) {
 | 
				
			|||||||
        e.preventDefault();
 | 
					        e.preventDefault();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (notePath) {
 | 
					        if (notePath) {
 | 
				
			||||||
            const tabContext = appContext.tabManager.openEmptyTab();
 | 
					            appContext.tabManager.openTabWithNote(notePath, false);
 | 
				
			||||||
            tabContext.setNote(notePath);
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        else {
 | 
					        else {
 | 
				
			||||||
            const address = $link.attr('href');
 | 
					            const address = $link.attr('href');
 | 
				
			||||||
 | 
				
			|||||||
@ -163,31 +163,31 @@ export default class TabManager extends Component {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    async switchToTab(tabId, notePath) {
 | 
					    async switchToTab(tabId, notePath) {
 | 
				
			||||||
        const tabContext = this.tabContexts.find(tc => tc.tabId === tabId)
 | 
					        const tabContext = this.tabContexts.find(tc => tc.tabId === tabId)
 | 
				
			||||||
            || this.openEmptyTab();
 | 
					            || await this.openEmptyTab();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.activateTab(tabContext.tabId);
 | 
					        this.activateTab(tabContext.tabId);
 | 
				
			||||||
        await tabContext.setNote(notePath);
 | 
					        await tabContext.setNote(notePath);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async openAndActivateEmptyTab() {
 | 
					    async openAndActivateEmptyTab() {
 | 
				
			||||||
        const tabContext = this.openEmptyTab();
 | 
					        const tabContext = await this.openEmptyTab();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        await this.activateTab(tabContext.tabId);
 | 
					        await this.activateTab(tabContext.tabId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        await tabContext.setEmpty();
 | 
					        await tabContext.setEmpty();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    openEmptyTab(tabId) {
 | 
					    async openEmptyTab(tabId) {
 | 
				
			||||||
        const tabContext = new TabContext(tabId);
 | 
					        const tabContext = new TabContext(tabId);
 | 
				
			||||||
        this.child(tabContext);
 | 
					        this.child(tabContext);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.triggerEvent('newTabOpened', {tabId: tabContext.tabId});
 | 
					        await this.triggerEvent('newTabOpened', {tabId: tabContext.tabId});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return tabContext;
 | 
					        return tabContext;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async openTabWithNote(notePath, activate, tabId = null) {
 | 
					    async openTabWithNote(notePath, activate, tabId = null) {
 | 
				
			||||||
        const tabContext = this.openEmptyTab(tabId);
 | 
					        const tabContext = await this.openEmptyTab(tabId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        await tabContext.setNote(notePath, !activate); // if activate is false then send normal noteSwitched event
 | 
					        await tabContext.setNote(notePath, !activate); // if activate is false then send normal noteSwitched event
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -211,8 +211,7 @@ export default class TabManager extends Component {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // if no tab with this note has been found we'll create new tab
 | 
					        // if no tab with this note has been found we'll create new tab
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const tabContext = this.openEmptyTab();
 | 
					        await this.openTabWithNote(noteId);
 | 
				
			||||||
        await tabContext.setNote(noteId);
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    activateTab(tabId, triggerEvent = true) {
 | 
					    activateTab(tabId, triggerEvent = true) {
 | 
				
			||||||
 | 
				
			|||||||
@ -108,8 +108,7 @@ class TreeContextMenu {
 | 
				
			|||||||
        const notePath = treeService.getNotePath(this.node);
 | 
					        const notePath = treeService.getNotePath(this.node);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (command === 'openInTab') {
 | 
					        if (command === 'openInTab') {
 | 
				
			||||||
            const tabContext = appContext.tabManager.openEmptyTab();
 | 
					            appContext.tabManager.openTabWithNote(notePath);
 | 
				
			||||||
            tabContext.setNote(notePath);
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        else if (command === "insertNoteAfter") {
 | 
					        else if (command === "insertNoteAfter") {
 | 
				
			||||||
            const parentNoteId = this.node.data.parentNoteId;
 | 
					            const parentNoteId = this.node.data.parentNoteId;
 | 
				
			||||||
 | 
				
			|||||||
@ -47,8 +47,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
 | 
				
			|||||||
                const notePath = treeService.getNotePath(node);
 | 
					                const notePath = treeService.getNotePath(node);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if (notePath) {
 | 
					                if (notePath) {
 | 
				
			||||||
                    const tabContext = appContext.tabManager.openEmptyTab();
 | 
					                    appContext.tabManager.openTabWithNote(notePath);
 | 
				
			||||||
                    tabContext.setNote(notePath);
 | 
					 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                e.stopPropagation();
 | 
					                e.stopPropagation();
 | 
				
			||||||
@ -81,9 +80,8 @@ export default class NoteTreeWidget extends TabAwareWidget {
 | 
				
			|||||||
                        node.setFocus(true);
 | 
					                        node.setFocus(true);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    else if (event.ctrlKey) {
 | 
					                    else if (event.ctrlKey) {
 | 
				
			||||||
                        const tabContext = appContext.tabManager.openEmptyTab();
 | 
					 | 
				
			||||||
                        const notePath = treeService.getNotePath(node);
 | 
					                        const notePath = treeService.getNotePath(node);
 | 
				
			||||||
                        tabContext.setNote(notePath);
 | 
					                        appContext.tabManager.openTabWithNote(notePath);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    else {
 | 
					                    else {
 | 
				
			||||||
                        node.setActive();
 | 
					                        node.setActive();
 | 
				
			||||||
 | 
				
			|||||||
@ -28,6 +28,23 @@ export default class TabCachingWidget extends TabAwareWidget {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    async newTabOpenedEvent({tabId}) {
 | 
				
			||||||
 | 
					        if (this.widgets[tabId]) {
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        this.widgets[tabId] = this.widgetFactory();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const $renderedWidget = this.widgets[tabId].render();
 | 
				
			||||||
 | 
					        this.$widget.after($renderedWidget);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        keyboardActionsService.updateDisplayedShortcuts($renderedWidget);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        await this.widgets[tabId].handleEvent('setTabContext', {tabContext: this.tabContext});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        this.child(this.widgets[tabId]); // add as child only once it is ready (rendered with tabContext)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async refreshWithNote() {
 | 
					    async refreshWithNote() {
 | 
				
			||||||
        for (const widget of Object.values(this.widgets)) {
 | 
					        for (const widget of Object.values(this.widgets)) {
 | 
				
			||||||
            widget.toggle(false);
 | 
					            widget.toggle(false);
 | 
				
			||||||
@ -39,21 +56,14 @@ export default class TabCachingWidget extends TabAwareWidget {
 | 
				
			|||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let widget = this.widgets[this.tabContext.tabId];
 | 
					        const widget = this.widgets[this.tabContext.tabId];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!widget) {
 | 
					        if (widget) {
 | 
				
			||||||
            widget = this.widgets[this.tabContext.tabId] = this.widgetFactory();
 | 
					            widget.toggle(widget.isEnabled());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
            const $renderedWidget = widget.render();
 | 
					        else {
 | 
				
			||||||
            this.$widget.after($renderedWidget);
 | 
					            console.error(`Widget for tab ${this.tabContext.tabId} not found.`);
 | 
				
			||||||
 | 
					 | 
				
			||||||
            keyboardActionsService.updateDisplayedShortcuts($renderedWidget);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            this.child(widget); // add as child only once it is ready (also rendered)
 | 
					 | 
				
			||||||
            await widget.handleEvent('setTabContext', {tabContext: this.tabContext});
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					 | 
				
			||||||
        widget.toggle(widget.isEnabled());
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    tabRemovedEvent({tabId}) {
 | 
					    tabRemovedEvent({tabId}) {
 | 
				
			||||||
 | 
				
			|||||||
@ -196,8 +196,7 @@ export default class RelationMapTypeWidget extends TypeWidget {
 | 
				
			|||||||
        const noteId = this.idToNoteId($noteBox.prop("id"));
 | 
					        const noteId = this.idToNoteId($noteBox.prop("id"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (command === "openInNewTab") {
 | 
					        if (command === "openInNewTab") {
 | 
				
			||||||
            const tabContext = appContext.tabManager.openEmptyTab();
 | 
					            appContext.tabManager.openTabWithNote(noteId);
 | 
				
			||||||
            tabContext.setNote(noteId);
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        else if (command === "remove") {
 | 
					        else if (command === "remove") {
 | 
				
			||||||
            const confirmDialog = await import('../../dialogs/confirm.js');
 | 
					            const confirmDialog = await import('../../dialogs/confirm.js');
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user