From 82d43fa1ee6818d556c52f956f962b660b6032af Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 15 Nov 2022 03:24:19 +0100 Subject: [PATCH] Allow empty text in prompter --- libs/widgets/prompter.cc | 16 ++++++++++++++-- libs/widgets/widgets/prompter.h | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/libs/widgets/prompter.cc b/libs/widgets/prompter.cc index 9f2df26b5e..a178cfc511 100644 --- a/libs/widgets/prompter.cc +++ b/libs/widgets/prompter.cc @@ -77,6 +77,18 @@ Prompter::init (bool with_cancel) show_all_children(); } +void +Prompter::set_allow_empty (bool yn) +{ + if (yn == allow_empty) { + return; + } + allow_empty = yn; + if (allow_empty) { + can_accept_from_entry = true; + } +} + void Prompter::on_show () { @@ -87,7 +99,7 @@ Prompter::on_show () if (first_show) { entry.signal_changed().connect (mem_fun (*this, &Prompter::on_entry_changed)); entry.signal_activate().connect (mem_fun (*this, &Prompter::entry_activated)); - can_accept_from_entry = !entry.get_text().empty(); + can_accept_from_entry = !entry.get_text().empty() || allow_empty; first_show = false; } @@ -130,7 +142,7 @@ Prompter::on_entry_changed () button, nothing will happen at all. */ - if (!entry.get_text().empty()) { + if (!entry.get_text().empty() || allow_empty) { set_response_sensitive (Gtk::RESPONSE_ACCEPT, true); set_default_response (Gtk::RESPONSE_ACCEPT); can_accept_from_entry = true; diff --git a/libs/widgets/widgets/prompter.h b/libs/widgets/widgets/prompter.h index 8ed7aa36f5..7237007bac 100644 --- a/libs/widgets/widgets/prompter.h +++ b/libs/widgets/widgets/prompter.h @@ -57,6 +57,7 @@ public: void change_labels (std::string ok, std::string cancel); void get_result (std::string &str, bool strip=true); + void set_allow_empty (bool yn = true); protected: Gtk::Entry& the_entry() { return entry; } @@ -70,6 +71,7 @@ private: Gtk::Label entryLabel; bool first_show; bool can_accept_from_entry; + bool allow_empty; void init (bool with_cancel); void entry_activated ();