mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 21:11:30 +08:00 
			
		
		
		
	more refactorings
This commit is contained in:
		
							parent
							
								
									0760dc742b
								
							
						
					
					
						commit
						562c729ed6
					
				| @ -180,9 +180,14 @@ class AppContext { | ||||
|         return this.tabContexts; | ||||
|     } | ||||
| 
 | ||||
|     /** @returns {TabContext} */ | ||||
|     getTabContextById(tabId) { | ||||
|         return this.tabContexts.find(tc => tc.tabId === tabId); | ||||
|     } | ||||
| 
 | ||||
|     /** @returns {TabContext} */ | ||||
|     getActiveTabContext() { | ||||
|         return this.tabContexts.find(tc => tc.tabId === this.activeTabId); | ||||
|         return this.getTabContextById(this.activeTabId); | ||||
|     } | ||||
| 
 | ||||
|     /** @returns {string|null} */ | ||||
| @ -253,14 +258,6 @@ class AppContext { | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     async refreshTabs(sourceTabId, noteId) { | ||||
|         for (const tc of this.tabContexts) { | ||||
|             if (tc.noteId === noteId && tc.tabId !== sourceTabId) { | ||||
|                 await this.reloadTab(tc); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     async reloadTab(tc) { | ||||
|         if (tc.note) { | ||||
|             noteDetailService.reloadNote(tc); | ||||
|  | ||||
| @ -190,6 +190,7 @@ ws.subscribeToOutsideSyncMessages(syncData => { | ||||
|         .filter(sync => sync.entityName === 'attributes') | ||||
|         .forEach(sync => noteIdsToRefresh.add(sync.noteId)); | ||||
| 
 | ||||
|     // FIXME
 | ||||
|     for (const noteId of noteIdsToRefresh) { | ||||
|         appContext.refreshTabs(null, noteId); | ||||
|     } | ||||
|  | ||||
| @ -1,4 +1,3 @@ | ||||
| import treeService from "./tree.js"; | ||||
| import protectedSessionHolder from "./protected_session_holder.js"; | ||||
| import server from "./server.js"; | ||||
| import bundleService from "./bundle.js"; | ||||
| @ -44,10 +43,6 @@ class TabContext extends Component { | ||||
|         /** @property {NoteFull} */ | ||||
|         this.note = await noteDetailService.loadNote(noteId); | ||||
| 
 | ||||
|         this.tabRow.updateTab(this.$tab[0], {title: this.note.title}); | ||||
| 
 | ||||
|         this.setupClasses(); | ||||
| 
 | ||||
|         //this.cleanup(); // esp. on windows autocomplete is not getting closed automatically
 | ||||
| 
 | ||||
|         setTimeout(async () => { | ||||
| @ -70,39 +65,12 @@ class TabContext extends Component { | ||||
|         this.trigger('tabNoteSwitched', {tabId: this.tabId}); | ||||
|     } | ||||
| 
 | ||||
|     async show() { | ||||
|     } | ||||
| 
 | ||||
|     hide() { | ||||
|         // FIXME
 | ||||
|     } | ||||
| 
 | ||||
|     isActive() { | ||||
|         return this.tabId === this.tabRow.activeTabId; | ||||
|     } | ||||
| 
 | ||||
|     async remove() { | ||||
|         await this.trigger('beforeTabRemove', {tabId: this.tabId}, true); | ||||
| 
 | ||||
|         this.trigger('tabRemoved', {tabId: this.tabId}); | ||||
|     } | ||||
| 
 | ||||
|     setupClasses() { | ||||
|         for (const clazz of Array.from(this.$tab[0].classList)) { // create copy to safely iterate over while removing classes
 | ||||
|             if (clazz !== 'note-tab') { | ||||
|                 this.$tab.removeClass(clazz); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         this.$tab.addClass(this.note.cssClass); | ||||
|         this.$tab.addClass(utils.getNoteTypeClass(this.note.type)); | ||||
|         this.$tab.addClass(utils.getMimeTypeClass(this.note.mime)); | ||||
|     } | ||||
| 
 | ||||
|     async activate() { | ||||
|         await this.tabRow.activateTab(this.$tab[0]); | ||||
|     } | ||||
| 
 | ||||
|     async saveNote() { | ||||
|         return; // FIXME
 | ||||
| 
 | ||||
| @ -125,19 +93,6 @@ class TabContext extends Component { | ||||
|         if (this.note.isProtected) { | ||||
|             protectedSessionHolder.touchProtectedSession(); | ||||
|         } | ||||
| 
 | ||||
|         // FIXME trigger "noteSaved" event so that title indicator is triggered
 | ||||
|         this.eventReceived('noteSaved'); | ||||
| 
 | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     async saveNoteIfChanged() { | ||||
|         if (this.isNoteChanged) { | ||||
|             await this.saveNote(); | ||||
| 
 | ||||
|             appContext.refreshTabs(this.tabId, this.note.noteId); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     getTabState() { | ||||
|  | ||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 zadam
						zadam