- 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
This commit is contained in:
royqh1979@gmail.com 2021-11-12 12:40:47 +08:00
parent 58ba490f32
commit d28805ea55
7 changed files with 67 additions and 30 deletions

View File

@ -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

View File

@ -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;

View File

@ -269,6 +269,7 @@ private:
int mTabStopBegin;
int mTabStopEnd;
int mTabStopY;
bool mCanAutoSave;
QString mLineBeforeTabStop;
QString mLineAfterTabStop;
QList<PTabStop> 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;

View File

@ -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) {

View File

@ -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)

View File

@ -15,7 +15,7 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="chkEnableAutoSave">
<widget class="QGroupBox" name="grpEnableAutoSave">
<property name="title">
<string>Enable auto save</string>
</property>

View File

@ -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<const QStyleOptionMenuItem *>(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()) {