From d46801ff1fcafa2daf3e71e089fb408fc6dae311 Mon Sep 17 00:00:00 2001 From: zadam Date: Wed, 13 Sep 2023 09:01:55 +0200 Subject: [PATCH] refactoring, tab switching handling shouldn't be on the widget level --- docs/backend_api/BAttachment.html | 6 +- .../becca_entities_battachment.js.html | 7 +- docs/frontend_api/FrontendScriptApi.html | 468 +++++++++++++++++- .../services_frontend_script_api.js.html | 26 +- src/public/app/components/note_context.js | 13 + .../app/components/root_command_executor.js | 20 + src/public/app/components/tab_manager.js | 17 +- .../app/services/frontend_script_api.js | 26 +- src/public/app/widgets/tab_row.js | 22 +- 9 files changed, 553 insertions(+), 52 deletions(-) diff --git a/docs/backend_api/BAttachment.html b/docs/backend_api/BAttachment.html index 26cf922cb9..42441d8462 100644 --- a/docs/backend_api/BAttachment.html +++ b/docs/backend_api/BAttachment.html @@ -1388,7 +1388,7 @@

convertT
Source:
@@ -1770,7 +1770,7 @@

getContent<
Source:
@@ -2815,7 +2815,7 @@

Properties
Source:
diff --git a/docs/backend_api/becca_entities_battachment.js.html b/docs/backend_api/becca_entities_battachment.js.html index 9e9b5f3800..676ebd455e 100644 --- a/docs/backend_api/becca_entities_battachment.js.html +++ b/docs/backend_api/becca_entities_battachment.js.html @@ -132,7 +132,12 @@

