summaryrefslogtreecommitdiff
path: root/gtk2_ardour
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2014-06-26 00:46:59 +0200
committerRobin Gareus <robin@gareus.org>2014-06-26 19:13:15 +0200
commit7658183a84791166747c698aca9c88ad2cfe5986 (patch)
tree2f47a0d28757058d95d5d06d8f9e5fe0fe9602a5 /gtk2_ardour
parentb90d7a01fad8ab1289106d2a862fde3b6b4fab8b (diff)
accept text-entry-change w/o enter and add filter_text option
Diffstat (limited to 'gtk2_ardour')
-rw-r--r--gtk2_ardour/option_editor.cc28
-rw-r--r--gtk2_ardour/option_editor.h7
2 files changed, 34 insertions, 1 deletions
diff --git a/gtk2_ardour/option_editor.cc b/gtk2_ardour/option_editor.cc
index f163ec8f3d..39817e464f 100644
--- a/gtk2_ardour/option_editor.cc
+++ b/gtk2_ardour/option_editor.cc
@@ -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
@@ -161,11 +164,36 @@ EntryOption::set_state_from_config ()
}
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.
diff --git a/gtk2_ardour/option_editor.h b/gtk2_ardour/option_editor.h
index d98bcb467a..c4ab78e19b 100644
--- a/gtk2_ardour/option_editor.h
+++ b/gtk2_ardour/option_editor.h
@@ -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;
};