mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 21:11:30 +08:00 
			
		
		
		
	fixes in enabling / disabling widgets in runtime
This commit is contained in:
		
							parent
							
								
									9f4a514562
								
							
						
					
					
						commit
						4ec671d199
					
				| @ -112,20 +112,6 @@ class TabContext extends Component { | |||||||
|             }); |             }); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 |  | ||||||
|     // FIXME
 |  | ||||||
|     async _setTitleBar() { |  | ||||||
|         document.title = "Trilium Notes"; |  | ||||||
| 
 |  | ||||||
|         const activeTabContext = this.getActiveTabContext(); |  | ||||||
| 
 |  | ||||||
|         if (activeTabContext && activeTabContext.notePath) { |  | ||||||
|             const note = await treeCache.getNote(treeService.getNoteIdFromNotePath(activeTabContext.notePath)); |  | ||||||
| 
 |  | ||||||
|             // it helps navigating in history if note title is included in the title
 |  | ||||||
|             document.title += " - " + note.title; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export default TabContext; | export default TabContext; | ||||||
| @ -13,9 +13,15 @@ class BasicWidget extends Component { | |||||||
|             this.appContext.trigger(eventName); |             this.appContext.trigger(eventName); | ||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
|  |         this.toggle(this.isEnabled()); | ||||||
|  | 
 | ||||||
|         return $widget; |         return $widget; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     isEnabled() { | ||||||
|  |         return true; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     /** |     /** | ||||||
|      * for overriding |      * for overriding | ||||||
|      */ |      */ | ||||||
|  | |||||||
| @ -27,8 +27,8 @@ const TPL = ` | |||||||
| export default class CalendarWidget extends CollapsibleWidget { | export default class CalendarWidget extends CollapsibleWidget { | ||||||
|     getWidgetTitle() { return "Calendar"; } |     getWidgetTitle() { return "Calendar"; } | ||||||
| 
 | 
 | ||||||
|     async isEnabled() { |     isEnabled() { | ||||||
|         return await super.isEnabled() |         return super.isEnabled() | ||||||
|             && this.note.hasOwnedLabel("dateNote"); |             && this.note.hasOwnedLabel("dateNote"); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -14,9 +14,9 @@ export default class EditedNotesWidget extends CollapsibleWidget { | |||||||
| 
 | 
 | ||||||
|     getMaxHeight() { return "200px"; } |     getMaxHeight() { return "200px"; } | ||||||
| 
 | 
 | ||||||
|     async isEnabled() { |     isEnabled() { | ||||||
|         return await super.isEnabled() |         return super.isEnabled() | ||||||
|             && await this.note.hasOwnedLabel("dateNote"); |             && this.note.hasOwnedLabel("dateNote"); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     async refreshWithNote(note) { |     async refreshWithNote(note) { | ||||||
|  | |||||||
| @ -8,7 +8,7 @@ export default class FlexContainer extends BasicWidget { | |||||||
|         this.children = widgets; |         this.children = widgets; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     render() { |     doRender() { | ||||||
|         this.$widget = $(`<div style="display: flex;">`); |         this.$widget = $(`<div style="display: flex;">`); | ||||||
| 
 | 
 | ||||||
|         for (const key in this.attrs) { |         for (const key in this.attrs) { | ||||||
|  | |||||||
| @ -1,19 +1,18 @@ | |||||||
| import BasicWidget from "./basic_widget.js"; | import BasicWidget from "./basic_widget.js"; | ||||||
| import appContext from "../services/app_context.js"; |  | ||||||
| 
 | 
 | ||||||
| const WIDGET_TPL = ` | const WIDGET_TPL = ` | ||||||
| <style> |  | ||||||
| .global-buttons { |  | ||||||
|     display: flex; |  | ||||||
|     justify-content: space-around; |  | ||||||
|     padding: 3px 0 3px 0; |  | ||||||
|     border: 1px solid var(--main-border-color); |  | ||||||
|     border-radius: 7px; |  | ||||||
|     margin: 3px 5px 5px 5px; |  | ||||||
| } |  | ||||||
| </style> |  | ||||||
| 
 |  | ||||||
| <div class="global-buttons"> | <div class="global-buttons"> | ||||||
|  |     <style> | ||||||
|  |     .global-buttons { | ||||||
|  |         display: flex; | ||||||
|  |         justify-content: space-around; | ||||||
|  |         padding: 3px 0 3px 0; | ||||||
|  |         border: 1px solid var(--main-border-color); | ||||||
|  |         border-radius: 7px; | ||||||
|  |         margin: 3px 5px 5px 5px; | ||||||
|  |     } | ||||||
|  |     </style> | ||||||
|  | 
 | ||||||
|     <a data-trigger-event="createTopLevelNote" |     <a data-trigger-event="createTopLevelNote" | ||||||
|        title="Create new top level note"  |        title="Create new top level note"  | ||||||
|        class="icon-action bx bx-folder-plus"></a> |        class="icon-action bx bx-folder-plus"></a> | ||||||
| @ -36,8 +35,8 @@ const WIDGET_TPL = ` | |||||||
| `;
 | `;
 | ||||||
| 
 | 
 | ||||||
| class GlobalButtonsWidget extends BasicWidget { | class GlobalButtonsWidget extends BasicWidget { | ||||||
|     doRender($widget) { |     doRender() { | ||||||
|         return $(WIDGET_TPL); |         return this.$widget = $(WIDGET_TPL); | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -39,14 +39,13 @@ export default class NoteTreeWidget extends TabAwareWidget { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     doRender() { |     doRender() { | ||||||
|         const $widget = $(TPL); |         this.$widget = $(TPL); | ||||||
|         const $tree = $widget; |  | ||||||
| 
 | 
 | ||||||
|         $tree.on("click", ".unhoist-button", hoistedNoteService.unhoist); |         this.$widget.on("click", ".unhoist-button", hoistedNoteService.unhoist); | ||||||
|         $tree.on("click", ".refresh-search-button", searchNotesService.refreshSearch); |         this.$widget.on("click", ".refresh-search-button", searchNotesService.refreshSearch); | ||||||
| 
 | 
 | ||||||
|         // fancytree doesn't support middle click so this is a way to support it
 |         // fancytree doesn't support middle click so this is a way to support it
 | ||||||
|         $widget.on('mousedown', '.fancytree-title', e => { |         this.$widget.on('mousedown', '.fancytree-title', e => { | ||||||
|             if (e.which === 2) { |             if (e.which === 2) { | ||||||
|                 const node = $.ui.fancytree.getNode(e); |                 const node = $.ui.fancytree.getNode(e); | ||||||
| 
 | 
 | ||||||
| @ -62,20 +61,20 @@ export default class NoteTreeWidget extends TabAwareWidget { | |||||||
|             } |             } | ||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
|         this.initialized = treeBuilder.prepareTree().then(treeData => this.initFancyTree($tree, treeData)); |         this.initialized = treeBuilder.prepareTree().then(treeData => this.initFancyTree(treeData)); | ||||||
| 
 | 
 | ||||||
|         return $widget; |         return this.$widget; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     async initFancyTree($tree, treeData) { |     async initFancyTree(treeData) { | ||||||
|         utils.assertArguments(treeData); |         utils.assertArguments(treeData); | ||||||
| 
 | 
 | ||||||
|         $tree.fancytree({ |         this.$widget.fancytree({ | ||||||
|             autoScroll: true, |             autoScroll: true, | ||||||
|             keyboard: false, // we takover keyboard handling in the hotkeys plugin
 |             keyboard: false, // we takover keyboard handling in the hotkeys plugin
 | ||||||
|             extensions: ["hotkeys", "dnd5", "clones"], |             extensions: ["hotkeys", "dnd5", "clones"], | ||||||
|             source: treeData, |             source: treeData, | ||||||
|             scrollParent: $tree, |             scrollParent: this.$widget, | ||||||
|             minExpandLevel: 2, // root can't be collapsed
 |             minExpandLevel: 2, // root can't be collapsed
 | ||||||
|             click: (event, data) => { |             click: (event, data) => { | ||||||
|                 const targetType = data.targetType; |                 const targetType = data.targetType; | ||||||
| @ -224,7 +223,7 @@ export default class NoteTreeWidget extends TabAwareWidget { | |||||||
|             } |             } | ||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
|         $tree.on('contextmenu', '.fancytree-node', e => { |         this.$widget.on('contextmenu', '.fancytree-node', e => { | ||||||
|             const node = $.ui.fancytree.getNode(e); |             const node = $.ui.fancytree.getNode(e); | ||||||
| 
 | 
 | ||||||
|             contextMenuWidget.initContextMenu(e, new TreeContextMenu(this, node)); |             contextMenuWidget.initContextMenu(e, new TreeContextMenu(this, node)); | ||||||
| @ -232,7 +231,7 @@ export default class NoteTreeWidget extends TabAwareWidget { | |||||||
|             return false; // blocks default browser right click menu
 |             return false; // blocks default browser right click menu
 | ||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
|         this.tree = $.ui.fancytree.getTree($tree); |         this.tree = $.ui.fancytree.getTree(this.$widget); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** @return {FancytreeNode[]} */ |     /** @return {FancytreeNode[]} */ | ||||||
| @ -411,6 +410,8 @@ export default class NoteTreeWidget extends TabAwareWidget { | |||||||
|     collapseTreeListener() { this.collapseTree(); } |     collapseTreeListener() { this.collapseTree(); } | ||||||
| 
 | 
 | ||||||
|     async refresh() { |     async refresh() { | ||||||
|  |         this.toggle(this.isEnabled()); | ||||||
|  | 
 | ||||||
|         const oldActiveNode = this.getActiveNode(); |         const oldActiveNode = this.getActiveNode(); | ||||||
| 
 | 
 | ||||||
|         if (oldActiveNode) { |         if (oldActiveNode) { | ||||||
|  | |||||||
| @ -9,6 +9,10 @@ export default class SidePaneContainer extends FlexContainer { | |||||||
|         this.children = widgets; |         this.children = widgets; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     isEnabled() { | ||||||
|  |         return super.isEnabled() && options.is(this.side + 'PaneVisible'); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     eventReceived(name, data, sync = false) { |     eventReceived(name, data, sync = false) { | ||||||
|         if (options.is(this.side + 'PaneVisible')) { |         if (options.is(this.side + 'PaneVisible')) { | ||||||
|             super.eventReceived(name, data, sync); |             super.eventReceived(name, data, sync); | ||||||
|  | |||||||
| @ -43,12 +43,12 @@ export default class TabAwareWidget extends BasicWidget { | |||||||
|         this.refresh(); |         this.refresh(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     async isEnabled() { |     isEnabled() { | ||||||
|         return !!this.note && this.tabContext.isActive(); |         return !!this.note && this.tabContext.isActive(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     async refresh() { |     async refresh() { | ||||||
|         if (await this.isEnabled()) { |         if (this.isEnabled()) { | ||||||
|             const start = Date.now(); |             const start = Date.now(); | ||||||
| 
 | 
 | ||||||
|             this.toggle(true); |             this.toggle(true); | ||||||
|  | |||||||
| @ -8,13 +8,12 @@ export default class TabCachingWidget extends TabAwareWidget { | |||||||
|         this.widgets = {}; |         this.widgets = {}; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     async isEnabled() { |     isEnabled() { | ||||||
|         return this.tabContext.isActive(); |         return this.tabContext && this.tabContext.isActive(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     doRender() { |     doRender() { | ||||||
|         this.$widget = $(`<div class="marker" style="display: none;">`); |         return this.$widget = $(`<div class="marker" style="display: none;">`); | ||||||
|         return this.$widget; |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     activeTabChangedListener(param) { |     activeTabChangedListener(param) { | ||||||
| @ -57,12 +56,12 @@ export default class TabCachingWidget extends TabAwareWidget { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     async toggle(show) { |     toggle(show) { | ||||||
|         for (const tabId in this.widgets) { |         for (const tabId in this.widgets) { | ||||||
|             this.widgets[tabId].toggle( |             this.widgets[tabId].toggle( | ||||||
|                 show |                 show | ||||||
|                 && this.tabContext && tabId === this.tabContext.tabId |                 && this.tabContext && tabId === this.tabContext.tabId | ||||||
|                 && await this.widgets[tabId].isEnabled()); |                 && this.widgets[tabId].isEnabled()); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 zadam
						zadam