Merge pull request #1119 from openscad/scintilla-updates

Scintilla updates
master
Marius Kintel 2014-12-30 02:51:38 -05:00
commit bc30dca513
10 changed files with 1922 additions and 666 deletions

View File

@ -247,6 +247,7 @@ HEADERS += src/typedefs.h \
src/ProgressWidget.h \
src/parsersettings.h \
src/renderer.h \
src/settings.h \
src/rendersettings.h \
src/colormap.h \
src/ThrownTogetherRenderer.h \
@ -399,6 +400,7 @@ SOURCES += src/version_check.cc \
src/FreetypeRenderer.cc \
src/FontCache.cc \
\
src/settings.cc \
src/rendersettings.cc \
src/highlighter.cc \
src/Preferences.cc \

View File

@ -45,6 +45,55 @@ Preferences *Preferences::instance = NULL;
const char * Preferences::featurePropertyName = "FeatureProperty";
Q_DECLARE_METATYPE(Feature *);
class SettingsReader : public Settings::Visitor
{
QSettings settings;
const Value getValue(const Settings::SettingsEntry& entry, const std::string& value) const {
if (value.empty()) {
return entry.defaultValue();
}
try {
switch (entry.defaultValue().type()) {
case Value::STRING:
return Value(value);
case Value::NUMBER:
return Value(boost::lexical_cast<int>(value));
case Value::BOOL:
return Value(boost::lexical_cast<bool>(value));
default:
assert(false && "invalid value type for settings");
}
} catch (const boost::bad_lexical_cast& e) {
return entry.defaultValue();
}
}
virtual void handle(Settings::SettingsEntry& entry) const {
Settings::Settings *s = Settings::Settings::inst();
std::string key = entry.category() + "/" + entry.name();
std::string value = settings.value(QString::fromStdString(key)).toString().toStdString();
s->set(entry, getValue(entry, value));
}
};
class SettingsWriter : public Settings::Visitor
{
virtual void handle(Settings::SettingsEntry& entry) const {
Settings::Settings *s = Settings::Settings::inst();
QSettings settings;
QString key = QString::fromStdString(entry.category() + "/" + entry.name());
if (entry.is_default()) {
settings.remove(key);
} else {
Value value = s->get(entry);
settings.setValue(key, QString::fromStdString(value.toString()));
}
}
};
Preferences::Preferences(QWidget *parent) : QMainWindow(parent)
{
setupUi(this);
@ -140,6 +189,22 @@ void Preferences::init() {
#endif
this->polysetCacheSizeEdit->setValidator(validator);
this->opencsgLimitEdit->setValidator(validator);
initComboBox(this->comboBoxIndentUsing, Settings::Settings::indentStyle);
initComboBox(this->comboBoxLineWrap, Settings::Settings::lineWrap);
initComboBox(this->comboBoxLineWrapIndentationStyle, Settings::Settings::lineWrapIndentationStyle);
initComboBox(this->comboBoxLineWrapVisualizationEnd, Settings::Settings::lineWrapVisualizationEnd);
initComboBox(this->comboBoxLineWrapVisualizationStart, Settings::Settings::lineWrapVisualizationBegin);
initComboBox(this->comboBoxShowWhitespace, Settings::Settings::showWhitespace);
initComboBox(this->comboBoxTabKeyFunction, Settings::Settings::tabKeyFunction);
initSpinBox(this->spinBoxIndentationWidth, Settings::Settings::indentationWidth);
initSpinBox(this->spinBoxLineWrapIndentationIndent, Settings::Settings::lineWrapIndentation);
initSpinBox(this->spinBoxShowWhitespaceSize, Settings::Settings::showWhitespaceSize);
initSpinBox(this->spinBoxTabWidth, Settings::Settings::tabWidth);
SettingsReader settingsReader;
Settings::Settings::inst()->visit(settingsReader);
emit editorConfigChanged();
}
Preferences::~Preferences()
@ -400,13 +465,96 @@ void Preferences::on_mouseWheelZoomBox_toggled(bool state)
settings.setValue("editor/ctrlmousewheelzoom", state);
}
void
Preferences::on_launcherBox_toggled(bool state)
void Preferences::on_launcherBox_toggled(bool state)
{
QSettings settings;
settings.setValue("launcher/showOnStartup", state);
}
void Preferences::on_spinBoxIndentationWidth_valueChanged(int val)
{
Settings::Settings::inst()->set(Settings::Settings::indentationWidth, Value(val));
fireEditorConfigChanged();
}
void Preferences::on_spinBoxTabWidth_valueChanged(int val)
{
Settings::Settings::inst()->set(Settings::Settings::tabWidth, Value(val));
fireEditorConfigChanged();
}
void Preferences::on_comboBoxLineWrap_activated(int val)
{
applyComboBox(comboBoxLineWrap, val, Settings::Settings::lineWrap);
}
void Preferences::on_comboBoxLineWrapIndentationStyle_activated(int val)
{
applyComboBox(comboBoxLineWrapIndentationStyle, val, Settings::Settings::lineWrapIndentationStyle);
}
void Preferences::on_spinBoxLineWrapIndentationIndent_valueChanged(int val)
{
Settings::Settings::inst()->set(Settings::Settings::lineWrapIndentation, Value(val));
fireEditorConfigChanged();
}
void Preferences::on_comboBoxLineWrapVisualizationStart_activated(int val)
{
applyComboBox(comboBoxLineWrapVisualizationStart, val, Settings::Settings::lineWrapVisualizationBegin);
}
void Preferences::on_comboBoxLineWrapVisualizationEnd_activated(int val)
{
applyComboBox(comboBoxLineWrapVisualizationEnd, val, Settings::Settings::lineWrapVisualizationEnd);
}
void Preferences::on_comboBoxShowWhitespace_activated(int val)
{
applyComboBox(comboBoxShowWhitespace, val, Settings::Settings::showWhitespace);
}
void Preferences::on_spinBoxShowWhitespaceSize_valueChanged(int val)
{
Settings::Settings::inst()->set(Settings::Settings::showWhitespaceSize, Value(val));
fireEditorConfigChanged();
}
void Preferences::on_checkBoxAutoIndent_toggled(bool val)
{
Settings::Settings::inst()->set(Settings::Settings::autoIndent, Value(val));
fireEditorConfigChanged();
}
void Preferences::on_comboBoxIndentUsing_activated(int val)
{
applyComboBox(comboBoxIndentUsing, val, Settings::Settings::indentStyle);
}
void Preferences::on_comboBoxTabKeyFunction_activated(int val)
{
applyComboBox(comboBoxTabKeyFunction, val, Settings::Settings::tabKeyFunction);
}
void Preferences::on_checkBoxHighlightCurrentLine_toggled(bool val)
{
Settings::Settings::inst()->set(Settings::Settings::highlightCurrentLine, Value(val));
fireEditorConfigChanged();
}
void Preferences::on_checkBoxEnableBraceMatching_toggled(bool val)
{
Settings::Settings::inst()->set(Settings::Settings::enableBraceMatching, Value(val));
fireEditorConfigChanged();
}
void Preferences::fireEditorConfigChanged() const
{
SettingsWriter settingsWriter;
Settings::Settings::inst()->visit(settingsWriter);
emit editorConfigChanged();
}
void Preferences::keyPressEvent(QKeyEvent *e)
{
#ifdef Q_OS_MAC
@ -500,6 +648,68 @@ void Preferences::updateGUI()
this->undockCheckBox->setChecked(getValue("advanced/undockableWindows").toBool());
this->undockCheckBox->setEnabled(this->reorderCheckBox->isChecked());
this->launcherBox->setChecked(getValue("launcher/showOnStartup").toBool());
Settings::Settings *s = Settings::Settings::inst();
updateComboBox(this->comboBoxLineWrap, Settings::Settings::lineWrap);
updateComboBox(this->comboBoxLineWrapIndentationStyle, Settings::Settings::lineWrapIndentationStyle);
updateComboBox(this->comboBoxLineWrapVisualizationStart, Settings::Settings::lineWrapVisualizationBegin);
updateComboBox(this->comboBoxLineWrapVisualizationEnd, Settings::Settings::lineWrapVisualizationEnd);
updateComboBox(this->comboBoxShowWhitespace, Settings::Settings::showWhitespace);
updateComboBox(this->comboBoxIndentUsing, Settings::Settings::indentStyle);
updateComboBox(this->comboBoxTabKeyFunction, Settings::Settings::tabKeyFunction);
this->spinBoxIndentationWidth->setValue(s->get(Settings::Settings::indentationWidth).toDouble());
this->spinBoxTabWidth->setValue(s->get(Settings::Settings::tabWidth).toDouble());
this->spinBoxLineWrapIndentationIndent->setValue(s->get(Settings::Settings::lineWrapIndentation).toDouble());
this->spinBoxShowWhitespaceSize->setValue(s->get(Settings::Settings::showWhitespaceSize).toDouble());
this->checkBoxAutoIndent->setChecked(s->get(Settings::Settings::autoIndent).toBool());
this->checkBoxHighlightCurrentLine->setChecked(s->get(Settings::Settings::highlightCurrentLine).toBool());
this->checkBoxEnableBraceMatching->setChecked(s->get(Settings::Settings::enableBraceMatching).toBool());
}
void Preferences::initComboBox(QComboBox *comboBox, const Settings::SettingsEntry& entry)
{
comboBox->clear();
Value::VectorType vector = entry.range().toVector();
for (Value::VectorType::iterator it = vector.begin();it != vector.end();it++) {
QString val = QString::fromStdString((*it)[0].toString());
QString text = QString::fromStdString((*it)[1].toString());
comboBox->addItem(text, val);
}
}
void Preferences::initSpinBox(QSpinBox *spinBox, const Settings::SettingsEntry& entry)
{
Value::RangeType range = entry.range().toRange();
spinBox->setMinimum(range.begin_value());
spinBox->setMaximum(range.end_value());
}
void Preferences::updateComboBox(QComboBox *comboBox, const Settings::SettingsEntry& entry)
{
Settings::Settings *s = Settings::Settings::inst();
Value value = s->get(entry);
QString text = QString::fromStdString(value.toString());
int idx = comboBox->findData(text);
if (idx >= 0) {
comboBox->setCurrentIndex(idx);
} else {
Value defaultValue = entry.defaultValue();
QString defaultText = QString::fromStdString(defaultValue.toString());
int defIdx = comboBox->findData(defaultText);
if (defIdx >= 0) {
comboBox->setCurrentIndex(defIdx);
} else {
comboBox->setCurrentIndex(0);
}
}
}
void Preferences::applyComboBox(QComboBox *comboBox, int val, Settings::SettingsEntry& entry)
{
QString s = comboBox->itemData(val).toString();
Settings::Settings::inst()->set(entry, Value(s.toStdString()));
fireEditorConfigChanged();
}
void Preferences::apply() const

View File

@ -1,9 +1,11 @@
#pragma once
#include "qtgettext.h"
#include <QMainWindow>
#include <QSettings>
#include "qtgettext.h"
#include "ui_Preferences.h"
#include "settings.h"
class Preferences : public QMainWindow, public Ui::Preferences
{
@ -43,6 +45,30 @@ public slots:
void on_launcherBox_toggled(bool);
void on_editorType_editTextChanged(const QString &);
//
// editor settings
//
// Indentation
void on_checkBoxAutoIndent_toggled(bool);
void on_comboBoxIndentUsing_activated(int);
void on_spinBoxIndentationWidth_valueChanged(int);
void on_spinBoxTabWidth_valueChanged(int);
void on_comboBoxTabKeyFunction_activated(int);
void on_comboBoxShowWhitespace_activated(int);
void on_spinBoxShowWhitespaceSize_valueChanged(int);
// Line wrap
void on_comboBoxLineWrap_activated(int);
void on_comboBoxLineWrapIndentationStyle_activated(int);
void on_spinBoxLineWrapIndentationIndent_valueChanged(int);
void on_comboBoxLineWrapVisualizationStart_activated(int);
void on_comboBoxLineWrapVisualizationEnd_activated(int);
// Display
void on_checkBoxHighlightCurrentLine_toggled(bool);
void on_checkBoxEnableBraceMatching_toggled(bool);
signals:
void requestRedraw() const;
void updateMdiMode(bool mdi) const;
@ -53,6 +79,7 @@ signals:
void openCSGSettingsChanged() const;
void syntaxHighlightChanged(const QString &s) const;
void editorTypeChanged(const QString &type);
void editorConfigChanged() const;
private:
Preferences(QWidget *parent = NULL);
@ -60,8 +87,18 @@ private:
void updateGUI();
void removeDefaultSettings();
void setupFeaturesPage();
void fireEditorConfigChanged() const;
void addPrefPage(QActionGroup *group, QAction *action, QWidget *widget);
/** Initialize combobox list values from the settings range values */
void initComboBox(QComboBox *comboBox, const Settings::SettingsEntry& entry);
/** Initialize spinbox min/max values from the settings range values */
void initSpinBox(QSpinBox *spinBox, const Settings::SettingsEntry& entry);
/** Update combobox from current settings */
void updateComboBox(QComboBox *comboBox, const Settings::SettingsEntry& entry);
/** Set value from combobox to settings */
void applyComboBox(QComboBox *comboBox, int val, Settings::SettingsEntry& entry);
QSettings::SettingsMap defaultmap;
QHash<const QAction *, QWidget *> prefPages;

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>852</width>
<height>554</height>
<width>621</width>
<height>413</height>
</rect>
</property>
<property name="sizePolicy">
@ -23,11 +23,11 @@
<bool>true</bool>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout_5">
<layout class="QVBoxLayout" name="verticalLayout_13">
<item>
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
<number>4</number>
<number>0</number>
</property>
<widget class="QWidget" name="page3DView">
<layout class="QVBoxLayout" name="verticalLayout_4">
@ -75,38 +75,62 @@
</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>645</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="pageEditor">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<widget class="QScrollArea" name="scrollArea_2">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_2">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>659</width>
<height>769</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_9">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_27">
<item>
<spacer name="horizontalSpacer_28">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>30</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_12">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Editor Type</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QComboBox" name="editorType">
<item>
@ -153,16 +177,26 @@
</item>
</layout>
</item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_28">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<spacer name="horizontalSpacer_29">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>30</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Font</string>
</property>
@ -171,11 +205,15 @@
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QFontComboBox" name="fontChooser">
<property name="currentFont">
<font>
<family>Nimbus Sans L</family>
<family>Liberation Sans</family>
<pointsize>12</pointsize>
</font>
</property>
@ -203,24 +241,55 @@
</item>
</layout>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_29">
<item>
<layout class="QHBoxLayout" name="syntaxHighlightLayout">
<property name="bottomMargin">
<number>0</number>
<spacer name="horizontalSpacer_30">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>30</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="labelColorSyntaxHighlighting">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Color syntax highlighting</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="0">
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>198</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="1">
<widget class="QCheckBox" name="mouseWheelZoomBox">
<property name="text">
<string>Ctrl/Cmd-Mouse-wheel zooms text</string>
</property>
</widget>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_26">
<item>
<widget class="QComboBox" name="syntaxHighlight">
<property name="sizePolicy">
@ -249,33 +318,31 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="mouseWheelZoomLayout">
<property name="topMargin">
<number>5</number>
</layout>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="groupBoxIndentation">
<property name="title">
<string>Indentation</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_16">
<item>
<widget class="QLabel" name="label_11">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
<widget class="QSpinBox" name="spinBoxIndentationWidth">
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="text">
<string>Use Ctrl/Cmd-Mouse-wheel to zoom text</string>
<property name="maximum">
<number>99</number>
</property>
<property name="value">
<number>4</number>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="mouseWheelZoomBox">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_6">
<spacer name="horizontalSpacer_11">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@ -289,23 +356,616 @@
</item>
</layout>
</item>
<item row="0" column="0">
<spacer name="horizontalSpacer_13">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>223</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="checkBoxAutoIndent">
<property name="text">
<string>Auto Indent</string>
</property>
</widget>
</item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<spacer name="verticalSpacer_4">
<spacer name="horizontalSpacer_8">
<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="QLabel" name="label_10">
<property name="text">
<string>Indent using</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_15">
<item>
<widget class="QComboBox" name="comboBoxIndentUsing">
<item>
<property name="text">
<string>Spaces</string>
</property>
</item>
<item>
<property name="text">
<string>Tabs</string>
</property>
</item>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_14">
<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 row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<spacer name="horizontalSpacer_15">
<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="QLabel" name="labelIndentationWidth">
<property name="text">
<string>Indentation width</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_12">
<item>
<spacer name="horizontalSpacer_16">
<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="QLabel" name="labelTabWidth">
<property name="text">
<string>Tab width</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_17">
<item>
<widget class="QSpinBox" name="spinBoxTabWidth">
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="value">
<number>4</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_17">
<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 row="4" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_13">
<item>
<spacer name="horizontalSpacer_19">
<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="QLabel" name="label_9">
<property name="text">
<string>Tab key function</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="4" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_18">
<item>
<widget class="QComboBox" name="comboBoxTabKeyFunction">
<item>
<property name="text">
<string>Indent</string>
</property>
</item>
<item>
<property name="text">
<string>Insert Tab</string>
</property>
</item>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_18">
<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 row="5" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_14">
<item>
<spacer name="horizontalSpacer_20">
<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="QLabel" name="labelWhitespaces">
<property name="text">
<string>Show whitespace</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="5" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_19">
<item>
<widget class="QComboBox" name="comboBoxShowWhitespace">
<item>
<property name="text">
<string>Never</string>
</property>
</item>
<item>
<property name="text">
<string>Always</string>
</property>
</item>
<item>
<property name="text">
<string>Only after indentation</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QLabel" name="labelShowWhitespacesSize">
<property name="text">
<string>Size</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBoxShowWhitespaceSize">
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>9</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_21">
<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>
</layout>
</widget>
</item>
<item row="3" column="0">
<widget class="QGroupBox" name="groupBoxDisplay">
<property name="title">
<string>Display</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0">
<widget class="QCheckBox" name="checkBoxEnableBraceMatching">
<property name="text">
<string>Enable brace matching</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="checkBoxHighlightCurrentLine">
<property name="text">
<string>Highlight current line</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="4" column="0">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>723</height>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0">
<widget class="QGroupBox" name="groupBoxLineWrap">
<property name="title">
<string>Line wrap</string>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_25">
<item>
<widget class="QComboBox" name="comboBoxLineWrap">
<item>
<property name="text">
<string>None</string>
</property>
</item>
<item>
<property name="text">
<string>Wrap at character boundaries</string>
</property>
</item>
<item>
<property name="text">
<string>Wrap at word boundaries</string>
</property>
</item>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_25">
<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 row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_21">
<item>
<spacer name="horizontalSpacer_23">
<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="QLabel" name="labelLineWrapIndentation">
<property name="text">
<string>Line wrap indentation</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_22">
<item>
<spacer name="horizontalSpacer_24">
<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="QLabel" name="labelLineWrapVisualization">
<property name="text">
<string>Line wrap visualization</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_24">
<item>
<widget class="QLabel" name="labelLineWrapIndentationStyle">
<property name="text">
<string>Style</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxLineWrapIndentationStyle">
<item>
<property name="text">
<string>Fixed</string>
</property>
</item>
<item>
<property name="text">
<string>Same</string>
</property>
</item>
<item>
<property name="text">
<string>Indented</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QLabel" name="labelLineWrapIndentationIndent">
<property name="text">
<string>Indent</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBoxLineWrapIndentationIndent">
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_26">
<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 row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_23">
<item>
<widget class="QLabel" name="labelLineWrapVisualizationStart">
<property name="text">
<string>Start</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxLineWrapVisualizationStart">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>None</string>
</property>
</item>
<item>
<property name="text">
<string>Text</string>
</property>
</item>
<item>
<property name="text">
<string>Border</string>
</property>
</item>
<item>
<property name="text">
<string>Margin</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QLabel" name="labelLineWrapVisualizationEnd">
<property name="text">
<string>End</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxLineWrapVisualizationEnd">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>None</string>
</property>
</item>
<item>
<property name="text">
<string>Text</string>
</property>
</item>
<item>
<property name="text">
<string>Border</string>
</property>
</item>
<item>
<property name="text">
<string>Margin</string>
</property>
</item>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_27">
<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 row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_20">
<item>
<spacer name="horizontalSpacer_22">
<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="QLabel" name="labelLineWrap">
<property name="text">
<string>Line wrap</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item row="0" column="1">
<spacer name="horizontalSpacer_4">
<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>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="pageUpdate">
<layout class="QVBoxLayout" name="verticalLayout_16">
<layout class="QVBoxLayout" name="verticalLayout_11">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
@ -522,6 +1182,39 @@
</widget>
<widget class="QWidget" name="pageAdvanced">
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QScrollArea" name="scrollAreaAdvanced">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOn</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaAdvancedWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>596</width>
<height>499</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_12">
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
@ -599,6 +1292,9 @@
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
@ -657,14 +1353,14 @@
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>11</height>
<height>40</height>
</size>
</property>
</spacer>
@ -675,6 +1371,10 @@
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QToolBar" name="toolBar">
<property name="windowTitle">
<string>toolBar</string>

View File

@ -43,6 +43,7 @@
#include "progress.h"
#include "dxfdim.h"
#include "legacyeditor.h"
#include "settings.h"
#ifdef USE_SCINTILLA_EDITOR
#include "scintillaeditor.h"
#endif
@ -192,6 +193,7 @@ MainWindow::MainWindow(const QString &filename)
#ifdef USE_SCINTILLA_EDITOR
if (useScintilla) {
editor = new ScintillaEditor(editorDockContents);
}
else
#endif
@ -199,6 +201,13 @@ MainWindow::MainWindow(const QString &filename)
Preferences::create(editor->colorSchemes());
#ifdef USE_SCINTILLA_EDITOR
if (useScintilla) {
connect(Preferences::inst(), SIGNAL(editorConfigChanged()), editor, SLOT(applySettings()));
Preferences::inst()->editorConfigChanged();
}
#endif
editorDockContents->layout()->addWidget(editor);
setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);

