From 2486e6106870d64e486c600c0fb96594ae771e12 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Mon, 20 Aug 2018 14:26:51 +0200 Subject: Fix handling of read-only editors when applying refactorings If e.g. a ".ui" file is open, there is a read-only text editor widget for the file, even though the file itself is writable. The application of refactorings or global text-based replace should not change the content of this read-only editor widget, but instead operate directly on the file as if it wasn't open in Qt Creator at all. It should also silently reload these files after modification on disk. Task-number: QTCREATORBUG-19958 Change-Id: I409d5d03059be4c3520a1031ff0fbfa9feb675bb Reviewed-by: David Schulz --- src/plugins/texteditor/refactoringchanges.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/plugins/texteditor/refactoringchanges.cpp b/src/plugins/texteditor/refactoringchanges.cpp index 5905fb5f68..9370a5f0c1 100644 --- a/src/plugins/texteditor/refactoringchanges.cpp +++ b/src/plugins/texteditor/refactoringchanges.cpp @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -178,8 +179,11 @@ RefactoringFile::RefactoringFile(const QString &fileName, const QSharedPointer editors = DocumentModel::editorsForFilePath(fileName); - if (!editors.isEmpty()) - m_editor = qobject_cast(editors.first()->widget()); + if (!editors.isEmpty()) { + auto editorWidget = qobject_cast(editors.first()->widget()); + if (editorWidget && !editorWidget->isReadOnly()) + m_editor = editorWidget; + } } RefactoringFile::~RefactoringFile() @@ -378,6 +382,8 @@ bool RefactoringFile::apply() if (!m_editor && m_textFileFormat.codec) { QTC_ASSERT(!m_fileName.isEmpty(), return false); QString error; + // suppress "file has changed" warnings if the file is open in a read-only editor + Core::FileChangeBlocker block(m_fileName); if (!m_textFileFormat.writeFile(m_fileName, doc->toPlainText(), &error)) { qWarning() << "Could not apply changes to" << m_fileName << ". Error: " << error; result = false; -- cgit v1.2.1