Source: becca/entities/battachment.js

} decrypt() { - if (this.isProtected && !this.isDecrypted && protectedSessionService.isProtectedSessionAvailable()) { + if (!this.isProtected || !this.attachmentId) { + this.isDecrypted = true; + return; + } + + if (!this.isDecrypted && protectedSessionService.isProtectedSessionAvailable()) { try { this.title = protectedSessionService.decryptString(this.title); this.isDecrypted = true; diff --git a/docs/frontend_api/FrontendScriptApi.html b/docs/frontend_api/FrontendScriptApi.html index 0d31af9d89..dfa5d1e70e 100644 --- a/docs/frontend_api/FrontendScriptApi.html +++ b/docs/frontend_api/FrontendScriptApi.html @@ -1738,7 +1738,7 @@
Parameters:
Source:
@@ -2469,7 +2469,7 @@
Parameters:
Source:
@@ -2624,7 +2624,7 @@
Parameters:
Source:
@@ -2682,6 +2682,112 @@
Returns:
+

getActiveContext() → {NoteContext}

+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + +
+ - returns active context (split) +
+ + + +
+
+ Type +
+
+ +NoteContext + + +
+
+ + + + + + + + + + + + +

getActiveContextCodeEditor() → {Promise.<CodeMirror>}

@@ -2734,7 +2840,7 @@

Source:
@@ -2869,7 +2975,7 @@
Returns:
- active note (loaded into right pane) + active note (loaded into center pane)
@@ -2946,7 +3052,7 @@

Source:
@@ -3056,7 +3162,7 @@

Source:
@@ -3114,6 +3220,112 @@
Returns:
+

getActiveMainContext() → {NoteContext}

+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + +
+ - returns active main context (first split in a tab, represents the tab as a whole) +
+ + + +
+
+ Type +
+
+ +NoteContext + + +
+
+ + + + + + + + + + + + +

getActiveNoteDetailWidget() → {Promise.<NoteDetailWidget>}

@@ -3167,7 +3379,7 @@

Source:
@@ -3322,7 +3534,7 @@
Parameters:
Source:
@@ -3477,7 +3689,7 @@
Parameters:
Source:
@@ -3638,6 +3850,112 @@
Returns:
+

getMainNoteContexts() → {Array.<NoteContext>}

+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + +
+ - returns all main contexts representing tabs +
+ + + +
+
+ Type +
+
+ +Array.<NoteContext> + + +
+
+ + + + + + + + + + + + +

getMonthNote(month) → {Promise.<FNote>}

@@ -3739,7 +4057,7 @@
Parameters:
Source:
@@ -3949,6 +4267,112 @@
Returns:
+

getNoteContexts() → {Array.<NoteContext>}

+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + +
+ - returns all note contexts (splits) in all tabs +
+ + + +
+
+ Type +
+
+ +Array.<NoteContext> + + +
+
+ + + + + + + + + + + + +

getNotes(noteIds, silentNotFoundErroropt) → {Promise.<Array.<FNote>>}

@@ -4202,7 +4626,7 @@

getTodayN
Source:
@@ -4357,7 +4781,7 @@

Parameters:
Source:
@@ -4512,7 +4936,7 @@
Parameters:
Source:
@@ -4662,7 +5086,7 @@
Parameters:
Source:
@@ -5347,7 +5771,7 @@
Parameters:
Source:
@@ -5521,7 +5945,7 @@
Parameters:
Source:
@@ -5676,7 +6100,7 @@
Parameters:
Source:
@@ -5830,7 +6254,7 @@
Parameters:
Source:
@@ -6620,7 +7044,7 @@
Parameters:
Source:
@@ -6771,7 +7195,7 @@
Parameters:
Source:
@@ -7475,7 +7899,7 @@

waitUn
Source:
diff --git a/docs/frontend_api/services_frontend_script_api.js.html b/docs/frontend_api/services_frontend_script_api.js.html index 22934874b1..328ab4125b 100644 --- a/docs/frontend_api/services_frontend_script_api.js.html +++ b/docs/frontend_api/services_frontend_script_api.js.html @@ -377,10 +377,34 @@

Source: services/frontend_script_api.js

/** * @method - * @returns {FNote} active note (loaded into right pane) + * @returns {FNote} active note (loaded into center pane) */ this.getActiveContextNote = () => appContext.tabManager.getActiveContextNote(); + /** + * @method + * @returns {NoteContext} - returns active context (split) + */ + this.getActiveContext = () => appContext.tabManager.getActiveContext(); + + /** + * @method + * @returns {NoteContext} - returns active main context (first split in a tab, represents the tab as a whole) + */ + this.getActiveMainContext = () => appContext.tabManager.getActiveMainContext(); + + /** + * @method + * @returns {NoteContext[]} - returns all note contexts (splits) in all tabs + */ + this.getNoteContexts = () => appContext.tabManager.getNoteContexts(); + + /** + * @method + * @returns {NoteContext[]} - returns all main contexts representing tabs + */ + this.getMainNoteContexts = () => appContext.tabManager.getMainNoteContexts(); + /** * See https://ckeditor.com/docs/ckeditor5/latest/api/module_core_editor_editor-Editor.html for documentation on the returned instance. * diff --git a/src/public/app/components/note_context.js b/src/public/app/components/note_context.js index 5dd0d7bc98..559e534bb4 100644 --- a/src/public/app/components/note_context.js +++ b/src/public/app/components/note_context.js @@ -105,11 +105,24 @@ class NoteContext extends Component { return appContext.tabManager.noteContexts.filter(nc => nc.ntxId === this.ntxId || nc.mainNtxId === this.ntxId); } + /** + * A main context represents a tab and also the first split. Further splits are the children contexts of the main context. + * Imagine you have a tab with 3 splits, each showing notes A, B, C (in this order). + * In such a scenario, A context is the main context (also representing the tab as a whole), and B, C are the children + * of context A. + * + * @returns {boolean} true if the context is main (= tab) + */ isMainContext() { // if null, then this is a main context return !this.mainNtxId; } + /** + * See docs for isMainContext() for better explanation. + * + * @returns {NoteContext} + */ getMainContext() { if (this.mainNtxId) { try { diff --git a/src/public/app/components/root_command_executor.js b/src/public/app/components/root_command_executor.js index 29c3aab1d3..e8c7fc5b4d 100644 --- a/src/public/app/components/root_command_executor.js +++ b/src/public/app/components/root_command_executor.js @@ -154,4 +154,24 @@ export default class RootCommandExecutor extends Component { }); } } + + firstTabCommand() {this.#goToTab(1);} + secondTabCommand() {this.#goToTab(2);} + thirdTabCommand() {this.#goToTab(3);} + fourthTabCommand() {this.#goToTab(4);} + fifthTabCommand() {this.#goToTab(5);} + sixthTabCommand() {this.#goToTab(6);} + seventhTabCommand() {this.#goToTab(7);} + eigthTabCommand() {this.#goToTab(8);} + ninthTabCommand() {this.#goToTab(9);} + lastTabCommand() {this.#goToTab(Number.POSITIVE_INFINITY);} + + #goToTab(tabNumber) { + const mainNoteContexts = appContext.tabManager.getMainNoteContexts(); + + const index = tabNumber === Number.POSITIVE_INFINITY ? mainNoteContexts.length - 1 : tabNumber - 1; + const tab = mainNoteContexts[index]; + + appContext.tabManager.activateNoteContext(tab.ntxId); + } } diff --git a/src/public/app/components/tab_manager.js b/src/public/app/components/tab_manager.js index feacc23d4d..57c9c8c5ca 100644 --- a/src/public/app/components/tab_manager.js +++ b/src/public/app/components/tab_manager.js @@ -173,7 +173,10 @@ export default class TabManager extends Component { return this.noteContexts; } - /** @returns {NoteContext[]} */ + /** + * Main context is essentially a tab (children are splits), so this returns tabs. + * @returns {NoteContext[]} + */ getMainNoteContexts() { return this.noteContexts.filter(nc => nc.isMainContext()); } @@ -189,14 +192,22 @@ export default class TabManager extends Component { return noteContext; } - /** @returns {NoteContext} */ + /** + * Get active context which represents the visible split with focus. Active context can, but doesn't have to be "main". + * + * @returns {NoteContext} + */ getActiveContext() { return this.activeNtxId ? this.getNoteContextById(this.activeNtxId) : null; } - /** @returns {NoteContext} */ + /** + * Get active main context which corresponds to the active tab. + * + * @returns {NoteContext} + */ getActiveMainContext() { return this.activeNtxId ? this.getNoteContextById(this.activeNtxId).getMainContext() diff --git a/src/public/app/services/frontend_script_api.js b/src/public/app/services/frontend_script_api.js index 6c9ef86360..c5a7084f9d 100644 --- a/src/public/app/services/frontend_script_api.js +++ b/src/public/app/services/frontend_script_api.js @@ -349,10 +349,34 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain /** * @method - * @returns {FNote} active note (loaded into right pane) + * @returns {FNote} active note (loaded into center pane) */ this.getActiveContextNote = () => appContext.tabManager.getActiveContextNote(); + /** + * @method + * @returns {NoteContext} - returns active context (split) + */ + this.getActiveContext = () => appContext.tabManager.getActiveContext(); + + /** + * @method + * @returns {NoteContext} - returns active main context (first split in a tab, represents the tab as a whole) + */ + this.getActiveMainContext = () => appContext.tabManager.getActiveMainContext(); + + /** + * @method + * @returns {NoteContext[]} - returns all note contexts (splits) in all tabs + */ + this.getNoteContexts = () => appContext.tabManager.getNoteContexts(); + + /** + * @method + * @returns {NoteContext[]} - returns all main contexts representing tabs + */ + this.getMainNoteContexts = () => appContext.tabManager.getMainNoteContexts(); + /** * See https://ckeditor.com/docs/ckeditor5/latest/api/module_core_editor_editor-Editor.html for documentation on the returned instance. * diff --git a/src/public/app/widgets/tab_row.js b/src/public/app/widgets/tab_row.js index 4172052d51..288dd02290 100644 --- a/src/public/app/widgets/tab_row.js +++ b/src/public/app/widgets/tab_row.js @@ -267,28 +267,8 @@ export default class TabRowWidget extends BasicWidget { } }); }); - - keyboardActionService.setupActionsForElement('window', $(document), this); - } - - goToTab(tabNumber) { - const index = tabNumber === Number.POSITIVE_INFINITY ? this.tabEls.length - 1 : tabNumber - 1; - const tab = this.tabEls[index]; - if (!tab) return; - appContext.tabManager.activateNoteContext(tab.getAttribute('data-ntx-id')); } - firstTabCommand() {this.goToTab(1);} - secondTabCommand() {this.goToTab(2);} - thirdTabCommand() {this.goToTab(3);} - fourthTabCommand() {this.goToTab(4);} - fifthTabCommand() {this.goToTab(5);} - sixthTabCommand() {this.goToTab(6);} - seventhTabCommand() {this.goToTab(7);} - eigthTabCommand() {this.goToTab(8);} - ninthTabCommand() {this.goToTab(9);} - lastTabCommand() {this.goToTab(Number.POSITIVE_INFINITY);} - setupStyle() { this.$style = $("