forked from qt-creator/qt-creator
QmlDesigner: Integrate Editor into Connections
Task-number: QDS-10530 Change-Id: I579c5e5d55b2136b96e32a448315dda8e720f2fb Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io> Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
This commit is contained in:
committed by
Thomas Hartmann
parent
3a7f41b78c
commit
26ac6c2606
@@ -204,7 +204,48 @@ Column {
|
||||
style: StudioTheme.Values.viewBarButtonStyle
|
||||
buttonIcon: StudioTheme.Constants.edit_medium
|
||||
tooltip: qsTr("Add something.")
|
||||
onClicked: console.log("OPEN EDITOR")
|
||||
onClicked: {
|
||||
expressionDialogLoader.show()
|
||||
}
|
||||
}
|
||||
|
||||
Loader {
|
||||
id: expressionDialogLoader
|
||||
parent: editor
|
||||
anchors.fill: parent
|
||||
visible: false
|
||||
active: visible
|
||||
|
||||
function show() {
|
||||
expressionDialogLoader.visible = true
|
||||
}
|
||||
|
||||
sourceComponent: Item {
|
||||
id: bindingEditorParent
|
||||
|
||||
Component.onCompleted: {
|
||||
bindingEditor.showWidget()
|
||||
bindingEditor.text = backend.source
|
||||
bindingEditor.showControls(false)
|
||||
bindingEditor.setMultilne(true)
|
||||
bindingEditor.updateWindowName()
|
||||
}
|
||||
|
||||
ActionEditor {
|
||||
id: bindingEditor
|
||||
|
||||
onRejected: {
|
||||
hideWidget()
|
||||
expressionDialogLoader.visible = false
|
||||
}
|
||||
|
||||
onAccepted: {
|
||||
backend.setNewSource(bindingEditor.text)
|
||||
hideWidget()
|
||||
expressionDialogLoader.visible = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ QString AbstractEditorDialog::editorValue() const
|
||||
void AbstractEditorDialog::setEditorValue(const QString &text)
|
||||
{
|
||||
if (m_editorWidget)
|
||||
m_editorWidget->document()->setPlainText(text);
|
||||
m_editorWidget->setEditorTextWithIndentation(text);
|
||||
}
|
||||
|
||||
void AbstractEditorDialog::unregisterAutoCompletion()
|
||||
|
||||
@@ -83,6 +83,18 @@ void ActionEditor::hideWidget()
|
||||
}
|
||||
}
|
||||
|
||||
void ActionEditor::showControls(bool show)
|
||||
{
|
||||
if (m_dialog)
|
||||
m_dialog->showControls(show);
|
||||
}
|
||||
|
||||
void QmlDesigner::ActionEditor::setMultilne(bool multiline)
|
||||
{
|
||||
if (m_dialog)
|
||||
m_dialog->setMultiline(multiline);
|
||||
}
|
||||
|
||||
QString ActionEditor::connectionValue() const
|
||||
{
|
||||
if (!m_dialog)
|
||||
|
||||
@@ -31,6 +31,9 @@ public:
|
||||
Q_INVOKABLE void showWidget(int x, int y);
|
||||
Q_INVOKABLE void hideWidget();
|
||||
|
||||
Q_INVOKABLE void showControls(bool show);
|
||||
Q_INVOKABLE void setMultilne(bool multiline);
|
||||
|
||||
QString connectionValue() const;
|
||||
void setConnectionValue(const QString &text);
|
||||
|
||||
|
||||
@@ -376,6 +376,37 @@ void ActionEditorDialog::updateComboBoxes([[maybe_unused]] int index, ComboBox t
|
||||
}
|
||||
}
|
||||
|
||||
void ActionEditorDialog::showControls(bool show)
|
||||
{
|
||||
if (m_comboBoxType)
|
||||
m_comboBoxType->setVisible(show);
|
||||
|
||||
if (m_actionPlaceholder)
|
||||
m_actionPlaceholder->setVisible(show);
|
||||
if (m_assignmentPlaceholder)
|
||||
m_assignmentPlaceholder->setVisible(show);
|
||||
|
||||
if (m_actionTargetItem)
|
||||
m_actionTargetItem->setVisible(show);
|
||||
if (m_actionMethod)
|
||||
m_actionMethod->setVisible(show);
|
||||
|
||||
if (m_assignmentTargetItem)
|
||||
m_assignmentTargetItem->setVisible(show);
|
||||
if (m_assignmentTargetProperty)
|
||||
m_assignmentTargetProperty->setVisible(show);
|
||||
if (m_assignmentSourceItem)
|
||||
m_assignmentSourceItem->setVisible(show);
|
||||
if (m_assignmentSourceProperty)
|
||||
m_assignmentSourceProperty->setVisible(show);
|
||||
}
|
||||
|
||||
void ActionEditorDialog::setMultiline(bool multiline)
|
||||
{
|
||||
if (m_editorWidget)
|
||||
m_editorWidget->m_isMultiline = multiline;
|
||||
}
|
||||
|
||||
void ActionEditorDialog::setupUIComponents()
|
||||
{
|
||||
m_comboBoxType = new QComboBox(this);
|
||||
|
||||
@@ -96,6 +96,9 @@ public:
|
||||
|
||||
void updateComboBoxes(int idx, ComboBox type);
|
||||
|
||||
void showControls(bool show);
|
||||
void setMultiline(bool multiline);
|
||||
|
||||
private:
|
||||
void setupUIComponents();
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/coreplugintr.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <plaintexteditmodifier.h>
|
||||
#include <qmljseditor/qmljsautocompleter.h>
|
||||
#include <qmljseditor/qmljscompletionassist.h>
|
||||
#include <qmljseditor/qmljseditor.h>
|
||||
@@ -46,7 +47,7 @@ BindingEditorWidget::BindingEditorWidget()
|
||||
? tr("Meta+Space")
|
||||
: tr("Ctrl+Space")));
|
||||
|
||||
connect(m_completionAction, &QAction::triggered, [this]() {
|
||||
connect(m_completionAction, &QAction::triggered, this, [this]() {
|
||||
invokeAssist(TextEditor::Completion);
|
||||
});
|
||||
}
|
||||
@@ -68,8 +69,17 @@ void BindingEditorWidget::unregisterAutoCompletion()
|
||||
bool BindingEditorWidget::event(QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::KeyPress) {
|
||||
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
||||
if ((keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter) && !keyEvent->modifiers()) {
|
||||
const QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
||||
const bool returnPressed = (keyEvent->key() == Qt::Key_Return)
|
||||
|| (keyEvent->key() == Qt::Key_Enter);
|
||||
const Qt::KeyboardModifiers mods = keyEvent->modifiers();
|
||||
constexpr Qt::KeyboardModifier submitModifier = Qt::ControlModifier;
|
||||
const bool submitModed = mods.testFlag(submitModifier);
|
||||
|
||||
if (!m_isMultiline && (returnPressed && !mods)) {
|
||||
emit returnKeyClicked();
|
||||
return true;
|
||||
} else if (m_isMultiline && (returnPressed && submitModed)) {
|
||||
emit returnKeyClicked();
|
||||
return true;
|
||||
}
|
||||
@@ -81,8 +91,22 @@ std::unique_ptr<TextEditor::AssistInterface> BindingEditorWidget::createAssistIn
|
||||
[[maybe_unused]] TextEditor::AssistKind assistKind, TextEditor::AssistReason assistReason) const
|
||||
{
|
||||
return std::make_unique<QmlJSEditor::QmlJSCompletionAssistInterface>(
|
||||
textCursor(), Utils::FilePath(),
|
||||
assistReason, qmljsdocument->semanticInfo());
|
||||
textCursor(), Utils::FilePath(), assistReason, qmljsdocument->semanticInfo());
|
||||
}
|
||||
|
||||
void BindingEditorWidget::setEditorTextWithIndentation(const QString &text)
|
||||
{
|
||||
auto *doc = document();
|
||||
doc->setPlainText(text);
|
||||
|
||||
//we don't need to indent an empty text
|
||||
//but is also needed for safer text.length()-1 below
|
||||
if (text.isEmpty())
|
||||
return;
|
||||
|
||||
auto modifier = std::make_unique<IndentingTextEditModifier>(
|
||||
doc, QTextCursor{doc});
|
||||
modifier->indent(0, text.length()-1);
|
||||
}
|
||||
|
||||
BindingDocument::BindingDocument()
|
||||
|
||||
@@ -32,6 +32,8 @@ public:
|
||||
std::unique_ptr<TextEditor::AssistInterface> createAssistInterface(
|
||||
TextEditor::AssistKind assistKind, TextEditor::AssistReason assistReason) const override;
|
||||
|
||||
void setEditorTextWithIndentation(const QString &text);
|
||||
|
||||
signals:
|
||||
void returnKeyClicked();
|
||||
|
||||
@@ -39,6 +41,7 @@ public:
|
||||
QmlJSEditor::QmlJSEditorDocument *qmljsdocument = nullptr;
|
||||
Core::IContext *m_context = nullptr;
|
||||
QAction *m_completionAction = nullptr;
|
||||
bool m_isMultiline = false;
|
||||
};
|
||||
|
||||
class BindingDocument : public QmlJSEditor::QmlJSEditorDocument
|
||||
|
||||
@@ -758,6 +758,14 @@ void ConnectionModelBackendDelegate::removeElse()
|
||||
setupHandlerAndStatements();
|
||||
}
|
||||
|
||||
void ConnectionModelBackendDelegate::setNewSource(const QString &newSource)
|
||||
{
|
||||
setSource(newSource);
|
||||
commitNewSource(newSource);
|
||||
setupHandlerAndStatements();
|
||||
setupCondition();
|
||||
}
|
||||
|
||||
int ConnectionModelBackendDelegate::currentRow() const
|
||||
{
|
||||
return m_currentRow;
|
||||
|
||||
@@ -284,6 +284,8 @@ public:
|
||||
Q_INVOKABLE void addElse();
|
||||
Q_INVOKABLE void removeElse();
|
||||
|
||||
Q_INVOKABLE void setNewSource(const QString &newSource);
|
||||
|
||||
void setCurrentRow(int i);
|
||||
void update();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user