diff --git a/NEWS.md b/NEWS.md index 2b9ff2fe..a5a351aa 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,9 @@ Version 0.8.6 For Dev-C++ 7 Beta - enhancement: greatly reduces memory usage for symbol parsing ( memory needed for bits/stdc++.h reduced from 150m+ to 80m+) - fix: currect compiler set not correctly updated when switch between normal file and project file + - fix: editor auto save settings not saved and applied + - fix: only auto save files that has new modifications + - fix: correctly auto save files with it's own name Version 0.8.5 For Dev-C++ 7 Beta - enhancement: use lighter color to draw menu seperators diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 33866062..8a9e3097 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -151,10 +151,12 @@ Editor::Editor(QWidget *parent, const QString& filename, connect(this, &QWidget::customContextMenuRequested, pMainWindow, &MainWindow::onEditorContextMenu); + mCanAutoSave = false; if (isNew && parentPageControl!=nullptr) { QString fileTemplate = pMainWindow->codeSnippetManager()->newFileTemplate(); if (!fileTemplate.isEmpty()) { insertCodeSnippet(fileTemplate); + mCanAutoSave = true; } } if (!isNew && parentPageControl!=nullptr) { @@ -1390,6 +1392,8 @@ void Editor::onStatusChanged(SynStatusChanges changes) } if (changes.testFlag(scModified)) { mCurrentLineModified = true; + if (mParentPageControl!=nullptr) + mCanAutoSave = true; } if (changes.testFlag(SynStatusChange::scCaretX) @@ -3120,6 +3124,16 @@ void Editor::onExportedFormatToken(PSynHighlighter syntaxHighlighter, int Line, } } +bool Editor::canAutoSave() const +{ + return mCanAutoSave; +} + +void Editor::setCanAutoSave(bool newCanAutoSave) +{ + mCanAutoSave = newCanAutoSave; +} + const QDateTime &Editor::hideTime() const { return mHideTime; diff --git a/RedPandaIDE/editor.h b/RedPandaIDE/editor.h index 52b07f33..70e44cfb 100644 --- a/RedPandaIDE/editor.h +++ b/RedPandaIDE/editor.h @@ -269,6 +269,7 @@ private: int mTabStopBegin; int mTabStopEnd; int mTabStopY; + bool mCanAutoSave; QString mLineBeforeTabStop; QString mLineAfterTabStop; QList mUserCodeInTabStops; @@ -312,6 +313,9 @@ public: const QDateTime &hideTime() const; void setHideTime(const QDateTime &newHideTime); + bool canAutoSave() const; + void setCanAutoSave(bool newCanAutoSave); + protected: void mouseReleaseEvent(QMouseEvent *event) override; diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index f9e93de8..06939749 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -799,8 +799,10 @@ void MainWindow::updateClassBrowserForEditor(Editor *editor) void MainWindow::resetAutoSaveTimer() { if (pSettings->editor().enableAutoSave()) { + mAutoSaveTimer.stop(); //minute to milliseconds mAutoSaveTimer.start(pSettings->editor().autoSaveInterval()*60*1000); + onAutoSaveTimeout(); } else { mAutoSaveTimer.stop(); } @@ -1547,35 +1549,47 @@ void MainWindow::prepareDebugger() void MainWindow::doAutoSave(Editor *e) { - if (!e) - return; - if (!e->modified()) + + if (!e || !e->canAutoSave()) return; QString filename = e->filename(); - QFileInfo fileInfo(filename); - QDir parent = fileInfo.absoluteDir(); - QString baseName = fileInfo.completeBaseName(); - QString suffix = fileInfo.suffix(); - switch(pSettings->editor().autoSaveStrategy()) { - case assOverwrite: - break; - case assAppendUnixTimestamp: - filename = parent.filePath( - QString("%1.%2.%3") - .arg(baseName) - .arg(QDateTime::currentSecsSinceEpoch()) - .arg(suffix)); - break; - case assAppendFormatedTimeStamp: { - QDateTime time = QDateTime::currentDateTime(); - filename = parent.filePath( - QString("%1.%2.%3") - .arg(baseName) - .arg(time.toString("yyyy.MM.dd.hh.mm.ss")) - .arg(suffix)); + try { + QFileInfo fileInfo(filename); + QDir parent = fileInfo.absoluteDir(); + QString baseName = fileInfo.completeBaseName(); + QString suffix = fileInfo.suffix(); + switch(pSettings->editor().autoSaveStrategy()) { + case assOverwrite: + e->save(); + return; + case assAppendUnixTimestamp: + filename = parent.filePath( + QString("%1.%2.%3") + .arg(baseName) + .arg(QDateTime::currentSecsSinceEpoch()) + .arg(suffix)); + break; + case assAppendFormatedTimeStamp: { + QDateTime time = QDateTime::currentDateTime(); + filename = parent.filePath( + QString("%1.%2.%3") + .arg(baseName) + .arg(time.toString("yyyy.MM.dd.hh.mm.ss")) + .arg(suffix)); + } + } + if (e->isNew()) { + e->saveAs(); + } else { + e->saveFile(filename); + e->setCanAutoSave(false); + } + } catch (FileError& error) { + QMessageBox::critical(e, + tr("Auto Save Error"), + tr("Auto save \"%1\" to \"%2\" failed:%3") + .arg(e->filename(), filename, error.reason())); } - } - e->saveFile(filename); } //static void limitActionShortCutScope(QAction* action,QWidget* scopeWidget) { diff --git a/RedPandaIDE/settingsdialog/editorautosavewidget.cpp b/RedPandaIDE/settingsdialog/editorautosavewidget.cpp index 85668668..15d961dd 100644 --- a/RedPandaIDE/settingsdialog/editorautosavewidget.cpp +++ b/RedPandaIDE/settingsdialog/editorautosavewidget.cpp @@ -34,7 +34,7 @@ void EditorAutoSaveWidget::doLoad() { //pSettings->editor().load(); //font - ui->chkEnableAutoSave->setChecked(pSettings->editor().enableAutoSave()); + ui->grpEnableAutoSave->setChecked(pSettings->editor().enableAutoSave()); ui->spinInterval->setValue(pSettings->editor().autoSaveInterval()); switch(pSettings->editor().autoSaveTarget()) { case astCurrentFile: @@ -60,7 +60,7 @@ void EditorAutoSaveWidget::doLoad() void EditorAutoSaveWidget::doSave() { - pSettings->editor().setEnableAutoSave(ui->chkEnableAutoSave->isChecked()); + pSettings->editor().setEnableAutoSave(ui->grpEnableAutoSave->isChecked()); pSettings->editor().setAutoSaveInterval(ui->spinInterval->value()); if (ui->rbCurrentFile->isChecked()) pSettings->editor().setAutoSaveTarget(astCurrentFile); @@ -74,6 +74,8 @@ void EditorAutoSaveWidget::doSave() pSettings->editor().setAutoSaveStrategy(assAppendUnixTimestamp); else pSettings->editor().setAutoSaveStrategy(assAppendFormatedTimeStamp); + pSettings->editor().save(); + pMainWindow->resetAutoSaveTimer(); } void EditorAutoSaveWidget::on_rbOverwrite_toggled(bool) diff --git a/RedPandaIDE/settingsdialog/editorautosavewidget.ui b/RedPandaIDE/settingsdialog/editorautosavewidget.ui index 5f36b260..7e6634dc 100644 --- a/RedPandaIDE/settingsdialog/editorautosavewidget.ui +++ b/RedPandaIDE/settingsdialog/editorautosavewidget.ui @@ -15,7 +15,7 @@ - + Enable auto save diff --git a/RedPandaIDE/widgets/darkfusionstyle.cpp b/RedPandaIDE/widgets/darkfusionstyle.cpp index 8a581ac9..ac5560fc 100644 --- a/RedPandaIDE/widgets/darkfusionstyle.cpp +++ b/RedPandaIDE/widgets/darkfusionstyle.cpp @@ -805,12 +805,12 @@ void DarkFusionStyle::drawControl(ControlElement element, const QStyleOption *op switch (element) { case CE_MenuItem: - painter->save(); // Draws one item in a popup menu. if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast(option)) { QColor highlightOutline = highlightedOutline; QColor highlight = option->palette.highlight().color(); if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) { + painter->save(); int w = 0; const int margin = int(QStyleHelper::dpiScaled(5, option)); if (!menuItem->text.isEmpty()) {