Command history: Save in file before each execution to avoid to lose it in case of... 71/20871/2
Antoine ELIAS [Thu, 21 Feb 2019 16:05:32 +0000 (17:05 +0100)]
Change-Id: I66b67a97ac0ec8ab30e3c7aa14a6e6f2ca68729b

scilab/CHANGES.md
scilab/modules/core/src/cpp/runner.cpp
scilab/modules/history_manager/includes/HistoryManager.h
scilab/modules/history_manager/src/cpp/HistoryManager.cpp
scilab/modules/history_manager/src/cpp/HistoryManager.hxx

index 62c2acd..9811c9d 100644 (file)
@@ -100,6 +100,7 @@ User Interface improvements:
 ----------------------------
 
 * The `ans` variable is editable as any other variable
+* Commands history is saved *before* executing a command to have the correct history on crash.
 
 
 Xcos
index 562786b..cd0687d 100644 (file)
@@ -21,6 +21,7 @@
 
 extern "C"
 {
+#include "HistoryManager.h"
 #include "BrowseVarManager.h"
 #include "FileBrowserChDir.h"
 #include "scicurdir.h"
@@ -172,6 +173,7 @@ int StaticRunner::launch()
         int err = 0;
 
         UpdateBrowseVar();
+        saveScilabHistoryToFile();
         cwd = scigetcwd(&err);
         if (cwd)
         {
index a8b3e64..6b610f9 100644 (file)
@@ -57,7 +57,13 @@ HISTORY_MANAGER_IMPEXP void displayScilabHistory(void);
 * @param a filename if NULL saves in default filename
 * @return TRUE or FALSE
 */
-HISTORY_MANAGER_IMPEXP BOOL writeScilabHistoryToFile(char *filename);
+HISTORY_MANAGER_IMPEXP BOOL writeScilabHistoryToFile(char* filename);
+
+/**
+* save history
+* @return TRUE or FALSE
+*/
+HISTORY_MANAGER_IMPEXP BOOL saveScilabHistoryToFile();
 
 /**
 * load history from a file
index 7594d22..a69e558 100644 (file)
@@ -128,6 +128,11 @@ void displayScilabHistory(void)
     HistoryManager::getInstance()->displayHistory();
 }
 /*------------------------------------------------------------------------*/
+BOOL saveScilabHistoryToFile()
+{
+    return HistoryManager::getInstance()->writeToFile();
+}
+/*------------------------------------------------------------------------*/
 BOOL writeScilabHistoryToFile(char* _pstFilename)
 {
     return HistoryManager::getInstance()->writeToFile(_pstFilename);
@@ -417,6 +422,12 @@ BOOL HistoryManager::writeToFile(char* _pstFilename)
     return FALSE;
 }
 /*------------------------------------------------------------------------*/
+BOOL HistoryManager::writeToFile()
+{
+       m_HF.setHistory(m_Commands);
+       return m_HF.writeToFile();
+}
+/*------------------------------------------------------------------------*/
 BOOL HistoryManager::loadFromFile(char* _pstFilename)
 {
     if (_pstFilename)
index 251af27..2aa12ec 100644 (file)
@@ -94,6 +94,13 @@ public:
     BOOL writeToFile(char* _pstFilename);
 
     /**
+    * save history
+    * default filename --> SCIHOME/history.scilab
+    * @return TRUE or FALSE
+    */
+    BOOL writeToFile();
+
+    /**
     * load history from a file
     * @param a filename if NULL load from default filename
     * default filename --> SCIHOME/<scilab version>history.scilab