From bd99669503c2626954808d8c4689d33b217e24c8 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Fri, 3 May 2024 15:24:00 +0200 Subject: [PATCH] QML: Add an "external" editor for opening .ui.qml files in Design Studio Using the logic from the landing page in design mode. Users can select Qt Design Studio from the Open With... menu, or even set it as the default editor in Preferences > Environment > MIME Types, "application/x-qt.ui+qml" Task-number: QTCREATORBUG-30754 Change-Id: Idd4e688f722dcf38735db7c1b9b31af02caeb045 Reviewed-by: Alessandro Portale Reviewed-by: --- .../qmlprojectmanager/qmlprojectplugin.cpp | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/plugins/qmlprojectmanager/qmlprojectplugin.cpp b/src/plugins/qmlprojectmanager/qmlprojectplugin.cpp index 9cd1bae9c67..1bc61c3b825 100644 --- a/src/plugins/qmlprojectmanager/qmlprojectplugin.cpp +++ b/src/plugins/qmlprojectmanager/qmlprojectplugin.cpp @@ -100,11 +100,6 @@ static void clearAlwaysOpenWithMode() ICore::settings()->remove(QmlProjectManager::Constants::ALWAYS_OPEN_UI_MODE); } -class QmlProjectPluginPrivate -{ -public: -}; - void openQDS(const FilePath &fileName) { const FilePath qdsPath = qdsInstallationEntry(); @@ -229,6 +224,26 @@ static QmlBuildSystem *qmlBuildSystemforFileNode(const FileNode *fileNode) return nullptr; } +class ExternalDesignStudioFactory : public Core::IEditorFactory +{ +public: + ExternalDesignStudioFactory() + { + setId("Qt.QtDesignStudio"); + setDisplayName(Tr::tr("Qt Design Studio")); + setMimeTypes({Utils::Constants::QMLUI_MIMETYPE}); + setEditorStarter([](const FilePath &filePath, [[maybe_unused]] QString *errorMessage) { + openInQDSWithProject(filePath); + return true; + }); + } +}; + +void setupExternalDesignStudio() +{ + static ExternalDesignStudioFactory theExternalDesignStudioFactory; +} + class QmlProjectPlugin final : public ExtensionSystem::IPlugin { Q_OBJECT @@ -274,6 +289,7 @@ private: void QmlProjectPlugin::initialize() { setupQmlProjectRunConfiguration(); + setupExternalDesignStudio(); if (!qmlDesignerEnabled()) { m_landingPage = new QdsLandingPage();