refactoring, tab switching handling shouldn't be on the widget level

This commit is contained in:
zadam 2023-09-13 09:01:55 +02:00
parent 7848c7e319
commit d46801ff1f
9 changed files with 553 additions and 52 deletions

View File

@ -1388,7 +1388,7 @@ larger amounts of data and generally not accessible to the user.</div>
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="becca_entities_battachment.js.html">becca/entities/battachment.js</a>, <a href="becca_entities_battachment.js.html#line134">line 134</a>
<a href="becca_entities_battachment.js.html">becca/entities/battachment.js</a>, <a href="becca_entities_battachment.js.html#line139">line 139</a>
</li></ul></dd>
@ -1770,7 +1770,7 @@ larger amounts of data and generally not accessible to the user.</div>
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="becca_entities_battachment.js.html">becca/entities/battachment.js</a>, <a href="becca_entities_battachment.js.html#line119">line 119</a>
<a href="becca_entities_battachment.js.html">becca/entities/battachment.js</a>, <a href="becca_entities_battachment.js.html#line124">line 124</a>
</li></ul></dd>
@ -2815,7 +2815,7 @@ This is a low-level method, for notes and branches use `note.deleteNote()` and '
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="becca_entities_battachment.js.html">becca/entities/battachment.js</a>, <a href="becca_entities_battachment.js.html#line129">line 129</a>
<a href="becca_entities_battachment.js.html">becca/entities/battachment.js</a>, <a href="becca_entities_battachment.js.html#line134">line 134</a>
</li></ul></dd>

View File

