accept text-entry-change w/o enter and add filter_text option
authorRobin Gareus <robin@gareus.org>
Wed, 25 Jun 2014 22:46:59 +0000 (00:46 +0200)
committerRobin Gareus <robin@gareus.org>
Thu, 26 Jun 2014 17:13:15 +0000 (19:13 +0200)
gtk2_ardour/option_editor.cc
gtk2_ardour/option_editor.h

index f163ec8f3d780aa832e97a3a938c492b9807563b..39817e464f9ce77382a52b9cc73ce269f845988b 100644 (file)
@@ -16,6 +16,7 @@
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
 */
+#include <algorithm>
 
 #include <gtkmm/box.h>
 #include <gtkmm/alignment.h>
@@ -146,6 +147,8 @@ EntryOption::EntryOption (string const & i, string const & n, sigc::slot<string>
        _label = manage (left_aligned_label (n + ":"));
        _entry = manage (new Entry);
        _entry->signal_activate().connect (sigc::mem_fun (*this, &EntryOption::activated));
+       _entry->signal_focus_out_event().connect (sigc::mem_fun (*this, &EntryOption::focus_out));
+       _entry->signal_insert_text().connect (sigc::mem_fun (*this, &EntryOption::filter_text));
 }
 
 void
@@ -160,12 +163,37 @@ EntryOption::set_state_from_config ()
        _entry->set_text (_get ());
 }
 
+void
+EntryOption::set_sensitive (bool s)
+{
+       _entry->set_sensitive (s);
+}
+
+void
+EntryOption::filter_text (const Glib::ustring&, int*)
+{
+       std::string text = _entry->get_text ();
+       for (size_t i = 0; i < _invalid.length(); ++i) {
+               text.erase (std::remove(text.begin(), text.end(), _invalid.at(i)), text.end());
+       }
+       if (text != _entry->get_text ()) {
+               _entry->set_text (text);
+       }
+}
+
 void
 EntryOption::activated ()
 {
        _set (_entry->get_text ());
 }
 
+bool
+EntryOption::focus_out (GdkEventFocus*)
+{
+       _set (_entry->get_text ());
+       return true;
+}
+
 /** Construct a BoolComboOption.
  *  @param i id
  *  @param n User-visible name.
index d98bcb467a31e28d394f2d3622988a3a46b29bcf..c4ab78e19b161711e210da60f180bed58072557b 100644 (file)
@@ -189,17 +189,22 @@ public:
        EntryOption (std::string const &, std::string const &, sigc::slot<std::string>, sigc::slot<bool, std::string>);
        void set_state_from_config ();
        void add_to_page (OptionEditorPage*);
+       void set_sensitive (bool);
+       void set_invalid_chars (std::string i) { _invalid = i; }
 
-        Gtk::Widget& tip_widget() { return *_entry; }
+       Gtk::Widget& tip_widget() { return *_entry; }
 
 private:
 
        void activated ();
+       bool focus_out (GdkEventFocus*);
+       void filter_text (const Glib::ustring&, int*);
 
        sigc::slot<std::string> _get; ///< slot to get the configuration variable's value
        sigc::slot<bool, std::string> _set;  ///< slot to set the configuration variable's value
        Gtk::Label* _label; ///< UI label
        Gtk::Entry* _entry; ///< UI entry
+       std::string _invalid;
 };