forked from qt-creator/qt-creator
QmlDesigner: Import only mandatory libraries or directories
Only mandatory files are imported by the newly created component. In the case that the import data is empty, All parent imports would be included. Task-number: QDS-9829 Change-Id: Ie96e2bc04a10e00b15ae12c5e58b5dc2392886ae Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -79,7 +79,8 @@ public:
|
||||
}
|
||||
|
||||
void performChanges(QmlJSRefactoringFilePtr currentFile,
|
||||
const QmlJSRefactoringChanges &refactoring) override
|
||||
const QmlJSRefactoringChanges &refactoring,
|
||||
const QString &imports = QString()) override
|
||||
{
|
||||
QString componentName = m_componentName;
|
||||
|
||||
@@ -128,18 +129,12 @@ public:
|
||||
const Utils::FilePath newFileName = path.pathAppended(componentName + QLatin1String(".")
|
||||
+ suffix);
|
||||
|
||||
QString imports;
|
||||
UiProgram *prog = currentFile->qmljsDocument()->qmlProgram();
|
||||
if (prog && prog->headers) {
|
||||
const unsigned int start = currentFile->startOf(prog->headers->firstSourceLocation());
|
||||
const unsigned int end = currentFile->startOf(prog->members->member->firstSourceLocation());
|
||||
imports = currentFile->textOf(start, end);
|
||||
}
|
||||
QString qmlImports = imports.size() ? imports : currentFile->qmlImports();
|
||||
|
||||
const unsigned int start = currentFile->startOf(m_firstSourceLocation);
|
||||
const unsigned int end = currentFile->startOf(m_lastSourceLocation);
|
||||
QString newComponentSource = imports + currentFile->textOf(start, end)
|
||||
+ QLatin1String("}\n");
|
||||
QString newComponentSource = qmlImports + currentFile->textOf(start, end)
|
||||
+ QLatin1String("}\n");
|
||||
|
||||
//Remove properties from resulting code...
|
||||
|
||||
@@ -248,7 +243,8 @@ void matchComponentFromObjectDefQuickFix(const QmlJSQuickFixAssistInterface *int
|
||||
|
||||
void performComponentFromObjectDef(QmlJSEditorWidget *editor,
|
||||
const QString &fileName,
|
||||
QmlJS::AST::UiObjectDefinition *objDef)
|
||||
QmlJS::AST::UiObjectDefinition *objDef,
|
||||
const QString &importData)
|
||||
{
|
||||
QmlJSRefactoringChanges refactoring(QmlJS::ModelManagerInterface::instance(),
|
||||
QmlJS::ModelManagerInterface::instance()->snapshot());
|
||||
@@ -257,7 +253,7 @@ void performComponentFromObjectDef(QmlJSEditorWidget *editor,
|
||||
QmlJSQuickFixAssistInterface interface(editor, TextEditor::AssistReason::ExplicitlyInvoked);
|
||||
Operation operation(&interface, objDef);
|
||||
|
||||
operation.performChanges(current, refactoring);
|
||||
operation.performChanges(current, refactoring, importData);
|
||||
}
|
||||
|
||||
} //namespace QmlJSEditor
|
||||
|
||||
@@ -15,6 +15,7 @@ QMLJSEDITOR_EXPORT void matchComponentFromObjectDefQuickFix(
|
||||
|
||||
QMLJSEDITOR_EXPORT void performComponentFromObjectDef(QmlJSEditorWidget *editor,
|
||||
const QString &fileName,
|
||||
QmlJS::AST::UiObjectDefinition *objDef);
|
||||
QmlJS::AST::UiObjectDefinition *objDef,
|
||||
const QString &importData);
|
||||
|
||||
} // namespace QmlJSEditor
|
||||
|
||||
@@ -40,7 +40,9 @@ protected:
|
||||
using Range = Utils::ChangeSet::Range;
|
||||
|
||||
virtual void performChanges(QmlJSTools::QmlJSRefactoringFilePtr currentFile,
|
||||
const QmlJSTools::QmlJSRefactoringChanges &refactoring) = 0;
|
||||
const QmlJSTools::QmlJSRefactoringChanges &refactoring,
|
||||
const QString &imports = QString())
|
||||
= 0;
|
||||
|
||||
const QmlJSTools::SemanticInfo &semanticInfo() const;
|
||||
|
||||
|
||||
@@ -50,7 +50,8 @@ public:
|
||||
}
|
||||
|
||||
void performChanges(QmlJSRefactoringFilePtr currentFile,
|
||||
const QmlJSRefactoringChanges &) override
|
||||
const QmlJSRefactoringChanges &,
|
||||
const QString &) override
|
||||
{
|
||||
Q_ASSERT(_objectInitializer);
|
||||
|
||||
@@ -115,7 +116,8 @@ public:
|
||||
}
|
||||
|
||||
void performChanges(QmlJSRefactoringFilePtr currentFile,
|
||||
const QmlJSRefactoringChanges &) override
|
||||
const QmlJSRefactoringChanges &,
|
||||
const QString &) override
|
||||
{
|
||||
Utils::ChangeSet changes;
|
||||
const int insertLoc = _message.location.begin() - _message.location.startColumn + 1;
|
||||
|
||||
@@ -90,7 +90,8 @@ public:
|
||||
}
|
||||
|
||||
void performChanges(QmlJSRefactoringFilePtr currentFile,
|
||||
const QmlJSRefactoringChanges &) override
|
||||
const QmlJSRefactoringChanges &,
|
||||
const QString &) override
|
||||
{
|
||||
UiScriptBinding *idBinding;
|
||||
const QString id = idOfObject(m_objDef, &idBinding);
|
||||
|
||||
Reference in New Issue
Block a user