2019-08-25 23:36:13 +08:00
|
|
|
import optionsService from './options.js';
|
2018-12-12 04:53:56 +08:00
|
|
|
import server from "./server.js";
|
2018-12-13 03:39:56 +08:00
|
|
|
import tree from "./tree.js";
|
2019-05-12 01:27:33 +08:00
|
|
|
import noteDetailService from "./note_detail.js";
|
2018-12-12 04:53:56 +08:00
|
|
|
|
2019-11-05 05:41:06 +08:00
|
|
|
let hoistedNoteId = 'root';
|
2018-12-12 04:53:56 +08:00
|
|
|
|
2019-08-25 23:36:13 +08:00
|
|
|
optionsService.waitForOptions().then(options => {
|
2019-08-23 05:31:02 +08:00
|
|
|
hoistedNoteId = options.get('hoistedNoteId');
|
2018-12-12 04:53:56 +08:00
|
|
|
});
|
|
|
|
|
2019-11-05 05:41:06 +08:00
|
|
|
function getHoistedNoteNoPromise() {
|
|
|
|
return hoistedNoteId;
|
|
|
|
}
|
|
|
|
|
2018-12-12 04:53:56 +08:00
|
|
|
async function getHoistedNoteId() {
|
2019-08-25 23:36:13 +08:00
|
|
|
await optionsService.waitForOptions();
|
2018-12-12 04:53:56 +08:00
|
|
|
|
|
|
|
return hoistedNoteId;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function setHoistedNoteId(noteId) {
|
2019-05-12 01:27:33 +08:00
|
|
|
if (noteId !== 'root') {
|
2020-01-12 19:48:17 +08:00
|
|
|
await appContext.filterTabs(noteId);
|
2019-05-12 01:27:33 +08:00
|
|
|
}
|
|
|
|
|
2019-05-12 03:27:27 +08:00
|
|
|
hoistedNoteId = noteId;
|
|
|
|
|
2018-12-12 04:53:56 +08:00
|
|
|
await server.put('options/hoistedNoteId/' + noteId);
|
2018-12-13 03:39:56 +08:00
|
|
|
|
|
|
|
await tree.reload();
|
2019-05-22 04:07:08 +08:00
|
|
|
|
2020-01-12 19:30:30 +08:00
|
|
|
const activeTabContext = appContext.getActiveTabContext();
|
2019-05-22 04:07:08 +08:00
|
|
|
|
|
|
|
if (activeTabContext) {
|
|
|
|
await tree.activateNote(activeTabContext.notePath);
|
|
|
|
}
|
2018-12-12 04:53:56 +08:00
|
|
|
}
|
|
|
|
|
2018-12-16 03:29:08 +08:00
|
|
|
async function unhoist() {
|
|
|
|
await setHoistedNoteId('root');
|
|
|
|
}
|
|
|
|
|
2019-04-17 03:40:04 +08:00
|
|
|
async function isTopLevelNode(node) {
|
|
|
|
return await isRootNode(node.getParent());
|
|
|
|
}
|
|
|
|
|
|
|
|
async function isRootNode(node) {
|
|
|
|
// even though check for 'root' should not be necessary, we keep it just in case
|
|
|
|
return node.data.noteId === "root"
|
|
|
|
|| node.data.noteId === await getHoistedNoteId();
|
|
|
|
}
|
|
|
|
|
2018-12-12 04:53:56 +08:00
|
|
|
export default {
|
|
|
|
getHoistedNoteId,
|
2019-11-05 05:41:06 +08:00
|
|
|
getHoistedNoteNoPromise,
|
2018-12-16 03:29:08 +08:00
|
|
|
setHoistedNoteId,
|
2019-04-17 03:40:04 +08:00
|
|
|
unhoist,
|
|
|
|
isTopLevelNode,
|
|
|
|
isRootNode
|
2018-12-12 04:53:56 +08:00
|
|
|
}
|