summaryrefslogtreecommitdiffstats
path: root/src/ui/widget
diff options
context:
space:
mode:
authorEduard Braun <eduard.braun2@gmx.de>2017-10-21 15:50:19 +0000
committerEduard Braun <eduard.braun2@gmx.de>2017-10-21 15:50:19 +0000
commitfd55cff81015288863feceaa9cb579e2cdb2986e (patch)
tree5274ccdb53d487e1d64312257e7d984026b321bb /src/ui/widget
parentAdd preference to load additional fonts from 'fonts' directories (diff)
downloadinkscape-fd55cff81015288863feceaa9cb579e2cdb2986e.tar.gz
inkscape-fd55cff81015288863feceaa9cb579e2cdb2986e.zip
Add preferences widget 'PrefMultiEntry'
This is a multiline text input, similar to 'PrefEntry' Newlines characters in the multiline input will be converted to '|' in the saved preference. This is because the XML parser will convert real newline characters to spaces when reading the preferences file the next time.
Diffstat (limited to 'src/ui/widget')
-rw-r--r--src/ui/widget/preferences-widget.cpp31
-rw-r--r--src/ui/widget/preferences-widget.h12
2 files changed, 43 insertions, 0 deletions
diff --git a/src/ui/widget/preferences-widget.cpp b/src/ui/widget/preferences-widget.cpp
index 2981316c0..e93b83db4 100644
--- a/src/ui/widget/preferences-widget.cpp
+++ b/src/ui/widget/preferences-widget.cpp
@@ -34,6 +34,7 @@
#include <glibmm/i18n.h>
#include <glibmm/convert.h>
+#include <glibmm/regex.h>
#ifdef WIN32
#include <windows.h>
@@ -859,6 +860,36 @@ void PrefEntry::on_changed()
}
}
+void PrefMultiEntry::init(Glib::ustring const &prefs_path, int height)
+{
+ // TODO: Figure out if there's a way to specify height in lines instead of px
+ // and how to obtain a reasonable default width if 'expand_widget' is not used
+ set_size_request(100, height);
+ set_hexpand(true);
+ set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
+ set_shadow_type(Gtk::SHADOW_IN);
+
+ add(_text);
+
+ _prefs_path = prefs_path;
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ Glib::ustring value = prefs->getString(_prefs_path);
+ value = Glib::Regex::create("\\|")->replace_literal(value, 0, "\n", (Glib::RegexMatchFlags)0);
+ _text.get_buffer()->set_text(value);
+ _text.get_buffer()->signal_changed().connect(sigc::mem_fun(*this, &PrefMultiEntry::on_changed));
+}
+
+void PrefMultiEntry::on_changed()
+{
+ if (get_visible()) //only take action if user changed value
+ {
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ Glib::ustring value = _text.get_buffer()->get_text();
+ value = Glib::Regex::create("\\n")->replace_literal(value, 0, "|", (Glib::RegexMatchFlags)0);
+ prefs->setString(_prefs_path, value);
+ }
+}
+
void PrefColorPicker::init(Glib::ustring const &label, Glib::ustring const &prefs_path,
guint32 default_rgba)
{
diff --git a/src/ui/widget/preferences-widget.h b/src/ui/widget/preferences-widget.h
index 142793509..2578be533 100644
--- a/src/ui/widget/preferences-widget.h
+++ b/src/ui/widget/preferences-widget.h
@@ -28,6 +28,8 @@
#include <sigc++/sigc++.h>
#include <gtkmm/checkbutton.h>
#include <gtkmm/radiobutton.h>
+#include <gtkmm/scrolledwindow.h>
+#include <gtkmm/textview.h>
#include <gtkmm/comboboxtext.h>
#include <gtkmm/drawingarea.h>
#include <gtkmm/grid.h>
@@ -195,6 +197,16 @@ protected:
void on_changed();
};
+class PrefMultiEntry : public Gtk::ScrolledWindow
+{
+public:
+ void init(Glib::ustring const &prefs_path, int height);
+protected:
+ Glib::ustring _prefs_path;
+ Gtk::TextView _text;
+ void on_changed();
+};
+
class PrefEntryButtonHBox : public Gtk::HBox
{
public: