forked from qt-creator/qt-creator
Settings page for the generic highlighter.
This commit is contained in:
@@ -0,0 +1,124 @@
|
|||||||
|
/**************************************************************************
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator
|
||||||
|
**
|
||||||
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
**
|
||||||
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
** Commercial Usage
|
||||||
|
**
|
||||||
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||||
|
** accordance with the Qt Commercial License Agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Nokia.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
**
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** If you are unsure which license is appropriate for your use, please
|
||||||
|
** contact the sales department at http://qt.nokia.com/contact.
|
||||||
|
**
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
#include "highlightersettings.h"
|
||||||
|
|
||||||
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
|
#include <QtCore/QSettings>
|
||||||
|
#include <QtCore/QString>
|
||||||
|
#include <QtCore/QLatin1String>
|
||||||
|
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
|
#include <QtCore/QDir>
|
||||||
|
#include <QtCore/QProcess>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace TextEditor {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
void applyDefaults(HighlighterSettings *settings)
|
||||||
|
{
|
||||||
|
settings->m_definitionFilesPath.clear();
|
||||||
|
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
|
static const QLatin1String kateSyntax("/share/apps/katepart/syntax");
|
||||||
|
|
||||||
|
// Wild guess.
|
||||||
|
QDir dir(QLatin1String("/usr") + kateSyntax);
|
||||||
|
if (dir.exists()) {
|
||||||
|
settings->m_definitionFilesPath = dir.path();
|
||||||
|
} else {
|
||||||
|
// Try kde-config.
|
||||||
|
QProcess process;
|
||||||
|
process.start(QLatin1String("kde-config"), QStringList(QLatin1String("--prefix")));
|
||||||
|
if (process.waitForStarted(5000)) {
|
||||||
|
process.waitForFinished(5000);
|
||||||
|
QString output = QString::fromLocal8Bit(process.readAllStandardOutput());
|
||||||
|
output.remove(QLatin1Char('\n'));
|
||||||
|
dir.setPath(output + kateSyntax);
|
||||||
|
if (dir.exists())
|
||||||
|
settings->m_definitionFilesPath = dir.path();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (settings->m_definitionFilesPath.isEmpty())
|
||||||
|
settings->m_definitionFilesPath = Core::ICore::instance()->resourcePath() +
|
||||||
|
QLatin1String("/generic-highlighter");
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace TextEditor
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
static const QLatin1String kDefinitionFilesPath("DefinitionFilesPath");
|
||||||
|
static const QLatin1String kGroupPostfix("HighlighterSettings");
|
||||||
|
|
||||||
|
QString groupSpecifier(const QString &postFix, const QString &category)
|
||||||
|
{
|
||||||
|
if (category.isEmpty())
|
||||||
|
return postFix;
|
||||||
|
return QString(category + postFix);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace anonymous
|
||||||
|
|
||||||
|
using namespace TextEditor;
|
||||||
|
using namespace Internal;
|
||||||
|
|
||||||
|
HighlighterSettings::HighlighterSettings()
|
||||||
|
{}
|
||||||
|
|
||||||
|
void HighlighterSettings::toSettings(const QString &category, QSettings *s) const
|
||||||
|
{
|
||||||
|
const QString &group = groupSpecifier(kGroupPostfix, category);
|
||||||
|
s->beginGroup(group);
|
||||||
|
s->setValue(kDefinitionFilesPath, m_definitionFilesPath);
|
||||||
|
s->endGroup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void HighlighterSettings::fromSettings(const QString &category, QSettings *s)
|
||||||
|
{
|
||||||
|
const QString &group = groupSpecifier(kGroupPostfix, category);
|
||||||
|
s->beginGroup(group);
|
||||||
|
|
||||||
|
if (!s->contains(kDefinitionFilesPath))
|
||||||
|
applyDefaults(this);
|
||||||
|
else
|
||||||
|
m_definitionFilesPath = s->value(kDefinitionFilesPath, QString()).toString();
|
||||||
|
|
||||||
|
s->endGroup();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HighlighterSettings::equals(const HighlighterSettings &highlighterSettings) const
|
||||||
|
{
|
||||||
|
return m_definitionFilesPath == highlighterSettings.m_definitionFilesPath;
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
/**************************************************************************
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator
|
||||||
|
**
|
||||||
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
**
|
||||||
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
** Commercial Usage
|
||||||
|
**
|
||||||
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||||
|
** accordance with the Qt Commercial License Agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Nokia.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
**
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** If you are unsure which license is appropriate for your use, please
|
||||||
|
** contact the sales department at http://qt.nokia.com/contact.
|
||||||
|
**
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
#ifndef HIGHLIGHTERSETTINGS_H
|
||||||
|
#define HIGHLIGHTERSETTINGS_H
|
||||||
|
|
||||||
|
#include <QtCore/QString>
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QSettings;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
namespace TextEditor {
|
||||||
|
|
||||||
|
struct HighlighterSettings
|
||||||
|
{
|
||||||
|
HighlighterSettings();
|
||||||
|
|
||||||
|
void toSettings(const QString &category, QSettings *s) const;
|
||||||
|
void fromSettings(const QString &category, QSettings *s);
|
||||||
|
|
||||||
|
bool equals(const HighlighterSettings &highlighterSettings) const;
|
||||||
|
|
||||||
|
QString m_definitionFilesPath;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline bool operator==(const HighlighterSettings &a, const HighlighterSettings &b)
|
||||||
|
{ return a.equals(b); }
|
||||||
|
|
||||||
|
inline bool operator!=(const HighlighterSettings &a, const HighlighterSettings &b)
|
||||||
|
{ return !a.equals(b); }
|
||||||
|
|
||||||
|
namespace Internal {
|
||||||
|
void applyDefaults(HighlighterSettings *settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace TextEditor
|
||||||
|
|
||||||
|
#endif // HIGHLIGHTERSETTINGS_H
|
||||||
@@ -0,0 +1,156 @@
|
|||||||
|
/**************************************************************************
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator
|
||||||
|
**
|
||||||
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
**
|
||||||
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
** Commercial Usage
|
||||||
|
**
|
||||||
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||||
|
** accordance with the Qt Commercial License Agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Nokia.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
**
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** If you are unsure which license is appropriate for your use, please
|
||||||
|
** contact the sales department at http://qt.nokia.com/contact.
|
||||||
|
**
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
#include "highlightersettingspage.h"
|
||||||
|
#include "highlightersettings.h"
|
||||||
|
#include "manager.h"
|
||||||
|
#include "ui_highlightersettingspage.h"
|
||||||
|
|
||||||
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
|
using namespace TextEditor;
|
||||||
|
using namespace Internal;
|
||||||
|
|
||||||
|
struct HighlighterSettingsPage::HighlighterSettingsPagePrivate
|
||||||
|
{
|
||||||
|
explicit HighlighterSettingsPagePrivate(const QString &id);
|
||||||
|
|
||||||
|
const QString m_id;
|
||||||
|
const QString m_displayName;
|
||||||
|
const QString m_settingsPrefix;
|
||||||
|
|
||||||
|
QString m_searchKeywords;
|
||||||
|
|
||||||
|
HighlighterSettings m_settings;
|
||||||
|
|
||||||
|
Ui::HighlighterSettingsPage m_page;
|
||||||
|
};
|
||||||
|
|
||||||
|
HighlighterSettingsPage::HighlighterSettingsPagePrivate::
|
||||||
|
HighlighterSettingsPagePrivate(const QString &id) :
|
||||||
|
m_id(id),
|
||||||
|
m_displayName(tr("Generic Highlighter")),
|
||||||
|
m_settingsPrefix(QLatin1String("text"))
|
||||||
|
{}
|
||||||
|
|
||||||
|
HighlighterSettingsPage::HighlighterSettingsPage(const QString &id, QObject *parent) :
|
||||||
|
TextEditorOptionsPage(parent),
|
||||||
|
m_d(new HighlighterSettingsPagePrivate(id))
|
||||||
|
{
|
||||||
|
if (QSettings *s = Core::ICore::instance()->settings())
|
||||||
|
m_d->m_settings.fromSettings(m_d->m_settingsPrefix, s);
|
||||||
|
|
||||||
|
connect(this, SIGNAL(definitionsLocationChanged()),
|
||||||
|
Manager::instance(), SLOT(registerMimeTypes()));
|
||||||
|
}
|
||||||
|
|
||||||
|
HighlighterSettingsPage::~HighlighterSettingsPage()
|
||||||
|
{
|
||||||
|
delete m_d;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString HighlighterSettingsPage::id() const
|
||||||
|
{
|
||||||
|
return m_d->m_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString HighlighterSettingsPage::displayName() const
|
||||||
|
{
|
||||||
|
return m_d->m_displayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget *HighlighterSettingsPage::createPage(QWidget *parent)
|
||||||
|
{
|
||||||
|
QWidget *w = new QWidget(parent);
|
||||||
|
m_d->m_page.setupUi(w);
|
||||||
|
|
||||||
|
settingsToUI();
|
||||||
|
|
||||||
|
if (m_d->m_searchKeywords.isEmpty()) {
|
||||||
|
QTextStream(&m_d->m_searchKeywords) << m_d->m_page.definitionFilesGroupBox->title()
|
||||||
|
<< m_d->m_page.locationLabel->text();
|
||||||
|
}
|
||||||
|
|
||||||
|
connect(m_d->m_page.resetButton, SIGNAL(clicked()), this, SLOT(reset()));
|
||||||
|
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HighlighterSettingsPage::apply()
|
||||||
|
{
|
||||||
|
if (settingsChanged())
|
||||||
|
settingsFromUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HighlighterSettingsPage::matches(const QString &s) const
|
||||||
|
{
|
||||||
|
return m_d->m_searchKeywords.contains(s, Qt::CaseInsensitive);
|
||||||
|
}
|
||||||
|
|
||||||
|
const HighlighterSettings &HighlighterSettingsPage::highlighterSettings() const
|
||||||
|
{
|
||||||
|
return m_d->m_settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HighlighterSettingsPage::settingsFromUI()
|
||||||
|
{
|
||||||
|
bool locationChanged = false;
|
||||||
|
if (m_d->m_settings.m_definitionFilesPath != m_d->m_page.definitionFilesPath->path())
|
||||||
|
locationChanged = true;
|
||||||
|
|
||||||
|
m_d->m_settings.m_definitionFilesPath = m_d->m_page.definitionFilesPath->path();
|
||||||
|
if (QSettings *s = Core::ICore::instance()->settings())
|
||||||
|
m_d->m_settings.toSettings(m_d->m_settingsPrefix, s);
|
||||||
|
|
||||||
|
if (locationChanged)
|
||||||
|
emit definitionsLocationChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void HighlighterSettingsPage::settingsToUI(const HighlighterSettings *settings)
|
||||||
|
{
|
||||||
|
if (settings) {
|
||||||
|
m_d->m_page.definitionFilesPath->setPath(settings->m_definitionFilesPath);
|
||||||
|
} else {
|
||||||
|
m_d->m_page.definitionFilesPath->setPath(m_d->m_settings.m_definitionFilesPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HighlighterSettingsPage::reset()
|
||||||
|
{
|
||||||
|
HighlighterSettings defaultSettings;
|
||||||
|
applyDefaults(&defaultSettings);
|
||||||
|
settingsToUI(&defaultSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HighlighterSettingsPage::settingsChanged() const
|
||||||
|
{
|
||||||
|
if (m_d->m_settings.m_definitionFilesPath != m_d->m_page.definitionFilesPath->path())
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
/**************************************************************************
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator
|
||||||
|
**
|
||||||
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
**
|
||||||
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
** Commercial Usage
|
||||||
|
**
|
||||||
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||||
|
** accordance with the Qt Commercial License Agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Nokia.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
**
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** If you are unsure which license is appropriate for your use, please
|
||||||
|
** contact the sales department at http://qt.nokia.com/contact.
|
||||||
|
**
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
#ifndef HIGHLIGHTERSETTINGSPAGE_H
|
||||||
|
#define HIGHLIGHTERSETTINGSPAGE_H
|
||||||
|
|
||||||
|
#include "texteditoroptionspage.h"
|
||||||
|
|
||||||
|
namespace TextEditor {
|
||||||
|
|
||||||
|
struct HighlighterSettings;
|
||||||
|
|
||||||
|
class HighlighterSettingsPage : public TextEditorOptionsPage
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
HighlighterSettingsPage(const QString &id, QObject *parent);
|
||||||
|
virtual ~HighlighterSettingsPage();
|
||||||
|
|
||||||
|
QString id() const;
|
||||||
|
QString displayName() const;
|
||||||
|
|
||||||
|
QWidget *createPage(QWidget *parent);
|
||||||
|
void apply();
|
||||||
|
void finish() {}
|
||||||
|
bool matches(const QString &s) const;
|
||||||
|
|
||||||
|
const HighlighterSettings &highlighterSettings() const;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void definitionsLocationChanged();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void reset();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void settingsFromUI();
|
||||||
|
void settingsToUI(const HighlighterSettings *settings = 0);
|
||||||
|
|
||||||
|
bool settingsChanged() const;
|
||||||
|
|
||||||
|
struct HighlighterSettingsPagePrivate;
|
||||||
|
HighlighterSettingsPagePrivate *m_d;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace TextEditor
|
||||||
|
|
||||||
|
#endif // HIGHLIGHTERSETTINGSPAGE_H
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>HighlighterSettingsPage</class>
|
||||||
|
<widget class="QWidget" name="HighlighterSettingsPage">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>453</width>
|
||||||
|
<height>230</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Form</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="definitionFilesGroupBox">
|
||||||
|
<property name="title">
|
||||||
|
<string>Syntax Definition Files</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="locationLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>Location:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="Utils::PathChooser" name="definitionFilesPath" native="true">
|
||||||
|
<zorder>locationLabel</zorder>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="resetButton">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Reset to default</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>R</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="../../coreplugin/core.qrc">
|
||||||
|
<normaloff>:/core/images/reset.png</normaloff>:/core/images/reset.png</iconset>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
<zorder>locationLabel</zorder>
|
||||||
|
<zorder>definitionFilesPath</zorder>
|
||||||
|
<zorder>resetButton</zorder>
|
||||||
|
<zorder>resetButton</zorder>
|
||||||
|
<zorder>resetButton</zorder>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="verticalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>146</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>
|
||||||
|
<resources>
|
||||||
|
<include location="../../coreplugin/core.qrc"/>
|
||||||
|
</resources>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
@@ -34,6 +34,7 @@
|
|||||||
#include "texteditorplugin.h"
|
#include "texteditorplugin.h"
|
||||||
#include "texteditorsettings.h"
|
#include "texteditorsettings.h"
|
||||||
#include "plaintexteditorfactory.h"
|
#include "plaintexteditorfactory.h"
|
||||||
|
#include "highlightersettings.h"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
@@ -133,6 +134,7 @@ bool Manager::isBuildingDefinition(const QString &id) const
|
|||||||
|
|
||||||
void Manager::registerMimeTypes()
|
void Manager::registerMimeTypes()
|
||||||
{
|
{
|
||||||
|
clear();
|
||||||
QFuture<Core::MimeType> future =
|
QFuture<Core::MimeType> future =
|
||||||
QtConcurrent::run(&Manager::gatherDefinitionsMimeTypes, this);
|
QtConcurrent::run(&Manager::gatherDefinitionsMimeTypes, this);
|
||||||
m_watcher.setFuture(future);
|
m_watcher.setFuture(future);
|
||||||
@@ -142,8 +144,8 @@ void Manager::registerMimeTypes()
|
|||||||
|
|
||||||
void Manager::gatherDefinitionsMimeTypes(QFutureInterface<Core::MimeType> &future)
|
void Manager::gatherDefinitionsMimeTypes(QFutureInterface<Core::MimeType> &future)
|
||||||
{
|
{
|
||||||
QDir definitionsDir(Core::ICore::instance()->resourcePath() +
|
const HighlighterSettings &settings = TextEditorSettings::instance()->highlighterSettings();
|
||||||
QLatin1String("/generic-highlighter"));
|
QDir definitionsDir(settings.m_definitionFilesPath);
|
||||||
|
|
||||||
QStringList filter(QLatin1String("*.xml"));
|
QStringList filter(QLatin1String("*.xml"));
|
||||||
definitionsDir.setNameFilters(filter);
|
definitionsDir.setNameFilters(filter);
|
||||||
@@ -247,3 +249,11 @@ void Manager::parseDefinitionMetadata(const QFileInfo &fileInfo,
|
|||||||
reader.clear();
|
reader.clear();
|
||||||
definitionFile.close();
|
definitionFile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Manager::clear()
|
||||||
|
{
|
||||||
|
m_priorityComp.m_priorityById.clear();
|
||||||
|
m_idByName.clear();
|
||||||
|
m_idByMimeType.clear();
|
||||||
|
m_definitions.clear();
|
||||||
|
}
|
||||||
|
|||||||
@@ -42,6 +42,7 @@
|
|||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QFileInfo;
|
class QFileInfo;
|
||||||
class QStringList;
|
class QStringList;
|
||||||
|
class QDir;
|
||||||
template <class> class QFutureInterface;
|
template <class> class QFutureInterface;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
@@ -63,14 +64,17 @@ public:
|
|||||||
bool isBuildingDefinition(const QString &id) const;
|
bool isBuildingDefinition(const QString &id) const;
|
||||||
const QSharedPointer<HighlightDefinition> &definition(const QString &id);
|
const QSharedPointer<HighlightDefinition> &definition(const QString &id);
|
||||||
|
|
||||||
private slots:
|
public slots:
|
||||||
void registerMimeTypes();
|
void registerMimeTypes();
|
||||||
|
|
||||||
|
private slots:
|
||||||
void registerMimeType(int index) const;
|
void registerMimeType(int index) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Manager();
|
Manager();
|
||||||
Q_DISABLE_COPY(Manager)
|
Q_DISABLE_COPY(Manager)
|
||||||
|
|
||||||
|
void clear();
|
||||||
void gatherDefinitionsMimeTypes(QFutureInterface<Core::MimeType> &future);
|
void gatherDefinitionsMimeTypes(QFutureInterface<Core::MimeType> &future);
|
||||||
void parseDefinitionMetadata(const QFileInfo &fileInfo,
|
void parseDefinitionMetadata(const QFileInfo &fileInfo,
|
||||||
QString *comment,
|
QString *comment,
|
||||||
|
|||||||
@@ -52,7 +52,9 @@ SOURCES += texteditorplugin.cpp \
|
|||||||
generichighlighter/highlightdefinition.cpp \
|
generichighlighter/highlightdefinition.cpp \
|
||||||
generichighlighter/highlighter.cpp \
|
generichighlighter/highlighter.cpp \
|
||||||
generichighlighter/manager.cpp \
|
generichighlighter/manager.cpp \
|
||||||
generichighlighter/highlightdefinitionhandler.cpp
|
generichighlighter/highlightdefinitionhandler.cpp \
|
||||||
|
generichighlighter/highlightersettingspage.cpp \
|
||||||
|
generichighlighter/highlightersettings.cpp
|
||||||
|
|
||||||
HEADERS += texteditorplugin.h \
|
HEADERS += texteditorplugin.h \
|
||||||
textfilewizard.h \
|
textfilewizard.h \
|
||||||
@@ -107,12 +109,15 @@ HEADERS += texteditorplugin.h \
|
|||||||
generichighlighter/highlightdefinition.h \
|
generichighlighter/highlightdefinition.h \
|
||||||
generichighlighter/highlighter.h \
|
generichighlighter/highlighter.h \
|
||||||
generichighlighter/manager.h \
|
generichighlighter/manager.h \
|
||||||
generichighlighter/highlightdefinitionhandler.h
|
generichighlighter/highlightdefinitionhandler.h \
|
||||||
|
generichighlighter/highlightersettingspage.h \
|
||||||
|
generichighlighter/highlightersettings.h
|
||||||
|
|
||||||
|
|
||||||
FORMS += behaviorsettingspage.ui \
|
FORMS += behaviorsettingspage.ui \
|
||||||
displaysettingspage.ui \
|
displaysettingspage.ui \
|
||||||
fontsettingspage.ui \
|
fontsettingspage.ui \
|
||||||
colorschemeedit.ui
|
colorschemeedit.ui \
|
||||||
|
generichighlighter/highlightersettingspage.ui
|
||||||
RESOURCES += texteditor.qrc
|
RESOURCES += texteditor.qrc
|
||||||
OTHER_FILES += TextEditor.pluginspec TextEditor.mimetypes.xml
|
OTHER_FILES += TextEditor.pluginspec TextEditor.mimetypes.xml
|
||||||
|
|||||||
@@ -71,9 +71,6 @@ TextEditorPlugin::TextEditorPlugin()
|
|||||||
{
|
{
|
||||||
QTC_ASSERT(!m_instance, return);
|
QTC_ASSERT(!m_instance, return);
|
||||||
m_instance = this;
|
m_instance = this;
|
||||||
|
|
||||||
connect(Core::ICore::instance(), SIGNAL(coreOpened()),
|
|
||||||
Manager::instance(), SLOT(registerMimeTypes()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TextEditorPlugin::~TextEditorPlugin()
|
TextEditorPlugin::~TextEditorPlugin()
|
||||||
@@ -145,6 +142,10 @@ bool TextEditorPlugin::initialize(const QStringList &arguments, QString *errorMe
|
|||||||
quickFixCommand->setDefaultKeySequence(QKeySequence(tr("Alt+Return")));
|
quickFixCommand->setDefaultKeySequence(QKeySequence(tr("Alt+Return")));
|
||||||
connect(quickFixShortcut, SIGNAL(activated()), this, SLOT(invokeQuickFix()));
|
connect(quickFixShortcut, SIGNAL(activated()), this, SLOT(invokeQuickFix()));
|
||||||
|
|
||||||
|
// Generic highlighter.
|
||||||
|
connect(Core::ICore::instance(), SIGNAL(coreOpened()),
|
||||||
|
Manager::instance(), SLOT(registerMimeTypes()));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,7 @@
|
|||||||
#include "storagesettings.h"
|
#include "storagesettings.h"
|
||||||
#include "tabsettings.h"
|
#include "tabsettings.h"
|
||||||
#include "texteditorplugin.h"
|
#include "texteditorplugin.h"
|
||||||
|
#include "highlightersettingspage.h"
|
||||||
|
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
@@ -60,6 +61,7 @@ public:
|
|||||||
FontSettingsPage *m_fontSettingsPage;
|
FontSettingsPage *m_fontSettingsPage;
|
||||||
BehaviorSettingsPage *m_behaviorSettingsPage;
|
BehaviorSettingsPage *m_behaviorSettingsPage;
|
||||||
DisplaySettingsPage *m_displaySettingsPage;
|
DisplaySettingsPage *m_displaySettingsPage;
|
||||||
|
HighlighterSettingsPage *m_highlighterSettingsPage;
|
||||||
|
|
||||||
CompletionSettings m_completionSettings;
|
CompletionSettings m_completionSettings;
|
||||||
|
|
||||||
@@ -160,6 +162,10 @@ TextEditorSettings::TextEditorSettings(QObject *parent)
|
|||||||
m_d->m_displaySettingsPage = new DisplaySettingsPage(displaySettingsPageParameters, this);
|
m_d->m_displaySettingsPage = new DisplaySettingsPage(displaySettingsPageParameters, this);
|
||||||
pm->addObject(m_d->m_displaySettingsPage);
|
pm->addObject(m_d->m_displaySettingsPage);
|
||||||
|
|
||||||
|
m_d->m_highlighterSettingsPage =
|
||||||
|
new HighlighterSettingsPage(QLatin1String("E.HighlighterSettings"), this);
|
||||||
|
pm->addObject(m_d->m_highlighterSettingsPage);
|
||||||
|
|
||||||
connect(m_d->m_fontSettingsPage, SIGNAL(changed(TextEditor::FontSettings)),
|
connect(m_d->m_fontSettingsPage, SIGNAL(changed(TextEditor::FontSettings)),
|
||||||
this, SIGNAL(fontSettingsChanged(TextEditor::FontSettings)));
|
this, SIGNAL(fontSettingsChanged(TextEditor::FontSettings)));
|
||||||
connect(m_d->m_behaviorSettingsPage, SIGNAL(tabSettingsChanged(TextEditor::TabSettings)),
|
connect(m_d->m_behaviorSettingsPage, SIGNAL(tabSettingsChanged(TextEditor::TabSettings)),
|
||||||
@@ -182,6 +188,7 @@ TextEditorSettings::~TextEditorSettings()
|
|||||||
pm->removeObject(m_d->m_fontSettingsPage);
|
pm->removeObject(m_d->m_fontSettingsPage);
|
||||||
pm->removeObject(m_d->m_behaviorSettingsPage);
|
pm->removeObject(m_d->m_behaviorSettingsPage);
|
||||||
pm->removeObject(m_d->m_displaySettingsPage);
|
pm->removeObject(m_d->m_displaySettingsPage);
|
||||||
|
pm->removeObject(m_d->m_highlighterSettingsPage);
|
||||||
|
|
||||||
delete m_d;
|
delete m_d;
|
||||||
|
|
||||||
@@ -258,6 +265,11 @@ const CompletionSettings &TextEditorSettings::completionSettings() const
|
|||||||
return m_d->m_completionSettings;
|
return m_d->m_completionSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const HighlighterSettings &TextEditorSettings::highlighterSettings() const
|
||||||
|
{
|
||||||
|
return m_d->m_highlighterSettingsPage->highlighterSettings();
|
||||||
|
}
|
||||||
|
|
||||||
void TextEditorSettings::setCompletionSettings(const TextEditor::CompletionSettings &settings)
|
void TextEditorSettings::setCompletionSettings(const TextEditor::CompletionSettings &settings)
|
||||||
{
|
{
|
||||||
if (m_d->m_completionSettings == settings)
|
if (m_d->m_completionSettings == settings)
|
||||||
|
|||||||
@@ -37,15 +37,13 @@
|
|||||||
namespace TextEditor {
|
namespace TextEditor {
|
||||||
|
|
||||||
class BaseTextEditor;
|
class BaseTextEditor;
|
||||||
class BehaviorSettingsPage;
|
|
||||||
class DisplaySettingsPage;
|
|
||||||
class FontSettingsPage;
|
|
||||||
class FontSettings;
|
class FontSettings;
|
||||||
struct TabSettings;
|
struct TabSettings;
|
||||||
struct StorageSettings;
|
struct StorageSettings;
|
||||||
struct BehaviorSettings;
|
struct BehaviorSettings;
|
||||||
struct DisplaySettings;
|
struct DisplaySettings;
|
||||||
struct CompletionSettings;
|
struct CompletionSettings;
|
||||||
|
struct HighlighterSettings;
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
class TextEditorSettingsPrivate;
|
class TextEditorSettingsPrivate;
|
||||||
@@ -74,6 +72,7 @@ public:
|
|||||||
const BehaviorSettings &behaviorSettings() const;
|
const BehaviorSettings &behaviorSettings() const;
|
||||||
const DisplaySettings &displaySettings() const;
|
const DisplaySettings &displaySettings() const;
|
||||||
const CompletionSettings &completionSettings() const;
|
const CompletionSettings &completionSettings() const;
|
||||||
|
const HighlighterSettings &highlighterSettings() const;
|
||||||
|
|
||||||
void setCompletionSettings(const TextEditor::CompletionSettings &);
|
void setCompletionSettings(const TextEditor::CompletionSettings &);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user