removed dependency on note tree widget from app context

This commit is contained in:
zadam 2020-02-07 20:56:49 +01:00
parent 62e1284790
commit 6d912c4897
9 changed files with 32 additions and 54 deletions

View file

@ -36,6 +36,7 @@ window.glob.isDesktop = utils.isDesktop;
window.glob.isMobile = utils.isMobile;
// required for CKEditor image upload plugin
// FIXME
window.glob.getActiveNode = () => appContext.getMainNoteTree().getActiveNode();
window.glob.getHeaders = server.getHeaders;
window.glob.showAddLinkDialog = () => import('./dialogs/add_link.js').then(d => d.showDialog());

View file

@ -36,6 +36,7 @@ export async function showDialog(nodes) {
}
async function moveNotesTo(notePath) {
// FIXME
const targetNode = await appContext.getMainNoteTree().getNodeFromPath(notePath);
await treeChangesService.moveToParentNote(movedNodes, targetNode);

View file

@ -90,6 +90,7 @@ async function showTree() {
}
$detail.on("click", ".note-menu-button", async e => {
// FIXME
const node = appContext.getMainNoteTree().getActiveNode();
const branch = treeCache.getBranch(node.data.branchId);
const note = await treeCache.getNote(node.data.noteId);

View file

@ -1,4 +1,3 @@
import NoteTreeWidget from "../widgets/note_tree.js";
import TabContext from "./tab_context.js";
import server from "./server.js";
import treeCache from "./tree_cache.js";
@ -10,6 +9,7 @@ import utils from "./utils.js";
import treeService from "./tree.js";
import ZoomService from "./zoom.js";
import Layout from "../widgets/layout.js";
import SpacedUpdate from "./spaced_update.js";
class AppContext {
constructor(layout) {
@ -17,8 +17,17 @@ class AppContext {
this.components = [];
/** @type {TabContext[]} */
this.tabContexts = [];
this.tabsChangedTaskId = null;
this.activeTabId = null;
this.tabsUpdate = new SpacedUpdate(async () => {
const openTabs = this.tabContexts
.map(tc => tc.getTabState())
.filter(t => !!t);
await server.put('options', {
openTabs: JSON.stringify(openTabs)
});
});
}
async start() {
@ -88,18 +97,16 @@ class AppContext {
filteredTabs[0].active = true;
}
for (const tab of filteredTabs) {
const tabContext = this.openEmptyTab();
tabContext.setNote(tab.notePath);
this.tabsUpdate.allowUpdateWithoutChange(() => {
for (const tab of filteredTabs) {
const tabContext = this.openEmptyTab();
tabContext.setNote(tab.notePath);
if (tab.active) {
this.activateTab(tabContext.tabId);
if (tab.active) {
this.activateTab(tabContext.tabId);
}
}
}
// previous opening triggered task to save tab changes but these are bogus changes (this is init)
// so we'll cancel it
this.clearOpenTabsTask();
});
}
showWidgets() {
@ -201,13 +208,6 @@ class AppContext {
await tabContext.setNote(notePath);
}
/**
* @return {NoteTreeWidget}
*/
getMainNoteTree() {
return this.noteTreeWidget;
}
getTab(newTab, state) {
if (!this.getActiveTabContext() || newTab) {
// if it's a new tab explicitly by user then it's in background
@ -266,35 +266,8 @@ class AppContext {
this.saveOpenTabs();
}
async saveOpenTabs() {
const openTabs = [];
for (const tabContext of this.tabContexts) {
const tabState = tabContext.getTabState();
if (tabState) {
openTabs.push(tabState);
}
}
await server.put('options', {
openTabs: JSON.stringify(openTabs)
});
}
clearOpenTabsTask() {
if (this.tabsChangedTaskId) {
clearTimeout(this.tabsChangedTaskId);
}
}
openTabsChangedListener() {
// we don't want to send too many requests with tab changes so we always schedule task to do this in 1 seconds,
// but if there's any change in between, we cancel the old one and schedule new one
// so effectively we kind of wait until user stopped e.g. quickly switching tabs
this.clearOpenTabsTask();
this.tabsChangedTaskId = setTimeout(() => this.saveOpenTabs(), 1000);
this.tabsUpdate.scheduleUpdate();
}
activateTab(tabId) {

View file

@ -34,7 +34,7 @@ export default class DialogEventComponent extends Component {
}
async cloneNotesToListener() {
// probably should not happen here
// FIXME
const selectedOrActiveNodes = this.appContext.getMainNoteTree().getSelectedOrActiveNodes();
const noteIds = selectedOrActiveNodes.map(node => node.data.noteId);
@ -44,6 +44,7 @@ export default class DialogEventComponent extends Component {
}
async moveNotesToListener() {
// FIXME
const selectedOrActiveNodes = this.appContext.getMainNoteTree().getSelectedOrActiveNodes();
const d = await import("../dialogs/move_to.js");
@ -51,6 +52,7 @@ export default class DialogEventComponent extends Component {
}
async editBranchPrefixListener() {
// FIXME
const node = this.appContext.getMainNoteTree().getActiveNode();
const editBranchPrefixDialog = await import("../dialogs/branch_prefix.js");

View file

@ -78,17 +78,17 @@ export default class Entrypoints extends Component {
}
toggleNoteHoistingListener() {
const node = appContext.getMainNoteTree().getActiveNode();
const note = appContext.getActiveTabNote();
hoistedNoteService.getHoistedNoteId().then(async hoistedNoteId => {
if (node.data.noteId === hoistedNoteId) {
if (note.noteId === hoistedNoteId) {
hoistedNoteService.unhoist();
}
else {
const note = await treeCache.getNote(node.data.noteId);
const note = await treeCache.getNote(note.noteId);
if (note.type !== 'search') {
hoistedNoteService.setHoistedNoteId(node.data.noteId);
hoistedNoteService.setHoistedNoteId(note.noteId);
}
}
});

View file

@ -17,6 +17,7 @@ const helpText = `
</p>`;
async function refreshSearch() {
// FIXME
const activeNode = appContext.getMainNoteTree().getActiveNode();
activeNode.load(true);

View file

@ -35,8 +35,6 @@ export default class NoteTreeWidget extends TabAwareWidget {
window.glob.cutIntoNote = () => this.cutIntoNoteListener();
this.appContext.noteTreeWidget = this;
this.tree = null;
}

View file

@ -107,6 +107,7 @@ export default class SearchBoxWidget extends BasicWidget {
return;
}
// FIXME
let activeNode = appContext.getMainNoteTree().getActiveNode();
const parentNote = await treeCache.getNote(activeNode.data.noteId);