From 877001587b5f3f244b6d8e68d9936fb0f197fea7 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Fri, 26 Feb 2021 20:26:43 +0800 Subject: [PATCH] small fixes --- src/core/notebook/node.cpp | 26 +++++++++++++++++++ src/core/notebook/node.h | 2 ++ src/data/extra/web/css/outline.css | 1 + src/data/extra/web/js/outline.js | 20 +++++++------- .../dialogs/folderpropertiesdialog.cpp | 4 +-- src/widgets/dialogs/notepropertiesdialog.cpp | 4 +-- src/widgets/notebooknodeexplorer.cpp | 23 +++++++++------- 7 files changed, 57 insertions(+), 23 deletions(-) diff --git a/src/core/notebook/node.cpp b/src/core/notebook/node.cpp index 47e4aada..51a19a1a 100644 --- a/src/core/notebook/node.cpp +++ b/src/core/notebook/node.cpp @@ -301,3 +301,29 @@ INotebookBackend *Node::getBackend() const { return m_notebook->getBackend().data(); } + +bool Node::canRename(const QString &p_newName) const +{ + if (p_newName == m_name) { + return true; + } + + if (p_newName.isEmpty()) { + return false; + } + + Q_ASSERT(m_parent); + if (p_newName.toLower() == m_name.toLower()) { + if (m_parent->containsChild(p_newName, true)) { + return false; + } else { + return true; + } + } + + if (m_parent->containsChild(p_newName, false)) { + return false; + } + + return true; +} diff --git a/src/core/notebook/node.h b/src/core/notebook/node.h index 70fb5283..acd79f8f 100644 --- a/src/core/notebook/node.h +++ b/src/core/notebook/node.h @@ -156,6 +156,8 @@ namespace vnotex INotebookBackend *getBackend() const; + bool canRename(const QString &p_newName) const; + static bool isAncestor(const Node *p_ancestor, const Node *p_child); protected: diff --git a/src/data/extra/web/css/outline.css b/src/data/extra/web/css/outline.css index b73b2ba1..f632c66e 100644 --- a/src/data/extra/web/css/outline.css +++ b/src/data/extra/web/css/outline.css @@ -135,6 +135,7 @@ .section-nav a { color: inherit !important; + white-space: nowrap; } .row { diff --git a/src/data/extra/web/js/outline.js b/src/data/extra/web/js/outline.js index 748f9f85..88548b47 100644 --- a/src/data/extra/web/js/outline.js +++ b/src/data/extra/web/js/outline.js @@ -1,4 +1,4 @@ -var toc = []; +var vxOutlineToc = []; var setVisible = function(node, visible) { var cl = 'hide-none'; @@ -61,32 +61,32 @@ window.addEventListener('load', function() { // Fetch the outline. var headers = postContent.querySelectorAll("h1, h2, h3, h4, h5, h6"); - toc = []; + vxOutlineToc = []; for (var i = 0; i < headers.length; ++i) { var header = headers[i]; - toc.push({ + vxOutlineToc.push({ level: parseInt(header.tagName.substr(1)), anchor: header.id, title: escapeHtml(header.textContent) }); } - if (toc.length == 0) { + if (vxOutlineToc.length == 0) { setOutlinePanelVisible(false); setVisible(floatingContainer, false); return; } - var baseLevel = baseLevelOfToc(toc); - var tocTree = tocToTree(toPerfectToc(toc, baseLevel), baseLevel); + var baseLevel = baseLevelOfToc(vxOutlineToc); + var tocTree = tocToTree(toPerfectToc(vxOutlineToc, baseLevel), baseLevel); outlineContent.innerHTML = tocTree; setOutlinePanelVisible(true); setVisible(floatingContainer, true); }); -// Return the topest level of @toc, starting from 1. +// Return the topest level of @vxOutlineToc, starting from 1. var baseLevelOfToc = function(p_toc) { var level = -1; for (i in p_toc) { @@ -130,7 +130,7 @@ var toPerfectToc = function(p_toc, p_baseLevel) { }; var itemToHtml = function(item) { - return '' + item.title + ''; + return '' + item.title + ''; }; // Turn a perfect toc to a tree using