From 841420360eab1f8fe321486f4ddd4ef821babf98 Mon Sep 17 00:00:00 2001 From: azivner Date: Sat, 15 Dec 2018 20:29:08 +0100 Subject: [PATCH] quick unhoist link/button --- src/public/javascripts/services/bootstrap.js | 3 +++ src/public/javascripts/services/hoisted_note.js | 7 ++++++- src/public/javascripts/services/tree.js | 11 ++++++++++- src/public/javascripts/services/tree_context_menu.js | 2 +- src/public/javascripts/services/tree_keybindings.js | 2 +- src/public/stylesheets/style.css | 6 ++++++ 6 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/public/javascripts/services/bootstrap.js b/src/public/javascripts/services/bootstrap.js index 5c9a10d0e..a15072a17 100644 --- a/src/public/javascripts/services/bootstrap.js +++ b/src/public/javascripts/services/bootstrap.js @@ -32,6 +32,7 @@ import tooltip from './tooltip.js'; import bundle from "./bundle.js"; import treeCache from "./tree_cache.js"; import libraryLoader from "./library_loader.js"; +import hoistedNoteService from './hoisted_note.js'; // required for CKEditor image upload plugin window.glob.getCurrentNode = treeService.getCurrentNode; @@ -84,6 +85,8 @@ $(document).on("click", "button[data-help-page]", e => { $("#logout-button").toggle(!utils.isElectron()); +$("#tree").on("click", ".unhoist-button", hoistedNoteService.unhoist); + if (utils.isElectron()) { require('electron').ipcRenderer.on('create-day-sub-note', async function(event, parentNoteId) { // this might occur when day note had to be created diff --git a/src/public/javascripts/services/hoisted_note.js b/src/public/javascripts/services/hoisted_note.js index 2a64ad822..db567239d 100644 --- a/src/public/javascripts/services/hoisted_note.js +++ b/src/public/javascripts/services/hoisted_note.js @@ -22,7 +22,12 @@ async function setHoistedNoteId(noteId) { await tree.reload(); } +async function unhoist() { + await setHoistedNoteId('root'); +} + export default { getHoistedNoteId, - setHoistedNoteId + setHoistedNoteId, + unhoist } \ No newline at end of file diff --git a/src/public/javascripts/services/tree.js b/src/public/javascripts/services/tree.js index 7389f733f..4ad1fcc8b 100644 --- a/src/public/javascripts/services/tree.js +++ b/src/public/javascripts/services/tree.js @@ -122,7 +122,7 @@ async function activateNote(notePath, newNote) { } // unhoist so we can activate the note - await hoistedNoteService.setHoistedNoteId('root'); + await hoistedNoteService.unhoist(); } if (glob.activeDialog) { @@ -417,6 +417,15 @@ function initFancyTree(tree) { }, clones: { highlightActiveClones: true + }, + renderNode: async function (event, data) { + const node = data.node; + + if (node.data.noteId !== 'root' && node.data.noteId === await hoistedNoteService.getHoistedNoteId()) { + const unhoistButton = $('  (unhoist)'); + + $(node.span).append(unhoistButton); + } } }); diff --git a/src/public/javascripts/services/tree_context_menu.js b/src/public/javascripts/services/tree_context_menu.js index d8d1f05fc..03d5a0425 100644 --- a/src/public/javascripts/services/tree_context_menu.js +++ b/src/public/javascripts/services/tree_context_menu.js @@ -215,7 +215,7 @@ function selectContextMenuItem(event, cmd) { hoistedNoteService.setHoistedNoteId(node.data.noteId); } else if (cmd === "unhoist") { - hoistedNoteService.setHoistedNoteId('root'); + hoistedNoteService.unhoist(); } else { messagingService.logError("Unknown command: " + cmd); diff --git a/src/public/javascripts/services/tree_keybindings.js b/src/public/javascripts/services/tree_keybindings.js index b3c8fca26..b5c63ca73 100644 --- a/src/public/javascripts/services/tree_keybindings.js +++ b/src/public/javascripts/services/tree_keybindings.js @@ -117,7 +117,7 @@ const keyBindings = { "ctrl+h": node => { hoistedNoteService.getHoistedNoteId().then(hoistedNoteId => { if (node.data.noteId === hoistedNoteId) { - hoistedNoteService.setHoistedNoteId('root'); + hoistedNoteService.unhoist(); } else { hoistedNoteService.setHoistedNoteId(node.data.noteId); diff --git a/src/public/stylesheets/style.css b/src/public/stylesheets/style.css index d33276dcf..420ba1bd1 100644 --- a/src/public/stylesheets/style.css +++ b/src/public/stylesheets/style.css @@ -698,4 +698,10 @@ div[data-notify="container"] { #export-form .form-check-label { padding: 2px; +} + +.unhoist-button { + text-decoration: underline !important; + color: blue !important; + cursor: pointer !important; } \ No newline at end of file