add auto-saving of modified editors

Task-number: QTCREATORBUG-2847
This commit is contained in:
Oswald Buddenhagen
2011-05-10 20:43:03 +02:00
parent a14955d0fb
commit 9ac137fb06
48 changed files with 398 additions and 89 deletions

View File

@@ -45,6 +45,7 @@
#include <QtGui/QMessageBox>
#include <QtGui/QMainWindow>
#include <QtGui/QUndoStack>
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
@@ -57,13 +58,16 @@ namespace Internal {
FormWindowFile::FormWindowFile(QDesignerFormWindowInterface *form, QObject *parent)
: Core::IFile(parent),
m_mimeType(QLatin1String(Designer::Constants::FORM_MIMETYPE)),
m_shouldAutoSave(false),
m_formWindow(form)
{
connect(m_formWindow->core()->formWindowManager(), SIGNAL(formWindowRemoved(QDesignerFormWindowInterface*)),
this, SLOT(slotFormWindowRemoved(QDesignerFormWindowInterface*)));
connect(m_formWindow->commandHistory(), SIGNAL(indexChanged(int)),
this, SLOT(setShouldAutoSave()));
}
bool FormWindowFile::save(QString *errorString, const QString &name /* = QString() */)
bool FormWindowFile::save(QString *errorString, const QString &name, bool autoSave)
{
const QString actualName = name.isEmpty() ? fileName() : name;
@@ -77,12 +81,16 @@ bool FormWindowFile::save(QString *errorString, const QString &name /* = QString
const QFileInfo fi(actualName);
const QString oldFormName = m_formWindow->fileName();
const QString formName = fi.absoluteFilePath();
m_formWindow->setFileName(formName);
if (!autoSave)
m_formWindow->setFileName(fi.absoluteFilePath());
const bool warningsEnabled = qdesigner_internal::QSimpleResource::setWarningsEnabled(false);
const bool writeOK = writeFile(actualName, errorString);
qdesigner_internal::QSimpleResource::setWarningsEnabled(warningsEnabled);
m_shouldAutoSave = false;
if (autoSave)
return writeOK;
if (!writeOK) {
m_formWindow->setFileName(oldFormName);
return false;
@@ -111,6 +119,11 @@ QString FormWindowFile::fileName() const
return m_fileName;
}
bool FormWindowFile::shouldAutoSave() const
{
return m_shouldAutoSave;
}
bool FormWindowFile::isModified() const
{
return m_formWindow && m_formWindow->isDirty();