From 52f713b59132f7d4223b6349cd4a7f51a713c62a Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Sat, 16 Apr 2022 18:02:11 -0600 Subject: [PATCH] option editor: allow EntryOption to have a list of valid chars (not just invalid) --- gtk2_ardour/option_editor.cc | 12 ++++++++++++ gtk2_ardour/option_editor.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/gtk2_ardour/option_editor.cc b/gtk2_ardour/option_editor.cc index d8887d6614..b66ad8c4a5 100644 --- a/gtk2_ardour/option_editor.cc +++ b/gtk2_ardour/option_editor.cc @@ -347,9 +347,21 @@ void EntryOption::filter_text (const Glib::ustring&, int*) { std::string text = _entry->get_text (); + + if (!_valid.empty()) { + for (std::string::const_iterator t = text.begin(); t != text.end(); ) { + if (_valid.find_first_of (*t) == std::string::npos) { + t = text.erase (t); + } else { + ++t; + } + } + } + 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); } diff --git a/gtk2_ardour/option_editor.h b/gtk2_ardour/option_editor.h index eb18255440..f4dfa9d86f 100644 --- a/gtk2_ardour/option_editor.h +++ b/gtk2_ardour/option_editor.h @@ -278,6 +278,7 @@ public: void add_to_page (OptionEditorPage*); void set_sensitive (bool); void set_invalid_chars (std::string i) { _invalid = i; } + void set_valid_chars (std::string i) { _valid = i; } Gtk::Widget& tip_widget() { return *_entry; } @@ -291,6 +292,7 @@ private: Gtk::Label* _label; ///< UI label Gtk::Entry* _entry; ///< UI entry std::string _invalid; + std::string _valid; };