forked from qt-creator/qt-creator
TextEditor: inline highlightersettingspage.ui
Change-Id: Icc4b2fe7013f2ebb2eb57cc5f581798c87866ff5 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -62,7 +62,7 @@ add_qtc_plugin(TextEditor
|
||||
formattexteditor.cpp formattexteditor.h
|
||||
highlighter.cpp highlighter.h
|
||||
highlightersettings.cpp highlightersettings.h
|
||||
highlightersettingspage.cpp highlightersettingspage.h highlightersettingspage.ui
|
||||
highlightersettingspage.cpp highlightersettingspage.h
|
||||
icodestylepreferences.cpp icodestylepreferences.h
|
||||
icodestylepreferencesfactory.cpp icodestylepreferencesfactory.h
|
||||
indenter.h
|
||||
|
||||
@@ -24,23 +24,110 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "highlightersettingspage.h"
|
||||
|
||||
#include "highlightersettings.h"
|
||||
#include "highlighter.h"
|
||||
#include "ui_highlightersettingspage.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/layoutbuilder.h>
|
||||
#include <utils/pathchooser.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDir>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QMessageBox>
|
||||
#include <QPointer>
|
||||
#include <QPushButton>
|
||||
|
||||
using namespace TextEditor::Internal;
|
||||
using namespace Utils;
|
||||
|
||||
namespace TextEditor {
|
||||
namespace Internal {
|
||||
|
||||
class HighlighterSettingsPage::HighlighterSettingsPagePrivate
|
||||
class HighlighterSettingsPageWidget : public QWidget
|
||||
{
|
||||
public:
|
||||
QLabel *definitionsInfolabel;
|
||||
QPushButton *downloadDefinitions;
|
||||
QLabel *updateStatus;
|
||||
PathChooser *definitionFilesPath;
|
||||
QPushButton *reloadDefinitions;
|
||||
QPushButton *resetCache;
|
||||
QLineEdit *ignoreEdit;
|
||||
|
||||
HighlighterSettingsPageWidget()
|
||||
{
|
||||
resize(521, 332);
|
||||
|
||||
definitionsInfolabel = new QLabel(this);
|
||||
definitionsInfolabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
definitionsInfolabel->setTextFormat(Qt::RichText);
|
||||
definitionsInfolabel->setAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter);
|
||||
definitionsInfolabel->setWordWrap(true);
|
||||
definitionsInfolabel->setOpenExternalLinks(true);
|
||||
definitionsInfolabel->setText(tr("<html><head/><body><p>Highlight definitions are provided by the "
|
||||
"<a href=\"https://api.kde.org/frameworks/syntax-highlighting/html/index.html\">"
|
||||
"KSyntaxHighlighting</a> engine.</p></body></html>"));
|
||||
|
||||
downloadDefinitions = new QPushButton(tr("Download Definitions"));
|
||||
downloadDefinitions->setToolTip(tr("Download missing and update existing syntax definition files."));
|
||||
|
||||
updateStatus = new QLabel;
|
||||
|
||||
definitionFilesPath = new PathChooser;
|
||||
definitionFilesPath->setExpectedKind(PathChooser::ExistingDirectory);
|
||||
definitionFilesPath->setHistoryCompleter("TextEditor.Highlighter.History");
|
||||
|
||||
reloadDefinitions = new QPushButton(tr("Reload Definitions"));
|
||||
reloadDefinitions->setToolTip(tr("Reload externally modified definition files."));
|
||||
|
||||
resetCache = new QPushButton(tr("Reset Remembered Definitions"));
|
||||
resetCache->setToolTip(tr("Reset definitions remembered for files that can be "
|
||||
"associated with more than one highlighter definition."));
|
||||
|
||||
ignoreEdit = new QLineEdit;
|
||||
|
||||
using namespace Layouting;
|
||||
Column {
|
||||
definitionsInfolabel,
|
||||
Space(3),
|
||||
Group {
|
||||
title(tr("Syntax Highlight Definition Files")),
|
||||
Column {
|
||||
Row { downloadDefinitions, updateStatus, st },
|
||||
Row { tr("User Highlight Definition Files"),
|
||||
definitionFilesPath, reloadDefinitions },
|
||||
Row { st, resetCache }
|
||||
}
|
||||
},
|
||||
Row { tr("Ignored file patterns:"), ignoreEdit },
|
||||
st
|
||||
}.attachTo(this);
|
||||
|
||||
connect(downloadDefinitions, &QPushButton::pressed,
|
||||
[label = QPointer<QLabel>(updateStatus)]() {
|
||||
Highlighter::downloadDefinitions([label] {
|
||||
if (label)
|
||||
label->setText(tr("Download finished"));
|
||||
});
|
||||
});
|
||||
|
||||
connect(reloadDefinitions, &QPushButton::pressed, this, [] {
|
||||
Highlighter::reload();
|
||||
});
|
||||
connect(resetCache, &QPushButton::clicked, this, [] {
|
||||
Highlighter::clearDefinitionForDocumentCache();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
} // Internal
|
||||
|
||||
class HighlighterSettingsPagePrivate
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(TextEditor::Internal::HighlighterSettingsPage)
|
||||
|
||||
@@ -50,17 +137,20 @@ public:
|
||||
void ensureInitialized();
|
||||
void migrateGenericHighlighterFiles();
|
||||
|
||||
void settingsFromUI();
|
||||
void settingsToUI();
|
||||
bool settingsChanged();
|
||||
|
||||
bool m_initialized = false;
|
||||
const QString m_settingsPrefix{"Text"};
|
||||
|
||||
HighlighterSettings m_settings;
|
||||
|
||||
QPointer<QWidget> m_widget;
|
||||
Ui::HighlighterSettingsPage *m_page = nullptr;
|
||||
QPointer<HighlighterSettingsPageWidget> m_widget;
|
||||
};
|
||||
|
||||
|
||||
void HighlighterSettingsPage::HighlighterSettingsPagePrivate::migrateGenericHighlighterFiles()
|
||||
void HighlighterSettingsPagePrivate::migrateGenericHighlighterFiles()
|
||||
{
|
||||
QDir userDefinitionPath(m_settings.definitionFilesPath().toString());
|
||||
if (userDefinitionPath.mkdir("syntax")) {
|
||||
@@ -73,7 +163,7 @@ void HighlighterSettingsPage::HighlighterSettingsPagePrivate::migrateGenericHigh
|
||||
}
|
||||
}
|
||||
|
||||
void HighlighterSettingsPage::HighlighterSettingsPagePrivate::ensureInitialized()
|
||||
void HighlighterSettingsPagePrivate::ensureInitialized()
|
||||
{
|
||||
if (m_initialized)
|
||||
return;
|
||||
@@ -100,46 +190,24 @@ HighlighterSettingsPage::~HighlighterSettingsPage()
|
||||
QWidget *HighlighterSettingsPage::widget()
|
||||
{
|
||||
if (!d->m_widget) {
|
||||
d->m_widget = new QWidget;
|
||||
d->m_page = new Ui::HighlighterSettingsPage;
|
||||
d->m_page->setupUi(d->m_widget);
|
||||
d->m_page->definitionFilesPath->setExpectedKind(Utils::PathChooser::ExistingDirectory);
|
||||
d->m_page->definitionFilesPath->setHistoryCompleter(QLatin1String("TextEditor.Highlighter.History"));
|
||||
connect(d->m_page->downloadDefinitions,
|
||||
&QPushButton::pressed,
|
||||
[label = QPointer<QLabel>(d->m_page->updateStatus)]() {
|
||||
Highlighter::downloadDefinitions([label](){
|
||||
if (label)
|
||||
label->setText(HighlighterSettingsPagePrivate::tr("Download finished"));
|
||||
});
|
||||
});
|
||||
connect(d->m_page->reloadDefinitions, &QPushButton::pressed, []() {
|
||||
Highlighter::reload();
|
||||
});
|
||||
connect(d->m_page->resetCache, &QPushButton::clicked, []() {
|
||||
Highlighter::clearDefinitionForDocumentCache();
|
||||
});
|
||||
|
||||
settingsToUI();
|
||||
d->m_widget = new HighlighterSettingsPageWidget;
|
||||
d->settingsToUI();
|
||||
}
|
||||
return d->m_widget;
|
||||
}
|
||||
|
||||
void HighlighterSettingsPage::apply()
|
||||
{
|
||||
if (!d->m_page) // page was not shown
|
||||
if (!d->m_widget) // page was not shown
|
||||
return;
|
||||
if (settingsChanged())
|
||||
settingsFromUI();
|
||||
if (d->settingsChanged())
|
||||
d->settingsFromUI();
|
||||
}
|
||||
|
||||
void HighlighterSettingsPage::finish()
|
||||
{
|
||||
delete d->m_widget;
|
||||
if (!d->m_page) // page was not shown
|
||||
return;
|
||||
delete d->m_page;
|
||||
d->m_page = nullptr;
|
||||
d->m_widget = nullptr;
|
||||
}
|
||||
|
||||
const HighlighterSettings &HighlighterSettingsPage::highlighterSettings() const
|
||||
@@ -148,26 +216,26 @@ const HighlighterSettings &HighlighterSettingsPage::highlighterSettings() const
|
||||
return d->m_settings;
|
||||
}
|
||||
|
||||
void HighlighterSettingsPage::settingsFromUI()
|
||||
void HighlighterSettingsPagePrivate::settingsFromUI()
|
||||
{
|
||||
d->ensureInitialized();
|
||||
d->m_settings.setDefinitionFilesPath(d->m_page->definitionFilesPath->filePath());
|
||||
d->m_settings.setIgnoredFilesPatterns(d->m_page->ignoreEdit->text());
|
||||
d->m_settings.toSettings(d->m_settingsPrefix, Core::ICore::settings());
|
||||
ensureInitialized();
|
||||
m_settings.setDefinitionFilesPath(m_widget->definitionFilesPath->filePath());
|
||||
m_settings.setIgnoredFilesPatterns(m_widget->ignoreEdit->text());
|
||||
m_settings.toSettings(m_settingsPrefix, Core::ICore::settings());
|
||||
}
|
||||
|
||||
void HighlighterSettingsPage::settingsToUI()
|
||||
void HighlighterSettingsPagePrivate::settingsToUI()
|
||||
{
|
||||
d->ensureInitialized();
|
||||
d->m_page->definitionFilesPath->setFilePath(d->m_settings.definitionFilesPath());
|
||||
d->m_page->ignoreEdit->setText(d->m_settings.ignoredFilesPatterns());
|
||||
ensureInitialized();
|
||||
m_widget->definitionFilesPath->setFilePath(m_settings.definitionFilesPath());
|
||||
m_widget->ignoreEdit->setText(m_settings.ignoredFilesPatterns());
|
||||
}
|
||||
|
||||
bool HighlighterSettingsPage::settingsChanged() const
|
||||
bool HighlighterSettingsPagePrivate::settingsChanged()
|
||||
{
|
||||
d->ensureInitialized();
|
||||
return d->m_settings.definitionFilesPath() != d->m_page->definitionFilesPath->filePath()
|
||||
|| d->m_settings.ignoredFilesPatterns() != d->m_page->ignoreEdit->text();
|
||||
ensureInitialized();
|
||||
return m_settings.definitionFilesPath() != m_widget->definitionFilesPath->filePath()
|
||||
|| m_settings.ignoredFilesPatterns() != m_widget->ignoreEdit->text();
|
||||
}
|
||||
|
||||
} // TextEditor
|
||||
|
||||
@@ -44,13 +44,7 @@ public:
|
||||
const HighlighterSettings &highlighterSettings() const;
|
||||
|
||||
private:
|
||||
void settingsFromUI();
|
||||
void settingsToUI();
|
||||
|
||||
bool settingsChanged() const;
|
||||
|
||||
class HighlighterSettingsPagePrivate;
|
||||
HighlighterSettingsPagePrivate *d;
|
||||
class HighlighterSettingsPagePrivate *d;
|
||||
};
|
||||
|
||||
} // namespace TextEditor
|
||||
} // TextEditor
|
||||
|
||||
@@ -1,202 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>TextEditor::Internal::HighlighterSettingsPage</class>
|
||||
<widget class="QWidget" name="TextEditor::Internal::HighlighterSettingsPage">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>521</width>
|
||||
<height>332</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string/>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="QLabel" name="definitionsInfolabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string><html><head/><body><p>Highlight definitions are provided by the <a href="https://api.kde.org/frameworks/syntax-highlighting/html/index.html">KSyntaxHighlighting</a> engine.</p></body></html></string>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::RichText</enum>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="openExternalLinks">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>3</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="definitionFilesGroupBox">
|
||||
<property name="title">
|
||||
<string>Syntax Highlight Definition Files</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QPushButton" name="downloadDefinitions">
|
||||
<property name="toolTip">
|
||||
<string>Download missing and update existing syntax definition files.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Download Definitions</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="updateStatus">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="locationLabel">
|
||||
<property name="text">
|
||||
<string>User Highlight Definition Files</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Utils::PathChooser" name="definitionFilesPath" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="reloadDefinitions">
|
||||
<property name="toolTip">
|
||||
<string>Reload externally modified definition files.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Reload Definitions</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="resetCache">
|
||||
<property name="toolTip">
|
||||
<string>Reset definitions remembered for files that can be associated with more than one highlighter definition.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Reset Remembered Definitions</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="ignoreLabel">
|
||||
<property name="text">
|
||||
<string>Ignored file patterns:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="ignoreEdit"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>117</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>Utils::PathChooser</class>
|
||||
<extends>QWidget</extends>
|
||||
<header location="global">utils/pathchooser.h</header>
|
||||
<container>1</container>
|
||||
<slots>
|
||||
<signal>editingFinished()</signal>
|
||||
<signal>browsingFinished()</signal>
|
||||
</slots>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>ignoreEdit</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -82,7 +82,6 @@ Project {
|
||||
"highlightersettings.h",
|
||||
"highlightersettingspage.cpp",
|
||||
"highlightersettingspage.h",
|
||||
"highlightersettingspage.ui",
|
||||
"icodestylepreferences.cpp",
|
||||
"icodestylepreferences.h",
|
||||
"icodestylepreferencesfactory.cpp",
|
||||
|
||||
Reference in New Issue
Block a user