Allow empty text in prompter

This commit is contained in:
Robin Gareus
2022-11-15 03:24:19 +01:00
parent d1b462c213
commit 82d43fa1ee
2 changed files with 16 additions and 2 deletions

View File

@@ -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;

View File

@@ -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 ();