mirror of https://github.com/vitalif/openscad
Get color schemes from editor; Enumerate from resource folder for scintilla.
parent
395795949e
commit
23275dc927
|
@ -1,4 +1,6 @@
|
|||
{
|
||||
"name" : "For Dark Background",
|
||||
"index" : 1100,
|
||||
"paper" : "#272822",
|
||||
"text" : "#ffffff",
|
||||
"caret" : {
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
{
|
||||
"name" : "For Light Background",
|
||||
"index" : 1000,
|
||||
"paper" : "#fff",
|
||||
"text" : "#272822",
|
||||
"caret" : {
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
{
|
||||
"name" : "Monokai",
|
||||
"index" : 1200,
|
||||
"paper" : "#272822",
|
||||
"text" : "#f8f8f2",
|
||||
"caret" : {
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
{
|
||||
"name" : "Solarized",
|
||||
"index" : 1300,
|
||||
"paper" : "#fdf6e3",
|
||||
"text" : "#657b83",
|
||||
"caret" : {
|
||||
|
|
|
@ -48,7 +48,10 @@ Q_DECLARE_METATYPE(Feature *);
|
|||
Preferences::Preferences(QWidget *parent) : QMainWindow(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
}
|
||||
|
||||
void Preferences::init() {
|
||||
|
||||
// Editor pane
|
||||
// Setup default font (Try to use a nice monospace font)
|
||||
QString fontfamily;
|
||||
|
@ -135,9 +138,6 @@ Preferences::Preferences(QWidget *parent) : QMainWindow(parent)
|
|||
#endif
|
||||
this->polysetCacheSizeEdit->setValidator(validator);
|
||||
this->opencsgLimitEdit->setValidator(validator);
|
||||
|
||||
setupFeaturesPage();
|
||||
updateGUI();
|
||||
}
|
||||
|
||||
Preferences::~Preferences()
|
||||
|
@ -272,7 +272,7 @@ void Preferences::on_editorType_editTextChanged(const QString &type)
|
|||
settings.setValue("editor/editortype", type);
|
||||
}
|
||||
|
||||
void Preferences::on_syntaxHighlight_currentIndexChanged(const QString &s)
|
||||
void Preferences::on_syntaxHighlight_activated(const QString &s)
|
||||
{
|
||||
QSettings settings;
|
||||
settings.setValue("editor/syntaxhighlight", s);
|
||||
|
@ -446,7 +446,14 @@ void Preferences::updateGUI()
|
|||
|
||||
QString shighlight = getValue("editor/syntaxhighlight").toString();
|
||||
int shidx = this->syntaxHighlight->findText(shighlight);
|
||||
if (shidx >= 0) this->syntaxHighlight->setCurrentIndex(shidx);
|
||||
if (shidx >= 0) {
|
||||
this->syntaxHighlight->setCurrentIndex(shidx);
|
||||
} else {
|
||||
int offidx = this->syntaxHighlight->findText("Off");
|
||||
if (offidx >= 0) {
|
||||
this->syntaxHighlight->setCurrentIndex(offidx);
|
||||
}
|
||||
}
|
||||
|
||||
QString editortypevar = getValue("editor/editortype").toString();
|
||||
int edidx = this->editorType->findText(editortypevar);
|
||||
|
@ -476,4 +483,21 @@ void Preferences::apply() const
|
|||
emit fontChanged(getValue("editor/fontfamily").toString(), getValue("editor/fontsize").toUInt());
|
||||
emit requestRedraw();
|
||||
emit openCSGSettingsChanged();
|
||||
emit syntaxHighlightChanged(getValue("editor/syntaxhighlight").toString());
|
||||
}
|
||||
|
||||
void Preferences::create(QWidget *parent, QStringList colorSchemes)
|
||||
{
|
||||
instance = new Preferences(parent);
|
||||
instance->syntaxHighlight->clear();
|
||||
instance->syntaxHighlight->addItems(colorSchemes);
|
||||
instance->init();
|
||||
instance->setupFeaturesPage();
|
||||
instance->updateGUI();
|
||||
}
|
||||
|
||||
Preferences *Preferences::inst() {
|
||||
assert(instance != NULL);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
|
|
@ -11,9 +11,12 @@ class Preferences : public QMainWindow, public Ui::Preferences
|
|||
|
||||
public:
|
||||
~Preferences();
|
||||
static Preferences *inst() { if (!instance) instance = new Preferences(); return instance; }
|
||||
|
||||
static void create(QWidget *parent, QStringList colorSchemes);
|
||||
static Preferences *inst();
|
||||
|
||||
QVariant getValue(const QString &key) const;
|
||||
void init();
|
||||
void apply() const;
|
||||
|
||||
public slots:
|
||||
|
@ -22,7 +25,7 @@ public slots:
|
|||
void on_colorSchemeChooser_itemSelectionChanged();
|
||||
void on_fontChooser_activated(const QString &);
|
||||
void on_fontSize_editTextChanged(const QString &);
|
||||
void on_syntaxHighlight_currentIndexChanged(const QString &);
|
||||
void on_syntaxHighlight_activated(const QString &);
|
||||
void on_openCSGWarningBox_toggled(bool);
|
||||
void on_enableOpenCSGBox_toggled(bool);
|
||||
void on_cgalCacheSizeEdit_textChanged(const QString &);
|
||||
|
@ -45,7 +48,7 @@ signals:
|
|||
void fontChanged(const QString &family, uint size) const;
|
||||
void colorSchemeChanged(const QString &scheme) const;
|
||||
void openCSGSettingsChanged() const;
|
||||
void syntaxHighlightChanged(const QString &s);
|
||||
void syntaxHighlightChanged(const QString &s) const;
|
||||
void editorTypeChanged(const QString &type);
|
||||
|
||||
private:
|
||||
|
|
|
@ -264,31 +264,6 @@
|
|||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>For Light Background</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>For Dark Background</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Monokai</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Solarized</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Off</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
|
|
|
@ -21,6 +21,7 @@ public:
|
|||
virtual QString selectedText() = 0;
|
||||
virtual bool find(const QString &, bool findNext = false, bool findBackwards = false) = 0;
|
||||
virtual void replaceSelectedText(const QString &) = 0;
|
||||
virtual QStringList colorSchemes() = 0;
|
||||
|
||||
signals:
|
||||
void contentsChanged();
|
||||
|
|
|
@ -235,9 +235,6 @@ Highlighter::Highlighter(QTextDocument *parent)
|
|||
tokentypes["_$quote"] << "_$quote";
|
||||
tokentypes["_$number"] << "_$number";
|
||||
|
||||
QString syntaxhighlight = Preferences::inst()->getValue("editor/syntaxhighlight").toString();
|
||||
this->assignFormatsToTokens(syntaxhighlight);
|
||||
|
||||
errorFormat.setBackground(Qt::red);
|
||||
errorState = false;
|
||||
errorPos = -1;
|
||||
|
|
|
@ -271,3 +271,15 @@ bool LegacyEditor::isContentModified()
|
|||
{
|
||||
return textedit->document()->isModified();
|
||||
}
|
||||
|
||||
QStringList LegacyEditor::colorSchemes()
|
||||
{
|
||||
QStringList colorSchemes;
|
||||
|
||||
colorSchemes
|
||||
<< "For Light Background"
|
||||
<< "For Dark Background"
|
||||
<< "Off";
|
||||
|
||||
return colorSchemes;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ public:
|
|||
bool find(const QString &, bool findNext = false, bool findBackwards = false);
|
||||
void replaceSelectedText(const QString &newText);
|
||||
bool findString(const QString & exp, bool findBackwards) const;
|
||||
QStringList colorSchemes();
|
||||
|
||||
public slots:
|
||||
void zoomIn();
|
||||
|
|
|
@ -183,8 +183,9 @@ MainWindow::MainWindow(const QString &filename)
|
|||
this->consoleDock->setConfigKey("view/hideConsole");
|
||||
this->consoleDock->setAction(this->viewActionHideConsole);
|
||||
|
||||
editortype = Preferences::inst()->getValue("editor/editortype").toString();
|
||||
useScintilla = (editortype == "QScintilla Editor");
|
||||
QSettings settings;
|
||||
editortype = settings.value("editor/editortype").toString();
|
||||
useScintilla = (editortype != "Simple Editor");
|
||||
|
||||
#ifdef USE_SCINTILLA_EDITOR
|
||||
if (useScintilla) {
|
||||
|
@ -194,6 +195,8 @@ MainWindow::MainWindow(const QString &filename)
|
|||
#endif
|
||||
editor = new LegacyEditor(editorDockContents);
|
||||
|
||||
Preferences::create(this, editor->colorSchemes());
|
||||
|
||||
editorDockContents->layout()->addWidget(editor);
|
||||
|
||||
setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
|
||||
|
@ -515,7 +518,6 @@ MainWindow::MainWindow(const QString &filename)
|
|||
}
|
||||
|
||||
// make sure it looks nice..
|
||||
QSettings settings;
|
||||
QByteArray windowState = settings.value("window/state", QByteArray()).toByteArray();
|
||||
restoreState(windowState);
|
||||
resize(settings.value("window/size", QSize(800, 600)).toSize());
|
||||
|
|
|
@ -187,6 +187,50 @@ void ScintillaEditor::noColor()
|
|||
qsci->setEdgeColor(Qt::black);
|
||||
}
|
||||
|
||||
QStringList ScintillaEditor::colorSchemes()
|
||||
{
|
||||
typedef std::multimap<int, QString> result_set_t;
|
||||
result_set_t result_set;
|
||||
|
||||
const fs::path resources = PlatformUtils::resourcesPath();
|
||||
const fs::path color_schemes = resources / "color-schemes" / "editor";
|
||||
|
||||
QStringList colorSchemes;
|
||||
fs::directory_iterator end_iter;
|
||||
|
||||
if (fs::exists(color_schemes) && fs::is_directory(color_schemes)) {
|
||||
for (fs::directory_iterator dir_iter(color_schemes); dir_iter != end_iter; ++dir_iter) {
|
||||
if (!fs::is_regular_file(dir_iter->status())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const fs::path path = (*dir_iter).path();
|
||||
const fs::path ext = path.extension();
|
||||
if (!(path.extension().string() == ".json")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
boost::property_tree::ptree pt;
|
||||
try {
|
||||
boost::property_tree::read_json(boosty::stringy(path).c_str(), pt);
|
||||
QString name = QString(pt.get<std::string>("name").c_str());
|
||||
int index = pt.get<int>("index");
|
||||
result_set.insert(result_set_t::value_type(index, name));
|
||||
} catch (const std::exception & e) {
|
||||
PRINTB("Error reading color scheme file '%s': %s", path.c_str() % e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (result_set_t::iterator it = result_set.begin();it != result_set.end();it++) {
|
||||
colorSchemes << (*it).second;
|
||||
}
|
||||
|
||||
colorSchemes << "Off";
|
||||
|
||||
return colorSchemes;
|
||||
}
|
||||
|
||||
void ScintillaEditor::setHighlightScheme(const QString &name)
|
||||
{
|
||||
fs::path resources = PlatformUtils::resourcesPath();
|
||||
|
|
|
@ -26,6 +26,7 @@ public:
|
|||
QString selectedText();
|
||||
bool find(const QString &, bool findNext = false, bool findBackwards = false);
|
||||
void replaceSelectedText(const QString&);
|
||||
QStringList colorSchemes();
|
||||
|
||||
private:
|
||||
void get_range(int *lineFrom, int *lineTo);
|
||||
|
|
Loading…
Reference in New Issue