diff --git a/src/core/historymgr.cpp b/src/core/historymgr.cpp index 3fbecd45..8e176154 100644 --- a/src/core/historymgr.cpp +++ b/src/core/historymgr.cpp @@ -94,6 +94,16 @@ const QVector> &HistoryMgr::getHistory() const return m_history; } +void HistoryMgr::removeFromHistory(const QString &p_itemPath) +{ + for (int i = m_history.size() - 1; i >= 0; --i) { + if (m_history[i]->m_item.m_path == p_itemPath) { + m_history.remove(i); + break; + } + } +} + void HistoryMgr::add(const QString &p_path, int p_lineNumber, ViewWindowMode p_mode, @@ -116,13 +126,7 @@ void HistoryMgr::add(const QString &p_path, // Maintain the combined queue. { - for (int i = m_history.size() - 1; i >= 0; --i) { - if (m_history[i]->m_item.m_path == item.m_path) { - // Erase it. - m_history.remove(i); - break; - } - } + removeFromHistory(item.m_path); auto fullItem = QSharedPointer::create(); fullItem->m_item = item; @@ -156,16 +160,35 @@ void HistoryMgr::add(const QString &p_path, emit historyUpdated(); } -void HistoryMgr::insertHistoryItem(QVector &p_history, const HistoryItem &p_item) +void HistoryMgr::remove(const QVector &p_paths, Notebook *p_notebook) +{ + for(const QString &p_itemPath : p_paths) { + if (p_notebook && m_perNotebookHistoryEnabled && p_notebook->history()) { + p_notebook->history()->removeHistory(p_itemPath); + } else { + auto &sessionConfig = ConfigMgr::getInst().getSessionConfig(); + sessionConfig.removeHistory(p_itemPath); + } + + removeFromHistory(p_itemPath); + } + + emit historyUpdated(); +} + +void HistoryMgr::removeHistoryItem(QVector &p_history, const QString &p_itemPath) { for (int i = p_history.size() - 1; i >= 0; --i) { - if (p_history[i].m_path == p_item.m_path) { - // Erase it. + if (p_history[i].m_path == p_itemPath) { p_history.remove(i); break; } } +} +void HistoryMgr::insertHistoryItem(QVector &p_history, const HistoryItem &p_item) +{ + removeHistoryItem(p_history, p_item.m_path); p_history.append(p_item); const int maxHistoryCount = ConfigMgr::getInst().getCoreConfig().getHistoryMaxCount(); diff --git a/src/core/historymgr.h b/src/core/historymgr.h index 30375fec..d2c1da1f 100644 --- a/src/core/historymgr.h +++ b/src/core/historymgr.h @@ -55,10 +55,14 @@ namespace vnotex bool p_readOnly, Notebook *p_notebook); + void remove(const QVector &p_paths, Notebook *p_notebook); + void clear(); LastClosedFile popLastClosedFile(); + static void removeHistoryItem(QVector &p_history, const QString &p_itemPath); + static void insertHistoryItem(QVector &p_history, const HistoryItem &p_item); signals: @@ -72,6 +76,8 @@ namespace vnotex // Sorted by last accessed time ascendingly. QVector> m_history; + void removeFromHistory(const QString &p_itemPath); + QVector m_lastClosedFiles; const bool m_perNotebookHistoryEnabled = false; diff --git a/src/core/notebook/bundlenotebook.cpp b/src/core/notebook/bundlenotebook.cpp index 9ebe13cd..61131e47 100644 --- a/src/core/notebook/bundlenotebook.cpp +++ b/src/core/notebook/bundlenotebook.cpp @@ -108,6 +108,13 @@ const QVector &BundleNotebook::getHistory() const return m_history; } +void BundleNotebook::removeHistory(const QString &p_itemPath) +{ + HistoryMgr::removeHistoryItem(m_history, p_itemPath); + + updateNotebookConfig(); +} + void BundleNotebook::addHistory(const HistoryItem &p_item) { HistoryItem item(p_item); diff --git a/src/core/notebook/bundlenotebook.h b/src/core/notebook/bundlenotebook.h index e60a5a93..6083945d 100644 --- a/src/core/notebook/bundlenotebook.h +++ b/src/core/notebook/bundlenotebook.h @@ -49,6 +49,8 @@ namespace vnotex const QVector &getHistory() const Q_DECL_OVERRIDE; + void removeHistory(const QString &p_itemPath) Q_DECL_OVERRIDE; + void addHistory(const HistoryItem &p_item) Q_DECL_OVERRIDE; void clearHistory() Q_DECL_OVERRIDE; diff --git a/src/core/notebook/historyi.h b/src/core/notebook/historyi.h index 14297777..f01fc95f 100644 --- a/src/core/notebook/historyi.h +++ b/src/core/notebook/historyi.h @@ -17,6 +17,8 @@ namespace vnotex virtual void addHistory(const HistoryItem &p_item) = 0; + virtual void removeHistory(const QString &p_itemPath) = 0; + virtual void clearHistory() = 0; }; } diff --git a/src/core/sessionconfig.cpp b/src/core/sessionconfig.cpp index f3dd073b..8345a0cb 100644 --- a/src/core/sessionconfig.cpp +++ b/src/core/sessionconfig.cpp @@ -484,6 +484,12 @@ void SessionConfig::addHistory(const HistoryItem &p_item) update(); } +void SessionConfig::removeHistory(const QString &p_itemPath) +{ + HistoryMgr::removeHistoryItem(m_history, p_itemPath); + update(); +} + void SessionConfig::clearHistory() { m_history.clear(); diff --git a/src/core/sessionconfig.h b/src/core/sessionconfig.h index 52ee7ee7..a3090307 100644 --- a/src/core/sessionconfig.h +++ b/src/core/sessionconfig.h @@ -146,6 +146,7 @@ namespace vnotex const QVector &getHistory() const; void addHistory(const HistoryItem &p_item); + void removeHistory(const QString &p_itemPath); void clearHistory(); private: diff --git a/src/widgets/notebooknodeexplorer.cpp b/src/widgets/notebooknodeexplorer.cpp index 227883fd..402c8d88 100644 --- a/src/widgets/notebooknodeexplorer.cpp +++ b/src/widgets/notebooknodeexplorer.cpp @@ -31,6 +31,7 @@ #include "widgetsfactory.h" #include "navigationmodemgr.h" +#include #include #include #include @@ -1695,6 +1696,7 @@ void NotebookNodeExplorer::removeNodes(QVector p_nodes, bool p_configOnl int nrDeleted = 0; QSet nodesNeedUpdate; + QVector pathsNeedRemove; for (auto node : p_nodes) { auto srcName = node->getName(); auto srcPath = node->fetchAbsolutePath(); @@ -1712,6 +1714,8 @@ void NotebookNodeExplorer::removeNodes(QVector p_nodes, bool p_configOnl m_notebook->moveNodeToRecycleBin(node); } + pathsNeedRemove.append(srcPath); + ++nrDeleted; } catch (Exception &p_e) { MessageBoxHelper::notify(MessageBoxHelper::Critical, @@ -1723,6 +1727,8 @@ void NotebookNodeExplorer::removeNodes(QVector p_nodes, bool p_configOnl nodesNeedUpdate.insert(srcParentNode); } + HistoryMgr::getInst().remove(pathsNeedRemove, m_notebook.data()); + for (auto node : nodesNeedUpdate) { updateNode(node); }