aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qmlprojectmanager/qmlprojectplugin.cpp
diff options
context:
space:
mode:
authorThomas Hartmann <[email protected]>2022-01-21 20:08:28 +0100
committerThomas Hartmann <[email protected]>2022-01-24 16:01:19 +0000
commit8d327c1cf73b9ca9207b14fed793f04a76a982e5 (patch)
tree569ba31ce3e199eacd931906cbffb502f305e220 /src/plugins/qmlprojectmanager/qmlprojectplugin.cpp
parent96083103d1b8a841c9fb3db4b8f1186a9b63333e (diff)
QmlProject: Add option to always open ui.qml files in qds
This patch adds an option to always open ui.qml files in Qt Design Studio. If that option is enabled an info bar is used to propose the option. Change-Id: Ia80ecd87de7fcf4c5824e7a8bb806c3d4d77b935 Reviewed-by: Alessandro Portale <[email protected]>
Diffstat (limited to 'src/plugins/qmlprojectmanager/qmlprojectplugin.cpp')
-rw-r--r--src/plugins/qmlprojectmanager/qmlprojectplugin.cpp60
1 files changed, 40 insertions, 20 deletions
diff --git a/src/plugins/qmlprojectmanager/qmlprojectplugin.cpp b/src/plugins/qmlprojectmanager/qmlprojectplugin.cpp
index ddc9462603b..2922c55aea7 100644
--- a/src/plugins/qmlprojectmanager/qmlprojectplugin.cpp
+++ b/src/plugins/qmlprojectmanager/qmlprojectplugin.cpp
@@ -56,7 +56,8 @@ using namespace ProjectExplorer;
namespace QmlProjectManager {
namespace Internal {
-const char openInQDSAppSetting[] = "OpenInQDSAppUiQml";
+const char openInQDSAppInfoBar[] = "OpenInQDSAppUiQml";
+const char alwaysOpenUiQmlInQDS[] = "J.QtQuick/QmlJSEditor.openUiQmlFilesInQDS";
static bool isQmlDesigner(const ExtensionSystem::PluginSpec *spec)
{
@@ -73,6 +74,16 @@ static bool qmlDesignerEnabled()
return it != plugins.end() && (*it)->plugin();
}
+static bool alwaysOpenUiQmlfileInQds()
+{
+ return Core::ICore::settings()->value(alwaysOpenUiQmlInQDS, false).toBool();
+}
+
+static void enableAlwaysOpenUiQmlfileInQds()
+{
+ return Core::ICore::settings()->setValue(alwaysOpenUiQmlInQDS, true);
+}
+
class QmlProjectPluginPrivate
{
public:
@@ -169,6 +180,21 @@ static bool findAndOpenProject(const Utils::FilePath &filePath)
return false;
}
+void QmlProjectPlugin::openInQDSWithProject(const Utils::FilePath &filePath)
+{
+ if (findAndOpenProject(filePath)) {
+ openQDS(filePath);
+ //The first one might be ignored when QDS is starting up
+ QTimer::singleShot(4000, [filePath] { openQDS(filePath); });
+ } else {
+ Core::AsynchronousMessageBox::warning(
+ tr("Qt Design Studio"),
+ tr("No project file (*.qmlproject) found for Qt Design "
+ "Studio.\n Qt Design Studio requires a .qmlproject "
+ "based project to open the .ui.qml file."));
+ }
+}
+
bool QmlProjectPlugin::initialize(const QStringList &, QString *errorMessage)
{
Q_UNUSED(errorMessage)
@@ -196,9 +222,9 @@ bool QmlProjectPlugin::initialize(const QStringList &, QString *errorMessage)
const QString description = tr("Files of the type ui.qml are intended for Qt Design Studio.");
if (!qdsInstallationExists()) {
- if (Core::ICore::infoBar()->canInfoBeAdded(openInQDSAppSetting)) {
+ if (Core::ICore::infoBar()->canInfoBeAdded(openInQDSAppInfoBar)) {
Utils::InfoBarEntry
- info(openInQDSAppSetting,
+ info(openInQDSAppInfoBar,
description + tr(" Learn more about Qt Design Studio here: ")
+ "<a href='https://www.qt.io/product/ui-design-tools'>Qt Design Studio</a>",
Utils::InfoBarEntry::GlobalSuppression::Disabled);
@@ -207,25 +233,19 @@ bool QmlProjectPlugin::initialize(const QStringList &, QString *errorMessage)
return;
}
- if (Core::ICore::infoBar()->canInfoBeAdded(openInQDSAppSetting)) {
+
+ if (alwaysOpenUiQmlfileInQds()) {
+ openInQDSWithProject(filePath);
+ } else if (Core::ICore::infoBar()->canInfoBeAdded(openInQDSAppInfoBar)) {
Utils::InfoBarEntry
- info(openInQDSAppSetting,
- description + "\n" + tr("Do you want to open this file in Qt Design Studio?"),
+ info(openInQDSAppInfoBar,
+ description + "\n" + tr("Do you want to open this file always in Qt Design Studio?"),
Utils::InfoBarEntry::GlobalSuppression::Disabled);
- info.addCustomButton(tr("Open in Qt Design Studio"), [filePath] {
- Core::ICore::infoBar()->removeInfo(openInQDSAppSetting);
-
- if (findAndOpenProject(filePath)) {
- openQDS(filePath);
- //The first one might be ignored when QDS is starting up
- QTimer::singleShot(4000, [filePath] { openQDS(filePath); });
- } else {
- Core::AsynchronousMessageBox::warning(
- tr("Qt Design Studio"),
- tr("No project file (*.qmlproject) found for Qt Design"
- "Studio.\n Qt Design Studio requires a .qmlproject "
- "based project to open the ui.qml file."));
- }
+ info.addCustomButton(tr("Always open in Qt Design Studio"), [filePath] {
+ Core::ICore::infoBar()->removeInfo(openInQDSAppInfoBar);
+
+ enableAlwaysOpenUiQmlfileInQds();
+ openInQDSWithProject(filePath);
});
Core::ICore::infoBar()->addInfo(info);
}