diff --git a/src/plugins/cppeditor/cpprefactoringchanges.cpp b/src/plugins/cppeditor/cpprefactoringchanges.cpp index 7ee709c118f..e0e0249c0ee 100644 --- a/src/plugins/cppeditor/cpprefactoringchanges.cpp +++ b/src/plugins/cppeditor/cpprefactoringchanges.cpp @@ -76,19 +76,19 @@ CppRefactoringFile::CppRefactoringFile(const FilePath &filePath, const QSharedPo { const Snapshot &snapshot = data->m_snapshot; m_cppDocument = snapshot.document(filePath); - m_formattingEnabled = true; + enableFormatting(); } CppRefactoringFile::CppRefactoringFile(QTextDocument *document, const FilePath &filePath) : RefactoringFile(document, filePath) { - m_formattingEnabled = true; + enableFormatting(); } CppRefactoringFile::CppRefactoringFile(TextEditor::TextEditorWidget *editor) : RefactoringFile(editor) { - m_formattingEnabled = true; + enableFormatting(); } Document::Ptr CppRefactoringFile::cppDocument() const @@ -235,7 +235,7 @@ const Token &CppRefactoringFile::tokenAt(unsigned index) const void CppRefactoringFile::fileChanged() { - QTC_ASSERT(!m_filePath.isEmpty(), return); + QTC_ASSERT(!filePath().isEmpty(), return); m_cppDocument.clear(); CppModelManager::updateSourceFiles({filePath()}); } diff --git a/src/plugins/qmljstools/qmljsrefactoringchanges.cpp b/src/plugins/qmljstools/qmljsrefactoringchanges.cpp index 6d16b1663cc..0e03454250a 100644 --- a/src/plugins/qmljstools/qmljsrefactoringchanges.cpp +++ b/src/plugins/qmljstools/qmljsrefactoringchanges.cpp @@ -61,7 +61,7 @@ QmlJSRefactoringFile::QmlJSRefactoringFile( { // the RefactoringFile is invalid if its not for a file with qml or js code if (ModelManagerInterface::guessLanguageOfFile(filePath) == Dialect::NoLanguage) - m_filePath.clear(); + invalidate(); } QmlJSRefactoringFile::QmlJSRefactoringFile(TextEditor::TextEditorWidget *editor, Document::Ptr document) @@ -69,7 +69,7 @@ QmlJSRefactoringFile::QmlJSRefactoringFile(TextEditor::TextEditorWidget *editor, , m_qmljsDocument(document) { if (document) - m_filePath = document->fileName(); + setFilePath(document->fileName()); // TODO: Is this really a different file path than in the editor? } Document::Ptr QmlJSRefactoringFile::qmljsDocument() const @@ -136,7 +136,7 @@ bool QmlJSRefactoringFile::isCursorOn(SourceLocation loc) const void QmlJSRefactoringFile::fileChanged() { - QTC_ASSERT(!m_filePath.isEmpty(), return); + QTC_ASSERT(!filePath().isEmpty(), return); m_qmljsDocument.clear(); m_data->m_modelManager->updateSourceFiles({filePath()}, true); } diff --git a/src/plugins/texteditor/refactoringchanges.h b/src/plugins/texteditor/refactoringchanges.h index 5d270b2f652..20de8dad87c 100644 --- a/src/plugins/texteditor/refactoringchanges.h +++ b/src/plugins/texteditor/refactoringchanges.h @@ -31,6 +31,7 @@ class TextEditorWidget; class TEXTEDITOR_EXPORT RefactoringFile { Q_DISABLE_COPY(RefactoringFile) + friend class PlainRefactoringFileFactory; // access to constructor public: using Range = Utils::ChangeSet::Range; @@ -39,8 +40,7 @@ public: bool isValid() const; const QTextDocument *document() const; - // mustn't use the cursor to change the document - const QTextCursor cursor() const; + const QTextCursor cursor() const; // mustn't use the cursor to change the document Utils::FilePath filePath() const; TextEditorWidget *editor() const; @@ -69,10 +69,16 @@ protected: RefactoringFile(TextEditorWidget *editor); RefactoringFile(const Utils::FilePath &filePath); - QTextDocument *mutableDocument() const; + void invalidate() { m_filePath.clear(); } + void setFilePath(const Utils::FilePath &filePath) { m_filePath = filePath; } // FIXME: Really necessary? + void enableFormatting() { m_formattingEnabled = true; } - // derived classes may want to clear language specific extra data - virtual void fileChanged() {} +private: + virtual void fileChanged() {} // derived classes may want to clear language specific extra data + virtual void indentSelection(const QTextCursor &selection, + const TextDocument *textDocument) const; + virtual void reindentSelection(const QTextCursor &selection, + const TextDocument *textDocument) const; enum IndentType {Indent, Reindent}; void indentOrReindent(const RefactoringSelections &ranges, IndentType indent); @@ -84,10 +90,7 @@ protected: static RefactoringSelections rangesToSelections(QTextDocument *document, const QList &ranges); - virtual void indentSelection(const QTextCursor &selection, - const TextDocument *textDocument) const; - virtual void reindentSelection(const QTextCursor &selection, - const TextDocument *textDocument) const; + QTextDocument *mutableDocument() const; Utils::FilePath m_filePath; mutable Utils::TextFileFormat m_textFileFormat; @@ -102,8 +105,6 @@ protected: int m_editorCursorPosition = -1; bool m_appliedOnce = false; bool m_formattingEnabled = false; - - friend class PlainRefactoringFileFactory; // access to constructor }; class TEXTEDITOR_EXPORT RefactoringFileFactory