mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
refactored TabContext => NoteContext
This commit is contained in:
parent
1a0aaf4a30
commit
98dfc77195
@ -27,7 +27,7 @@ async function setupActionsForElement(scope, $el, component) {
|
|||||||
|
|
||||||
for (const action of actions) {
|
for (const action of actions) {
|
||||||
for (const shortcut of action.effectiveShortcuts) {
|
for (const shortcut of action.effectiveShortcuts) {
|
||||||
utils.bindElShortcut($el, shortcut, () => component.triggerCommand(action.actionName, {ntxId: appContext.tabManager.activeTabId}));
|
utils.bindElShortcut($el, shortcut, () => component.triggerCommand(action.actionName, {ntxId: appContext.tabManager.activeNtxId}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ async function setupActionsForElement(scope, $el, component) {
|
|||||||
getActionsForScope("window").then(actions => {
|
getActionsForScope("window").then(actions => {
|
||||||
for (const action of actions) {
|
for (const action of actions) {
|
||||||
for (const shortcut of action.effectiveShortcuts) {
|
for (const shortcut of action.effectiveShortcuts) {
|
||||||
utils.bindGlobalShortcut(shortcut, () => appContext.triggerCommand(action.actionName, {ntxId: appContext.tabManager.activeTabId}));
|
utils.bindGlobalShortcut(shortcut, () => appContext.triggerCommand(action.actionName, {ntxId: appContext.tabManager.activeNtxId}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -60,11 +60,11 @@ class NoteContext extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getAllSubNoteContexts() {
|
getSubContexts() {
|
||||||
return appContext.tabManager.noteContexts.filter(nc => nc.ntxId === this.ntxId || nc.mainNtxId === this.ntxId);
|
return appContext.tabManager.noteContexts.filter(nc => nc.ntxId === this.ntxId || nc.mainNtxId === this.ntxId);
|
||||||
}
|
}
|
||||||
|
|
||||||
getMainNoteContext() {
|
getMainContext() {
|
||||||
if (this.mainNtxId) {
|
if (this.mainNtxId) {
|
||||||
return appContext.tabManager.getNoteContextById(this.mainNtxId);
|
return appContext.tabManager.getNoteContextById(this.mainNtxId);
|
||||||
}
|
}
|
||||||
@ -138,7 +138,7 @@ class NoteContext extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isActive() {
|
isActive() {
|
||||||
return appContext.tabManager.activeTabId === this.ntxId;
|
return appContext.tabManager.activeNtxId === this.ntxId;
|
||||||
}
|
}
|
||||||
|
|
||||||
getTabState() {
|
getTabState() {
|
||||||
|
@ -12,7 +12,7 @@ export default class TabManager extends Component {
|
|||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.activeTabId = null;
|
this.activeNtxId = null;
|
||||||
|
|
||||||
this.tabsUpdate = new SpacedUpdate(async () => {
|
this.tabsUpdate = new SpacedUpdate(async () => {
|
||||||
if (!appContext.isMainWindow) {
|
if (!appContext.isMainWindow) {
|
||||||
@ -156,8 +156,15 @@ export default class TabManager extends Component {
|
|||||||
|
|
||||||
/** @returns {NoteContext} */
|
/** @returns {NoteContext} */
|
||||||
getActiveContext() {
|
getActiveContext() {
|
||||||
return this.activeTabId
|
return this.activeNtxId
|
||||||
? this.getNoteContextById(this.activeTabId)
|
? this.getNoteContextById(this.activeNtxId)
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @returns {NoteContext} */
|
||||||
|
getActiveMainContext() {
|
||||||
|
return this.activeNtxId
|
||||||
|
? this.getNoteContextById(this.activeNtxId).getMainContext()
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,11 +278,11 @@ export default class TabManager extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
activateNoteContext(ntxId, triggerEvent = true) {
|
activateNoteContext(ntxId, triggerEvent = true) {
|
||||||
if (ntxId === this.activeTabId) {
|
if (ntxId === this.activeNtxId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.activeTabId = ntxId;
|
this.activeNtxId = ntxId;
|
||||||
|
|
||||||
if (triggerEvent) {
|
if (triggerEvent) {
|
||||||
this.triggerEvent('activeTabChanged', {
|
this.triggerEvent('activeTabChanged', {
|
||||||
@ -289,19 +296,19 @@ export default class TabManager extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async removeNoteContext(ntxId) {
|
async removeNoteContext(ntxId) {
|
||||||
const mainNoteContextToRemove = this.getNoteContextById(ntxId).getMainNoteContext();
|
const mainNoteContextToRemove = this.getNoteContextById(ntxId).getMainContext();
|
||||||
|
|
||||||
// close dangling autocompletes after closing the tab
|
// close dangling autocompletes after closing the tab
|
||||||
$(".aa-input").autocomplete("close");
|
$(".aa-input").autocomplete("close");
|
||||||
|
|
||||||
const ntxIdsToRemove = mainNoteContextToRemove.getAllSubNoteContexts().map(nc => nc.ntxId);
|
const ntxIdsToRemove = mainNoteContextToRemove.getSubContexts().map(nc => nc.ntxId);
|
||||||
|
|
||||||
await this.triggerEvent('beforeTabRemove', { ntxIds: ntxIdsToRemove });
|
await this.triggerEvent('beforeTabRemove', { ntxIds: ntxIdsToRemove });
|
||||||
|
|
||||||
if (this.mainNoteContexts.length <= 1) {
|
if (this.mainNoteContexts.length <= 1) {
|
||||||
await this.openAndActivateEmptyTab();
|
await this.openAndActivateEmptyTab();
|
||||||
}
|
}
|
||||||
else if (ntxIdsToRemove.includes(this.activeTabId)) {
|
else if (ntxIdsToRemove.includes(this.activeNtxId)) {
|
||||||
const idx = this.mainNoteContexts.findIndex(nc => nc.ntxId === mainNoteContextToRemove.ntxId);
|
const idx = this.mainNoteContexts.findIndex(nc => nc.ntxId === mainNoteContextToRemove.ntxId);
|
||||||
|
|
||||||
if (idx === this.mainNoteContexts.length - 1) {
|
if (idx === this.mainNoteContexts.length - 1) {
|
||||||
@ -332,21 +339,21 @@ export default class TabManager extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
activateNextTabCommand() {
|
activateNextTabCommand() {
|
||||||
const oldIdx = this.mainNoteContexts.findIndex(nc => nc.ntxId === this.activeTabId);
|
const oldIdx = this.mainNoteContexts.findIndex(nc => nc.ntxId === this.activeNtxId);
|
||||||
const newActiveTabId = this.mainNoteContexts[oldIdx === this.noteContexts.length - 1 ? 0 : oldIdx + 1].ntxId;
|
const newActiveTabId = this.mainNoteContexts[oldIdx === this.noteContexts.length - 1 ? 0 : oldIdx + 1].ntxId;
|
||||||
|
|
||||||
this.activateNoteContext(newActiveTabId);
|
this.activateNoteContext(newActiveTabId);
|
||||||
}
|
}
|
||||||
|
|
||||||
activatePreviousTabCommand() {
|
activatePreviousTabCommand() {
|
||||||
const oldIdx = this.mainNoteContexts.findIndex(nc => nc.ntxId === this.activeTabId);
|
const oldIdx = this.mainNoteContexts.findIndex(nc => nc.ntxId === this.activeNtxId);
|
||||||
const newActiveTabId = this.mainNoteContexts[oldIdx === 0 ? this.noteContexts.length - 1 : oldIdx - 1].ntxId;
|
const newActiveTabId = this.mainNoteContexts[oldIdx === 0 ? this.noteContexts.length - 1 : oldIdx - 1].ntxId;
|
||||||
|
|
||||||
this.activateNoteContext(newActiveTabId);
|
this.activateNoteContext(newActiveTabId);
|
||||||
}
|
}
|
||||||
|
|
||||||
closeActiveTabCommand() {
|
closeActiveTabCommand() {
|
||||||
this.removeNoteContext(this.activeTabId);
|
this.removeNoteContext(this.activeNtxId);
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeUnloadEvent() {
|
beforeUnloadEvent() {
|
||||||
|
@ -49,13 +49,14 @@ export default class PaneContainer extends FlexContainer {
|
|||||||
toggleInt(show) {} // not needed
|
toggleInt(show) {} // not needed
|
||||||
|
|
||||||
toggleExt(show) {
|
toggleExt(show) {
|
||||||
const activeTabId = appContext.tabManager.getActiveContext().getMainNoteContext().ntxId;
|
const activeMainContext = appContext.tabManager.getActiveMainContext();
|
||||||
|
const activeNtxId = activeMainContext ? activeMainContext.ntxId : null;
|
||||||
|
|
||||||
for (const ntxId in this.widgets) {
|
for (const ntxId in this.widgets) {
|
||||||
const noteContext = appContext.tabManager.getNoteContextById(ntxId);
|
const noteContext = appContext.tabManager.getNoteContextById(ntxId);
|
||||||
|
|
||||||
const widget = this.widgets[ntxId];
|
const widget = this.widgets[ntxId];
|
||||||
widget.toggleExt(show && activeTabId && [noteContext.ntxId, noteContext.mainNtxId].includes(activeTabId));
|
widget.toggleExt(show && activeNtxId && [noteContext.ntxId, noteContext.mainNtxId].includes(activeNtxId));
|
||||||
|
|
||||||
if (!widget.hasBeenAlreadyShown) {
|
if (!widget.hasBeenAlreadyShown) {
|
||||||
widget.handleEvent('activeTabChanged', {noteContext});
|
widget.handleEvent('activeTabChanged', {noteContext});
|
||||||
@ -79,11 +80,11 @@ export default class PaneContainer extends FlexContainer {
|
|||||||
|
|
||||||
const promises = [];
|
const promises = [];
|
||||||
|
|
||||||
if (appContext.tabManager.getActiveContext().getMainNoteContext() === data.noteContext.getMainNoteContext()) {
|
if (appContext.tabManager.getActiveMainContext() === data.noteContext.getMainContext()) {
|
||||||
promises.push(widget.handleEvent('activeTabChanged', data));
|
promises.push(widget.handleEvent('activeTabChanged', data));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const subNoteContext of data.noteContext.getMainNoteContext().getAllSubNoteContexts()) {
|
for (const subNoteContext of data.noteContext.getMainContext().getSubContexts()) {
|
||||||
const subWidget = this.widgets[subNoteContext.ntxId];
|
const subWidget = this.widgets[subNoteContext.ntxId];
|
||||||
|
|
||||||
if (!subWidget) {
|
if (!subWidget) {
|
||||||
@ -112,7 +113,7 @@ export default class PaneContainer extends FlexContainer {
|
|||||||
if (name === 'activeTabChanged') {
|
if (name === 'activeTabChanged') {
|
||||||
const promises = [];
|
const promises = [];
|
||||||
|
|
||||||
for (const subNoteContext of data.noteContext.getMainNoteContext().getAllSubNoteContexts()) {
|
for (const subNoteContext of data.noteContext.getMainContext().getSubContexts()) {
|
||||||
console.log("subNoteContext", subNoteContext);
|
console.log("subNoteContext", subNoteContext);
|
||||||
|
|
||||||
const widget = this.widgets[subNoteContext.ntxId];
|
const widget = this.widgets[subNoteContext.ntxId];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user