diff --git a/src/libs/modelinglib/qmt/document_controller/documentcontroller.cpp b/src/libs/modelinglib/qmt/document_controller/documentcontroller.cpp index 8af722de62b..f6271ff14d3 100644 --- a/src/libs/modelinglib/qmt/document_controller/documentcontroller.cpp +++ b/src/libs/modelinglib/qmt/document_controller/documentcontroller.cpp @@ -76,20 +76,17 @@ DocumentController::DocumentController(QObject *parent) : { // project controller connect(m_projectController, &ProjectController::changed, this, &DocumentController::changed); - connect(m_projectController, &ProjectController::modificationChanged, this, &DocumentController::modificationChanged); // model controller m_modelController->setUndoController(m_undoController); - connect(m_modelController, &ModelController::modified, [this](){ - m_projectController->setModified(true); - }); + connect(m_modelController, &ModelController::modified, + m_projectController, &ProjectController::setModified); // diagram controller m_diagramController->setModelController(m_modelController); m_diagramController->setUndoController(m_undoController); - connect(m_diagramController, &DiagramController::modified, [this](){ - m_projectController->setModified(true); - }); + connect(m_diagramController, &DiagramController::modified, + m_projectController, &ProjectController::setModified); // diagram scene controller m_diagramSceneController->setModelController(m_modelController); diff --git a/src/libs/modelinglib/qmt/document_controller/documentcontroller.h b/src/libs/modelinglib/qmt/document_controller/documentcontroller.h index b9eb3a53719..d9a253773f9 100644 --- a/src/libs/modelinglib/qmt/document_controller/documentcontroller.h +++ b/src/libs/modelinglib/qmt/document_controller/documentcontroller.h @@ -61,7 +61,6 @@ public: signals: void changed(); - void modificationChanged(bool modified); void modelClipboardChanged(bool isEmpty); void diagramClipboardChanged(bool isEmpty); diff --git a/src/libs/modelinglib/qmt/project_controller/projectcontroller.cpp b/src/libs/modelinglib/qmt/project_controller/projectcontroller.cpp index 384bb52281a..9698a2f601f 100644 --- a/src/libs/modelinglib/qmt/project_controller/projectcontroller.cpp +++ b/src/libs/modelinglib/qmt/project_controller/projectcontroller.cpp @@ -43,7 +43,8 @@ ProjectIsModifiedException::ProjectIsModifiedException() } ProjectController::ProjectController(QObject *parent) - : QObject(parent) + : QObject(parent), + m_isModified(false) { } @@ -58,7 +59,7 @@ void ProjectController::newProject(const QString &fileName) rootPackage->setName(tr("Model")); m_project->setRootPackage(rootPackage); m_project->setFileName(fileName); - setModified(false); + m_isModified = false; emit fileNameChanged(m_project->fileName()); emit changed(); } @@ -67,18 +68,17 @@ void ProjectController::setFileName(const QString &fileName) { if (fileName != m_project->fileName()) { m_project->setFileName(fileName); - setModified(true); + setModified(); emit fileNameChanged(m_project->fileName()); } } -void ProjectController::setModified(bool modified) +void ProjectController::setModified() { - if (m_isModified == modified) - return; - - m_isModified = modified; - emit modificationChanged(modified); + if (!m_isModified) { + m_isModified = true; + emit changed(); + } } void ProjectController::load() @@ -89,7 +89,7 @@ void ProjectController::load() throw NoFileNameException(); ProjectSerializer serializer; serializer.load(m_project->fileName(), m_project.data()); - setModified(false); + m_isModified = false; emit changed(); } @@ -99,7 +99,7 @@ void ProjectController::save() throw NoFileNameException(); ProjectSerializer serializer; serializer.save(m_project->fileName(), m_project.data()); - setModified(false); + m_isModified = false; emit changed(); } diff --git a/src/libs/modelinglib/qmt/project_controller/projectcontroller.h b/src/libs/modelinglib/qmt/project_controller/projectcontroller.h index a4eb47f9a60..73daf2a2ac9 100644 --- a/src/libs/modelinglib/qmt/project_controller/projectcontroller.h +++ b/src/libs/modelinglib/qmt/project_controller/projectcontroller.h @@ -58,7 +58,6 @@ public: signals: void changed(); void fileNameChanged(const QString &fileName); - void modificationChanged(bool modified); public: Project *project() const { return m_project.data(); } @@ -66,7 +65,7 @@ public: void newProject(const QString &fileName); void setFileName(const QString &fileName); - void setModified(bool modified); + void setModified(); void load(); void save(); @@ -74,7 +73,7 @@ public: private: QScopedPointer m_project; - bool m_isModified = false; + bool m_isModified; }; } // namespace qmt diff --git a/src/plugins/android/androidmanifestdocument.cpp b/src/plugins/android/androidmanifestdocument.cpp index 01b1e3d8106..e3473a891b0 100644 --- a/src/plugins/android/androidmanifestdocument.cpp +++ b/src/plugins/android/androidmanifestdocument.cpp @@ -43,12 +43,8 @@ AndroidManifestDocument::AndroidManifestDocument(AndroidManifestEditorWidget *ed setId(Constants::ANDROID_MANIFEST_EDITOR_ID); setMimeType(QLatin1String(Constants::ANDROID_MANIFEST_MIME_TYPE)); setSuspendAllowed(false); - connect(editorWidget, &AndroidManifestEditorWidget::modificationChanged, - this, &Core::IDocument::setModified); - connect(this, &Core::IDocument::modificationChanged, - editorWidget, &AndroidManifestEditorWidget::setModified); - - setModified(editorWidget->isModified()); + connect(editorWidget, &AndroidManifestEditorWidget::guiChanged, + this, &Core::IDocument::changed); } bool AndroidManifestDocument::save(QString *errorString, const QString &fileName, bool autoSave) @@ -59,6 +55,11 @@ bool AndroidManifestDocument::save(QString *errorString, const QString &fileName return result; } +bool AndroidManifestDocument::isModified() const +{ + return TextDocument::isModified() || m_editorWidget->isModified(); +} + bool AndroidManifestDocument::isSaveAsAllowed() const { return false; diff --git a/src/plugins/android/androidmanifestdocument.h b/src/plugins/android/androidmanifestdocument.h index 28b8bc8306e..169047f0516 100644 --- a/src/plugins/android/androidmanifestdocument.h +++ b/src/plugins/android/androidmanifestdocument.h @@ -39,6 +39,7 @@ public: bool save(QString *errorString, const QString &fileName = QString(), bool autoSave = false) override; + bool isModified() const override; bool isSaveAsAllowed() const override; private: diff --git a/src/plugins/android/androidmanifesteditorwidget.cpp b/src/plugins/android/androidmanifesteditorwidget.cpp index 6c8f7670715..a2d1d8beed8 100644 --- a/src/plugins/android/androidmanifesteditorwidget.cpp +++ b/src/plugins/android/androidmanifesteditorwidget.cpp @@ -101,7 +101,7 @@ Project *androidProject(const Utils::FileName &fileName) AndroidManifestEditorWidget::AndroidManifestEditorWidget() : QStackedWidget(), - m_modified(false), + m_dirty(false), m_stayClean(false) { m_textEditorWidget = new AndroidManifestTextEditorWidget(this); @@ -138,7 +138,7 @@ void AndroidManifestEditorWidget::initializePage() QGroupBox *packageGroupBox = new QGroupBox(mainWidget); topLayout->addWidget(packageGroupBox); - auto setDirtyFunc = [this] { setModified(); }; + auto setDirtyFunc = [this] { setDirty(); }; packageGroupBox->setTitle(tr("Package")); { QFormLayout *formLayout = new QFormLayout(); @@ -206,7 +206,7 @@ void AndroidManifestEditorWidget::initializePage() connect(m_packageNameLineEdit, &QLineEdit::textEdited, this, &AndroidManifestEditorWidget::setPackageName); connect(m_versionCode, static_cast(&QSpinBox::valueChanged), - this, &AndroidManifestEditorWidget::setModified); + this, &AndroidManifestEditorWidget::setDirty); connect(m_versionNameLinedit, &QLineEdit::textEdited, this, setDirtyFunc); connect(m_androidMinSdkVersion, @@ -524,17 +524,17 @@ void AndroidManifestEditorWidget::updateAfterFileLoad() setActivePage(Source); } -void AndroidManifestEditorWidget::setModified(bool modified) +void AndroidManifestEditorWidget::setDirty(bool dirty) { - if (m_stayClean || modified == m_modified) + if (m_stayClean || dirty == m_dirty) return; - m_modified = modified; - emit modificationChanged(modified); + m_dirty = dirty; + emit guiChanged(); } bool AndroidManifestEditorWidget::isModified() const { - return m_modified + return m_dirty || !m_hIconPath.isEmpty() || !m_mIconPath.isEmpty() || !m_lIconPath.isEmpty(); @@ -819,7 +819,7 @@ void AndroidManifestEditorWidget::syncToWidgets(const QDomDocument &doc) updateAddRemovePermissionButtons(); m_stayClean = false; - m_modified = false; + m_dirty = false; } int extractVersion(const QString &string) @@ -862,7 +862,7 @@ void AndroidManifestEditorWidget::syncToEditor() m_textEditorWidget->setPlainText(result); m_textEditorWidget->document()->setModified(true); - m_modified = false; + m_dirty = false; } namespace { @@ -1253,7 +1253,7 @@ void AndroidManifestEditorWidget::setLDPIIcon() return; m_lIconPath = file; m_lIconButton->setIcon(QIcon(file)); - setModified(true); + setDirty(true); } void AndroidManifestEditorWidget::setMDPIIcon() @@ -1263,7 +1263,7 @@ void AndroidManifestEditorWidget::setMDPIIcon() return; m_mIconPath = file; m_mIconButton->setIcon(QIcon(file)); - setModified(true); + setDirty(true); } void AndroidManifestEditorWidget::setHDPIIcon() @@ -1273,12 +1273,12 @@ void AndroidManifestEditorWidget::setHDPIIcon() return; m_hIconPath = file; m_hIconButton->setIcon(QIcon(file)); - setModified(true); + setDirty(true); } void AndroidManifestEditorWidget::defaultPermissionOrFeatureCheckBoxClicked() { - setModified(true); + setDirty(true); } void AndroidManifestEditorWidget::updateAddRemovePermissionButtons() @@ -1293,7 +1293,7 @@ void AndroidManifestEditorWidget::addPermission() { m_permissionsModel->addPermission(m_permissionsComboBox->currentText()); updateAddRemovePermissionButtons(); - setModified(true); + setDirty(true); } void AndroidManifestEditorWidget::removePermission() @@ -1302,7 +1302,7 @@ void AndroidManifestEditorWidget::removePermission() if (idx.isValid()) m_permissionsModel->removePermission(idx.row()); updateAddRemovePermissionButtons(); - setModified(true); + setDirty(true); } void AndroidManifestEditorWidget::setPackageName() @@ -1312,7 +1312,7 @@ void AndroidManifestEditorWidget::setPackageName() bool valid = checkPackageName(packageName); m_packageNameWarning->setVisible(!valid); m_packageNameWarningIcon->setVisible(!valid); - setModified(true); + setDirty(true); } diff --git a/src/plugins/android/androidmanifesteditorwidget.h b/src/plugins/android/androidmanifesteditorwidget.h index 899393ca349..9dab5e8d1a3 100644 --- a/src/plugins/android/androidmanifesteditorwidget.h +++ b/src/plugins/android/androidmanifesteditorwidget.h @@ -101,10 +101,10 @@ public: Core::IEditor *editor() const; TextEditor::TextEditorWidget *textEditorWidget() const; - void setModified(bool modified = true); + void setDirty(bool dirty = true); signals: - void modificationChanged(bool modified); + void guiChanged(); protected: bool eventFilter(QObject *obj, QEvent *event); @@ -150,7 +150,7 @@ private: QString parseComment(QXmlStreamReader &reader, QXmlStreamWriter &writer); void parseUnknownElement(QXmlStreamReader &reader, QXmlStreamWriter &writer); - bool m_modified; // indicates that we need to call syncToEditor() + bool m_dirty; // indicates that we need to call syncToEditor() bool m_stayClean; int m_errorLine; int m_errorColumn; diff --git a/src/plugins/bineditor/bineditorplugin.cpp b/src/plugins/bineditor/bineditorplugin.cpp index 050bbcb6971..5fcccd78386 100644 --- a/src/plugins/bineditor/bineditorplugin.cpp +++ b/src/plugins/bineditor/bineditorplugin.cpp @@ -320,6 +320,12 @@ public: } public: + bool isModified() const override + { + return isTemporary()/*e.g. memory view*/ ? false + : m_widget->isModified(); + } + bool isFileReadOnly() const override { const FileName fn = filePath(); if (fn.isEmpty()) @@ -385,12 +391,7 @@ public: connect(m_addressEdit, &QLineEdit::editingFinished, this, &BinEditor::jumpToAddress); connect(widget, &BinEditorWidget::modificationChanged, - m_file, &IDocument::setModified); - connect(m_file, &IDocument::modificationChanged, - widget, &BinEditorWidget::setModified); - - m_file->setModified(widget->isModified()); - + m_file, &IDocument::changed); updateCursorPosition(widget->cursorPosition()); } diff --git a/src/plugins/coreplugin/documentmanager.cpp b/src/plugins/coreplugin/documentmanager.cpp index 2553b96e612..6ba6d61ca24 100644 --- a/src/plugins/coreplugin/documentmanager.cpp +++ b/src/plugins/coreplugin/documentmanager.cpp @@ -1052,7 +1052,6 @@ void DocumentManager::checkForReload() documentsToClose << document; } else if (defaultBehavior == IDocument::IgnoreAll) { // content change or removed, but settings say ignore - document->setModified(true); success = document->reload(&errorString, IDocument::FlagIgnore, type); // either the default behavior is to always ask, // or the ReloadUnmodified default behavior didn't kick in, @@ -1070,7 +1069,6 @@ void DocumentManager::checkForReload() // content change, IDocument wants to ask user if (previousReloadAnswer == ReloadNone) { // answer already given, ignore - document->setModified(true); success = document->reload(&errorString, IDocument::FlagIgnore, IDocument::TypeContents); } else if (previousReloadAnswer == ReloadAll) { // answer already given, reload @@ -1086,7 +1084,6 @@ void DocumentManager::checkForReload() break; case ReloadSkipCurrent: case ReloadNone: - document->setModified(true); success = document->reload(&errorString, IDocument::FlagIgnore, IDocument::TypeContents); break; case CloseCurrent: diff --git a/src/plugins/coreplugin/idocument.cpp b/src/plugins/coreplugin/idocument.cpp index 9023eb73eae..fefff6a701b 100644 --- a/src/plugins/coreplugin/idocument.cpp +++ b/src/plugins/coreplugin/idocument.cpp @@ -79,7 +79,6 @@ public: bool hasWriteWarning = false; bool restored = false; bool isSuspendAllowed = false; - bool isModified = false; }; } // namespace Internal @@ -201,17 +200,7 @@ bool IDocument::shouldAutoSave() const bool IDocument::isModified() const { - return d->isModified; -} - -void IDocument::setModified(bool modified) -{ - if (d->isModified == modified) - return; - - d->isModified = modified; - emit modificationChanged(modified); - emit changed(); + return false; } bool IDocument::isSaveAsAllowed() const diff --git a/src/plugins/coreplugin/idocument.h b/src/plugins/coreplugin/idocument.h index 79cc403e6f4..acb1feb58b8 100644 --- a/src/plugins/coreplugin/idocument.h +++ b/src/plugins/coreplugin/idocument.h @@ -106,9 +106,6 @@ public: bool isTemporary() const; void setTemporary(bool temporary); - bool isModified() const; - void setModified(bool modified); - virtual QString fallbackSaveAsPath() const; virtual QString fallbackSaveAsFileName() const; @@ -116,6 +113,7 @@ public: void setMimeType(const QString &mimeType); virtual bool shouldAutoSave() const; + virtual bool isModified() const; virtual bool isSaveAsAllowed() const; bool isSuspendAllowed() const; void setSuspendAllowed(bool value); @@ -138,8 +136,6 @@ signals: // For meta data changes: file name, modified state, ... void changed(); - void modificationChanged(bool modified); - // For changes in the contents of the document void contentsChanged(); diff --git a/src/plugins/designer/formwindowfile.cpp b/src/plugins/designer/formwindowfile.cpp index a6c58617fc9..44ec146b776 100644 --- a/src/plugins/designer/formwindowfile.cpp +++ b/src/plugins/designer/formwindowfile.cpp @@ -59,9 +59,6 @@ FormWindowFile::FormWindowFile(QDesignerFormWindowInterface *form, QObject *pare connect(m_formWindow->commandHistory(), &QUndoStack::indexChanged, this, &FormWindowFile::setShouldAutoSave); connect(m_formWindow.data(), &QDesignerFormWindowInterface::changed, this, &FormWindowFile::updateIsModified); - connect(this, &IDocument::modificationChanged, m_formWindow.data(), &QDesignerFormWindowInterface::setDirty); - - setModified(m_formWindow->isDirty()); m_resourceHandler = new ResourceHandler(form); connect(this, &FormWindowFile::filePathChanged, @@ -189,7 +186,10 @@ void FormWindowFile::updateIsModified() bool value = m_formWindow && m_formWindow->isDirty(); if (value) emit contentsChanged(); - setModified(value); + if (value == m_isModified) + return; + m_isModified = value; + emit changed(); } bool FormWindowFile::shouldAutoSave() const @@ -197,6 +197,11 @@ bool FormWindowFile::shouldAutoSave() const return m_shouldAutoSave; } +bool FormWindowFile::isModified() const +{ + return m_formWindow && m_formWindow->isDirty(); +} + bool FormWindowFile::isSaveAsAllowed() const { return true; diff --git a/src/plugins/designer/formwindowfile.h b/src/plugins/designer/formwindowfile.h index f12e854a2a1..7ee62bb9518 100644 --- a/src/plugins/designer/formwindowfile.h +++ b/src/plugins/designer/formwindowfile.h @@ -53,6 +53,7 @@ public: QByteArray contents() const override; bool setContents(const QByteArray &contents) override; bool shouldAutoSave() const override; + bool isModified() const override; bool isSaveAsAllowed() const override; bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override; QString fallbackSaveAsFileName() const override; @@ -81,6 +82,7 @@ private: // Might actually go out of scope before the IEditor due // to deleting the WidgetHost which owns it. QPointer m_formWindow; + bool m_isModified = false; ResourceHandler *m_resourceHandler = nullptr; }; diff --git a/src/plugins/modeleditor/extpropertiesmview.cpp b/src/plugins/modeleditor/extpropertiesmview.cpp index 20376216583..529f251dca2 100644 --- a/src/plugins/modeleditor/extpropertiesmview.cpp +++ b/src/plugins/modeleditor/extpropertiesmview.cpp @@ -92,7 +92,7 @@ void ExtPropertiesMView::onConfigPathChanged(const QString &path) if (path.isEmpty()) { if (!project->configPath().isEmpty()) { project->setConfigPath(QString()); - m_projectController->setModified(true); + m_projectController->setModified(); modified = true; } } else { @@ -103,7 +103,7 @@ void ExtPropertiesMView::onConfigPathChanged(const QString &path) QString configPath = projectDir.relativeFilePath(absConfigPath.filePath()); if (configPath != project->configPath()) { project->setConfigPath(configPath); - m_projectController->setModified(true); + m_projectController->setModified(); modified = true; } } diff --git a/src/plugins/modeleditor/modeldocument.cpp b/src/plugins/modeleditor/modeldocument.cpp index 82a38f19ef8..e75ff0760e1 100644 --- a/src/plugins/modeleditor/modeldocument.cpp +++ b/src/plugins/modeleditor/modeldocument.cpp @@ -94,7 +94,7 @@ bool ModelDocument::save(QString *errorString, const QString &name, bool autoSav } if (autoSave) { - d->documentController->projectController()->setModified(true); + d->documentController->projectController()->setModified(); } else { setFilePath(Utils::FileName::fromString(d->documentController->projectController()->project()->fileName())); emit changed(); @@ -108,6 +108,11 @@ bool ModelDocument::shouldAutoSave() const return isModified(); } +bool ModelDocument::isModified() const +{ + return d->documentController ? d->documentController->projectController()->isModified() : false; +} + bool ModelDocument::isSaveAsAllowed() const { return true; @@ -135,10 +140,6 @@ Core::IDocument::OpenResult ModelDocument::load(QString *errorString, const QStr { d->documentController = ModelEditorPlugin::modelsManager()->createModel(this); connect(d->documentController, &qmt::DocumentController::changed, this, &IDocument::changed); - connect(d->documentController, &qmt::DocumentController::modificationChanged, this, &IDocument::setModified); - connect(this, &IDocument::modificationChanged, - d->documentController->projectController(), &qmt::ProjectController::setModified); - setModified(d->documentController->projectController()->isModified()); try { d->documentController->loadProject(fileName); diff --git a/src/plugins/modeleditor/modeldocument.h b/src/plugins/modeleditor/modeldocument.h index 2d0a0aafee2..f83085866ab 100644 --- a/src/plugins/modeleditor/modeldocument.h +++ b/src/plugins/modeleditor/modeldocument.h @@ -52,6 +52,7 @@ public: const QString &realFileName) override; bool save(QString *errorString, const QString &fileName, bool autoSave) override; bool shouldAutoSave() const override; + bool isModified() const override; bool isSaveAsAllowed() const override; bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override; diff --git a/src/plugins/resourceeditor/resourceeditorw.cpp b/src/plugins/resourceeditor/resourceeditorw.cpp index 765aa5e1104..2058c3a2eaf 100644 --- a/src/plugins/resourceeditor/resourceeditorw.cpp +++ b/src/plugins/resourceeditor/resourceeditorw.cpp @@ -63,14 +63,10 @@ ResourceEditorDocument::ResourceEditorDocument(QObject *parent) : setId(ResourceEditor::Constants::RESOURCEEDITOR_ID); setMimeType(QLatin1String(ResourceEditor::Constants::C_RESOURCE_MIMETYPE)); connect(m_model, &RelativeResourceModel::dirtyChanged, - this, &ResourceEditorDocument::setModified); - connect(this, &IDocument::modificationChanged, - m_model, &RelativeResourceModel::setDirty); + this, &ResourceEditorDocument::dirtyChanged); connect(m_model, &ResourceModel::contentsChanged, this, &IDocument::contentsChanged); - setModified(m_model->dirty()); - if (debugResourceEditorW) qDebug() << "ResourceEditorFile::ResourceEditorFile()"; } @@ -128,16 +124,20 @@ Core::IDocument::OpenResult ResourceEditorDocument::open(QString *errorString, if (debugResourceEditorW) qDebug() << "ResourceEditorW::open: " << fileName; + setBlockDirtyChanged(true); + m_model->setFileName(realFileName); OpenResult openResult = m_model->reload(); if (openResult != OpenResult::Success) { *errorString = m_model->errorMessage(); + setBlockDirtyChanged(false); emit loaded(false); return openResult; } setFilePath(FileName::fromString(fileName)); + setBlockDirtyChanged(false); m_model->setDirty(fileName != realFileName); m_shouldAutoSave = false; @@ -155,10 +155,12 @@ bool ResourceEditorDocument::save(QString *errorString, const QString &name, boo if (actualName.isEmpty()) return false; + m_blockDirtyChanged = true; m_model->setFileName(actualName.toString()); if (!m_model->save()) { *errorString = m_model->errorMessage(); m_model->setFileName(oldFileName.toString()); + m_blockDirtyChanged = false; return false; } @@ -166,10 +168,12 @@ bool ResourceEditorDocument::save(QString *errorString, const QString &name, boo if (autoSave) { m_model->setFileName(oldFileName.toString()); m_model->setDirty(true); + m_blockDirtyChanged = false; return true; } setFilePath(actualName); + m_blockDirtyChanged = false; emit changed(); return true; @@ -209,6 +213,11 @@ void ResourceEditorDocument::setFilePath(const FileName &newName) IDocument::setFilePath(newName); } +void ResourceEditorDocument::setBlockDirtyChanged(bool value) +{ + m_blockDirtyChanged = value; +} + RelativeResourceModel *ResourceEditorDocument::model() const { return m_model; @@ -229,6 +238,11 @@ bool ResourceEditorDocument::shouldAutoSave() const return m_shouldAutoSave; } +bool ResourceEditorDocument::isModified() const +{ + return m_model->dirty(); +} + bool ResourceEditorDocument::isSaveAsAllowed() const { return true; @@ -250,6 +264,16 @@ bool ResourceEditorDocument::reload(QString *errorString, ReloadFlag flag, Chang return true; } +void ResourceEditorDocument::dirtyChanged(bool dirty) +{ + if (m_blockDirtyChanged) + return; // We emit changed() afterwards, unless it was an autosave + + if (debugResourceEditorW) + qDebug() << " ResourceEditorW::dirtyChanged" << dirty; + emit changed(); +} + void ResourceEditorW::onUndoStackChanged(bool canUndo, bool canRedo) { m_plugin->onUndoStackChanged(this, canUndo, canRedo); diff --git a/src/plugins/resourceeditor/resourceeditorw.h b/src/plugins/resourceeditor/resourceeditorw.h index 0ac7005df4f..3d8d139e3c2 100644 --- a/src/plugins/resourceeditor/resourceeditorw.h +++ b/src/plugins/resourceeditor/resourceeditorw.h @@ -58,9 +58,11 @@ public: QByteArray contents() const override; bool setContents(const QByteArray &contents) override; bool shouldAutoSave() const override; + bool isModified() const override; bool isSaveAsAllowed() const override; bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override; void setFilePath(const Utils::FileName &newName) override; + void setBlockDirtyChanged(bool value); RelativeResourceModel *model() const; void setShouldAutoSave(bool save); @@ -69,8 +71,10 @@ signals: void loaded(bool success); private: + void dirtyChanged(bool); RelativeResourceModel *m_model; + bool m_blockDirtyChanged = false; bool m_shouldAutoSave = false; }; diff --git a/src/plugins/scxmleditor/common/mainwidget.cpp b/src/plugins/scxmleditor/common/mainwidget.cpp index e68b5736008..09c00c0f623 100644 --- a/src/plugins/scxmleditor/common/mainwidget.cpp +++ b/src/plugins/scxmleditor/common/mainwidget.cpp @@ -789,11 +789,6 @@ bool MainWidget::isDirty() const return m_document->changed(); } -void MainWidget::setDirty(bool dirty) -{ - m_document->setChanged(dirty); -} - void MainWidget::fitToView() { StateView *view = m_views.last(); diff --git a/src/plugins/scxmleditor/common/mainwidget.h b/src/plugins/scxmleditor/common/mainwidget.h index 64e17a97303..6b75895b0f3 100644 --- a/src/plugins/scxmleditor/common/mainwidget.h +++ b/src/plugins/scxmleditor/common/mainwidget.h @@ -87,7 +87,6 @@ public: QString contents() const; QUndoStack *undoStack() const; bool isDirty() const; - void setDirty(bool dirty); void newDocument(); void refresh(); OutputPane::WarningModel *warningModel() const; diff --git a/src/plugins/scxmleditor/plugin_interface/scxmldocument.cpp b/src/plugins/scxmleditor/plugin_interface/scxmldocument.cpp index 1ad7b9ba2f9..22cbdf4d4e7 100644 --- a/src/plugins/scxmleditor/plugin_interface/scxmldocument.cpp +++ b/src/plugins/scxmleditor/plugin_interface/scxmldocument.cpp @@ -643,14 +643,6 @@ bool ScxmlDocument::changed() const return !m_undoStack->isClean(); } -void ScxmlDocument::setChanged(bool modified) -{ - if (modified) - ; // we lack a setDirty method in QUndoStack - else - m_undoStack->setClean(); -} - ScxmlTag *ScxmlDocument::scxmlRootTag() const { ScxmlTag *tag = rootTag(); diff --git a/src/plugins/scxmleditor/plugin_interface/scxmldocument.h b/src/plugins/scxmleditor/plugin_interface/scxmldocument.h index 5d654d4d0b1..19506731f23 100644 --- a/src/plugins/scxmleditor/plugin_interface/scxmldocument.h +++ b/src/plugins/scxmleditor/plugin_interface/scxmldocument.h @@ -156,7 +156,6 @@ public: * @return - true if changed, false otherwise */ bool changed() const; - void setChanged(bool modified); /** * @brief rootTag - return rootTag of the document @@ -278,7 +277,6 @@ private: ScxmlTag *createScxmlTag(); QString m_fileName; QUndoStack *m_undoStack; - int m_cleanIndex; QVector m_tags; QHash m_nextIdHash; QHash m_idMap; diff --git a/src/plugins/scxmleditor/scxmleditordocument.cpp b/src/plugins/scxmleditor/scxmleditordocument.cpp index 97569bc7d29..d7c09b9e883 100644 --- a/src/plugins/scxmleditor/scxmleditordocument.cpp +++ b/src/plugins/scxmleditor/scxmleditordocument.cpp @@ -52,12 +52,9 @@ ScxmlEditorDocument::ScxmlEditorDocument(MainWidget *designWidget, QObject *pare // Designer needs UTF-8 regardless of settings. setCodec(QTextCodec::codecForName("UTF-8")); - connect(m_designWidget.data(), &Common::MainWidget::dirtyChanged, this, [this](bool modified){ - setModified(modified); + connect(m_designWidget.data(), &Common::MainWidget::dirtyChanged, this, [this]{ + emit changed(); }); - connect(this, &IDocument::modificationChanged, m_designWidget.data(), &Common::MainWidget::setDirty); - - setModified(m_designWidget->isDirty()); } Core::IDocument::OpenResult ScxmlEditorDocument::open(QString *errorString, const QString &fileName, const QString &realFileName) @@ -132,6 +129,11 @@ MainWidget *ScxmlEditorDocument::designWidget() const return m_designWidget; } +bool ScxmlEditorDocument::isModified() const +{ + return m_designWidget && m_designWidget->isDirty(); +} + bool ScxmlEditorDocument::reload(QString *errorString, ReloadFlag flag, ChangeType type) { if (flag == FlagIgnore) { diff --git a/src/plugins/scxmleditor/scxmleditordocument.h b/src/plugins/scxmleditor/scxmleditordocument.h index a3211c656e9..2ccb98213d5 100644 --- a/src/plugins/scxmleditor/scxmleditordocument.h +++ b/src/plugins/scxmleditor/scxmleditordocument.h @@ -53,6 +53,7 @@ public: bool save(QString *errorString, const QString &fileName, bool autoSave) override; bool shouldAutoSave() const override; bool isSaveAsAllowed() const override; + bool isModified() const override; bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override; // Internal diff --git a/src/plugins/texteditor/textdocument.cpp b/src/plugins/texteditor/textdocument.cpp index 418a0bd11a1..e3e73546443 100644 --- a/src/plugins/texteditor/textdocument.cpp +++ b/src/plugins/texteditor/textdocument.cpp @@ -236,16 +236,13 @@ void TextDocumentPrivate::updateRevisions() TextDocument::TextDocument(Id id) : d(new TextDocumentPrivate) { - connect(&d->m_document, &QTextDocument::modificationChanged, [this](bool modified) { + QObject::connect(&d->m_document, &QTextDocument::modificationChanged, [this](bool modified) { // we only want to update the block revisions when going back to the saved version, // e.g. with undo if (!modified) d->updateRevisions(); - setModified(modified); + emit changed(); }); - connect(this, &IDocument::modificationChanged, &d->m_document, &QTextDocument::setModified); - - setModified(d->m_document.isModified()); connect(&d->m_document, &QTextDocument::contentsChanged, this, &Core::IDocument::contentsChanged); @@ -598,6 +595,11 @@ bool TextDocument::isFileReadOnly() const return d->m_fileIsReadOnly; } +bool TextDocument::isModified() const +{ + return d->m_document.isModified(); +} + void TextDocument::checkPermissions() { bool previousReadOnly = d->m_fileIsReadOnly; diff --git a/src/plugins/texteditor/textdocument.h b/src/plugins/texteditor/textdocument.h index 78cd3dd4b8e..6aa2e0bd7c6 100644 --- a/src/plugins/texteditor/textdocument.h +++ b/src/plugins/texteditor/textdocument.h @@ -103,6 +103,7 @@ public: bool setContents(const QByteArray &contents) override; bool shouldAutoSave() const override; bool isFileReadOnly() const override; + bool isModified() const override; bool isSaveAsAllowed() const override; void checkPermissions() override; bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override; diff --git a/src/plugins/vcsbase/submiteditorfile.cpp b/src/plugins/vcsbase/submiteditorfile.cpp index 9a38537078c..9136118bf7e 100644 --- a/src/plugins/vcsbase/submiteditorfile.cpp +++ b/src/plugins/vcsbase/submiteditorfile.cpp @@ -44,6 +44,7 @@ using namespace Utils; SubmitEditorFile::SubmitEditorFile(const VcsBaseSubmitEditorParameters *parameters, VcsBaseSubmitEditor *parent) : Core::IDocument(parent), + m_modified(false), m_editor(parent) { setId(parameters->id); @@ -82,6 +83,14 @@ bool SubmitEditorFile::setContents(const QByteArray &contents) return m_editor->setFileContents(contents); } +void SubmitEditorFile::setModified(bool modified) +{ + if (m_modified == modified) + return; + m_modified = modified; + emit changed(); +} + bool SubmitEditorFile::save(QString *errorString, const QString &fileName, bool autoSave) { const FileName fName = fileName.isEmpty() ? filePath() : FileName::fromString(fileName); diff --git a/src/plugins/vcsbase/submiteditorfile.h b/src/plugins/vcsbase/submiteditorfile.h index 82263f9ef03..e2da2f72fa8 100644 --- a/src/plugins/vcsbase/submiteditorfile.h +++ b/src/plugins/vcsbase/submiteditorfile.h @@ -45,10 +45,14 @@ public: QByteArray contents() const override; bool setContents(const QByteArray &contents) override; + bool isModified() const override { return m_modified; } bool save(QString *errorString, const QString &fileName, bool autoSave) override; ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const override; + void setModified(bool modified = true); + private: + bool m_modified; VcsBaseSubmitEditor *m_editor; };