13
0

option editor: allow EntryOption to have a list of valid chars (not just invalid)

This commit is contained in:
Paul Davis 2022-04-16 18:02:11 -06:00
parent bae15f216b
commit 52f713b591
2 changed files with 14 additions and 0 deletions

View File

@ -347,9 +347,21 @@ void
EntryOption::filter_text (const Glib::ustring&, int*) EntryOption::filter_text (const Glib::ustring&, int*)
{ {
std::string text = _entry->get_text (); 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) { for (size_t i = 0; i < _invalid.length(); ++i) {
text.erase (std::remove(text.begin(), text.end(), _invalid.at(i)), text.end()); text.erase (std::remove(text.begin(), text.end(), _invalid.at(i)), text.end());
} }
if (text != _entry->get_text ()) { if (text != _entry->get_text ()) {
_entry->set_text (text); _entry->set_text (text);
} }

View File

@ -278,6 +278,7 @@ public:
void add_to_page (OptionEditorPage*); void add_to_page (OptionEditorPage*);
void set_sensitive (bool); void set_sensitive (bool);
void set_invalid_chars (std::string i) { _invalid = i; } void set_invalid_chars (std::string i) { _invalid = i; }
void set_valid_chars (std::string i) { _valid = i; }
Gtk::Widget& tip_widget() { return *_entry; } Gtk::Widget& tip_widget() { return *_entry; }
@ -291,6 +292,7 @@ private:
Gtk::Label* _label; ///< UI label Gtk::Label* _label; ///< UI label
Gtk::Entry* _entry; ///< UI entry Gtk::Entry* _entry; ///< UI entry
std::string _invalid; std::string _invalid;
std::string _valid;
}; };