forked from qt-creator/qt-creator
TextEditor: Introduce PlainRefactoringFileFactory
This makes it immediately clear that there are more specialized variants available, which helps users make a conscious decision. Change-Id: I35feb4bed2d91fb4f83ede6e731d9ce89fd4af3f Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -46,7 +46,7 @@ static FileToFixits fixitsPerFile(const QList<ClangFixIt> &fixIts)
|
||||
|
||||
void ClangFixItOperation::perform()
|
||||
{
|
||||
const TextEditor::RefactoringFileFactory refactoringChanges;
|
||||
const TextEditor::PlainRefactoringFileFactory refactoringChanges;
|
||||
const FileToFixits fileToFixIts = fixitsPerFile(fixIts);
|
||||
|
||||
for (auto i = fileToFixIts.cbegin(), end = fileToFixIts.cend(); i != end; ++i) {
|
||||
|
||||
@@ -41,7 +41,7 @@ static Range toRange(const QTextDocument *doc, DiagnosticRange locations)
|
||||
|
||||
void ClangToolQuickFixOperation::perform()
|
||||
{
|
||||
TextEditor::RefactoringFileFactory changes;
|
||||
TextEditor::PlainRefactoringFileFactory changes;
|
||||
QMap<QString, TextEditor::RefactoringFilePtr> refactoringFiles;
|
||||
|
||||
for (const ExplainingStep &step : m_diagnostic.explainingSteps) {
|
||||
|
||||
@@ -1839,7 +1839,7 @@ void CppModelManager::renameIncludes(const FilePath &oldFilePath, const FilePath
|
||||
if (oldFilePath.absolutePath() != newFilePath.absolutePath())
|
||||
return;
|
||||
|
||||
const TextEditor::RefactoringFileFactory changes;
|
||||
const TextEditor::PlainRefactoringFileFactory changes;
|
||||
|
||||
QString oldFileName = oldFilePath.fileName();
|
||||
QString newFileName = newFilePath.fileName();
|
||||
|
||||
@@ -1739,7 +1739,7 @@ void Client::log(const QString &message) const
|
||||
|
||||
TextEditor::RefactoringFilePtr Client::createRefactoringFile(const FilePath &filePath) const
|
||||
{
|
||||
return TextEditor::RefactoringFileFactory().file(filePath);
|
||||
return TextEditor::PlainRefactoringFileFactory().file(filePath);
|
||||
}
|
||||
|
||||
void Client::setCompletionResultsLimit(int limit)
|
||||
|
||||
@@ -539,7 +539,7 @@ FilePaths BaseFileFind::replaceAll(const QString &text, const SearchResultItems
|
||||
if (items.isEmpty())
|
||||
return {};
|
||||
|
||||
RefactoringFileFactory refactoring;
|
||||
PlainRefactoringFileFactory refactoring;
|
||||
|
||||
QHash<FilePath, SearchResultItems> changes;
|
||||
for (const SearchResultItem &item : items)
|
||||
|
||||
@@ -26,13 +26,6 @@ using namespace Utils;
|
||||
|
||||
namespace TextEditor {
|
||||
|
||||
RefactoringFileFactory::~RefactoringFileFactory() = default;
|
||||
|
||||
RefactoringFilePtr RefactoringFileFactory::file(const FilePath &filePath) const
|
||||
{
|
||||
return RefactoringFilePtr(new RefactoringFile(filePath));
|
||||
}
|
||||
|
||||
RefactoringFile::RefactoringFile(QTextDocument *document, const FilePath &filePath)
|
||||
: m_filePath(filePath)
|
||||
, m_document(document)
|
||||
@@ -474,4 +467,11 @@ RefactoringSelections RefactoringFile::rangesToSelections(QTextDocument *documen
|
||||
return selections;
|
||||
}
|
||||
|
||||
RefactoringFileFactory::~RefactoringFileFactory() = default;
|
||||
|
||||
RefactoringFilePtr PlainRefactoringFileFactory::file(const Utils::FilePath &filePath) const
|
||||
{
|
||||
return RefactoringFilePtr(new RefactoringFile(filePath));
|
||||
}
|
||||
|
||||
} // namespace TextEditor
|
||||
|
||||
@@ -20,12 +20,12 @@ class QTextDocument;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace TextEditor {
|
||||
class TextDocument;
|
||||
class TextEditorWidget;
|
||||
class PlainRefactoringFileFactory;
|
||||
class RefactoringFile;
|
||||
using RefactoringFilePtr = QSharedPointer<RefactoringFile>;
|
||||
class RefactoringFileFactory;
|
||||
using RefactoringSelections = QVector<QPair<QTextCursor, QTextCursor>>;
|
||||
class TextDocument;
|
||||
class TextEditorWidget;
|
||||
|
||||
// ### listen to the m_editor::destroyed signal?
|
||||
class TEXTEDITOR_EXPORT RefactoringFile
|
||||
@@ -103,17 +103,20 @@ protected:
|
||||
bool m_appliedOnce = false;
|
||||
bool m_formattingEnabled = false;
|
||||
|
||||
friend class RefactoringFileFactory; // access to constructor
|
||||
friend class PlainRefactoringFileFactory; // access to constructor
|
||||
};
|
||||
|
||||
class TEXTEDITOR_EXPORT RefactoringFileFactory
|
||||
{
|
||||
public:
|
||||
virtual ~RefactoringFileFactory();
|
||||
virtual RefactoringFilePtr file(const Utils::FilePath &filePath) const = 0;
|
||||
};
|
||||
|
||||
// TODO: Make pure virtual and introduce dedicated subclass for generic refactoring,
|
||||
// so no one instantiates this one by mistake.
|
||||
virtual RefactoringFilePtr file(const Utils::FilePath &filePath) const;
|
||||
class TEXTEDITOR_EXPORT PlainRefactoringFileFactory final : public RefactoringFileFactory
|
||||
{
|
||||
public:
|
||||
RefactoringFilePtr file(const Utils::FilePath &filePath) const override;
|
||||
};
|
||||
|
||||
} // namespace TextEditor
|
||||
|
||||
@@ -514,7 +514,7 @@ bool TextDocument::applyChangeSet(const ChangeSet &changeSet)
|
||||
{
|
||||
if (changeSet.isEmpty())
|
||||
return true;
|
||||
RefactoringFileFactory changes;
|
||||
PlainRefactoringFileFactory changes;
|
||||
const RefactoringFilePtr file = changes.file(filePath());
|
||||
file->setChangeSet(changeSet);
|
||||
return file->apply();
|
||||
|
||||
Reference in New Issue
Block a user