forked from qt-creator/qt-creator
TextEditor: Clean up RefactoringFile interface
Change-Id: I1e415b6b51065d16bc49a25118931723b600c00b Reviewed-by: David Schulz <david.schulz@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -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()});
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<Range> &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
|
||||
|
||||
Reference in New Issue
Block a user