diff options
| author | Eduard Braun <eduard.braun2@gmx.de> | 2017-10-21 15:50:19 +0000 |
|---|---|---|
| committer | Eduard Braun <eduard.braun2@gmx.de> | 2017-10-21 15:50:19 +0000 |
| commit | fd55cff81015288863feceaa9cb579e2cdb2986e (patch) | |
| tree | 5274ccdb53d487e1d64312257e7d984026b321bb /src/ui/widget/preferences-widget.cpp | |
| parent | Add preference to load additional fonts from 'fonts' directories (diff) | |
| download | inkscape-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/preferences-widget.cpp')
| -rw-r--r-- | src/ui/widget/preferences-widget.cpp | 31 |
1 files changed, 31 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) { |
