ソースを参照

feature/add_history_del (#2297)

* feature/add_history_del

* del debug

* adj 1

* adj 2

* adj name

* adj to call by address

* adj to call by address

* adj to call by address

* adj func name

* adj code grammar

* adj per
chendapao 2 年 前
コミット
e76c6829f7

+ 33 - 10
src/core/historymgr.cpp

@@ -94,6 +94,16 @@ const QVector<QSharedPointer<HistoryItemFull>> &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<HistoryItemFull>::create();
         fullItem->m_item = item;
@@ -156,16 +160,35 @@ void HistoryMgr::add(const QString &p_path,
     emit historyUpdated();
 }
 
-void HistoryMgr::insertHistoryItem(QVector<HistoryItem> &p_history, const HistoryItem &p_item)
+void HistoryMgr::remove(const QVector<QString> &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<HistoryItem> &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<HistoryItem> &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();

+ 6 - 0
src/core/historymgr.h

@@ -55,10 +55,14 @@ namespace vnotex
                  bool p_readOnly,
                  Notebook *p_notebook);
 
+        void remove(const QVector<QString> &p_paths, Notebook *p_notebook);
+
         void clear();
 
         LastClosedFile popLastClosedFile();
 
+        static void removeHistoryItem(QVector<HistoryItem> &p_history, const QString &p_itemPath);
+
         static void insertHistoryItem(QVector<HistoryItem> &p_history, const HistoryItem &p_item);
 
     signals:
@@ -72,6 +76,8 @@ namespace vnotex
         // Sorted by last accessed time ascendingly.
         QVector<QSharedPointer<HistoryItemFull>> m_history;
 
+        void removeFromHistory(const QString &p_itemPath);
+
         QVector<LastClosedFile> m_lastClosedFiles;
 
         const bool m_perNotebookHistoryEnabled = false;

+ 7 - 0
src/core/notebook/bundlenotebook.cpp

@@ -108,6 +108,13 @@ const QVector<HistoryItem> &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);

+ 2 - 0
src/core/notebook/bundlenotebook.h

@@ -49,6 +49,8 @@ namespace vnotex
 
         const QVector<HistoryItem> &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;

+ 2 - 0
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;
     };
 }

+ 6 - 0
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();

+ 1 - 0
src/core/sessionconfig.h

@@ -146,6 +146,7 @@ namespace vnotex
 
         const QVector<HistoryItem> &getHistory() const;
         void addHistory(const HistoryItem &p_item);
+        void removeHistory(const QString &p_itemPath);
         void clearHistory();
 
     private:

+ 6 - 0
src/widgets/notebooknodeexplorer.cpp

@@ -31,6 +31,7 @@
 #include "widgetsfactory.h"
 #include "navigationmodemgr.h"
 
+#include <core/historymgr.h>
 #include <core/fileopenparameters.h>
 #include <core/events.h>
 #include <core/configmgr.h>
@@ -1695,6 +1696,7 @@ void NotebookNodeExplorer::removeNodes(QVector<Node *> p_nodes, bool p_configOnl
 
     int nrDeleted = 0;
     QSet<Node *> nodesNeedUpdate;
+    QVector<QString> pathsNeedRemove;
     for (auto node : p_nodes) {
         auto srcName = node->getName();
         auto srcPath = node->fetchAbsolutePath();
@@ -1712,6 +1714,8 @@ void NotebookNodeExplorer::removeNodes(QVector<Node *> 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<Node *> p_nodes, bool p_configOnl
         nodesNeedUpdate.insert(srcParentNode);
     }
 
+    HistoryMgr::getInst().remove(pathsNeedRemove, m_notebook.data());
+
     for (auto node : nodesNeedUpdate) {
         updateNode(node);
     }