View File

@ -6,6 +6,65 @@
#include <Qsci/qscicommandset.h>
#include "Preferences.h"
#include "PlatformUtils.h"
#include "settings.h"
class SettingsConverter {
public:
QsciScintilla::WrapMode toWrapMode(Value val);
QsciScintilla::WrapVisualFlag toLineWrapVisualization(Value val);
QsciScintilla::WrapIndentMode toLineWrapIndentationStyle(Value val);
QsciScintilla::WhitespaceVisibility toShowWhitespaces(Value val);
};
QsciScintilla::WrapMode SettingsConverter::toWrapMode(Value val)
{
std::string v = val.toString();
if (v == "Char") {
return QsciScintilla::WrapCharacter;
} else if (v == "Word") {
return QsciScintilla::WrapWord;
} else {
return QsciScintilla::WrapNone;
}
}
QsciScintilla::WrapVisualFlag SettingsConverter::toLineWrapVisualization(Value val)
{
std::string v = val.toString();
if (v == "Text") {
return QsciScintilla::WrapFlagByText;
} else if (v == "Border") {
return QsciScintilla::WrapFlagByBorder;
} else if (v == "Margin") {
return QsciScintilla::WrapFlagInMargin;
} else {
return QsciScintilla::WrapFlagNone;
}
}
QsciScintilla::WrapIndentMode SettingsConverter::toLineWrapIndentationStyle(Value val)
{
std::string v = val.toString();
if (v == "Same") {
return QsciScintilla::WrapIndentSame;
} else if (v == "Indented") {
return QsciScintilla::WrapIndentIndented;
} else {
return QsciScintilla::WrapIndentFixed;
}
}
QsciScintilla::WhitespaceVisibility SettingsConverter::toShowWhitespaces(Value val)
{
std::string v = val.toString();
if (v == "Always") {
return QsciScintilla::WsVisible;
} else if (v == "AfterIndentation") {
return QsciScintilla::WsVisibleAfterIndent;
} else {
return QsciScintilla::WsInvisible;
}
}
EditorColorScheme::EditorColorScheme(fs::path path) : path(path)
{
@ -60,7 +119,7 @@ ScintillaEditor::ScintillaEditor(QWidget *parent) : EditorInterface(parent)
QsciCommand *c;
#ifdef Q_OS_MAC
// Alt-Backspace should delete left word (Alt-Delete already deletes right word)
c= qsci->standardCommands()->find(QsciCommand::DeleteWordLeft);
c = qsci->standardCommands()->find(QsciCommand::DeleteWordLeft);
c->setKey(Qt::Key_Backspace | Qt::ALT);
#endif
// Cmd/Ctrl-T is handled by the menu
@ -70,34 +129,54 @@ ScintillaEditor::ScintillaEditor(QWidget *parent) : EditorInterface(parent)
c = qsci->standardCommands()->boundTo(Qt::Key_D | Qt::CTRL);
c->setKey(0);
// Ctrl-Shift-Z should redo on all platforms
c= qsci->standardCommands()->find(QsciCommand::Redo);
c = qsci->standardCommands()->find(QsciCommand::Redo);
c->setKey(Qt::Key_Z | Qt::CTRL | Qt::SHIFT);
scintillaLayout->setContentsMargins(0, 0, 0, 0);
scintillaLayout->addWidget(qsci);
qsci->setBraceMatching (QsciScintilla::SloppyBraceMatch);
qsci->setWrapMode(QsciScintilla::WrapCharacter);
qsci->setWrapVisualFlags(QsciScintilla::WrapFlagByBorder, QsciScintilla::WrapFlagNone, 0);
qsci->setAutoIndent(true);
qsci->indicatorDefine(QsciScintilla::RoundBoxIndicator, indicatorNumber);
qsci->markerDefine(QsciScintilla::Circle, markerNumber);
qsci->setUtf8(true);
qsci->setTabIndents(true);
qsci->setTabWidth(8);
qsci->setIndentationWidth(4);
qsci->setIndentationsUseTabs(false);
qsci->setFolding(QsciScintilla::BoxedTreeFoldStyle, 4);
lexer = new ScadLexer(this);
qsci->setLexer(lexer);
initMargin();
qsci->setFolding(QsciScintilla::BoxedTreeFoldStyle, 4);
qsci->setCaretLineVisible(true);
connect(qsci, SIGNAL(textChanged()), this, SIGNAL(contentsChanged()));
connect(qsci, SIGNAL(modificationChanged(bool)), this, SIGNAL(modificationChanged(bool)));
}
/**
* Apply the settings that are changeable in the preferences. This is also
* called in the event handler from the preferences.
*/
void ScintillaEditor::applySettings()
{
SettingsConverter conv;
Settings::Settings *s = Settings::Settings::inst();
qsci->setIndentationWidth(s->get(Settings::Settings::indentationWidth).toDouble());
qsci->setTabWidth(s->get(Settings::Settings::tabWidth).toDouble());
qsci->setWrapMode(conv.toWrapMode(s->get(Settings::Settings::lineWrap)));
qsci->setWrapIndentMode(conv.toLineWrapIndentationStyle(s->get(Settings::Settings::lineWrapIndentationStyle)));
qsci->setWrapVisualFlags(conv.toLineWrapVisualization(s->get(Settings::Settings::lineWrapVisualizationEnd)),
conv.toLineWrapVisualization(s->get(Settings::Settings::lineWrapVisualizationBegin)),
s->get(Settings::Settings::lineWrapIndentation).toDouble());
qsci->setWhitespaceVisibility(conv.toShowWhitespaces(s->get(Settings::Settings::showWhitespace)));
qsci->setWhitespaceSize(s->get(Settings::Settings::showWhitespaceSize).toDouble());
qsci->setAutoIndent(s->get(Settings::Settings::autoIndent).toBool());
std::string indentStyle = s->get(Settings::Settings::indentStyle).toString();
qsci->setIndentationsUseTabs(indentStyle == "Tabs");
std::string tabKeyFunction = s->get(Settings::Settings::tabKeyFunction).toString();
qsci->setTabIndents(tabKeyFunction == "Indent");
qsci->setBraceMatching(s->get(Settings::Settings::enableBraceMatching).toBool() ? QsciScintilla::SloppyBraceMatch : QsciScintilla::NoBraceMatch);
qsci->setCaretLineVisible(s->get(Settings::Settings::highlightCurrentLine).toBool());
}
void ScintillaEditor::setPlainText(const QString &text)
{
qsci->setText(text);
@ -127,7 +206,7 @@ void ScintillaEditor::highlightError(int error_pos)
{
int line, index;
qsci->lineIndexFromPosition(error_pos, &line, &index);
qsci->fillIndicatorRange(line, index, line, index+1, indicatorNumber);
qsci->fillIndicatorRange(line, index, line, index + 1, indicatorNumber);
qsci->markerAdd(line, markerNumber);
}
@ -309,7 +388,7 @@ QStringList ScintillaEditor::colorSchemes()
const colorscheme_set_t colorscheme_set = enumerateColorSchemes();
QStringList colorSchemes;
for (colorscheme_set_t::const_iterator it = colorscheme_set.begin();it != colorscheme_set.end();it++) {
for (colorscheme_set_t::const_iterator it = colorscheme_set.begin(); it != colorscheme_set.end(); it++) {
colorSchemes << (*it).second.get()->name();
}
colorSchemes << "Off";
@ -321,7 +400,7 @@ void ScintillaEditor::setHighlightScheme(const QString &name)
{
const colorscheme_set_t colorscheme_set = enumerateColorSchemes();
for (colorscheme_set_t::const_iterator it = colorscheme_set.begin();it != colorscheme_set.end();it++) {
for (colorscheme_set_t::const_iterator it = colorscheme_set.begin(); it != colorscheme_set.end(); it++) {
const EditorColorScheme *colorScheme = (*it).second.get();
if (colorScheme->name() == name) {
setColormap(colorScheme);
@ -441,7 +520,7 @@ void ScintillaEditor::indentSelection()
{
int lineFrom, lineTo;
getRange(&lineFrom, &lineTo);
for (int line = lineFrom;line <= lineTo;line++) {
for (int line = lineFrom; line <= lineTo; line++) {
qsci->indent(line);
}
}
@ -450,7 +529,7 @@ void ScintillaEditor::unindentSelection()
{
int lineFrom, lineTo;
getRange(&lineFrom, &lineTo);
for (int line = lineFrom;line <= lineTo;line++) {
for (int line = lineFrom; line <= lineTo; line++) {
qsci->unindent(line);
}
}
@ -461,7 +540,7 @@ void ScintillaEditor::commentSelection()
int lineFrom, lineTo;
getRange(&lineFrom, &lineTo);
for (int line = lineFrom;line <= lineTo;line++) {
for (int line = lineFrom; line <= lineTo; line++) {
qsci->insertAt("//", line, 0);
}
@ -476,7 +555,7 @@ void ScintillaEditor::uncommentSelection()
int lineFrom, lineTo;
getRange(&lineFrom, &lineTo);
for (int line = lineFrom;line <= lineTo;line++) {
for (int line = lineFrom; line <= lineTo; line++) {
QString lineText = qsci->text(line);
if (lineText.startsWith("//")) {
qsci->setSelection(line, 0, line, 2);

View File

@ -87,6 +87,7 @@ public slots:
private slots:
void onTextChanged();
void applySettings();
private:
QVBoxLayout *scintillaLayout;

139
src/settings.cc Normal file
View File

@ -0,0 +1,139 @@
#include "settings.h"
#include "printutils.h"
#include <boost/assign/std/vector.hpp>
using namespace boost::assign; // bring 'operator+=()' into scope
namespace Settings {
static std::list<SettingsEntry *> entries;
SettingsEntry::SettingsEntry(const std::string category, const std::string name, const Value range, const Value def)
: _category(category), _name(name), _value(def), _range(range), _default(def)
{
entries.push_back(this);
}
SettingsEntry::~SettingsEntry()
{
}
const std::string & SettingsEntry::category() const
{
return _category;
}
const std::string & SettingsEntry::name() const
{
return _name;
}
const Value & SettingsEntry::defaultValue() const
{
return _default;
}
const Value & SettingsEntry::range() const
{
return _range;
}
bool SettingsEntry::is_default() const
{
return _value == _default;
}
static Value value(std::string s1, std::string s2) {
Value::VectorType v;
v += Value(s1), Value(s2);
return v;
}
static Value values(std::string s1, std::string s1disp, std::string s2, std::string s2disp) {
Value::VectorType v;
v += value(s1, s1disp), value(s2, s2disp);
return v;
}
static Value values(std::string s1, std::string s1disp, std::string s2, std::string s2disp, std::string s3, std::string s3disp) {
Value::VectorType v;
v += value(s1, s1disp), value(s2, s2disp), value(s3, s3disp);
return v;
}
static Value values(std::string s1, std::string s1disp, std::string s2, std::string s2disp, std::string s3, std::string s3disp, std::string s4, std::string s4disp) {
Value::VectorType v;
v += value(s1, s1disp), value(s2, s2disp), value(s3, s3disp), value(s4, s4disp);
return v;
}
Settings *Settings::inst(bool erase)
{
static Settings *instance = new Settings;
if (erase) {
delete instance;
instance = NULL;
}
return instance;
}
Settings::Settings()
{
}
Settings::~Settings()
{
}
void Settings::visit(Visitor& visitor)
{
for (std::list<SettingsEntry *>::iterator it = entries.begin();it != entries.end();it++) {
visitor.handle(*(*it));
}
}
Value Settings::get(const SettingsEntry& entry)
{
return entry._value;
}
void Settings::set(SettingsEntry& entry, const Value val)
{
entry._value = val;
}
Visitor::Visitor()
{
}
Visitor::~Visitor()
{
}
/*
* Supported settings entry types are: bool / int and string selection
*
* String selection is used to handle comboboxes and has two values
* per config selection. The first value is used internally for both
* finding the combobox selection and for storing the value in the
* external settings file. The second value is the display value that
* can be translated.
*/
SettingsEntry Settings::indentationWidth("editor", "indentationWidth", Value(Value::RangeType(1, 16)), Value(4));
SettingsEntry Settings::tabWidth("editor", "tabWidth", Value(Value::RangeType(1, 16)), Value(8));
SettingsEntry Settings::lineWrap("editor", "lineWrap", values("None", _("None"), "Char", _("Wrap at character boundaries"), "Word", _("Wrap at word boundaries")), Value("Word"));
SettingsEntry Settings::lineWrapIndentationStyle("editor", "lineWrapIndentationStyle", values("Fixed", _("Fixed"), "Same", _("Same"), "Indented", _("Indented")), Value("Fixed"));
SettingsEntry Settings::lineWrapIndentation("editor", "lineWrapIndentation", Value(Value::RangeType(0, 999)), Value(4));
SettingsEntry Settings::lineWrapVisualizationBegin("editor", "lineWrapVisualizationBegin", values("None", _("None"), "Text", _("Text"), "Border", _("Border"), "Margin", _("Margin")), Value("None"));
SettingsEntry Settings::lineWrapVisualizationEnd("editor", "lineWrapVisualizationEnd", values("None", _("None"), "Text", _("Text"), "Border", _("Border"), "Margin", _("Margin")), Value("Border"));
SettingsEntry Settings::showWhitespace("editor", "showWhitespaces", values("Never", _("Never"), "Always", _("Always"), "AfterIndentation", _("After indentation")), Value("Never"));
SettingsEntry Settings::showWhitespaceSize("editor", "showWhitespacesSize", Value(Value::RangeType(1, 16)), Value(2));
SettingsEntry Settings::autoIndent("editor", "autoIndent", Value(true), Value(true));
SettingsEntry Settings::indentStyle("editor", "indentStyle", values("Spaces", _("Spaces"), "Tabs", _("Tabs")), Value("Spaces"));
SettingsEntry Settings::tabKeyFunction("editor", "tabKeyFunction", values("Indent", _("Indent"), "InsertTab", _("Insert Tab")), Value("Indent"));
SettingsEntry Settings::highlightCurrentLine("editor", "highlightCurrentLine", Value(true), Value(true));
SettingsEntry Settings::enableBraceMatching("editor", "enableBraceMatching", Value(true), Value(true));
}

75
src/settings.h Normal file
View File

@ -0,0 +1,75 @@
#pragma once
#include <map>
#include <list>
#include <string>
#include "value.h"
namespace Settings {
class SettingsEntry
{
private:
std::string _category;
std::string _name;
Value _value;
Value _range;
Value _default;
public:
const std::string & category() const;
const std::string & name() const;
virtual const Value & defaultValue() const;
virtual const Value & range() const;
virtual bool is_default() const;
protected:
SettingsEntry(const std::string category, const std::string name, const Value range, const Value def);
virtual ~SettingsEntry();
friend class Settings;
};
class Settings
{
public:
static SettingsEntry indentationWidth;
static SettingsEntry tabWidth;
static SettingsEntry lineWrap;
static SettingsEntry lineWrapIndentationStyle;
static SettingsEntry lineWrapIndentation;
static SettingsEntry lineWrapVisualizationBegin;
static SettingsEntry lineWrapVisualizationEnd;
static SettingsEntry showWhitespace;
static SettingsEntry showWhitespaceSize;
static SettingsEntry autoIndent;
static SettingsEntry indentStyle;
static SettingsEntry tabKeyFunction;
static SettingsEntry highlightCurrentLine;
static SettingsEntry enableBraceMatching;
static Settings *inst(bool erase = false);
void visit(class Visitor& visitor);
Value defaultValue(const SettingsEntry& entry);
Value get(const SettingsEntry& entry);
void set(SettingsEntry& entry, const Value val);
private:
Settings();
virtual ~Settings();
};
class Visitor
{
public:
Visitor();
virtual ~Visitor();
virtual void handle(SettingsEntry& entry) const = 0;
};
}

View File

@ -82,6 +82,10 @@ public:
this->end_val == other.end_val;
}
double begin_value() { return begin_val; }
double step_value() { return step_val; }
double end_value() { return end_val; }
iterator begin() { return iterator(*this, RANGE_TYPE_BEGIN); }
iterator end() { return iterator(*this, RANGE_TYPE_END); }