Let user choose if continue to save, if backup file creation failed.
This commit is contained in:
parent
ac20a2c458
commit
edeb47d2c2
|
@ -53,24 +53,6 @@
|
|||
#include "project.h"
|
||||
#include <qt_utils/charsetinfo.h>
|
||||
|
||||
SaveException::SaveException(const QString& reason) {
|
||||
mReason = reason;
|
||||
mReasonBuffer = mReason.toLocal8Bit();
|
||||
}
|
||||
|
||||
SaveException::SaveException(const QString&& reason) {
|
||||
mReason = reason;
|
||||
mReasonBuffer = mReason.toLocal8Bit();
|
||||
}
|
||||
|
||||
const QString& SaveException::reason() const noexcept{
|
||||
return mReason;
|
||||
}
|
||||
|
||||
const char* SaveException::what() const noexcept {
|
||||
return mReasonBuffer;
|
||||
}
|
||||
|
||||
QHash<ParserLanguage,std::weak_ptr<CppParser>> Editor::mSharedParsers;
|
||||
|
||||
Editor::Editor(QWidget *parent):
|
||||
|
@ -252,14 +234,20 @@ void Editor::saveFile(QString filename) {
|
|||
}
|
||||
if (!fileExists(filename)) {
|
||||
if (!stringToFile(text(),backupFilename)) {
|
||||
QMessageBox::critical(pMainWindow,tr("Error"),
|
||||
tr("Can't generate temporary backup file '%1'.").arg(backupFilename));
|
||||
return;
|
||||
if (QMessageBox::question(pMainWindow,tr("Error"),
|
||||
tr("Can't generate temporary backup file '%1'.").arg(backupFilename)
|
||||
+"<br />"
|
||||
+tr("Continue to save?"),
|
||||
QMessageBox::Yes | QMessageBox::No,QMessageBox::No)!=QMessageBox::Yes)
|
||||
return;
|
||||
}
|
||||
} else if (!QFile::copy(filename,backupFilename)) {
|
||||
QMessageBox::critical(pMainWindow,tr("Error"),
|
||||
tr("Can't generate temporary backup file '%1'.").arg(backupFilename));
|
||||
return;
|
||||
if (QMessageBox::question(pMainWindow,tr("Error"),
|
||||
tr("Can't generate temporary backup file '%1'.").arg(backupFilename)
|
||||
+"<br />"
|
||||
+tr("Continue to save?"),
|
||||
QMessageBox::Yes | QMessageBox::No,QMessageBox::No)!=QMessageBox::Yes)
|
||||
return;
|
||||
}
|
||||
this->document()->saveToFile(file,encoding,
|
||||
pSettings->editor().defaultEncoding(),
|
||||
|
@ -298,7 +286,7 @@ bool Editor::save(bool force, bool doReparse) {
|
|||
setModified(false);
|
||||
mIsNew = false;
|
||||
updateCaption();
|
||||
} catch (SaveException& exception) {
|
||||
} catch (FileError& exception) {
|
||||
if (!force) {
|
||||
QMessageBox::critical(pMainWindow,tr("Error"),
|
||||
exception.reason());
|
||||
|
@ -414,7 +402,7 @@ bool Editor::saveAs(const QString &name, bool fromProject){
|
|||
saveFile(mFilename);
|
||||
mIsNew = false;
|
||||
setModified(false);
|
||||
} catch (SaveException& exception) {
|
||||
} catch (FileError& exception) {
|
||||
QMessageBox::critical(pMainWindow,tr("Error"),
|
||||
exception.reason());
|
||||
return false;
|
||||
|
|
|
@ -41,20 +41,6 @@ struct TabStop {
|
|||
|
||||
using PTabStop = std::shared_ptr<TabStop>;
|
||||
|
||||
class SaveException: public std::exception {
|
||||
|
||||
public:
|
||||
explicit SaveException(const QString& reason);
|
||||
explicit SaveException(const QString&& reason);
|
||||
// exception interface
|
||||
const QString& reason() const noexcept;
|
||||
public:
|
||||
const char *what() const noexcept override;
|
||||
private:
|
||||
QString mReason;
|
||||
QByteArray mReasonBuffer;
|
||||
};
|
||||
|
||||
class Editor : public QSynedit::QSynEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
|
@ -5372,13 +5372,9 @@ void MainWindow::on_actionSave_triggered()
|
|||
{
|
||||
Editor * editor = mEditorList->getEditor();
|
||||
if (editor) {
|
||||
try {
|
||||
editor->save();
|
||||
editor->save();
|
||||
// if (editor->inProject() && (mProject))
|
||||
// mProject->saveAll();
|
||||
} catch(FileError e) {
|
||||
QMessageBox::critical(editor,tr("Error"),e.reason());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5386,11 +5382,7 @@ void MainWindow::on_actionSaveAs_triggered()
|
|||
{
|
||||
Editor * editor = mEditorList->getEditor();
|
||||
if (editor) {
|
||||
try {
|
||||
editor->saveAs();
|
||||
} catch(FileError e) {
|
||||
QMessageBox::critical(editor,tr("Error"),e.reason());
|
||||
}
|
||||
editor->saveAs();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -547,21 +547,19 @@ void Document::loadUTF32BOMFile(QFile &file)
|
|||
this->setText(text);
|
||||
}
|
||||
|
||||
void Document::saveUTF16File(QFile &file)
|
||||
void Document::saveUTF16File(QFile &file, QTextCodec* codec)
|
||||
{
|
||||
QString text=getTextStr();
|
||||
QTextCodec* codec=QTextCodec::codecForName(ENCODING_UTF16);
|
||||
if (!codec)
|
||||
return;
|
||||
QString text=getTextStr();
|
||||
file.write(codec->fromUnicode(text));
|
||||
}
|
||||
|
||||
void Document::saveUTF32File(QFile &file)
|
||||
void Document::saveUTF32File(QFile &file, QTextCodec* codec)
|
||||
{
|
||||
QString text=getTextStr();
|
||||
QTextCodec* codec=QTextCodec::codecForName(ENCODING_UTF32);
|
||||
if (!codec)
|
||||
return;
|
||||
QString text=getTextStr();
|
||||
file.write(codec->fromUnicode(text));
|
||||
}
|
||||
|
||||
|
@ -757,10 +755,10 @@ void Document::saveToFile(QFile &file, const QByteArray& encoding,
|
|||
if (mLines.isEmpty())
|
||||
return;
|
||||
if (realEncoding == ENCODING_UTF16) {
|
||||
saveUTF16File(file);
|
||||
saveUTF16File(file,codec);
|
||||
return;
|
||||
} else if (realEncoding == ENCODING_UTF32) {
|
||||
saveUTF32File(file);
|
||||
saveUTF32File(file,codec);
|
||||
return;
|
||||
} if (realEncoding == ENCODING_UTF8_BOM) {
|
||||
file.putChar(0xEF);
|
||||
|
|
|
@ -136,8 +136,8 @@ private:
|
|||
bool tryLoadFileByEncoding(QByteArray encodingName, QFile& file);
|
||||
void loadUTF16BOMFile(QFile& file);
|
||||
void loadUTF32BOMFile(QFile& file);
|
||||
void saveUTF16File(QFile& file);
|
||||
void saveUTF32File(QFile& file);
|
||||
void saveUTF16File(QFile& file, QTextCodec* codec);
|
||||
void saveUTF32File(QFile& file, QTextCodec* codec);
|
||||
|
||||
private:
|
||||
DocumentLines mLines;
|
||||
|
|
Loading…
Reference in New Issue