diff --git a/src/core/widgetconfig.cpp b/src/core/widgetconfig.cpp index 1dd2c3a0..d846dfb0 100644 --- a/src/core/widgetconfig.cpp +++ b/src/core/widgetconfig.cpp @@ -3,6 +3,7 @@ using namespace vnotex; #define READINT(key) readInt(appObj, userObj, (key)) +#define READBOOL(key) readBool(appObj, userObj, (key)) WidgetConfig::WidgetConfig(ConfigMgr *p_mgr, IConfig *p_topConfig) : IConfig(p_mgr, p_topConfig) @@ -24,6 +25,7 @@ void WidgetConfig::init(const QJsonObject &p_app, m_findAndReplaceOptions = static_cast(READINT(QStringLiteral("find_and_replace_options"))); m_noteExplorerViewOrder = READINT(QStringLiteral("note_explorer_view_order")); + m_noteExplorerRecycleBinNodeShown = READBOOL(QStringLiteral("note_explorer_recycle_bin_node_shown")); } QJsonObject WidgetConfig::toJson() const @@ -32,6 +34,7 @@ QJsonObject WidgetConfig::toJson() const obj[QStringLiteral("outline_auto_expanded_level")] = m_outlineAutoExpandedLevel; obj[QStringLiteral("find_and_replace_options")] = static_cast(m_findAndReplaceOptions); obj[QStringLiteral("note_explorer_view_order")] = m_noteExplorerViewOrder; + obj[QStringLiteral("note_explorer_recycle_bin_node_shown")] = m_noteExplorerRecycleBinNodeShown; return obj; } @@ -64,3 +67,13 @@ void WidgetConfig::setNoteExplorerViewOrder(int p_viewOrder) { updateConfig(m_noteExplorerViewOrder, p_viewOrder, this); } + +bool WidgetConfig::isNoteExplorerRecycleBinNodeShown() const +{ + return m_noteExplorerRecycleBinNodeShown; +} + +void WidgetConfig::setNoteExplorerRecycleBinNodeShown(bool p_shown) +{ + updateConfig(m_noteExplorerRecycleBinNodeShown, p_shown, this); +} diff --git a/src/core/widgetconfig.h b/src/core/widgetconfig.h index fa2631d9..3db92a4f 100644 --- a/src/core/widgetconfig.h +++ b/src/core/widgetconfig.h @@ -27,12 +27,17 @@ namespace vnotex int getNoteExplorerViewOrder() const; void setNoteExplorerViewOrder(int p_viewOrder); + bool isNoteExplorerRecycleBinNodeShown() const; + void setNoteExplorerRecycleBinNodeShown(bool p_shown); + private: int m_outlineAutoExpandedLevel = 6; FindOptions m_findAndReplaceOptions = FindOption::None; int m_noteExplorerViewOrder = 0; + + bool m_noteExplorerRecycleBinNodeShown = false; }; } diff --git a/src/data/core/vnotex.json b/src/data/core/vnotex.json index 8d1a306d..25e96370 100644 --- a/src/data/core/vnotex.json +++ b/src/data/core/vnotex.json @@ -287,6 +287,7 @@ "//comment" : "Default find options in FindAndReplace", "find_and_replace_options" : 16, "//comment" : "View order of the note explorer", - "note_explorer_view_order" : 0 + "note_explorer_view_order" : 0, + "note_explorer_recycle_bin_node_shown" : false } } diff --git a/src/widgets/notebookexplorer.cpp b/src/widgets/notebookexplorer.cpp index 40ad73ac..b611151b 100644 --- a/src/widgets/notebookexplorer.cpp +++ b/src/widgets/notebookexplorer.cpp @@ -64,6 +64,7 @@ void NotebookExplorer::setupUI() mainLayout->addWidget(m_selector); m_nodeExplorer = new NotebookNodeExplorer(this); + m_nodeExplorer->setRecycleBinNodeVisible(ConfigMgr::getInst().getWidgetConfig().isNoteExplorerRecycleBinNodeShown()); connect(m_nodeExplorer, &NotebookNodeExplorer::nodeActivated, &VNoteX::getInst(), &VNoteX::openNodeRequested); connect(m_nodeExplorer, &NotebookNodeExplorer::nodeAboutToMove, @@ -91,6 +92,18 @@ TitleBar *NotebookExplorer::setupTitleBar(QWidget *p_parent) }); } + { + auto btn = titleBar->addActionButton(QStringLiteral("recycle_bin.svg"), tr("Toggle Recycle Bin Node")); + btn->defaultAction()->setCheckable(true); + btn->defaultAction()->setChecked(ConfigMgr::getInst().getWidgetConfig().isNoteExplorerRecycleBinNodeShown()); + connect(btn, &QToolButton::triggered, + this, [this](QAction *p_act) { + const bool checked = p_act->isChecked(); + ConfigMgr::getInst().getWidgetConfig().setNoteExplorerRecycleBinNodeShown(checked); + m_nodeExplorer->setRecycleBinNodeVisible(checked); + }); + } + titleBar->addMenuAction(QStringLiteral("manage_notebooks.svg"), tr("&Manage Notebooks"), titleBar, diff --git a/src/widgets/notebooknodeexplorer.cpp b/src/widgets/notebooknodeexplorer.cpp index 479863c8..a142c696 100644 --- a/src/widgets/notebooknodeexplorer.cpp +++ b/src/widgets/notebooknodeexplorer.cpp @@ -388,6 +388,10 @@ void NotebookNodeExplorer::loadChildren(QTreeWidgetItem *p_item, Node *p_node, i void NotebookNodeExplorer::loadRecycleBinNode(Node *p_node) const { + if (!m_recycleBinNodeVisible) { + return; + } + auto item = new QTreeWidgetItem(); item->setWhatsThis(Column::Name, tr("Recycle bin of this notebook. Deleted files could be found here. " @@ -400,6 +404,10 @@ void NotebookNodeExplorer::loadRecycleBinNode(Node *p_node) const void NotebookNodeExplorer::loadRecycleBinNode(QTreeWidgetItem *p_item, Node *p_node, int p_level) const { + if (!m_recycleBinNodeVisible) { + return; + } + if (!p_node->isLoaded()) { p_node->load(); } @@ -1393,3 +1401,13 @@ void NotebookNodeExplorer::sortNodes(QVector> &p_nodes, int break; } } + +void NotebookNodeExplorer::setRecycleBinNodeVisible(bool p_visible) +{ + if (m_recycleBinNodeVisible == p_visible) { + return; + } + + m_recycleBinNodeVisible = p_visible; + reload(); +} diff --git a/src/widgets/notebooknodeexplorer.h b/src/widgets/notebooknodeexplorer.h index b623dbd8..1498b203 100644 --- a/src/widgets/notebooknodeexplorer.h +++ b/src/widgets/notebooknodeexplorer.h @@ -102,6 +102,8 @@ namespace vnotex void reload(); + void setRecycleBinNodeVisible(bool p_visible); + signals: void nodeActivated(Node *p_node, const QSharedPointer &p_paras); @@ -222,6 +224,8 @@ namespace vnotex QScopedPointer> m_navigationWrapper; + bool m_recycleBinNodeVisible = false; + static QIcon s_folderNodeIcon; static QIcon s_fileNodeIcon; static QIcon s_recycleBinNodeIcon;