forked from qt-creator/qt-creator
QmlDesigner: Update subcomponent manager only for added import
Subcomponent update is needed after an import is added to parse and
load the import components. Instead of updating all imports and folders,
just update the import folder when adding a new import. This also fixes
regression cause by: d3f2394e8f
Task-number: QDS-4179
Change-Id: I6c0ba5139818004fdf54dfa10f03c7b013dfa46d
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -374,6 +374,11 @@ void DesignDocument::updateSubcomponentManager()
|
||||
currentModel()->imports() + currentModel()->possibleImports());
|
||||
}
|
||||
|
||||
void DesignDocument::updateSubcomponentManagerImport(const Import &import)
|
||||
{
|
||||
m_subComponentManager->updateImport(import);
|
||||
}
|
||||
|
||||
void DesignDocument::deleteSelected()
|
||||
{
|
||||
if (!currentModel())
|
||||
|
@@ -69,6 +69,7 @@ public:
|
||||
void attachRewriterToModel();
|
||||
void close();
|
||||
void updateSubcomponentManager();
|
||||
void updateSubcomponentManagerImport(const Import &import);
|
||||
|
||||
bool isUndoAvailable() const;
|
||||
bool isRedoAvailable() const;
|
||||
|
@@ -292,6 +292,7 @@ void ItemLibraryWidget::handleAddImport(int index)
|
||||
}
|
||||
|
||||
m_model->changeImports({import}, {});
|
||||
QmlDesignerPlugin::instance()->currentDesignDocument()->updateSubcomponentManagerImport(import);
|
||||
|
||||
m_stackedWidget->setCurrentIndex(0); // switch to the Components view after import is added
|
||||
updateSearch();
|
||||
|
@@ -48,6 +48,7 @@ public:
|
||||
explicit SubComponentManager(Model *model, QObject *parent = nullptr);
|
||||
|
||||
void update(const QUrl &fileUrl, const QList<Import> &imports);
|
||||
void updateImport(const Import &import);
|
||||
|
||||
QStringList qmlFiles() const;
|
||||
QStringList directories() const;
|
||||
@@ -57,8 +58,8 @@ private: // functions
|
||||
void parseFile(const QString &canonicalFilePath, bool addToLibrary, const QString&);
|
||||
void parseFile(const QString &canonicalFilePath);
|
||||
|
||||
void addImport(int pos, const Import &import);
|
||||
void removeImport(int pos);
|
||||
void addImport(const Import &import, int index = -1);
|
||||
void removeImport(int index);
|
||||
void parseDirectories();
|
||||
QFileInfoList watchedFiles(const QString &canonicalDirPath);
|
||||
void unregisterQmlFile(const QFileInfo &fileInfo, const QString &qualifier);
|
||||
|
@@ -69,10 +69,10 @@ SubComponentManager::SubComponentManager(Model *model, QObject *parent)
|
||||
this, [this](const QString &path) { parseDirectory(path); });
|
||||
}
|
||||
|
||||
void SubComponentManager::addImport(int pos, const Import &import)
|
||||
void SubComponentManager::addImport(const Import &import, int index)
|
||||
{
|
||||
if (debug)
|
||||
qDebug() << Q_FUNC_INFO << pos << import.file().toUtf8();
|
||||
qDebug() << Q_FUNC_INFO << index << import.file().toUtf8();
|
||||
|
||||
if (import.isFileImport()) {
|
||||
QFileInfo dirInfo = QFileInfo(m_filePath.resolved(import.file()).toLocalFile());
|
||||
@@ -97,12 +97,15 @@ void SubComponentManager::addImport(int pos, const Import &import)
|
||||
// TODO: QDeclarativeDomImport::Library
|
||||
}
|
||||
|
||||
m_imports.insert(pos, import);
|
||||
if (index == -1)
|
||||
m_imports.append(import);
|
||||
else
|
||||
m_imports.insert(index, import);
|
||||
}
|
||||
|
||||
void SubComponentManager::removeImport(int pos)
|
||||
void SubComponentManager::removeImport(int index)
|
||||
{
|
||||
const Import import = m_imports.takeAt(pos);
|
||||
const Import import = m_imports.takeAt(index);
|
||||
|
||||
if (import.isFileImport()) {
|
||||
const QFileInfo dirInfo = QFileInfo(m_filePath.resolved(import.file()).toLocalFile());
|
||||
@@ -499,7 +502,7 @@ void SubComponentManager::update(const QUrl &filePath, const QList<Import> &impo
|
||||
removeImport(ii);
|
||||
|
||||
for (int ii = i; ii < imports.size(); ++ii) {
|
||||
addImport(ii, imports.at(ii));
|
||||
addImport(imports.at(ii), ii);
|
||||
}
|
||||
|
||||
const QString newPath = newDir.absoluteFilePath();
|
||||
@@ -513,5 +516,42 @@ void SubComponentManager::update(const QUrl &filePath, const QList<Import> &impo
|
||||
parseDirectories();
|
||||
}
|
||||
|
||||
void SubComponentManager::updateImport(const Import &import)
|
||||
{
|
||||
addImport(import);
|
||||
|
||||
if (import.isFileImport()) {
|
||||
QFileInfo dirInfo = QFileInfo(m_filePath.resolved(import.file()).toLocalFile());
|
||||
if (dirInfo.exists() && dirInfo.isDir())
|
||||
parseDirectory(dirInfo.canonicalFilePath(), true, dirInfo.baseName().toUtf8());
|
||||
} else {
|
||||
QString url = import.url();
|
||||
url.replace('.', '/');
|
||||
QFileInfo dirInfo = QFileInfo(url);
|
||||
const QStringList importPathList = importPaths();
|
||||
bool parsed = false;
|
||||
for (const QString &path : importPathList) {
|
||||
QString fullUrl = path + '/' + url;
|
||||
dirInfo = QFileInfo(fullUrl);
|
||||
|
||||
if (dirInfo.exists() && dirInfo.isDir()) {
|
||||
parseDirectory(dirInfo.canonicalFilePath(), false);
|
||||
parsed = true;
|
||||
}
|
||||
|
||||
QString fullUrlVersion = path + '/' + url + '.' + import.version().split('.').constFirst();
|
||||
dirInfo = QFileInfo(fullUrlVersion);
|
||||
|
||||
if (dirInfo.exists() && dirInfo.isDir()) {
|
||||
parseDirectory(dirInfo.canonicalFilePath(), false);
|
||||
parsed = true;
|
||||
}
|
||||
|
||||
if (parsed)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
||||
|
Reference in New Issue
Block a user