mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-06-29 10:32:10 +08:00
cabana: create autosave file when there are unsaved changes (#27542)
old-commit-hash: ee615a30775c56be2c13a4acb4a755072000b8d6
This commit is contained in:
+30
-1
@@ -214,6 +214,7 @@ void MainWindow::undoStackIndexChanged(int index) {
|
||||
}
|
||||
prev_undostack_index = index;
|
||||
prev_undostack_count = count;
|
||||
autoSave();
|
||||
}
|
||||
|
||||
void MainWindow::undoStackCleanChanged(bool clean) {
|
||||
@@ -255,7 +256,18 @@ void MainWindow::openFile() {
|
||||
|
||||
void MainWindow::loadFile(const QString &fn) {
|
||||
if (!fn.isEmpty()) {
|
||||
QFile file(fn);
|
||||
QString dbc_fn = fn;
|
||||
|
||||
// Prompt user to load auto saved file if it exists.
|
||||
if (QFile::exists(fn + AUTO_SAVE_EXTENSION)) {
|
||||
auto ret = QMessageBox::question(this, tr("Auto saved DBC found"), tr("Auto saved DBC file from previous session found. Do you want to load it instead?"));
|
||||
if (ret == QMessageBox::Yes) {
|
||||
dbc_fn += AUTO_SAVE_EXTENSION;
|
||||
UndoStack::instance()->resetClean(); // Force user to save on close so the auto saved file is not lost
|
||||
}
|
||||
}
|
||||
|
||||
QFile file(dbc_fn);
|
||||
if (file.open(QIODevice::ReadOnly)) {
|
||||
auto dbc_name = QFileInfo(fn).baseName();
|
||||
QString error;
|
||||
@@ -340,7 +352,23 @@ void MainWindow::save() {
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::autoSave() {
|
||||
if (!current_file.isEmpty() && !UndoStack::instance()->isClean()) {
|
||||
QFile file(current_file + AUTO_SAVE_EXTENSION);
|
||||
if (file.open(QIODevice::WriteOnly)) {
|
||||
file.write(dbc()->generateDBC().toUtf8());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::cleanupAutoSaveFile() {
|
||||
if (!current_file.isEmpty()) {
|
||||
QFile::remove(current_file + AUTO_SAVE_EXTENSION);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::saveFile(const QString &fn) {
|
||||
cleanupAutoSaveFile();
|
||||
QFile file(fn);
|
||||
if (file.open(QIODevice::WriteOnly)) {
|
||||
file.write(dbc()->generateDBC().toUtf8());
|
||||
@@ -445,6 +473,7 @@ void MainWindow::dockCharts(bool dock) {
|
||||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent *event) {
|
||||
cleanupAutoSaveFile();
|
||||
remindSaveChanges();
|
||||
|
||||
main_win = nullptr;
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include "tools/cabana/videowidget.h"
|
||||
#include "tools/cabana/tools/findsimilarbits.h"
|
||||
|
||||
const QString AUTO_SAVE_EXTENSION = ".tmp";
|
||||
|
||||
class MainWindow : public QMainWindow {
|
||||
Q_OBJECT
|
||||
|
||||
@@ -42,6 +44,8 @@ signals:
|
||||
protected:
|
||||
void remindSaveChanges();
|
||||
void saveFile(const QString &fn);
|
||||
void autoSave();
|
||||
void cleanupAutoSaveFile();
|
||||
void setCurrentFile(const QString &fn);
|
||||
void updateRecentFileActions();
|
||||
void createActions();
|
||||
|
||||
Reference in New Issue
Block a user