disable save backup

This commit is contained in:
Roy Qu 2023-01-15 17:01:54 +08:00
parent dbc9a1829c
commit 00c19d1f4f
1 changed files with 44 additions and 40 deletions

View File

@ -206,26 +206,29 @@ Editor::~Editor() {
void Editor::loadFile(QString filename) { void Editor::loadFile(QString filename) {
if (filename.isEmpty()) { if (filename.isEmpty()) {
filename=mFilename; filename=mFilename;
for (int i=0;i<100;i++) { // save backup
QString backfilename = filename+".savebak"; // for (int i=0;i<100;i++) {
if (i>0) // QString backfilename = filename+".savebak";
backfilename += QString("%1").arg(i); // if (i>0)
if (fileExists(backfilename)) { // backfilename += QString("%1").arg(i);
if (QMessageBox::question(this,tr("Restore backup"), // if (fileExists(backfilename)) {
tr("Backup file '%1' detected.").arg(backfilename) // if (QMessageBox::question(this,tr("Restore backup"),
+"<br />" // tr("Backup file '%1' detected.").arg(backfilename)
+tr("Error occurred at last save.") // +"<br />"
+"<br />" // +tr("Error occurred at last save.")
+tr("Do you want to load the backup file?"), // +"<br />"
QMessageBox::Yes | QMessageBox::No)==QMessageBox::Yes) // +tr("Do you want to load the backup file?"),
filename = backfilename; // QMessageBox::Yes | QMessageBox::No)==QMessageBox::Yes)
break; // filename = backfilename;
} // break;
} // }
// }
} else { } else {
filename = QFileInfo(filename).absoluteFilePath(); filename = QFileInfo(filename).absoluteFilePath();
} }
//FileError should by catched by the caller of loadFile();
this->document()->loadFromFile(filename,mEncodingOption,mFileEncoding); this->document()->loadFromFile(filename,mEncodingOption,mFileEncoding);
//this->setModified(false); //this->setModified(false);
updateCaption(); updateCaption();
@ -257,36 +260,37 @@ void Editor::saveFile(QString filename) {
QByteArray encoding = mFileEncoding; QByteArray encoding = mFileEncoding;
if (mEncodingOption!=ENCODING_AUTO_DETECT || mFileEncoding==ENCODING_ASCII) if (mEncodingOption!=ENCODING_AUTO_DETECT || mFileEncoding==ENCODING_ASCII)
encoding = mEncodingOption; encoding = mEncodingOption;
QString backupFilename=filename+".savebak"; // save backup
int count=1; // QString backupFilename=filename+".savebak";
while (fileExists(backupFilename)) { // int count=1;
backupFilename=filename+QString(".savebak%1").arg(count); // while (fileExists(backupFilename)) {
count++; // backupFilename=filename+QString(".savebak%1").arg(count);
} // count++;
if (!fileExists(filename)) { // }
if (!stringToFile(text(),backupFilename)) { // if (!fileExists(filename)) {
if (QMessageBox::question(pMainWindow,tr("Error"), // if (!stringToFile(text(),backupFilename)) {
tr("Can't generate temporary backup file '%1'.").arg(backupFilename) // if (QMessageBox::question(pMainWindow,tr("Error"),
+"<br />" // tr("Can't generate temporary backup file '%1'.").arg(backupFilename)
+tr("Continue to save?"), // +"<br />"
QMessageBox::Yes | QMessageBox::No,QMessageBox::No)!=QMessageBox::Yes) // +tr("Continue to save?"),
return; // QMessageBox::Yes | QMessageBox::No,QMessageBox::No)!=QMessageBox::Yes)
} // return;
} else if (!QFile::copy(filename,backupFilename)) { // }
if (QMessageBox::question(pMainWindow,tr("Error"), // } else if (!QFile::copy(filename,backupFilename)) {
tr("Can't generate temporary backup file '%1'.").arg(backupFilename) // if (QMessageBox::question(pMainWindow,tr("Error"),
+"<br />" // tr("Can't generate temporary backup file '%1'.").arg(backupFilename)
+tr("Continue to save?"), // +"<br />"
QMessageBox::Yes | QMessageBox::No,QMessageBox::No)!=QMessageBox::Yes) // +tr("Continue to save?"),
return; // QMessageBox::Yes | QMessageBox::No,QMessageBox::No)!=QMessageBox::Yes)
} // return;
// }
this->document()->saveToFile(file,encoding, this->document()->saveToFile(file,encoding,
pSettings->editor().defaultEncoding(), pSettings->editor().defaultEncoding(),
mFileEncoding); mFileEncoding);
if (isVisible() && mParentPageControl) if (isVisible() && mParentPageControl)
pMainWindow->updateForEncodingInfo(this); pMainWindow->updateForEncodingInfo(this);
emit fileSaved(filename, inProject()); emit fileSaved(filename, inProject());
QFile::remove(backupFilename); // QFile::remove(backupFilename);
} }
void Editor::convertToEncoding(const QByteArray &encoding) void Editor::convertToEncoding(const QByteArray &encoding)