add button in note explorer to toggle recycle bin node

This commit is contained in:
Le Tan 2021-02-25 21:01:08 +08:00
parent f51a6510aa
commit c7c6d41eff
6 changed files with 55 additions and 1 deletions

View File

@ -3,6 +3,7 @@
using namespace vnotex; using namespace vnotex;
#define READINT(key) readInt(appObj, userObj, (key)) #define READINT(key) readInt(appObj, userObj, (key))
#define READBOOL(key) readBool(appObj, userObj, (key))
WidgetConfig::WidgetConfig(ConfigMgr *p_mgr, IConfig *p_topConfig) WidgetConfig::WidgetConfig(ConfigMgr *p_mgr, IConfig *p_topConfig)
: IConfig(p_mgr, p_topConfig) : IConfig(p_mgr, p_topConfig)
@ -24,6 +25,7 @@ void WidgetConfig::init(const QJsonObject &p_app,
m_findAndReplaceOptions = static_cast<FindOptions>(READINT(QStringLiteral("find_and_replace_options"))); m_findAndReplaceOptions = static_cast<FindOptions>(READINT(QStringLiteral("find_and_replace_options")));
m_noteExplorerViewOrder = READINT(QStringLiteral("note_explorer_view_order")); m_noteExplorerViewOrder = READINT(QStringLiteral("note_explorer_view_order"));
m_noteExplorerRecycleBinNodeShown = READBOOL(QStringLiteral("note_explorer_recycle_bin_node_shown"));
} }
QJsonObject WidgetConfig::toJson() const QJsonObject WidgetConfig::toJson() const
@ -32,6 +34,7 @@ QJsonObject WidgetConfig::toJson() const
obj[QStringLiteral("outline_auto_expanded_level")] = m_outlineAutoExpandedLevel; obj[QStringLiteral("outline_auto_expanded_level")] = m_outlineAutoExpandedLevel;
obj[QStringLiteral("find_and_replace_options")] = static_cast<int>(m_findAndReplaceOptions); obj[QStringLiteral("find_and_replace_options")] = static_cast<int>(m_findAndReplaceOptions);
obj[QStringLiteral("note_explorer_view_order")] = m_noteExplorerViewOrder; obj[QStringLiteral("note_explorer_view_order")] = m_noteExplorerViewOrder;
obj[QStringLiteral("note_explorer_recycle_bin_node_shown")] = m_noteExplorerRecycleBinNodeShown;
return obj; return obj;
} }
@ -64,3 +67,13 @@ void WidgetConfig::setNoteExplorerViewOrder(int p_viewOrder)
{ {
updateConfig(m_noteExplorerViewOrder, p_viewOrder, this); 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);
}

View File

@ -27,12 +27,17 @@ namespace vnotex
int getNoteExplorerViewOrder() const; int getNoteExplorerViewOrder() const;
void setNoteExplorerViewOrder(int p_viewOrder); void setNoteExplorerViewOrder(int p_viewOrder);
bool isNoteExplorerRecycleBinNodeShown() const;
void setNoteExplorerRecycleBinNodeShown(bool p_shown);
private: private:
int m_outlineAutoExpandedLevel = 6; int m_outlineAutoExpandedLevel = 6;
FindOptions m_findAndReplaceOptions = FindOption::None; FindOptions m_findAndReplaceOptions = FindOption::None;
int m_noteExplorerViewOrder = 0; int m_noteExplorerViewOrder = 0;
bool m_noteExplorerRecycleBinNodeShown = false;
}; };
} }

View File

@ -287,6 +287,7 @@
"//comment" : "Default find options in FindAndReplace", "//comment" : "Default find options in FindAndReplace",
"find_and_replace_options" : 16, "find_and_replace_options" : 16,
"//comment" : "View order of the note explorer", "//comment" : "View order of the note explorer",
"note_explorer_view_order" : 0 "note_explorer_view_order" : 0,
"note_explorer_recycle_bin_node_shown" : false
} }
} }

View File

@ -64,6 +64,7 @@ void NotebookExplorer::setupUI()
mainLayout->addWidget(m_selector); mainLayout->addWidget(m_selector);
m_nodeExplorer = new NotebookNodeExplorer(this); m_nodeExplorer = new NotebookNodeExplorer(this);
m_nodeExplorer->setRecycleBinNodeVisible(ConfigMgr::getInst().getWidgetConfig().isNoteExplorerRecycleBinNodeShown());
connect(m_nodeExplorer, &NotebookNodeExplorer::nodeActivated, connect(m_nodeExplorer, &NotebookNodeExplorer::nodeActivated,
&VNoteX::getInst(), &VNoteX::openNodeRequested); &VNoteX::getInst(), &VNoteX::openNodeRequested);
connect(m_nodeExplorer, &NotebookNodeExplorer::nodeAboutToMove, 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"), titleBar->addMenuAction(QStringLiteral("manage_notebooks.svg"),
tr("&Manage Notebooks"), tr("&Manage Notebooks"),
titleBar, titleBar,

View File

@ -388,6 +388,10 @@ void NotebookNodeExplorer::loadChildren(QTreeWidgetItem *p_item, Node *p_node, i
void NotebookNodeExplorer::loadRecycleBinNode(Node *p_node) const void NotebookNodeExplorer::loadRecycleBinNode(Node *p_node) const
{ {
if (!m_recycleBinNodeVisible) {
return;
}
auto item = new QTreeWidgetItem(); auto item = new QTreeWidgetItem();
item->setWhatsThis(Column::Name, item->setWhatsThis(Column::Name,
tr("Recycle bin of this notebook. Deleted files could be found here. " 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 void NotebookNodeExplorer::loadRecycleBinNode(QTreeWidgetItem *p_item, Node *p_node, int p_level) const
{ {
if (!m_recycleBinNodeVisible) {
return;
}
if (!p_node->isLoaded()) { if (!p_node->isLoaded()) {
p_node->load(); p_node->load();
} }
@ -1393,3 +1401,13 @@ void NotebookNodeExplorer::sortNodes(QVector<QSharedPointer<Node>> &p_nodes, int
break; break;
} }
} }
void NotebookNodeExplorer::setRecycleBinNodeVisible(bool p_visible)
{
if (m_recycleBinNodeVisible == p_visible) {
return;
}
m_recycleBinNodeVisible = p_visible;
reload();
}

View File

@ -102,6 +102,8 @@ namespace vnotex
void reload(); void reload();
void setRecycleBinNodeVisible(bool p_visible);
signals: signals:
void nodeActivated(Node *p_node, const QSharedPointer<FileOpenParameters> &p_paras); void nodeActivated(Node *p_node, const QSharedPointer<FileOpenParameters> &p_paras);
@ -222,6 +224,8 @@ namespace vnotex
QScopedPointer<NavigationModeWrapper<QTreeWidget, QTreeWidgetItem>> m_navigationWrapper; QScopedPointer<NavigationModeWrapper<QTreeWidget, QTreeWidgetItem>> m_navigationWrapper;
bool m_recycleBinNodeVisible = false;
static QIcon s_folderNodeIcon; static QIcon s_folderNodeIcon;
static QIcon s_fileNodeIcon; static QIcon s_fileNodeIcon;
static QIcon s_recycleBinNodeIcon; static QIcon s_recycleBinNodeIcon;