add exclude patterns for external nodes

implement reloadNodes() to reload all the notebook.
This commit is contained in:
Le Tan 2021-03-16 20:08:59 +08:00
parent df33ee6770
commit 2bad915583
16 changed files with 162 additions and 43 deletions

View File

@ -8,6 +8,7 @@ using namespace vnotex;
#define READSTR(key) readString(appObj, userObj, (key)) #define READSTR(key) readString(appObj, userObj, (key))
#define READINT(key) readInt(appObj, userObj, (key)) #define READINT(key) readInt(appObj, userObj, (key))
#define READBOOL(key) readBool(appObj, userObj, (key)) #define READBOOL(key) readBool(appObj, userObj, (key))
#define READSTRLIST(key) readStringList(appObj, userObj, (key))
QStringList CoreConfig::s_availableLocales; QStringList CoreConfig::s_availableLocales;
@ -46,6 +47,8 @@ void CoreConfig::init(const QJsonObject &p_app,
if (m_toolBarIconSize <= 0) { if (m_toolBarIconSize <= 0) {
m_toolBarIconSize = 16; m_toolBarIconSize = 16;
} }
loadNoteManagement(appObj, userObj);
} }
QJsonObject CoreConfig::toJson() const QJsonObject CoreConfig::toJson() const
@ -97,6 +100,20 @@ void CoreConfig::loadShortcuts(const QJsonObject &p_app, const QJsonObject &p_us
} }
} }
void CoreConfig::loadNoteManagement(const QJsonObject &p_app, const QJsonObject &p_user)
{
const auto topAppObj = p_app.value(QStringLiteral("note_management")).toObject();
const auto topUserObj = p_user.value(QStringLiteral("note_management")).toObject();
// External node.
{
const auto appObj = topAppObj.value(QStringLiteral("external_node")).toObject();
const auto userObj = topUserObj.value(QStringLiteral("external_node")).toObject();
m_externalNodeExcludePatterns = READSTRLIST(QStringLiteral("exclude_patterns"));
}
}
QJsonObject CoreConfig::saveShortcuts() const QJsonObject CoreConfig::saveShortcuts() const
{ {
QJsonObject obj; QJsonObject obj;
@ -126,3 +143,8 @@ void CoreConfig::setToolBarIconSize(int p_size)
Q_ASSERT(p_size > 0); Q_ASSERT(p_size > 0);
updateConfig(m_toolBarIconSize, p_size, this); updateConfig(m_toolBarIconSize, p_size, this);
} }
const QStringList &CoreConfig::getExternalNodeExcludePatterns() const
{
return m_externalNodeExcludePatterns;
}

View File

@ -56,11 +56,15 @@ namespace vnotex
int getToolBarIconSize() const; int getToolBarIconSize() const;
void setToolBarIconSize(int p_size); void setToolBarIconSize(int p_size);
const QStringList &getExternalNodeExcludePatterns() const;
static const QStringList &getAvailableLocales(); static const QStringList &getAvailableLocales();
private: private:
void loadShortcuts(const QJsonObject &p_app, const QJsonObject &p_user); void loadShortcuts(const QJsonObject &p_app, const QJsonObject &p_user);
void loadNoteManagement(const QJsonObject &p_app, const QJsonObject &p_user);
QJsonObject saveShortcuts() const; QJsonObject saveShortcuts() const;
// Theme name. // Theme name.
@ -75,6 +79,8 @@ namespace vnotex
// Icon size of MainWindow tool bar. // Icon size of MainWindow tool bar.
int m_toolBarIconSize = 16; int m_toolBarIconSize = 16;
QStringList m_externalNodeExcludePatterns;
static QStringList s_availableLocales; static QStringList s_availableLocales;
}; };
} // ns vnotex } // ns vnotex

View File

