forked from qt-creator/qt-creator
QmlDesigner: Parse .metainfo files from the share folder
We have some plugins that essentially only contain a .metainfo file. the possibility to drop .metainfo files into that folder simplifies things. In QDS 3.2 this will be used for the particle library. Change-Id: I0c4bb7f66bb8eaa3f806ec9d34c6991d08ef5a5f Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -30,10 +30,16 @@
|
||||
#include "iwidgetplugin.h"
|
||||
|
||||
#include <coreplugin/messagebox.h>
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <utils/filepath.h>
|
||||
|
||||
#include "pluginmanager/widgetpluginmanager.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QMessageBox>
|
||||
#include <QDir>
|
||||
#include <QDirIterator>
|
||||
#include <QMutex>
|
||||
|
||||
enum {
|
||||
@@ -43,6 +49,30 @@ enum {
|
||||
namespace QmlDesigner {
|
||||
namespace Internal {
|
||||
|
||||
|
||||
static QString globalMetaInfoPath()
|
||||
{
|
||||
#ifdef SHARE_QML_PATH
|
||||
if (qEnvironmentVariableIsSet("LOAD_QML_FROM_SOURCE"))
|
||||
return QLatin1String(SHARE_QML_PATH) + "/globalMetaInfo";
|
||||
#endif
|
||||
return Core::ICore::resourcePath("qmldesigner/globalMetaInfo").toString();
|
||||
}
|
||||
|
||||
Utils::FilePaths allGlobalMetaInfoFiles()
|
||||
{
|
||||
static Utils::FilePaths paths;
|
||||
|
||||
if (!paths.isEmpty())
|
||||
return paths;
|
||||
|
||||
QDirIterator it(globalMetaInfoPath(), { "*.metainfo" }, QDir::Files, QDirIterator::Subdirectories);
|
||||
while (it.hasNext())
|
||||
paths.append(Utils::FilePath::fromString(it.next()));
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
class MetaInfoPrivate
|
||||
{
|
||||
Q_DISABLE_COPY(MetaInfoPrivate)
|
||||
@@ -99,6 +129,19 @@ void MetaInfoPrivate::parseItemLibraryDescriptions()
|
||||
errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
const Utils::FilePaths allMetaInfoFiles = allGlobalMetaInfoFiles();
|
||||
for (const Utils::FilePath &path : allMetaInfoFiles) {
|
||||
Internal::MetaInfoReader reader(*m_q);
|
||||
try {
|
||||
reader.readMetaInfoFile(path.toString());
|
||||
} catch (const InvalidMetaInfoException &e) {
|
||||
qWarning() << e.description();
|
||||
const QString errorMessage = path.toString() + QLatin1Char('\n') + QLatin1Char('\n') + reader.errors().join(QLatin1Char('\n'));
|
||||
Core::AsynchronousMessageBox::warning(QCoreApplication::translate("QmlDesigner::Internal::MetaInfoPrivate", "Invalid meta info"),
|
||||
errorMessage);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user