forked from qt-creator/qt-creator
qmljs: make refactoring work on Object Bindings
“Move Component to Separate File” and “Wrap Component in Loader” did work only for UiObjectDefinitions, extended them to UiObjectBindings. Task-number: QTCREATORBUG-12904 Change-Id: I5216110c1edfc6e4536f83eba39e74919c918d50 Reviewed-by: Tim Jenssen <tim.jenssen@digia.com>
This commit is contained in:
@@ -60,18 +60,12 @@ namespace {
|
||||
|
||||
class Operation: public QmlJSQuickFixOperation
|
||||
{
|
||||
UiObjectDefinition *m_objDef;
|
||||
QString m_idName, m_componentName;
|
||||
|
||||
SourceLocation m_firstSourceLocation;
|
||||
SourceLocation m_lastSourceLocation;
|
||||
public:
|
||||
Operation(const QSharedPointer<const QmlJSQuickFixAssistInterface> &interface,
|
||||
UiObjectDefinition *objDef)
|
||||
: QmlJSQuickFixOperation(interface, 0)
|
||||
, m_objDef(objDef)
|
||||
void init()
|
||||
{
|
||||
Q_ASSERT(m_objDef != 0);
|
||||
|
||||
m_idName = idOfObject(m_objDef);
|
||||
if (!m_idName.isEmpty()) {
|
||||
m_componentName = m_idName;
|
||||
m_componentName[0] = m_componentName.at(0).toUpper();
|
||||
@@ -81,6 +75,26 @@ public:
|
||||
"Move Component into Separate File"));
|
||||
}
|
||||
|
||||
Operation(const QSharedPointer<const QmlJSQuickFixAssistInterface> &interface,
|
||||
UiObjectDefinition *objDef)
|
||||
: QmlJSQuickFixOperation(interface, 0),
|
||||
m_idName(idOfObject(objDef)),
|
||||
m_firstSourceLocation(objDef->firstSourceLocation()),
|
||||
m_lastSourceLocation(objDef->lastSourceLocation())
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
Operation(const QSharedPointer<const QmlJSQuickFixAssistInterface> &interface,
|
||||
UiObjectBinding *objDef)
|
||||
: QmlJSQuickFixOperation(interface, 0),
|
||||
m_idName(idOfObject(objDef)),
|
||||
m_firstSourceLocation(objDef->qualifiedTypeNameId->firstSourceLocation()),
|
||||
m_lastSourceLocation(objDef->lastSourceLocation())
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
virtual void performChanges(QmlJSRefactoringFilePtr currentFile,
|
||||
const QmlJSRefactoringChanges &refactoring)
|
||||
{
|
||||
@@ -102,8 +116,8 @@ public:
|
||||
imports = currentFile->textOf(start, end);
|
||||
}
|
||||
|
||||
const int start = currentFile->startOf(m_objDef->firstSourceLocation());
|
||||
const int end = currentFile->startOf(m_objDef->lastSourceLocation());
|
||||
const int start = currentFile->startOf(m_firstSourceLocation);
|
||||
const int end = currentFile->startOf(m_lastSourceLocation);
|
||||
const QString txt = imports + currentFile->textOf(start, end)
|
||||
+ QLatin1String("}\n");
|
||||
|
||||
@@ -165,6 +179,11 @@ void ComponentFromObjectDef::match(const QmlJSQuickFixInterface &interface, Quic
|
||||
result.append(QuickFixOperation::Ptr(new Operation(interface, objDef)));
|
||||
return;
|
||||
}
|
||||
} else if (UiObjectBinding *objBinding = cast<UiObjectBinding *>(node)) {
|
||||
if (!interface->currentFile()->isCursorOn(objBinding->qualifiedTypeNameId))
|
||||
return;
|
||||
result.append(QuickFixOperation::Ptr(new Operation(interface, objBinding)));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user