- enhancement: Pause autosave timer when autosave new files.

This commit is contained in:
Roy Qu 2023-01-26 11:33:27 +08:00
parent 7b13d3a519
commit 79bf453c6c
1 changed files with 30 additions and 31 deletions

View File

@ -2431,12 +2431,7 @@ void MainWindow::doAutoSave(Editor *e)
QString suffix = fileInfo.suffix(); QString suffix = fileInfo.suffix();
switch(pSettings->editor().autoSaveStrategy()) { switch(pSettings->editor().autoSaveStrategy()) {
case assOverwrite: case assOverwrite:
if (e->isNew()) { e->save();
mAutoSaveTimer.stop();
e->save();
mAutoSaveTimer.start(pSettings->editor().autoSaveInterval()*60*1000);
} else
e->save();
return; return;
case assAppendUnixTimestamp: case assAppendUnixTimestamp:
filename = parent.filePath( filename = parent.filePath(
@ -2455,9 +2450,7 @@ void MainWindow::doAutoSave(Editor *e)
} }
} }
if (e->isNew()) { if (e->isNew()) {
mAutoSaveTimer.stop();
e->saveAs(); e->saveAs();
mAutoSaveTimer.start(pSettings->editor().autoSaveInterval()*60*1000);
} else { } else {
e->saveFile(filename); e->saveFile(filename);
e->setCanAutoSave(false); e->setCanAutoSave(false);
@ -3449,35 +3442,41 @@ void MainWindow::onAutoSaveTimeout()
return; return;
if (!pSettings->editor().enableAutoSave()) if (!pSettings->editor().enableAutoSave())
return; return;
int updateCount = 0; mAutoSaveTimer.stop();
switch (pSettings->editor().autoSaveTarget()) { {
case astCurrentFile: { auto action=finally([this]{
Editor *e = mEditorList->getEditor(); mAutoSaveTimer.start(pSettings->editor().autoSaveInterval()*60*1000);
doAutoSave(e); });
updateCount++; int updateCount = 0;
} switch (pSettings->editor().autoSaveTarget()) {
break; case astCurrentFile: {
case astAllOpennedFiles: Editor *e = mEditorList->getEditor();
for (int i=0;i<mEditorList->pageCount();i++) {
Editor *e = (*mEditorList)[i];
doAutoSave(e); doAutoSave(e);
updateCount++; updateCount++;
} }
break; break;
case astAllProjectFiles: case astAllOpennedFiles:
if (!mProject) for (int i=0;i<mEditorList->pageCount();i++) {
return; Editor *e = (*mEditorList)[i];
for (int i=0;i<mEditorList->pageCount();i++) { doAutoSave(e);
Editor *e = (*mEditorList)[i]; updateCount++;
if (!e->inProject()) }
break;
case astAllProjectFiles:
if (!mProject)
return; return;
doAutoSave(e); for (int i=0;i<mEditorList->pageCount();i++) {
updateCount++; Editor *e = (*mEditorList)[i];
if (!e->inProject())
return;
doAutoSave(e);
updateCount++;
}
//todo: auto save project files
break;
} }
//todo: auto save project files updateStatusbarMessage(tr("%1 files autosaved").arg(updateCount));
break;
} }
updateStatusbarMessage(tr("%1 files autosaved").arg(updateCount));
} }
void MainWindow::onWatchViewContextMenu(const QPoint &pos) void MainWindow::onWatchViewContextMenu(const QPoint &pos)