mirror of https://github.com/vitalif/openscad
#665 support multiple open files with the same basename. Always clean up backups on window close
parent
3e6f659990
commit
0b8929cf1c
|
@ -1045,9 +1045,14 @@ void MainWindow::saveBackup()
|
||||||
QString backupPath = QString::fromStdString(path);
|
QString backupPath = QString::fromStdString(path);
|
||||||
if (!backupPath.endsWith("/")) backupPath.append("/");
|
if (!backupPath.endsWith("/")) backupPath.append("/");
|
||||||
|
|
||||||
if (this->fileName.isEmpty()) {
|
QString basename = "unsaved";
|
||||||
|
if (!this->fileName.isEmpty()) {
|
||||||
|
QFileInfo fileInfo = QFileInfo(this->fileName);
|
||||||
|
basename = fileInfo.baseName();
|
||||||
|
}
|
||||||
|
|
||||||
if (!this->tempFile) {
|
if (!this->tempFile) {
|
||||||
this->tempFile = new QTemporaryFile(backupPath.append("unsaved-backup-XXXXXXXX.scad"));
|
this->tempFile = new QTemporaryFile(backupPath.append(basename + "-backup-XXXXXXXX.scad"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!this->tempFile->isOpen()) && (! this->tempFile->open())) {
|
if ((!this->tempFile->isOpen()) && (! this->tempFile->open())) {
|
||||||
|
@ -1057,23 +1062,6 @@ void MainWindow::saveBackup()
|
||||||
return writeBackup(this->tempFile);
|
return writeBackup(this->tempFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
QFileInfo fileInfo = QFileInfo(this->fileName);
|
|
||||||
|
|
||||||
backupPath.append(fileInfo.baseName())
|
|
||||||
.append("-backup.")
|
|
||||||
.append(fileInfo.suffix());
|
|
||||||
|
|
||||||
QFile file(backupPath);
|
|
||||||
|
|
||||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
|
||||||
PRINTB("WARNING: Failed to open backup file for writing: %s (%s)", backupPath.toLocal8Bit().constData() % file.errorString().toLocal8Bit().constData());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
writeBackup(&file);
|
|
||||||
file.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::actionSave()
|
void MainWindow::actionSave()
|
||||||
{
|
{
|
||||||
if (this->fileName.isEmpty()) {
|
if (this->fileName.isEmpty()) {
|
||||||
|
|
Loading…
Reference in New Issue