mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 22:09:52 +08:00
support reloading content of notebook and folder from disk
This commit is contained in:
parent
f33c7f86d3
commit
72970cd404
@ -115,6 +115,11 @@ void VDirectoryTree::initActions()
|
|||||||
m_openLocationAct->setToolTip(tr("Open the folder containing this folder in operating system"));
|
m_openLocationAct->setToolTip(tr("Open the folder containing this folder in operating system"));
|
||||||
connect(m_openLocationAct, &QAction::triggered,
|
connect(m_openLocationAct, &QAction::triggered,
|
||||||
this, &VDirectoryTree::openDirectoryLocation);
|
this, &VDirectoryTree::openDirectoryLocation);
|
||||||
|
|
||||||
|
m_reloadAct = new QAction(tr("&Reload From Disk"), this);
|
||||||
|
m_reloadAct->setToolTip(tr("Reload the content of this folder (or notebook) from disk"));
|
||||||
|
connect(m_reloadAct, &QAction::triggered,
|
||||||
|
this, &VDirectoryTree::reloadFromDisk);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VDirectoryTree::setNotebook(VNotebook *p_notebook)
|
void VDirectoryTree::setNotebook(VNotebook *p_notebook)
|
||||||
@ -140,7 +145,9 @@ void VDirectoryTree::setNotebook(VNotebook *p_notebook)
|
|||||||
if (!m_notebook->open()) {
|
if (!m_notebook->open()) {
|
||||||
VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
|
VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
|
||||||
tr("Fail to open notebook <span style=\"%1\">%2</span>.")
|
tr("Fail to open notebook <span style=\"%1\">%2</span>.")
|
||||||
.arg(g_config->c_dataTextStyle).arg(m_notebook->getName()), "",
|
.arg(g_config->c_dataTextStyle).arg(m_notebook->getName()),
|
||||||
|
tr("Please check if path <span style=\"%1\">%2</span> exists.")
|
||||||
|
.arg(g_config->c_dataTextStyle).arg(m_notebook->getPath()),
|
||||||
QMessageBox::Ok, QMessageBox::Ok, this);
|
QMessageBox::Ok, QMessageBox::Ok, this);
|
||||||
clear();
|
clear();
|
||||||
return;
|
return;
|
||||||
@ -202,7 +209,9 @@ void VDirectoryTree::buildSubTree(QTreeWidgetItem *p_parent, int p_depth)
|
|||||||
if (!dir->open()) {
|
if (!dir->open()) {
|
||||||
VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
|
VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
|
||||||
tr("Fail to open folder <span style=\"%1\">%2</span>.")
|
tr("Fail to open folder <span style=\"%1\">%2</span>.")
|
||||||
.arg(g_config->c_dataTextStyle).arg(dir->getName()), "",
|
.arg(g_config->c_dataTextStyle).arg(dir->getName()),
|
||||||
|
tr("Please check if path <span style=\"%1\">%2</span> exists.")
|
||||||
|
.arg(g_config->c_dataTextStyle).arg(dir->retrivePath()),
|
||||||
QMessageBox::Ok, QMessageBox::Ok, this);
|
QMessageBox::Ok, QMessageBox::Ok, this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -355,8 +364,10 @@ void VDirectoryTree::contextMenuRequested(QPoint pos)
|
|||||||
menu.addAction(pasteAct);
|
menu.addAction(pasteAct);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
menu.addSeparator();
|
||||||
|
menu.addAction(m_reloadAct);
|
||||||
|
|
||||||
if (item) {
|
if (item) {
|
||||||
menu.addSeparator();
|
|
||||||
menu.addAction(m_openLocationAct);
|
menu.addAction(m_openLocationAct);
|
||||||
menu.addAction(dirInfoAct);
|
menu.addAction(dirInfoAct);
|
||||||
}
|
}
|
||||||
@ -532,6 +543,81 @@ void VDirectoryTree::openDirectoryLocation() const
|
|||||||
QDesktopServices::openUrl(url);
|
QDesktopServices::openUrl(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VDirectoryTree::reloadFromDisk()
|
||||||
|
{
|
||||||
|
if (!m_notebook) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString info;
|
||||||
|
VDirectory *curDir = NULL;
|
||||||
|
QTreeWidgetItem *curItem = currentItem();
|
||||||
|
if (curItem) {
|
||||||
|
// Reload current directory.
|
||||||
|
curDir = getVDirectory(curItem);
|
||||||
|
info = tr("Are you sure to reload folder <span style=\"%1\">%2</span>?")
|
||||||
|
.arg(g_config->c_dataTextStyle).arg(curDir->getName());
|
||||||
|
} else {
|
||||||
|
// Reload notebook.
|
||||||
|
info = tr("Are you sure to reload notebook <span style=\"%1\">%2</span>?")
|
||||||
|
.arg(g_config->c_dataTextStyle).arg(m_notebook->getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
int ret = VUtils::showMessage(QMessageBox::Information, tr("Information"),
|
||||||
|
info,
|
||||||
|
tr("VNote will close all the related notes before reload."),
|
||||||
|
QMessageBox::Ok | QMessageBox::Cancel,
|
||||||
|
QMessageBox::Ok, this);
|
||||||
|
|
||||||
|
if (ret != QMessageBox::Ok) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_notebookCurrentDirMap.remove(m_notebook);
|
||||||
|
|
||||||
|
if (curItem) {
|
||||||
|
if (!m_editArea->closeFile(curDir, false)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setCurrentItem(NULL);
|
||||||
|
|
||||||
|
curItem->setExpanded(false);
|
||||||
|
curDir->setExpanded(false);
|
||||||
|
|
||||||
|
curDir->close();
|
||||||
|
|
||||||
|
// Remove all its children.
|
||||||
|
QList<QTreeWidgetItem *> children = curItem->takeChildren();
|
||||||
|
for (int i = 0; i < children.size(); ++i) {
|
||||||
|
delete children[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
buildSubTree(curItem, 1);
|
||||||
|
|
||||||
|
setCurrentItem(curItem);
|
||||||
|
} else {
|
||||||
|
if (!m_editArea->closeFile(m_notebook, false)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_notebook->close();
|
||||||
|
|
||||||
|
if (!m_notebook->open()) {
|
||||||
|
VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
|
||||||
|
tr("Fail to open notebook <span style=\"%1\">%2</span>.")
|
||||||
|
.arg(g_config->c_dataTextStyle).arg(m_notebook->getName()),
|
||||||
|
tr("Please check if path <span style=\"%1\">%2</span> exists.")
|
||||||
|
.arg(g_config->c_dataTextStyle).arg(m_notebook->getPath()),
|
||||||
|
QMessageBox::Ok, QMessageBox::Ok, this);
|
||||||
|
clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateDirectoryTree();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void VDirectoryTree::copySelectedDirectories(bool p_cut)
|
void VDirectoryTree::copySelectedDirectories(bool p_cut)
|
||||||
{
|
{
|
||||||
QList<QTreeWidgetItem *> items = selectedItems();
|
QList<QTreeWidgetItem *> items = selectedItems();
|
||||||
|
@ -56,6 +56,9 @@ private slots:
|
|||||||
void pasteDirectoriesInCurDir();
|
void pasteDirectoriesInCurDir();
|
||||||
void openDirectoryLocation() const;
|
void openDirectoryLocation() const;
|
||||||
|
|
||||||
|
// Reload the content of current directory.
|
||||||
|
void reloadFromDisk();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
||||||
void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
|
void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
|
||||||
@ -123,6 +126,9 @@ private:
|
|||||||
QAction *pasteAct;
|
QAction *pasteAct;
|
||||||
QAction *m_openLocationAct;
|
QAction *m_openLocationAct;
|
||||||
|
|
||||||
|
// Reload content from disk.
|
||||||
|
QAction *m_reloadAct;
|
||||||
|
|
||||||
// Navigation Mode.
|
// Navigation Mode.
|
||||||
// Map second key to QTreeWidgetItem.
|
// Map second key to QTreeWidgetItem.
|
||||||
QMap<QChar, QTreeWidgetItem *> m_keyMap;
|
QMap<QChar, QTreeWidgetItem *> m_keyMap;
|
||||||
|
@ -82,12 +82,12 @@ bool VNotebook::writeConfig() const
|
|||||||
return VConfigManager::writeDirectoryConfig(m_path, json);
|
return VConfigManager::writeDirectoryConfig(m_path, json);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString VNotebook::getName() const
|
const QString &VNotebook::getName() const
|
||||||
{
|
{
|
||||||
return m_name;
|
return m_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString VNotebook::getPath() const
|
const QString &VNotebook::getPath() const
|
||||||
{
|
{
|
||||||
return m_path;
|
return m_path;
|
||||||
}
|
}
|
||||||
|
@ -33,8 +33,8 @@ public:
|
|||||||
// if @p_path is not inside this notebook.
|
// if @p_path is not inside this notebook.
|
||||||
VFile *tryLoadFile(const QString &p_path);
|
VFile *tryLoadFile(const QString &p_path);
|
||||||
|
|
||||||
QString getName() const;
|
const QString &getName() const;
|
||||||
QString getPath() const;
|
const QString &getPath() const;
|
||||||
|
|
||||||
VDirectory *getRootDir() const;
|
VDirectory *getRootDir() const;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user