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
|
class Operation: public QmlJSQuickFixOperation
|
||||||
{
|
{
|
||||||
UiObjectDefinition *m_objDef;
|
|
||||||
QString m_idName, m_componentName;
|
QString m_idName, m_componentName;
|
||||||
|
SourceLocation m_firstSourceLocation;
|
||||||
|
SourceLocation m_lastSourceLocation;
|
||||||
public:
|
public:
|
||||||
Operation(const QSharedPointer<const QmlJSQuickFixAssistInterface> &interface,
|
void init()
|
||||||
UiObjectDefinition *objDef)
|
|
||||||
: QmlJSQuickFixOperation(interface, 0)
|
|
||||||
, m_objDef(objDef)
|
|
||||||
{
|
{
|
||||||
Q_ASSERT(m_objDef != 0);
|
|
||||||
|
|
||||||
m_idName = idOfObject(m_objDef);
|
|
||||||
if (!m_idName.isEmpty()) {
|
if (!m_idName.isEmpty()) {
|
||||||
m_componentName = m_idName;
|
m_componentName = m_idName;
|
||||||
m_componentName[0] = m_componentName.at(0).toUpper();
|
m_componentName[0] = m_componentName.at(0).toUpper();
|
||||||
@@ -81,6 +75,26 @@ public:
|
|||||||
"Move Component into Separate File"));
|
"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,
|
virtual void performChanges(QmlJSRefactoringFilePtr currentFile,
|
||||||
const QmlJSRefactoringChanges &refactoring)
|
const QmlJSRefactoringChanges &refactoring)
|
||||||
{
|
{
|
||||||
@@ -102,8 +116,8 @@ public:
|
|||||||
imports = currentFile->textOf(start, end);
|
imports = currentFile->textOf(start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
const int start = currentFile->startOf(m_objDef->firstSourceLocation());
|
const int start = currentFile->startOf(m_firstSourceLocation);
|
||||||
const int end = currentFile->startOf(m_objDef->lastSourceLocation());
|
const int end = currentFile->startOf(m_lastSourceLocation);
|
||||||
const QString txt = imports + currentFile->textOf(start, end)
|
const QString txt = imports + currentFile->textOf(start, end)
|
||||||
+ QLatin1String("}\n");
|
+ QLatin1String("}\n");
|
||||||
|
|
||||||
@@ -165,6 +179,11 @@ void ComponentFromObjectDef::match(const QmlJSQuickFixInterface &interface, Quic
|
|||||||
result.append(QuickFixOperation::Ptr(new Operation(interface, objDef)));
|
result.append(QuickFixOperation::Ptr(new Operation(interface, objDef)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} else if (UiObjectBinding *objBinding = cast<UiObjectBinding *>(node)) {
|
||||||
|
if (!interface->currentFile()->isCursorOn(objBinding->qualifiedTypeNameId))
|
||||||
|
return;
|
||||||
|
result.append(QuickFixOperation::Ptr(new Operation(interface, objBinding)));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,15 +77,16 @@ protected:
|
|||||||
Result result;
|
Result result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
class Operation: public QmlJSQuickFixOperation
|
class Operation: public QmlJSQuickFixOperation
|
||||||
{
|
{
|
||||||
Q_DECLARE_TR_FUNCTIONS(QmlJSEditor::Internal::Operation)
|
Q_DECLARE_TR_FUNCTIONS(QmlJSEditor::Internal::Operation)
|
||||||
|
|
||||||
UiObjectDefinition *m_objDef;
|
T *m_objDef;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Operation(const QSharedPointer<const QmlJSQuickFixAssistInterface> &interface,
|
Operation(const QSharedPointer<const QmlJSQuickFixAssistInterface> &interface,
|
||||||
UiObjectDefinition *objDef)
|
T *objDef)
|
||||||
: QmlJSQuickFixOperation(interface, 0)
|
: QmlJSQuickFixOperation(interface, 0)
|
||||||
, m_objDef(objDef)
|
, m_objDef(objDef)
|
||||||
{
|
{
|
||||||
@@ -156,7 +157,7 @@ public:
|
|||||||
changes.insert(afterOpenBrace, innerIdForwarders);
|
changes.insert(afterOpenBrace, innerIdForwarders);
|
||||||
}
|
}
|
||||||
|
|
||||||
const int objDefStart = m_objDef->firstSourceLocation().begin();
|
const int objDefStart = m_objDef->qualifiedTypeNameId->firstSourceLocation().begin();
|
||||||
const int objDefEnd = m_objDef->lastSourceLocation().end();
|
const int objDefEnd = m_objDef->lastSourceLocation().end();
|
||||||
changes.insert(objDefStart, comment +
|
changes.insert(objDefStart, comment +
|
||||||
QString::fromLatin1("Component {\n"
|
QString::fromLatin1("Component {\n"
|
||||||
@@ -188,9 +189,14 @@ void WrapInLoader::match(const QmlJSQuickFixInterface &interface, QuickFixOperat
|
|||||||
return;
|
return;
|
||||||
// check that the node is not the root node
|
// check that the node is not the root node
|
||||||
if (i > 0 && !cast<UiProgram*>(path.at(i - 1))) {
|
if (i > 0 && !cast<UiProgram*>(path.at(i - 1))) {
|
||||||
result.append(QuickFixOperation::Ptr(new Operation(interface, objDef)));
|
result.append(QuickFixOperation::Ptr(new Operation<UiObjectDefinition>(interface, objDef)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} else if (UiObjectBinding *objBinding = cast<UiObjectBinding *>(node)) {
|
||||||
|
if (!interface->currentFile()->isCursorOn(objBinding->qualifiedTypeNameId))
|
||||||
|
return;
|
||||||
|
result.append(QuickFixOperation::Ptr(new Operation<UiObjectBinding>(interface, objBinding)));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user