forked from qt-creator/qt-creator
QuickFix: Migrate to a nicer API for cross-file quick fixes.
This commit is contained in:
@@ -92,7 +92,7 @@ public:
|
||||
"Move Component into '%1.qml'").arg(m_componentName));
|
||||
}
|
||||
|
||||
virtual void perform()
|
||||
virtual void performChanges(TextEditor::RefactoringFile *currentFile, QmlJSRefactoringChanges *refactoring)
|
||||
{
|
||||
const QString newFileName = QFileInfo(fileName()).path()
|
||||
+ QDir::separator() + m_componentName + QLatin1String(".qml");
|
||||
@@ -110,14 +110,15 @@ public:
|
||||
const QString txt = imports + state().textOf(start, end)
|
||||
+ QLatin1String("}\n");
|
||||
|
||||
// stop if we can't create the new file
|
||||
if (!refactoring->createFile(newFileName, txt))
|
||||
return;
|
||||
|
||||
Utils::ChangeSet changes;
|
||||
changes.replace(start, end, m_componentName + QLatin1String(" {\n"));
|
||||
refactoringChanges()->changeFile(fileName(), changes);
|
||||
refactoringChanges()->reindent(fileName(), range(start, end + 1));
|
||||
currentFile->change(changes);
|
||||
currentFile->indent(range(start, end + 1));
|
||||
|
||||
refactoringChanges()->createFile(newFileName, txt);
|
||||
refactoringChanges()->reindent(newFileName, range(0, txt.length() - 1));
|
||||
refactoringChanges()->apply();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -75,8 +75,6 @@ unsigned QmlJSQuickFixState::startPosition(const QmlJS::AST::SourceLocation &loc
|
||||
QmlJSQuickFixOperation::QmlJSQuickFixOperation(const QmlJSQuickFixState &state, int priority)
|
||||
: QuickFixOperation(priority)
|
||||
, _state(state)
|
||||
, _refactoringChanges(new QmlJSRefactoringChanges(ExtensionSystem::PluginManager::instance()->getObject<QmlJS::ModelManagerInterface>(),
|
||||
state.snapshot()))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -84,6 +82,15 @@ QmlJSQuickFixOperation::~QmlJSQuickFixOperation()
|
||||
{
|
||||
}
|
||||
|
||||
void QmlJSQuickFixOperation::perform()
|
||||
{
|
||||
QmlJSRefactoringChanges refactoring(ExtensionSystem::PluginManager::instance()->getObject<QmlJS::ModelManagerInterface>(),
|
||||
_state.snapshot());
|
||||
TextEditor::RefactoringFile current = refactoring.file(fileName());
|
||||
|
||||
performChanges(¤t, &refactoring);
|
||||
}
|
||||
|
||||
const QmlJSQuickFixState &QmlJSQuickFixOperation::state() const
|
||||
{
|
||||
return _state;
|
||||
@@ -94,11 +101,6 @@ QString QmlJSQuickFixOperation::fileName() const
|
||||
return state().document()->fileName();
|
||||
}
|
||||
|
||||
QmlJSRefactoringChanges *QmlJSQuickFixOperation::refactoringChanges() const
|
||||
{
|
||||
return _refactoringChanges.data();
|
||||
}
|
||||
|
||||
QmlJSQuickFixFactory::QmlJSQuickFixFactory()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -105,16 +105,17 @@ public:
|
||||
QmlJSQuickFixOperation(const QmlJSQuickFixState &state, int priority = -1);
|
||||
virtual ~QmlJSQuickFixOperation();
|
||||
|
||||
virtual void perform();
|
||||
|
||||
protected:
|
||||
virtual void performChanges(TextEditor::RefactoringFile *currentFile, QmlJSRefactoringChanges *refactoring) = 0;
|
||||
|
||||
/// \returns A const-reference to the state of the operation.
|
||||
const QmlJSQuickFixState &state() const;
|
||||
|
||||
/// \returns The name of the file for for which this operation is invoked.
|
||||
QString fileName() const;
|
||||
|
||||
/// \returns The refactoring changes associated with this quick-fix operation.
|
||||
QmlJSRefactoringChanges *refactoringChanges() const;
|
||||
|
||||
protected: // Utility functions forwarding to QmlJSQuickFixState
|
||||
/// \see QmlJSQuickFixState#startPosition
|
||||
unsigned startPosition(const QmlJS::AST::SourceLocation &loc) const
|
||||
@@ -126,7 +127,6 @@ protected: // Utility functions forwarding to QmlJSQuickFixState
|
||||
|
||||
private:
|
||||
QmlJSQuickFixState _state;
|
||||
QScopedPointer<QmlJSRefactoringChanges> _refactoringChanges;
|
||||
};
|
||||
|
||||
class QmlJSQuickFixFactory: public TextEditor::QuickFixFactory
|
||||
|
||||
@@ -88,7 +88,7 @@ private:
|
||||
"Split initializer"));
|
||||
}
|
||||
|
||||
virtual void perform()
|
||||
virtual void performChanges(TextEditor::RefactoringFile *currentFile, QmlJSRefactoringChanges *)
|
||||
{
|
||||
Q_ASSERT(_objectInitializer != 0);
|
||||
|
||||
@@ -107,12 +107,9 @@ private:
|
||||
changes.insert(startPosition(_objectInitializer->rbraceToken),
|
||||
QLatin1String("\n"));
|
||||
|
||||
RefactoringFile file = refactoringChanges()->file(fileName());
|
||||
file.change(changes);
|
||||
file.indent(range(startPosition(_objectInitializer->lbraceToken),
|
||||
startPosition(_objectInitializer->rbraceToken)));
|
||||
|
||||
refactoringChanges()->apply();
|
||||
currentFile->change(changes);
|
||||
currentFile->indent(range(startPosition(_objectInitializer->lbraceToken),
|
||||
startPosition(_objectInitializer->rbraceToken)));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
#include <texteditor/texteditorsettings.h>
|
||||
#include <texteditor/tabsettings.h>
|
||||
|
||||
|
||||
using namespace QmlJS;
|
||||
using namespace QmlJSEditor;
|
||||
|
||||
@@ -46,13 +45,6 @@ QmlJSRefactoringChanges::QmlJSRefactoringChanges(ModelManagerInterface *modelMan
|
||||
Q_ASSERT(modelManager);
|
||||
}
|
||||
|
||||
QStringList QmlJSRefactoringChanges::apply()
|
||||
{
|
||||
const QStringList changedFiles = TextEditor::RefactoringChanges::apply();
|
||||
m_modelManager->updateSourceFiles(changedFiles, true);
|
||||
return changedFiles;
|
||||
}
|
||||
|
||||
void QmlJSRefactoringChanges::indentSelection(const QTextCursor &selection) const
|
||||
{
|
||||
// ### shares code with QmlJSTextEditor::indent
|
||||
@@ -71,3 +63,8 @@ void QmlJSRefactoringChanges::indentSelection(const QTextCursor &selection) cons
|
||||
block = block.next();
|
||||
} while (block.isValid() && block != end);
|
||||
}
|
||||
|
||||
void QmlJSRefactoringChanges::fileChanged(const QString &fileName)
|
||||
{
|
||||
m_modelManager->updateSourceFiles(QStringList(fileName), true);
|
||||
}
|
||||
|
||||
@@ -46,10 +46,9 @@ public:
|
||||
QmlJSRefactoringChanges(QmlJS::ModelManagerInterface *modelManager,
|
||||
const QmlJS::Snapshot &snapshot);
|
||||
|
||||
virtual QStringList apply();
|
||||
|
||||
private:
|
||||
virtual void indentSelection(const QTextCursor &selection) const;
|
||||
virtual void fileChanged(const QString &fileName);
|
||||
|
||||
private:
|
||||
QmlJS::ModelManagerInterface *m_modelManager;
|
||||
|
||||
@@ -634,11 +634,11 @@ void QmlOutlineModel::reparentNodes(QmlOutlineItem *targetItem, int row, QList<Q
|
||||
}
|
||||
|
||||
QmlJSRefactoringChanges refactoring(QmlJS::ModelManagerInterface::instance(), m_semanticInfo.snapshot);
|
||||
refactoring.changeFile(m_semanticInfo.document->fileName(), changeSet);
|
||||
TextEditor::RefactoringFile file = refactoring.file(m_semanticInfo.document->fileName());
|
||||
file.change(changeSet);
|
||||
foreach (const Utils::ChangeSet::Range &range, changedRanges) {
|
||||
refactoring.reindent(m_semanticInfo.document->fileName(), range);
|
||||
file.indent(range);
|
||||
}
|
||||
refactoring.apply();
|
||||
}
|
||||
|
||||
void QmlOutlineModel::moveObjectMember(AST::UiObjectMember *toMove,
|
||||
|
||||
Reference in New Issue
Block a user