forked from qt-creator/qt-creator
QmlDesigner: Auxiliary data auto-fold
- Made TextEditorWidget::restoreState() virtual - Added function to fold qml Auxiliary Data - Extended settings page to fit the new option Task: QDS-1667 Change-Id: Id1256fcc72a67ac822888d5fd2e23d6076349573 Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -37,6 +37,7 @@ const char AUTO_FORMAT_ON_SAVE[] = "QmlJSEditor.AutoFormatOnSave";
|
|||||||
const char AUTO_FORMAT_ONLY_CURRENT_PROJECT[] = "QmlJSEditor.AutoFormatOnlyCurrentProject";
|
const char AUTO_FORMAT_ONLY_CURRENT_PROJECT[] = "QmlJSEditor.AutoFormatOnlyCurrentProject";
|
||||||
const char QML_CONTEXTPANE_KEY[] = "QmlJSEditor.ContextPaneEnabled";
|
const char QML_CONTEXTPANE_KEY[] = "QmlJSEditor.ContextPaneEnabled";
|
||||||
const char QML_CONTEXTPANEPIN_KEY[] = "QmlJSEditor.ContextPanePinned";
|
const char QML_CONTEXTPANEPIN_KEY[] = "QmlJSEditor.ContextPanePinned";
|
||||||
|
const char FOLD_AUX_DATA[] = "QmlJSEditor.FoldAuxData";
|
||||||
|
|
||||||
using namespace QmlJSEditor;
|
using namespace QmlJSEditor;
|
||||||
using namespace QmlJSEditor::Internal;
|
using namespace QmlJSEditor::Internal;
|
||||||
@@ -45,7 +46,8 @@ QmlJsEditingSettings::QmlJsEditingSettings()
|
|||||||
: m_enableContextPane(false),
|
: m_enableContextPane(false),
|
||||||
m_pinContextPane(false),
|
m_pinContextPane(false),
|
||||||
m_autoFormatOnSave(false),
|
m_autoFormatOnSave(false),
|
||||||
m_autoFormatOnlyCurrentProject(false)
|
m_autoFormatOnlyCurrentProject(false),
|
||||||
|
m_foldAuxData(false)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void QmlJsEditingSettings::set()
|
void QmlJsEditingSettings::set()
|
||||||
@@ -62,6 +64,7 @@ void QmlJsEditingSettings::fromSettings(QSettings *settings)
|
|||||||
m_autoFormatOnSave = settings->value(AUTO_FORMAT_ON_SAVE, QVariant(false)).toBool();
|
m_autoFormatOnSave = settings->value(AUTO_FORMAT_ON_SAVE, QVariant(false)).toBool();
|
||||||
m_autoFormatOnlyCurrentProject
|
m_autoFormatOnlyCurrentProject
|
||||||
= settings->value(AUTO_FORMAT_ONLY_CURRENT_PROJECT, QVariant(false)).toBool();
|
= settings->value(AUTO_FORMAT_ONLY_CURRENT_PROJECT, QVariant(false)).toBool();
|
||||||
|
m_foldAuxData = settings->value(FOLD_AUX_DATA, QVariant(true)).toBool();
|
||||||
settings->endGroup();
|
settings->endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,6 +75,7 @@ void QmlJsEditingSettings::toSettings(QSettings *settings) const
|
|||||||
settings->setValue(QML_CONTEXTPANEPIN_KEY, m_pinContextPane);
|
settings->setValue(QML_CONTEXTPANEPIN_KEY, m_pinContextPane);
|
||||||
settings->setValue(AUTO_FORMAT_ON_SAVE, m_autoFormatOnSave);
|
settings->setValue(AUTO_FORMAT_ON_SAVE, m_autoFormatOnSave);
|
||||||
settings->setValue(AUTO_FORMAT_ONLY_CURRENT_PROJECT, m_autoFormatOnlyCurrentProject);
|
settings->setValue(AUTO_FORMAT_ONLY_CURRENT_PROJECT, m_autoFormatOnlyCurrentProject);
|
||||||
|
settings->setValue(FOLD_AUX_DATA, m_foldAuxData);
|
||||||
settings->endGroup();
|
settings->endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +84,8 @@ bool QmlJsEditingSettings::equals(const QmlJsEditingSettings &other) const
|
|||||||
return m_enableContextPane == other.m_enableContextPane
|
return m_enableContextPane == other.m_enableContextPane
|
||||||
&& m_pinContextPane == other.m_pinContextPane
|
&& m_pinContextPane == other.m_pinContextPane
|
||||||
&& m_autoFormatOnSave == other.m_autoFormatOnSave
|
&& m_autoFormatOnSave == other.m_autoFormatOnSave
|
||||||
&& m_autoFormatOnlyCurrentProject == other.m_autoFormatOnlyCurrentProject;
|
&& m_autoFormatOnlyCurrentProject == other.m_autoFormatOnlyCurrentProject
|
||||||
|
&& m_foldAuxData == other.m_foldAuxData;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QmlJsEditingSettings::enableContextPane() const
|
bool QmlJsEditingSettings::enableContextPane() const
|
||||||
@@ -123,6 +128,16 @@ void QmlJsEditingSettings::setAutoFormatOnlyCurrentProject(const bool autoFormat
|
|||||||
m_autoFormatOnlyCurrentProject = autoFormatOnlyCurrentProject;
|
m_autoFormatOnlyCurrentProject = autoFormatOnlyCurrentProject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool QmlJsEditingSettings::foldAuxData() const
|
||||||
|
{
|
||||||
|
return m_foldAuxData;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlJsEditingSettings::setFoldAuxData(const bool foldAuxData)
|
||||||
|
{
|
||||||
|
m_foldAuxData = foldAuxData;
|
||||||
|
}
|
||||||
|
|
||||||
class QmlJsEditingSettingsPageWidget final : public Core::IOptionsPageWidget
|
class QmlJsEditingSettingsPageWidget final : public Core::IOptionsPageWidget
|
||||||
{
|
{
|
||||||
Q_DECLARE_TR_FUNCTIONS(QmlDesigner::Internal::QmlJsEditingSettingsPage)
|
Q_DECLARE_TR_FUNCTIONS(QmlDesigner::Internal::QmlJsEditingSettingsPage)
|
||||||
@@ -137,6 +152,7 @@ public:
|
|||||||
m_ui.textEditHelperCheckBoxPin->setChecked(s.pinContextPane());
|
m_ui.textEditHelperCheckBoxPin->setChecked(s.pinContextPane());
|
||||||
m_ui.autoFormatOnSave->setChecked(s.autoFormatOnSave());
|
m_ui.autoFormatOnSave->setChecked(s.autoFormatOnSave());
|
||||||
m_ui.autoFormatOnlyCurrentProject->setChecked(s.autoFormatOnlyCurrentProject());
|
m_ui.autoFormatOnlyCurrentProject->setChecked(s.autoFormatOnlyCurrentProject());
|
||||||
|
m_ui.foldAuxDataCheckBox->setChecked(s.foldAuxData());
|
||||||
}
|
}
|
||||||
|
|
||||||
void apply() final
|
void apply() final
|
||||||
@@ -146,6 +162,7 @@ public:
|
|||||||
s.setPinContextPane(m_ui.textEditHelperCheckBoxPin->isChecked());
|
s.setPinContextPane(m_ui.textEditHelperCheckBoxPin->isChecked());
|
||||||
s.setAutoFormatOnSave(m_ui.autoFormatOnSave->isChecked());
|
s.setAutoFormatOnSave(m_ui.autoFormatOnSave->isChecked());
|
||||||
s.setAutoFormatOnlyCurrentProject(m_ui.autoFormatOnlyCurrentProject->isChecked());
|
s.setAutoFormatOnlyCurrentProject(m_ui.autoFormatOnlyCurrentProject->isChecked());
|
||||||
|
s.setFoldAuxData(m_ui.foldAuxDataCheckBox->isChecked());
|
||||||
s.set();
|
s.set();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,11 +60,15 @@ namespace QmlJSEditor {
|
|||||||
bool autoFormatOnlyCurrentProject() const;
|
bool autoFormatOnlyCurrentProject() const;
|
||||||
void setAutoFormatOnlyCurrentProject(const bool autoFormatOnlyCurrentProject);
|
void setAutoFormatOnlyCurrentProject(const bool autoFormatOnlyCurrentProject);
|
||||||
|
|
||||||
|
bool foldAuxData() const;
|
||||||
|
void setFoldAuxData(const bool foldAuxData);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_enableContextPane;
|
bool m_enableContextPane;
|
||||||
bool m_pinContextPane;
|
bool m_pinContextPane;
|
||||||
bool m_autoFormatOnSave;
|
bool m_autoFormatOnSave;
|
||||||
bool m_autoFormatOnlyCurrentProject;
|
bool m_autoFormatOnlyCurrentProject;
|
||||||
|
bool m_foldAuxData;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool operator==(const QmlJsEditingSettings &s1, const QmlJsEditingSettings &s2)
|
inline bool operator==(const QmlJsEditingSettings &s1, const QmlJsEditingSettings &s2)
|
||||||
|
|||||||
@@ -79,6 +79,22 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QGroupBox" name="groupBox_3">
|
||||||
|
<property name="title">
|
||||||
|
<string>Features</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="foldAuxDataCheckBox">
|
||||||
|
<property name="text">
|
||||||
|
<string>Auto-fold auxiliary data</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
#include "qmljsquickfixassist.h"
|
#include "qmljsquickfixassist.h"
|
||||||
#include "qmloutlinemodel.h"
|
#include "qmloutlinemodel.h"
|
||||||
#include "quicktoolbar.h"
|
#include "quicktoolbar.h"
|
||||||
|
#include "qmljseditingsettingspage.h"
|
||||||
|
|
||||||
#include <qmljs/qmljsbind.h>
|
#include <qmljs/qmljsbind.h>
|
||||||
#include <qmljs/qmljsevaluate.h>
|
#include <qmljs/qmljsevaluate.h>
|
||||||
@@ -158,6 +159,24 @@ void QmlJSEditorWidget::finalizeInitialization()
|
|||||||
createToolBar();
|
createToolBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool QmlJSEditorWidget::restoreState(const QByteArray &state)
|
||||||
|
{
|
||||||
|
QStringList qmlTypes { QmlJSTools::Constants::QML_MIMETYPE,
|
||||||
|
QmlJSTools::Constants::QBS_MIMETYPE,
|
||||||
|
QmlJSTools::Constants::QMLTYPES_MIMETYPE,
|
||||||
|
QmlJSTools::Constants::QMLUI_MIMETYPE };
|
||||||
|
|
||||||
|
if (QmlJsEditingSettings::get().foldAuxData() && qmlTypes.contains(textDocument()->mimeType())) {
|
||||||
|
int version = 0;
|
||||||
|
QDataStream stream(state);
|
||||||
|
stream >> version;
|
||||||
|
if (version < 1)
|
||||||
|
foldAuxiliaryData();
|
||||||
|
}
|
||||||
|
|
||||||
|
return TextEditorWidget::restoreState(state);
|
||||||
|
}
|
||||||
|
|
||||||
QModelIndex QmlJSEditorWidget::outlineModelIndex()
|
QModelIndex QmlJSEditorWidget::outlineModelIndex()
|
||||||
{
|
{
|
||||||
if (!m_outlineModelIndex.isValid()) {
|
if (!m_outlineModelIndex.isValid()) {
|
||||||
@@ -217,6 +236,27 @@ void QmlJSEditorWidget::updateCodeWarnings(Document::Ptr doc)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QmlJSEditorWidget::foldAuxiliaryData()
|
||||||
|
{
|
||||||
|
QTextDocument *doc = document();
|
||||||
|
auto documentLayout = qobject_cast<TextDocumentLayout*>(doc->documentLayout());
|
||||||
|
QTC_ASSERT(documentLayout, return);
|
||||||
|
QTextBlock block = doc->lastBlock();
|
||||||
|
|
||||||
|
while (block.isValid() && block.isVisible()) {
|
||||||
|
if (TextDocumentLayout::canFold(block) && block.next().isVisible()) {
|
||||||
|
const QString trimmedText = block.text().trimmed();
|
||||||
|
if (trimmedText.startsWith("/*##^##")) {
|
||||||
|
TextDocumentLayout::doFoldOrUnfold(block, false);
|
||||||
|
documentLayout->requestUpdate();
|
||||||
|
documentLayout->emitDocumentSizeChanged();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
block = block.previous();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void QmlJSEditorWidget::modificationChanged(bool changed)
|
void QmlJSEditorWidget::modificationChanged(bool changed)
|
||||||
{
|
{
|
||||||
if (!changed && m_modelManager)
|
if (!changed && m_modelManager)
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ public:
|
|||||||
QmlJSEditorWidget();
|
QmlJSEditorWidget();
|
||||||
|
|
||||||
void finalizeInitialization() override;
|
void finalizeInitialization() override;
|
||||||
|
bool restoreState(const QByteArray &state) override;
|
||||||
|
|
||||||
QmlJSEditorDocument *qmlJsEditorDocument() const;
|
QmlJSEditorDocument *qmlJsEditorDocument() const;
|
||||||
|
|
||||||
@@ -92,6 +93,7 @@ private:
|
|||||||
void semanticInfoUpdated(const QmlJSTools::SemanticInfo &semanticInfo);
|
void semanticInfoUpdated(const QmlJSTools::SemanticInfo &semanticInfo);
|
||||||
|
|
||||||
void updateCodeWarnings(QmlJS::Document::Ptr doc);
|
void updateCodeWarnings(QmlJS::Document::Ptr doc);
|
||||||
|
void foldAuxiliaryData();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void contextMenuEvent(QContextMenuEvent *e) override;
|
void contextMenuEvent(QContextMenuEvent *e) override;
|
||||||
|
|||||||
@@ -190,7 +190,7 @@ public:
|
|||||||
virtual void openFinishedSuccessfully();
|
virtual void openFinishedSuccessfully();
|
||||||
// IEditor
|
// IEditor
|
||||||
QByteArray saveState() const;
|
QByteArray saveState() const;
|
||||||
bool restoreState(const QByteArray &state);
|
virtual bool restoreState(const QByteArray &state);
|
||||||
void gotoLine(int line, int column = 0, bool centerLine = true, bool animate = false);
|
void gotoLine(int line, int column = 0, bool centerLine = true, bool animate = false);
|
||||||
int position(TextPositionOperation posOp = CurrentPosition,
|
int position(TextPositionOperation posOp = CurrentPosition,
|
||||||
int at = -1) const;
|
int at = -1) const;
|
||||||
|
|||||||
Reference in New Issue
Block a user