forked from qt-creator/qt-creator
QmlDesigner: Propose to open a .ui.qml file instead of .qml
If the project contains .ui.qml files the designer proposes to open .ui.qml files instead of opening a .qml file. This encourages to not open the .qml files in the designer. This feature can be disabled. Change-Id: I47a877ea72fafb07ebee485b8f22509f6162993c Reviewed-by: Tim Jenssen <tim.jenssen@theqtcompany.com>
This commit is contained in:
committed by
Tim Jenssen
parent
e12949a38a
commit
e1f5fd202a
@@ -53,6 +53,7 @@ void DesignerSettings::fromSettings(QSettings *settings)
|
||||
restoreValue(settings, DesignerSettingsKey::CANVASWIDTH, 10000);
|
||||
restoreValue(settings, DesignerSettingsKey::CANVASHEIGHT, 10000);
|
||||
restoreValue(settings, DesignerSettingsKey::WARNING_FOR_FEATURES_IN_DESIGNER, true);
|
||||
restoreValue(settings, DesignerSettingsKey::WARNING_FOR_QML_FILES_INSTEAD_OF_UIQML_FILES, true);
|
||||
restoreValue(settings, DesignerSettingsKey::WARNING_FOR_DESIGNER_FEATURES_IN_EDITOR, false);
|
||||
restoreValue(settings, DesignerSettingsKey::SHOW_DEBUGVIEW, false);
|
||||
restoreValue(settings, DesignerSettingsKey::ENABLE_DEBUGVIEW, false);
|
||||
|
@@ -42,6 +42,7 @@ const char CONTAINERPADDING[] = "ContainerPadding";
|
||||
const char CANVASWIDTH[] = "CanvasWidth";
|
||||
const char CANVASHEIGHT[] = "CanvasHeight";
|
||||
const char WARNING_FOR_FEATURES_IN_DESIGNER[] = "WarnAboutQtQuickFeaturesInDesigner";
|
||||
const char WARNING_FOR_QML_FILES_INSTEAD_OF_UIQML_FILES[] = "WarnAboutQmlFilesInsteadOfUiQmlFiles";
|
||||
const char WARNING_FOR_DESIGNER_FEATURES_IN_EDITOR[] = "WarnAboutQtQuickDesignerFeaturesInCodeEditor";
|
||||
const char SHOW_DEBUGVIEW[] = "ShowQtQuickDesignerDebugView";
|
||||
const char ENABLE_DEBUGVIEW[] = "EnableQtQuickDesignerDebugView";
|
||||
|
92
src/plugins/qmldesigner/openuiqmlfiledialog.cpp
Normal file
92
src/plugins/qmldesigner/openuiqmlfiledialog.cpp
Normal file
@@ -0,0 +1,92 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "openuiqmlfiledialog.h"
|
||||
#include "ui_openuiqmlfiledialog.h"
|
||||
|
||||
#include <qmldesignerplugin.h>
|
||||
|
||||
#include <QDir>
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
OpenUiQmlFileDialog::OpenUiQmlFileDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::OpenUiQmlFileDialog)
|
||||
{
|
||||
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
ui->setupUi(this);
|
||||
|
||||
connect(ui->cancelButton, &QPushButton::clicked, this, &QDialog::close);
|
||||
connect(ui->openButton, &QPushButton::clicked, [this] {
|
||||
QListWidgetItem *item = ui->listWidget->currentItem();
|
||||
if (item) {
|
||||
m_uiFileOpened = true;
|
||||
m_uiQmlFile = item->data(Qt::UserRole).toString();
|
||||
}
|
||||
close();
|
||||
});
|
||||
connect(ui->listWidget, &QListWidget::itemDoubleClicked, [this](QListWidgetItem *item) {
|
||||
if (item) {
|
||||
m_uiFileOpened = true;
|
||||
m_uiQmlFile = item->data(Qt::UserRole).toString();
|
||||
}
|
||||
close();
|
||||
});
|
||||
connect(ui->checkBox, &QCheckBox::toggled, [this](bool b){
|
||||
DesignerSettings settings = QmlDesignerPlugin::instance()->settings();
|
||||
settings.insert(DesignerSettingsKey::WARNING_FOR_QML_FILES_INSTEAD_OF_UIQML_FILES, !b);
|
||||
QmlDesignerPlugin::instance()->setSettings(settings);
|
||||
});
|
||||
}
|
||||
|
||||
OpenUiQmlFileDialog::~OpenUiQmlFileDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
bool OpenUiQmlFileDialog::uiFileOpened() const
|
||||
{
|
||||
return m_uiFileOpened;
|
||||
}
|
||||
|
||||
void OpenUiQmlFileDialog::setUiQmlFiles(const QString &projectPath, const QStringList &stringList)
|
||||
{
|
||||
QDir projectDir(projectPath);
|
||||
|
||||
foreach (const QString &fileName, stringList) {
|
||||
QListWidgetItem *item = new QListWidgetItem(projectDir.relativeFilePath(fileName), ui->listWidget);
|
||||
item->setData(Qt::UserRole, fileName);
|
||||
ui->listWidget->addItem(item);
|
||||
}
|
||||
ui->listWidget->setCurrentItem(ui->listWidget->item(0));
|
||||
}
|
||||
|
||||
QString OpenUiQmlFileDialog::uiQmlFile() const
|
||||
{
|
||||
return m_uiQmlFile;
|
||||
}
|
||||
|
||||
} // namespace QmlDesigner
|
54
src/plugins/qmldesigner/openuiqmlfiledialog.h
Normal file
54
src/plugins/qmldesigner/openuiqmlfiledialog.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
namespace Ui {
|
||||
class OpenUiQmlFileDialog;
|
||||
}
|
||||
|
||||
class OpenUiQmlFileDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit OpenUiQmlFileDialog(QWidget *parent = 0);
|
||||
~OpenUiQmlFileDialog();
|
||||
bool uiFileOpened() const;
|
||||
void setUiQmlFiles(const QString &projectPath, const QStringList &stringList);
|
||||
QString uiQmlFile() const;
|
||||
|
||||
private:
|
||||
Ui::OpenUiQmlFileDialog *ui;
|
||||
bool m_uiFileOpened = false;
|
||||
QString m_uiQmlFile;
|
||||
};
|
||||
|
||||
|
||||
} // namespace QmlDesigner
|
58
src/plugins/qmldesigner/openuiqmlfiledialog.ui
Normal file
58
src/plugins/qmldesigner/openuiqmlfiledialog.ui
Normal file
@@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>QmlDesigner::OpenUiQmlFileDialog</class>
|
||||
<widget class="QDialog" name="QmlDesigner::OpenUiQmlFileDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>600</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Open ui.qml file</string>
|
||||
</property>
|
||||
<property name="modal">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>You are opening a .qml file in the designer. Do you want to open a .ui.qml file instead?</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="checkBox">
|
||||
<property name="text">
|
||||
<string>Do not show this dialog again</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QPushButton" name="openButton">
|
||||
<property name="text">
|
||||
<string>Open ui.qml file</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<widget class="QPushButton" name="cancelButton">
|
||||
<property name="text">
|
||||
<string>Cancel</string>
|
||||
</property>
|
||||
<property name="default">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="3">
|
||||
<widget class="QListWidget" name="listWidget"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
@@ -29,6 +29,7 @@
|
||||
#include "designmodewidget.h"
|
||||
#include "settingspage.h"
|
||||
#include "designmodecontext.h"
|
||||
#include "openuiqmlfiledialog.h"
|
||||
|
||||
#include <metainfo.h>
|
||||
#include <connectionview.h>
|
||||
@@ -53,6 +54,9 @@
|
||||
#include <extensionsystem/pluginspec.h>
|
||||
#include <qmljs/qmljsmodelmanagerinterface.h>
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <projectexplorer/project.h>
|
||||
#include <projectexplorer/target.h>
|
||||
#include <projectexplorer/session.h>
|
||||
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/qtcassert.h>
|
||||
@@ -220,6 +224,32 @@ void QmlDesignerPlugin::extensionsInitialized()
|
||||
&d->shortCutManager, &ShortCutManager::updateActions);
|
||||
}
|
||||
|
||||
static QStringList allUiQmlFilesforCurrentProject(const Utils::FileName &fileName)
|
||||
{
|
||||
QStringList list;
|
||||
ProjectExplorer::Project *currentProject = ProjectExplorer::SessionManager::projectForFile(fileName);
|
||||
|
||||
if (currentProject) {
|
||||
foreach (const QString &fileName, currentProject->files(ProjectExplorer::Project::SourceFiles)) {
|
||||
if (fileName.endsWith(".ui.qml"))
|
||||
list.append(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
static QString projectPath(const Utils::FileName &fileName)
|
||||
{
|
||||
QString path;
|
||||
ProjectExplorer::Project *currentProject = ProjectExplorer::SessionManager::projectForFile(fileName);
|
||||
|
||||
if (currentProject)
|
||||
path = currentProject->projectDirectory().toString();
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
void QmlDesignerPlugin::createDesignModeWidget()
|
||||
{
|
||||
d->mainWidget = new Internal::DesignModeWidget;
|
||||
@@ -256,6 +286,7 @@ void QmlDesignerPlugin::createDesignModeWidget()
|
||||
|
||||
connect(Core::ModeManager::instance(), &Core::ModeManager::currentModeChanged,
|
||||
[=] (Core::Id newMode, Core::Id oldMode) {
|
||||
|
||||
if (d && Core::EditorManager::currentEditor() && checkIfEditorIsQtQuick
|
||||
(Core::EditorManager::currentEditor()) && !documentIsAlreadyOpen(
|
||||
currentDesignDocument(), Core::EditorManager::currentEditor(), newMode)) {
|
||||
@@ -270,14 +301,34 @@ void QmlDesignerPlugin::createDesignModeWidget()
|
||||
});
|
||||
}
|
||||
|
||||
static bool warningsForQmlFilesInsteadOfUiQmlEnabled()
|
||||
{
|
||||
DesignerSettings settings = QmlDesignerPlugin::instance()->settings();
|
||||
return settings.value(DesignerSettingsKey::WARNING_FOR_QML_FILES_INSTEAD_OF_UIQML_FILES).toBool();
|
||||
}
|
||||
|
||||
void QmlDesignerPlugin::showDesigner()
|
||||
{
|
||||
QTC_ASSERT(!d->documentManager.hasCurrentDesignDocument(), return);
|
||||
|
||||
d->mainWidget->initialize();
|
||||
|
||||
const Utils::FileName fileName = Core::EditorManager::currentEditor()->document()->filePath();
|
||||
const QStringList allUiQmlFiles = allUiQmlFilesforCurrentProject(fileName);
|
||||
if (warningsForQmlFilesInsteadOfUiQmlEnabled() && !fileName.endsWith(".ui.qml") && !allUiQmlFiles.isEmpty()) {
|
||||
OpenUiQmlFileDialog dialog(d->mainWidget);
|
||||
dialog.setUiQmlFiles(projectPath(fileName), allUiQmlFiles);
|
||||
dialog.exec();
|
||||
if (dialog.uiFileOpened()) {
|
||||
Core::ModeManager::activateMode(Core::Constants::MODE_EDIT);
|
||||
Core::EditorManager::openEditorAt(dialog.uiQmlFile(), 0, 0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
d->shortCutManager.disconnectUndoActions(currentDesignDocument());
|
||||
d->documentManager.setCurrentDesignDocument(Core::EditorManager::currentEditor());
|
||||
d->shortCutManager.connectUndoActions(currentDesignDocument());
|
||||
d->mainWidget->initialize();
|
||||
|
||||
if (d->documentManager.hasCurrentDesignDocument()) {
|
||||
activateAutoSynchronization();
|
||||
|
@@ -8,7 +8,8 @@ HEADERS += $$PWD/qmldesignerconstants.h \
|
||||
$$PWD/documentmanager.h \
|
||||
$$PWD/documentwarningwidget.h \
|
||||
$$PWD/styledoutputpaneplaceholder.h \
|
||||
$$PWD/qmldesignericons.h
|
||||
$$PWD/qmldesignericons.h \
|
||||
$$PWD/openuiqmlfiledialog.h
|
||||
|
||||
SOURCES += $$PWD/qmldesignerplugin.cpp \
|
||||
$$PWD/shortcutmanager.cpp \
|
||||
@@ -18,6 +19,8 @@ SOURCES += $$PWD/qmldesignerplugin.cpp \
|
||||
$$PWD/designmodecontext.cpp \
|
||||
$$PWD/documentmanager.cpp \
|
||||
$$PWD/documentwarningwidget.cpp \
|
||||
$$PWD/styledoutputpaneplaceholder.cpp
|
||||
$$PWD/styledoutputpaneplaceholder.cpp \
|
||||
$$PWD/openuiqmlfiledialog.cpp
|
||||
|
||||
FORMS += $$PWD/settingspage.ui
|
||||
FORMS += $$PWD/settingspage.ui \
|
||||
$$PWD/openuiqmlfiledialog.ui
|
||||
|
@@ -95,6 +95,9 @@ DesignerSettings SettingsPageWidget::settings() const
|
||||
settings.insert(DesignerSettingsKey::CANVASHEIGHT, m_ui.spinCanvasHeight->value());
|
||||
settings.insert(DesignerSettingsKey::WARNING_FOR_FEATURES_IN_DESIGNER,
|
||||
m_ui.designerWarningsCheckBox->isChecked());
|
||||
settings.insert(DesignerSettingsKey::WARNING_FOR_QML_FILES_INSTEAD_OF_UIQML_FILES,
|
||||
m_ui.designerWarningsUiQmlfiles->isChecked());
|
||||
|
||||
settings.insert(DesignerSettingsKey::WARNING_FOR_DESIGNER_FEATURES_IN_EDITOR,
|
||||
m_ui.designerWarningsInEditorCheckBox->isChecked());
|
||||
settings.insert(DesignerSettingsKey::SHOW_DEBUGVIEW,
|
||||
@@ -144,6 +147,8 @@ void SettingsPageWidget::setSettings(const DesignerSettings &settings)
|
||||
DesignerSettingsKey::CANVASHEIGHT).toInt());
|
||||
m_ui.designerWarningsCheckBox->setChecked(settings.value(
|
||||
DesignerSettingsKey::WARNING_FOR_FEATURES_IN_DESIGNER).toBool());
|
||||
m_ui.designerWarningsUiQmlfiles->setChecked(settings.value(
|
||||
DesignerSettingsKey::WARNING_FOR_QML_FILES_INSTEAD_OF_UIQML_FILES).toBool());
|
||||
m_ui.designerWarningsInEditorCheckBox->setChecked(settings.value(
|
||||
DesignerSettingsKey::WARNING_FOR_DESIGNER_FEATURES_IN_EDITOR).toBool());
|
||||
m_ui.designerShowDebuggerCheckBox->setChecked(settings.value(
|
||||
|
@@ -293,6 +293,16 @@
|
||||
<string>Warnings</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="designerWarningsInEditorCheckBox">
|
||||
<property name="toolTip">
|
||||
<string>Also warns in the code editor about QML features that are not properly supported by the Qt Quick Designer.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Warn about unsupported features of Qt Quick Designer in the code editor</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QCheckBox" name="designerWarningsCheckBox">
|
||||
<property name="toolTip">
|
||||
@@ -303,13 +313,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="designerWarningsInEditorCheckBox">
|
||||
<item row="2" column="0">
|
||||
<widget class="QCheckBox" name="designerWarningsUiQmlfiles">
|
||||
<property name="toolTip">
|
||||
<string>Also warns in the code editor about QML features that are not properly supported by the Qt Quick Designer.</string>
|
||||
<string>Qt Quick Designer will propose to open .ui.qml files instead of opening a .qml file.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Warn about unsupported features of Qt Quick Designer in the code editor</string>
|
||||
<string>Warn about using .qml files instead of .ui.qml files</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
Reference in New Issue
Block a user