@ -132,7 +132,12 @@ class BAttachment extends AbstractBeccaEntity {
}
decrypt() {
if (this.isProtected &amp;&amp; !this.isDecrypted &amp;&amp; protectedSessionService.isProtectedSessionAvailable()) {
if (!this.isProtected || !this.attachmentId) {
this.isDecrypted = true;
return;
}
if (!this.isDecrypted &amp;&amp; protectedSessionService.isProtectedSessionAvailable()) {
try {
this.title = protectedSessionService.decryptString(this.title);
this.isDecrypted = true;

View File

@ -1738,7 +1738,7 @@ See <a href="https://day.js.org">https://day.js.org</a> for documentation
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line490">line 490</a>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line514">line 514</a>
</li></ul></dd>
@ -2469,7 +2469,7 @@ See <a href="https://day.js.org">https://day.js.org</a> for documentation
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line534">line 534</a>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line558">line 558</a>
</li></ul></dd>
@ -2624,7 +2624,7 @@ See <a href="https://day.js.org">https://day.js.org</a> for documentation
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line526">line 526</a>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line550">line 550</a>
</li></ul></dd>
@ -2682,6 +2682,112 @@ See <a href="https://day.js.org">https://day.js.org</a> for documentation
<h4 class="name" id="getActiveContext"><span class="type-signature"></span>getActiveContext<span class="signature">()</span><span class="type-signature"> &rarr; {NoteContext}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line360">line 360</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
- returns active context (split)
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">NoteContext</span>
</dd>
</dl>
<h4 class="name" id="getActiveContextCodeEditor"><span class="type-signature"></span>getActiveContextCodeEditor<span class="signature">()</span><span class="type-signature"> &rarr; {Promise.&lt;CodeMirror>}</span></h4>
@ -2734,7 +2840,7 @@ See <a href="https://day.js.org">https://day.js.org</a> for documentation
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line370">line 370</a>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line394">line 394</a>
</li></ul></dd>
@ -2869,7 +2975,7 @@ See <a href="https://day.js.org">https://day.js.org</a> for documentation
<div class="param-desc">
active note (loaded into right pane)
active note (loaded into center pane)
</div>
@ -2946,7 +3052,7 @@ See <a href="https://day.js.org">https://day.js.org</a> for documentation
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line385">line 385</a>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line409">line 409</a>
</li></ul></dd>
@ -3056,7 +3162,7 @@ See <a href="https://day.js.org">https://day.js.org</a> for documentation
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line362">line 362</a>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line386">line 386</a>
</li></ul></dd>
@ -3114,6 +3220,112 @@ See <a href="https://day.js.org">https://day.js.org</a> for documentation
<h4 class="name" id="getActiveMainContext"><span class="type-signature"></span>getActiveMainContext<span class="signature">()</span><span class="type-signature"> &rarr; {NoteContext}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line366">line 366</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
- returns active main context (first split in a tab, represents the tab as a whole)
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">NoteContext</span>
</dd>
</dl>
<h4 class="name" id="getActiveNoteDetailWidget"><span class="type-signature"></span>getActiveNoteDetailWidget<span class="signature">()</span><span class="type-signature"> &rarr; {Promise.&lt;NoteDetailWidget>}</span></h4>
@ -3167,7 +3379,7 @@ implementation of actual widget type.
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line379">line 379</a>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line403">line 403</a>
</li></ul></dd>
@ -3322,7 +3534,7 @@ implementation of actual widget type.
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line394">line 394</a>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line418">line 418</a>
</li></ul></dd>
@ -3477,7 +3689,7 @@ implementation of actual widget type.
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line438">line 438</a>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line462">line 462</a>
</li></ul></dd>
@ -3638,6 +3850,112 @@ if some action needs to happen on only one specific instance.
<h4 class="name" id="getMainNoteContexts"><span class="type-signature"></span>getMainNoteContexts<span class="signature">()</span><span class="type-signature"> &rarr; {Array.&lt;NoteContext>}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line378">line 378</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
- returns all main contexts representing tabs
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Array.&lt;NoteContext></span>
</dd>
</dl>
<h4 class="name" id="getMonthNote"><span class="type-signature"></span>getMonthNote<span class="signature">(month)</span><span class="type-signature"> &rarr; {Promise.&lt;<a href="FNote.html">FNote</a>>}</span></h4>
@ -3739,7 +4057,7 @@ if some action needs to happen on only one specific instance.
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line456">line 456</a>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line480">line 480</a>
</li></ul></dd>
@ -3949,6 +4267,112 @@ if some action needs to happen on only one specific instance.
<h4 class="name" id="getNoteContexts"><span class="type-signature"></span>getNoteContexts<span class="signature">()</span><span class="type-signature"> &rarr; {Array.&lt;NoteContext>}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line372">line 372</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
- returns all note contexts (splits) in all tabs
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Array.&lt;NoteContext></span>
</dd>
</dl>
<h4 class="name" id="getNotes"><span class="type-signature"></span>getNotes<span class="signature">(noteIds, silentNotFoundError<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise.&lt;Array.&lt;<a href="FNote.html">FNote</a>>>}</span></h4>
@ -4202,7 +4626,7 @@ otherwise (by e.g. createLink())
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line429">line 429</a>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line453">line 453</a>
</li></ul></dd>
@ -4357,7 +4781,7 @@ otherwise (by e.g. createLink())
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line447">line 447</a>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line471">line 471</a>
</li></ul></dd>
@ -4512,7 +4936,7 @@ otherwise (by e.g. createLink())
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line465">line 465</a>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line489">line 489</a>
</li></ul></dd>
@ -4662,7 +5086,7 @@ otherwise (by e.g. createLink())
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line545">line 545</a>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line569">line 569</a>
</li></ul></dd>
@ -5347,7 +5771,7 @@ otherwise (by e.g. createLink())
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line409">line 409</a>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line433">line 433</a>
</li></ul></dd>
@ -5521,7 +5945,7 @@ otherwise (by e.g. createLink())
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line419">line 419</a>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line443">line 443</a>
</li></ul></dd>
@ -5676,7 +6100,7 @@ otherwise (by e.g. createLink())
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line519">line 519</a>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line543">line 543</a>
</li></ul></dd>
@ -5830,7 +6254,7 @@ otherwise (by e.g. createLink())
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line510">line 510</a>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line534">line 534</a>
</li></ul></dd>
@ -6620,7 +7044,7 @@ Internally this serializes the anonymous function into string and sends it to ba
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line474">line 474</a>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line498">line 498</a>
</li></ul></dd>
@ -6771,7 +7195,7 @@ Internally this serializes the anonymous function into string and sends it to ba
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line401">line 401</a>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line425">line 425</a>
</li></ul></dd>
@ -7475,7 +7899,7 @@ Typical use case is when a new note has been created, we should wait until it is
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line502">line 502</a>
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line526">line 526</a>
</li></ul></dd>

View File

@ -377,10 +377,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.
*

View File

@ -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 {

View File

@ -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);
}
}

View File

@ -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()

View File

@ -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.
*

View File

@ -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 = $("<style>");
this.$widget.append(this.$style);
@ -637,7 +617,7 @@ export default class TabRowWidget extends BasicWidget {
// update tab id for the new main context
this.getTabById(oldMainNtxId).attr("data-ntx-id", newMainNtxId);
this.updateTabById(newMainNtxId);
this.updateTabById(newMainNtxId);
}
contextsReopenedEvent({mainNtxId, tabPosition}) {