From fd55cff81015288863feceaa9cb579e2cdb2986e Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Sat, 21 Oct 2017 17:50:19 +0200 Subject: 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. --- src/ui/widget/preferences-widget.cpp | 31 +++++++++++++++++++++++++++++++ src/ui/widget/preferences-widget.h | 12 ++++++++++++ 2 files changed, 43 insertions(+) (limited to 'src') 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 #include +#include #ifdef WIN32 #include @@ -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 #include #include +#include +#include #include #include #include @@ -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: -- cgit v1.2.3