@ -3,6 +3,7 @@
#include <QSharedPointer> #include <QSharedPointer>
#include <QJsonObject> #include <QJsonObject>
#include <QJsonArray>
namespace vnotex namespace vnotex
{ {
@ -80,6 +81,19 @@ namespace vnotex
return read(p_default, p_user, p_key).toString(); return read(p_default, p_user, p_key).toString();
} }
static QStringList readStringList(const QJsonObject &p_default,
const QJsonObject &p_user,
const QString &p_key)
{
auto arr = read(p_default, p_user, p_key).toArray();
QStringList res;
res.reserve(arr.size());
for (const auto &ele : arr) {
res.push_back(ele.toString());
}
return res;
}
static QString readString(const QJsonObject &p_obj, static QString readString(const QJsonObject &p_obj,
const QString &p_key) const QString &p_key)
{ {

View File

@ -347,7 +347,8 @@ QSharedPointer<Node> Notebook::copyAsNode(Node *p_parent,
return m_configMgr->copyAsNode(p_parent, p_flags, p_path); return m_configMgr->copyAsNode(p_parent, p_flags, p_path);
} }
void Notebook::reloadNode(Node *p_node) void Notebook::reloadNodes()
{ {
m_configMgr->reloadNode(p_node); m_root.clear();
getRootNode();
} }

View File

@ -127,7 +127,7 @@ namespace vnotex
bool isBuiltInFolder(const Node *p_node, const QString &p_name) const; bool isBuiltInFolder(const Node *p_node, const QString &p_name) const;
void reloadNode(Node *p_node); void reloadNodes();
static const QString c_defaultAttachmentFolder; static const QString c_defaultAttachmentFolder;

View File

@ -77,8 +77,6 @@ namespace vnotex
virtual QVector<QSharedPointer<ExternalNode>> fetchExternalChildren(Node *p_node) const = 0; virtual QVector<QSharedPointer<ExternalNode>> fetchExternalChildren(Node *p_node) const = 0;
virtual void reloadNode(Node *p_node) = 0;
protected: protected:
// Version of the config processing code. // Version of the config processing code.
virtual QString getCodeVersion() const; virtual QString getCodeVersion() const;

View File

@ -16,6 +16,7 @@
#include <exception.h> #include <exception.h>
#include <core/configmgr.h> #include <core/configmgr.h>
#include <core/editorconfig.h> #include <core/editorconfig.h>
#include <core/coreconfig.h>
#include <utils/contentmediautils.h> #include <utils/contentmediautils.h>
@ -166,6 +167,10 @@ const QString VXNotebookConfigMgr::c_nodeConfigName = "vx.json";
const QString VXNotebookConfigMgr::c_recycleBinFolderName = "vx_recycle_bin"; const QString VXNotebookConfigMgr::c_recycleBinFolderName = "vx_recycle_bin";
bool VXNotebookConfigMgr::s_initialized = false;
QVector<QRegExp> VXNotebookConfigMgr::s_externalNodeExcludePatterns;
VXNotebookConfigMgr::VXNotebookConfigMgr(const QString &p_name, VXNotebookConfigMgr::VXNotebookConfigMgr(const QString &p_name,
const QString &p_displayName, const QString &p_displayName,
const QString &p_description, const QString &p_description,
@ -174,6 +179,17 @@ VXNotebookConfigMgr::VXNotebookConfigMgr(const QString &p_name,
: BundleNotebookConfigMgr(p_backend, p_parent), : BundleNotebookConfigMgr(p_backend, p_parent),
m_info(p_name, p_displayName, p_description) m_info(p_name, p_displayName, p_description)
{ {
if (!s_initialized) {
s_initialized = true;
const auto &patterns = ConfigMgr::getInst().getCoreConfig().getExternalNodeExcludePatterns();
s_externalNodeExcludePatterns.reserve(patterns.size());
for (const auto &pat : patterns) {
if (!pat.isEmpty()) {
s_externalNodeExcludePatterns.push_back(QRegExp(pat, Qt::CaseInsensitive, QRegExp::Wildcard));
}
}
}
} }
QString VXNotebookConfigMgr::getName() const QString VXNotebookConfigMgr::getName() const
@ -927,6 +943,10 @@ QVector<QSharedPointer<ExternalNode>> VXNotebookConfigMgr::fetchExternalChildren
continue; continue;
} }
if (isExcludedFromExternalNode(folder)) {
continue;
}
if (p_node->containsContainerChild(folder)) { if (p_node->containsContainerChild(folder)) {
continue; continue;
} }
@ -943,6 +963,10 @@ QVector<QSharedPointer<ExternalNode>> VXNotebookConfigMgr::fetchExternalChildren
continue; continue;
} }
if (isExcludedFromExternalNode(file)) {
continue;
}
if (p_node->containsContentChild(file)) { if (p_node->containsContentChild(file)) {
continue; continue;
} }
@ -954,7 +978,12 @@ QVector<QSharedPointer<ExternalNode>> VXNotebookConfigMgr::fetchExternalChildren
return externalNodes; return externalNodes;
} }
void VXNotebookConfigMgr::reloadNode(Node *p_node) bool VXNotebookConfigMgr::isExcludedFromExternalNode(const QString &p_name) const
{ {
// TODO. for (const auto &regExp : s_externalNodeExcludePatterns) {
if (regExp.exactMatch(p_name)) {
return true;
}
}
return false;
} }

View File

@ -5,6 +5,7 @@
#include <QDateTime> #include <QDateTime>
#include <QVector> #include <QVector>
#include <QRegExp>
#include "../global.h" #include "../global.h"
@ -70,8 +71,6 @@ namespace vnotex
QVector<QSharedPointer<ExternalNode>> fetchExternalChildren(Node *p_node) const Q_DECL_OVERRIDE; QVector<QSharedPointer<ExternalNode>> fetchExternalChildren(Node *p_node) const Q_DECL_OVERRIDE;
void reloadNode(Node *p_node) Q_DECL_OVERRIDE;
private: private:
// Config of a file child. // Config of a file child.
struct NodeFileConfig struct NodeFileConfig
@ -190,8 +189,14 @@ namespace vnotex
void inheritNodeFlags(const Node *p_node, Node *p_child) const; void inheritNodeFlags(const Node *p_node, Node *p_child) const;
bool isExcludedFromExternalNode(const QString &p_name) const;
Info m_info; Info m_info;
static bool s_initialized;
static QVector<QRegExp> s_externalNodeExcludePatterns;
// Name of the node's config file. // Name of the node's config file.
static const QString c_nodeConfigName; static const QString c_nodeConfigName;

View File

@ -27,7 +27,16 @@
"NewWorkspace" : "Ctrl+G, N", "NewWorkspace" : "Ctrl+G, N",
"Export" : "Ctrl+G, T" "Export" : "Ctrl+G, T"
}, },
"toolbar_icon_size" : 16 "toolbar_icon_size" : 16,
"note_management" : {
"external_node" : {
"//comment" : "Wildcard patterns of files and folders to exclude as external files",
"exclude_patterns" : [
".gitignore",
".git"
]
}
}
}, },
"editor" : { "editor" : {
"core": { "core": {

View File

@ -102,6 +102,16 @@ void MainWindow::setupStatusBar()
void MainWindow::setupTipsArea() void MainWindow::setupTipsArea()
{ {
connect(&VNoteX::getInst(), &VNoteX::tipsRequested,
this, &MainWindow::showTips);
}
void MainWindow::createTipsArea()
{
if (m_tipsLabel) {
return;
}
m_tipsLabel = new QLabel(this); m_tipsLabel = new QLabel(this);
m_tipsLabel->setObjectName("MainWindowTipsLabel"); m_tipsLabel->setObjectName("MainWindowTipsLabel");
m_tipsLabel->hide(); m_tipsLabel->hide();
@ -113,9 +123,6 @@ void MainWindow::setupTipsArea()
this, [this]() { this, [this]() {
setTipsAreaVisible(false); setTipsAreaVisible(false);
}); });
connect(&VNoteX::getInst(), &VNoteX::tipsRequested,
this, &MainWindow::showTips);
} }
void MainWindow::setupCentralWidget() void MainWindow::setupCentralWidget()
@ -623,6 +630,8 @@ void MainWindow::exportNotes()
void MainWindow::showTips(const QString &p_message, int p_timeoutMilliseconds) void MainWindow::showTips(const QString &p_message, int p_timeoutMilliseconds)
{ {
createTipsArea();
m_tipsTimer->stop(); m_tipsTimer->stop();
setTipsAreaVisible(false); setTipsAreaVisible(false);
@ -639,6 +648,7 @@ void MainWindow::showTips(const QString &p_message, int p_timeoutMilliseconds)
void MainWindow::setTipsAreaVisible(bool p_visible) void MainWindow::setTipsAreaVisible(bool p_visible)
{ {
Q_ASSERT(m_tipsLabel);
if (p_visible) { if (p_visible) {
m_tipsLabel->adjustSize(); m_tipsLabel->adjustSize();
int labelW = m_tipsLabel->width(); int labelW = m_tipsLabel->width();

View File

@ -106,6 +106,8 @@ namespace vnotex
void setupTipsArea(); void setupTipsArea();
void createTipsArea();
void saveStateAndGeometry(); void saveStateAndGeometry();
void loadStateAndGeometry(); void loadStateAndGeometry();

View File

@ -76,6 +76,8 @@ void NotebookExplorer::setupUI()
&VNoteX::getInst(), &VNoteX::nodeAboutToMove); &VNoteX::getInst(), &VNoteX::nodeAboutToMove);
connect(m_nodeExplorer, &NotebookNodeExplorer::nodeAboutToRemove, connect(m_nodeExplorer, &NotebookNodeExplorer::nodeAboutToRemove,
&VNoteX::getInst(), &VNoteX::nodeAboutToRemove); &VNoteX::getInst(), &VNoteX::nodeAboutToRemove);
connect(m_nodeExplorer, &NotebookNodeExplorer::nodeAboutToReload,
&VNoteX::getInst(), &VNoteX::nodeAboutToReload);
mainLayout->addWidget(m_nodeExplorer); mainLayout->addWidget(m_nodeExplorer);
setFocusProxy(m_nodeExplorer); setFocusProxy(m_nodeExplorer);

View File

@ -761,6 +761,9 @@ void NotebookNodeExplorer::createContextMenuOnRoot(QMenu *p_menu)
act = createAction(Action::Reload, p_menu); act = createAction(Action::Reload, p_menu);
p_menu->addAction(act); p_menu->addAction(act);
act = createAction(Action::ReloadIndex, p_menu);
p_menu->addAction(act);
act = createAction(Action::OpenLocation, p_menu); act = createAction(Action::OpenLocation, p_menu);
p_menu->addAction(act); p_menu->addAction(act);
} }
@ -775,6 +778,9 @@ void NotebookNodeExplorer::createContextMenuOnNode(QMenu *p_menu, const Node *p_
act = createAction(Action::Reload, p_menu); act = createAction(Action::Reload, p_menu);
p_menu->addAction(act); p_menu->addAction(act);
act = createAction(Action::ReloadIndex, p_menu);
p_menu->addAction(act);
if (selectedSize == 1) { if (selectedSize == 1) {
act = createAction(Action::EmptyRecycleBin, p_menu); act = createAction(Action::EmptyRecycleBin, p_menu);
p_menu->addAction(act); p_menu->addAction(act);
@ -800,6 +806,9 @@ void NotebookNodeExplorer::createContextMenuOnNode(QMenu *p_menu, const Node *p_
act = createAction(Action::Reload, p_menu); act = createAction(Action::Reload, p_menu);
p_menu->addAction(act); p_menu->addAction(act);
act = createAction(Action::ReloadIndex, p_menu);
p_menu->addAction(act);
if (selectedSize == 1) { if (selectedSize == 1) {
p_menu->addSeparator(); p_menu->addSeparator();
@ -845,6 +854,9 @@ void NotebookNodeExplorer::createContextMenuOnNode(QMenu *p_menu, const Node *p_
act = createAction(Action::Reload, p_menu); act = createAction(Action::Reload, p_menu);
p_menu->addAction(act); p_menu->addAction(act);
act = createAction(Action::ReloadIndex, p_menu);
p_menu->addAction(act);
act = createAction(Action::Sort, p_menu); act = createAction(Action::Sort, p_menu);
p_menu->addAction(act); p_menu->addAction(act);
@ -1091,14 +1103,28 @@ QAction *NotebookNodeExplorer::createAction(Action p_act, QObject *p_parent)
connect(act, &QAction::triggered, connect(act, &QAction::triggered,
this, [this]() { this, [this]() {
auto node = currentExploredFolderNode(); auto node = currentExploredFolderNode();
if (m_notebook && node) {
// TODO: emit signals to notify other components.
m_notebook->reloadNode(node);
}
updateNode(node); updateNode(node);
}); });
break; break;
case Action::ReloadIndex:
act = new QAction(tr("Re&load Index From Disk"), p_parent);
connect(act, &QAction::triggered,
this, [this]() {
if (!m_notebook) {
return;
}
auto event = QSharedPointer<Event>::create();
emit nodeAboutToReload(m_notebook->getRootNode().data(), event);
if (!event->m_response.toBool()) {
return;
}
reload();
});
break;
case Action::ImportToConfig: case Action::ImportToConfig:
act = new QAction(tr("&Import To Index"), p_parent); act = new QAction(tr("&Import To Index"), p_parent);
connect(act, &QAction::triggered, connect(act, &QAction::triggered,

View File

@ -123,6 +123,8 @@ namespace vnotex
// @m_response of @p_event: true to continue the removal, false to cancel the removal. // @m_response of @p_event: true to continue the removal, false to cancel the removal.
void nodeAboutToRemove(Node *p_node, const QSharedPointer<Event> &p_event); void nodeAboutToRemove(Node *p_node, const QSharedPointer<Event> &p_event);
void nodeAboutToReload(Node *p_node, const QSharedPointer<Event> &p_event);
private: private:
enum Column { Name = 0 }; enum Column { Name = 0 };
@ -142,6 +144,7 @@ namespace vnotex
RemoveFromConfig, RemoveFromConfig,
Sort, Sort,
Reload, Reload,
ReloadIndex,
ImportToConfig, ImportToConfig,
Open Open
}; };

View File

@ -61,37 +61,16 @@ ViewArea::ViewArea(QWidget *p_parent)
}); });
connect(&VNoteX::getInst(), &VNoteX::nodeAboutToMove, connect(&VNoteX::getInst(), &VNoteX::nodeAboutToMove,
this, [this](Node *p_node, const QSharedPointer<Event> &p_event) { this, &ViewArea::handleNodeChange);
if (p_event->m_handled) {
return;
}
bool ret = close(p_node, false);
p_event->m_response = ret;
p_event->m_handled = !ret;
});
connect(&VNoteX::getInst(), &VNoteX::nodeAboutToRemove, connect(&VNoteX::getInst(), &VNoteX::nodeAboutToRemove,
this, [this](Node *p_node, const QSharedPointer<Event> &p_event) { this, &ViewArea::handleNodeChange);
if (p_event->m_handled) {
return;
}
bool ret = close(p_node, false);
p_event->m_response = ret;
p_event->m_handled = !ret;
});
connect(&VNoteX::getInst(), &VNoteX::nodeAboutToRename, connect(&VNoteX::getInst(), &VNoteX::nodeAboutToRename,
this, [this](Node *p_node, const QSharedPointer<Event> &p_event) { this, &ViewArea::handleNodeChange);
if (p_event->m_handled) {
return;
}
bool ret = close(p_node, false); connect(&VNoteX::getInst(), &VNoteX::nodeAboutToReload,
p_event->m_response = ret; this, &ViewArea::handleNodeChange);
p_event->m_handled = !ret;
});
auto &configMgr = ConfigMgr::getInst(); auto &configMgr = ConfigMgr::getInst();
connect(&configMgr, &ConfigMgr::editorConfigChanged, connect(&configMgr, &ConfigMgr::editorConfigChanged,
@ -130,6 +109,17 @@ ViewArea::~ViewArea()
Q_ASSERT(m_workspaces.isEmpty()); Q_ASSERT(m_workspaces.isEmpty());
} }
void ViewArea::handleNodeChange(Node *p_node, const QSharedPointer<Event> &p_event)
{
if (p_event->m_handled) {
return;
}
bool ret = close(p_node, false);
p_event->m_response = ret;
p_event->m_handled = !ret;
}
void ViewArea::setupUI() void ViewArea::setupUI()
{ {
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

View File

@ -127,6 +127,8 @@ namespace vnotex
bool close(bool p_force); bool close(bool p_force);
void handleNodeChange(Node *p_node, const QSharedPointer<Event> &p_event);
private: private:
enum class SplitType enum class SplitType
{ {