forked from qt-creator/qt-creator
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 <alessandro.portale@qt.io>
This commit is contained in:
@@ -38,6 +38,7 @@ const char AUTO_FORMAT_ONLY_CURRENT_PROJECT[] = "QmlJSEditor.AutoFormatOnlyCurre
|
||||
const char QML_CONTEXTPANE_KEY[] = "QmlJSEditor.ContextPaneEnabled";
|
||||
const char QML_CONTEXTPANEPIN_KEY[] = "QmlJSEditor.ContextPanePinned";
|
||||
const char FOLD_AUX_DATA[] = "QmlJSEditor.FoldAuxData";
|
||||
const char OPEN_UIQML_FILES_IN_QDS[] = "QmlJSEditor.openUiQmlFilesInQDS";
|
||||
|
||||
using namespace QmlJSEditor;
|
||||
using namespace QmlJSEditor::Internal;
|
||||
@@ -47,7 +48,8 @@ QmlJsEditingSettings::QmlJsEditingSettings()
|
||||
m_pinContextPane(false),
|
||||
m_autoFormatOnSave(false),
|
||||
m_autoFormatOnlyCurrentProject(false),
|
||||
m_foldAuxData(false)
|
||||
m_foldAuxData(false),
|
||||
m_openUiQmlFilesInQDS(false)
|
||||
{}
|
||||
|
||||
void QmlJsEditingSettings::set()
|
||||
@@ -65,6 +67,7 @@ void QmlJsEditingSettings::fromSettings(QSettings *settings)
|
||||
m_autoFormatOnlyCurrentProject
|
||||
= settings->value(AUTO_FORMAT_ONLY_CURRENT_PROJECT, QVariant(false)).toBool();
|
||||
m_foldAuxData = settings->value(FOLD_AUX_DATA, QVariant(true)).toBool();
|
||||
m_openUiQmlFilesInQDS = settings->value(OPEN_UIQML_FILES_IN_QDS, QVariant(false)).toBool();
|
||||
settings->endGroup();
|
||||
}
|
||||
|
||||
@@ -76,16 +79,18 @@ void QmlJsEditingSettings::toSettings(QSettings *settings) const
|
||||
settings->setValue(AUTO_FORMAT_ON_SAVE, m_autoFormatOnSave);
|
||||
settings->setValue(AUTO_FORMAT_ONLY_CURRENT_PROJECT, m_autoFormatOnlyCurrentProject);
|
||||
settings->setValue(FOLD_AUX_DATA, m_foldAuxData);
|
||||
settings->setValue(OPEN_UIQML_FILES_IN_QDS, m_openUiQmlFilesInQDS);
|
||||
settings->endGroup();
|
||||
}
|
||||
|
||||
bool QmlJsEditingSettings::equals(const QmlJsEditingSettings &other) const
|
||||
{
|
||||
return m_enableContextPane == other.m_enableContextPane
|
||||
&& m_pinContextPane == other.m_pinContextPane
|
||||
&& m_autoFormatOnSave == other.m_autoFormatOnSave
|
||||
&& m_autoFormatOnlyCurrentProject == other.m_autoFormatOnlyCurrentProject
|
||||
&& m_foldAuxData == other.m_foldAuxData;
|
||||
return m_enableContextPane == other.m_enableContextPane
|
||||
&& m_pinContextPane == other.m_pinContextPane
|
||||
&& m_autoFormatOnSave == other.m_autoFormatOnSave
|
||||
&& m_autoFormatOnlyCurrentProject == other.m_autoFormatOnlyCurrentProject
|
||||
&& m_foldAuxData == other.m_foldAuxData
|
||||
&& m_openUiQmlFilesInQDS == other.m_openUiQmlFilesInQDS;
|
||||
}
|
||||
|
||||
bool QmlJsEditingSettings::enableContextPane() const
|
||||
@@ -138,6 +143,16 @@ void QmlJsEditingSettings::setFoldAuxData(const bool foldAuxData)
|
||||
m_foldAuxData = foldAuxData;
|
||||
}
|
||||
|
||||
void QmlJsEditingSettings::setOpenUiQmlFilesInQDS(const bool openUiQmlFilesInQDS)
|
||||
{
|
||||
m_openUiQmlFilesInQDS = openUiQmlFilesInQDS;
|
||||
}
|
||||
|
||||
bool QmlJsEditingSettings::openUiQmlFilesInQDS() const
|
||||
{
|
||||
return m_openUiQmlFilesInQDS;
|
||||
}
|
||||
|
||||
class QmlJsEditingSettingsPageWidget final : public Core::IOptionsPageWidget
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(QmlDesigner::Internal::QmlJsEditingSettingsPage)
|
||||
@@ -153,6 +168,7 @@ public:
|
||||
m_ui.autoFormatOnSave->setChecked(s.autoFormatOnSave());
|
||||
m_ui.autoFormatOnlyCurrentProject->setChecked(s.autoFormatOnlyCurrentProject());
|
||||
m_ui.foldAuxDataCheckBox->setChecked(s.foldAuxData());
|
||||
m_ui.openUiQmlFilesInQDS->setChecked(s.openUiQmlFilesInQDS());
|
||||
}
|
||||
|
||||
void apply() final
|
||||
@@ -163,6 +179,7 @@ public:
|
||||
s.setAutoFormatOnSave(m_ui.autoFormatOnSave->isChecked());
|
||||
s.setAutoFormatOnlyCurrentProject(m_ui.autoFormatOnlyCurrentProject->isChecked());
|
||||
s.setFoldAuxData(m_ui.foldAuxDataCheckBox->isChecked());
|
||||
s.setOpenUiQmlFilesInQDS(m_ui.openUiQmlFilesInQDS->isChecked());
|
||||
s.set();
|
||||
}
|
||||
|
||||
|
||||
@@ -64,6 +64,9 @@ public:
|
||||
bool foldAuxData() const;
|
||||
void setFoldAuxData(const bool foldAuxData);
|
||||
|
||||
bool openUiQmlFilesInQDS() const;
|
||||
void setOpenUiQmlFilesInQDS(const bool foldAuxData);
|
||||
|
||||
friend bool operator==(const QmlJsEditingSettings &s1, const QmlJsEditingSettings &s2)
|
||||
{ return s1.equals(s2); }
|
||||
friend bool operator!=(const QmlJsEditingSettings &s1, const QmlJsEditingSettings &s2)
|
||||
@@ -75,6 +78,7 @@ private:
|
||||
bool m_autoFormatOnSave;
|
||||
bool m_autoFormatOnlyCurrentProject;
|
||||
bool m_foldAuxData;
|
||||
bool m_openUiQmlFilesInQDS;
|
||||
};
|
||||
|
||||
namespace Internal {
|
||||
|
||||
@@ -92,6 +92,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="openUiQmlFilesInQDS">
|
||||
<property name="text">
|
||||
<string>Open .ui.qml files in Qt Design Studio</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@@ -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)) {
|
||||
Utils::InfoBarEntry
|
||||
info(openInQDSAppSetting,
|
||||
description + "\n" + tr("Do you want to open this file 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."));
|
||||
}
|
||||
if (alwaysOpenUiQmlfileInQds()) {
|
||||
openInQDSWithProject(filePath);
|
||||
} else if (Core::ICore::infoBar()->canInfoBeAdded(openInQDSAppInfoBar)) {
|
||||
Utils::InfoBarEntry
|
||||
info(openInQDSAppInfoBar,
|
||||
description + "\n" + tr("Do you want to open this file always in Qt Design Studio?"),
|
||||
Utils::InfoBarEntry::GlobalSuppression::Disabled);
|
||||
info.addCustomButton(tr("Always open in Qt Design Studio"), [filePath] {
|
||||
Core::ICore::infoBar()->removeInfo(openInQDSAppInfoBar);
|
||||
|
||||
enableAlwaysOpenUiQmlfileInQds();
|
||||
openInQDSWithProject(filePath);
|
||||
});
|
||||
Core::ICore::infoBar()->addInfo(info);
|
||||
}
|
||||
|
||||
@@ -45,6 +45,8 @@ public:
|
||||
static bool qdsInstallationExists();
|
||||
|
||||
private:
|
||||
static void openInQDSWithProject(const Utils::FilePath &filePath);
|
||||
|
||||
bool initialize(const QStringList &arguments, QString *errorString) final;
|
||||
|
||||
class QmlProjectPluginPrivate *d = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user