update history file after every statement is executed instead of only when the program cleanly exits

Issue #924 new
brolin created an issue

Thank you for creating SpeedCrunch, which I use (version 0.12) on Windows 10 Enterprise for x86-64. I switched to SpeedCrunch because I want both the input and output of the session in my calculator application on Windows NT and GNU+Linux to automatically persist between sessions, without having to do anything special, like with Mathdroid for Android. Apparently SpeedCrunch updates its history file (history.json) only when it cleanly exits, not after every statement, which could cause a significant loss to the persistent history if SpeedCrunch unexpectedly stops running, such as if it crashes or if the power to the computer is interrupted. Please at least add an option to update the history file after every statement is executed if not to make this new behaviour unconditional if Save History on Exit is enabled. Or maybe Save History on Exit, which is currently a checkbox in the Settings menu, could be replaced with a submenu named Save History and containing the following three mutex buttons (“radio buttons” but this is anachronistic because cars seem to have stopped using mechanically mutually exclusive buttons for radio station presets decades ago, maybe when the tuner was changed from analog to digital (even if the radio medium is still analog)): Never; On exit; After every statement and on exit

Comments (4)

  1. brolin reporter

    I tried to edit the master source using the Bitbucket Web editor but my change could not be submitted. Here is my commit message:

    mainwindow.cpp edited online with Bitbucket: implement my change requested in issue #924. I have not tested this change because I do not even have a local copy of the source codebase of SpeedCrunch although I do already have Visual Studio installed but it looks like my change should work. I also defined a new constant, SESSION_HISTORY_FILE_NAME, using a preprocessor macro near the beginning of the file to prevent duplicating the "/history.json" (including quotation marks) string literal. I do not know if this string literal is used outside of this file nor if this is your preferred way of defining a constant so feel free to change how this constant is defined but I really think it should be a constant defined only once instead of being duplicated in case it is changed in the future. Even if you cannot yet publish a build with this change, can you please check if SpeedCrunch still builds with my change and, if it still builds, if my change seems to have the desired effect?

    And here is a patch for my changes:

    [brolin@succubus64] [0] [85] /cygdrive/c/Users/brolin/Downloads/SpeedCrunch/
    $ diff -u mainwindow.cpp.orig mainwindow.cpp.brolin
    --- mainwindow.cpp.orig 2019-08-16 11:26:34.209064300 -0700
    +++ mainwindow.cpp.brolin       2019-08-16 11:24:30.023966600 -0700
    @@ -79,6 +79,8 @@
     #include <shlobj.h>
     #endif // Q_OS_WIN32
    
    +#define SESSION_HISTORY_FILE_NAME "/history.json"
    +
     QTranslator* MainWindow::createTranslator(const QString& langCode)
     {
         QTranslator* translator = new QTranslator;
    @@ -2160,7 +2162,7 @@
         QString data_path = Settings::getDataPath();
         QDir qdir;
         qdir.mkpath(data_path);
    -    data_path.append("/history.json");
    +    data_path.append(SESSION_HISTORY_FILE_NAME);
    
         QFile file(data_path);
         if (!file.open(QIODevice::ReadOnly))
    @@ -2218,6 +2220,14 @@
         m_widgets.editor->stopAutoComplete();
         if (!result.isNan())
             m_conditions.autoAns = true;
    +
    +    if(m_settings->sessionSave) {
    +        QString data_path = Settings::getDataPath();
    +        QDir qdir;
    +        qdir.mkpath(data_path);
    +        data_path.append(SESSION_HISTORY_FILE_NAME);
    +        saveSession(data_path);
    +    }
     }
    
     void MainWindow::clearTextEditSelection(QPlainTextEdit* edit)
    @@ -2350,7 +2360,7 @@
             QString data_path = Settings::getDataPath();
             QDir qdir;
             qdir.mkpath(data_path);
    -        data_path.append("/history.json");
    +        data_path.append(SESSION_HISTORY_FILE_NAME);
             saveSession(data_path);
         }
         e->accept();
    [brolin@succubus64] [1] [86] /cygdrive/c/Users/brolin/Downloads/SpeedCrunch/
    $
    
  2. Log in to comment