diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2011-12-01 19:32:56 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2011-12-01 19:32:56 +0000 |
commit | b504c8cc906775f7edb26859d33f9393f7bec5cc (patch) | |
tree | 14c10b5fde3fa8b514d40a5e710be80279986c5f /libs/gtkmm2ext/prompter.cc | |
parent | 28c721bbfee4de92fed4f8ec10403f9f51022fad (diff) |
fix a number of fundamental issues with Gtkmm2ext::Prompter, mostly centered on bad behaviour when Enter/Return is pressed
git-svn-id: svn://localhost/ardour2/branches/3.0@10848 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/gtkmm2ext/prompter.cc')
-rw-r--r-- | libs/gtkmm2ext/prompter.cc | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/libs/gtkmm2ext/prompter.cc b/libs/gtkmm2ext/prompter.cc index 5eab2614c8..2f7b43e0d5 100644 --- a/libs/gtkmm2ext/prompter.cc +++ b/libs/gtkmm2ext/prompter.cc @@ -32,12 +32,16 @@ using namespace Gtkmm2ext; Prompter::Prompter (Gtk::Window& parent, bool modal) : Gtk::Dialog ("", parent, modal) + , first_show (true) + , can_accept_from_entry (false) { init (); } Prompter::Prompter (bool modal) : Gtk::Dialog ("", modal) + , first_show (true) + , can_accept_from_entry (false) { init (); } @@ -70,11 +74,25 @@ Prompter::init () get_vbox()->pack_start (entryBox); show_all_children(); - entry.signal_changed().connect (mem_fun (*this, &Prompter::on_entry_changed)); - entry.signal_activate().connect (bind (mem_fun (*this, &Prompter::response), Gtk::RESPONSE_ACCEPT)); } void +Prompter::on_show () +{ + /* don't connect to signals till shown, so that we don't change the + response sensitivity etc. when the setup of the dialog sets the text. + */ + + if (first_show) { + entry.signal_changed().connect (mem_fun (*this, &Prompter::on_entry_changed)); + entry.signal_activate().connect (mem_fun (*this, &Prompter::entry_activated)); + first_show = false; + } + + Dialog::on_show (); +} + +void Prompter::change_labels (string /*okstr*/, string /*cancelstr*/) { // dynamic_cast<Gtk::Label*>(ok.get_child())->set_text (okstr); @@ -91,6 +109,16 @@ Prompter::get_result (string &str, bool strip) } void +Prompter::entry_activated () +{ + if (can_accept_from_entry) { + response (Gtk::RESPONSE_ACCEPT); + } else { + response (Gtk::RESPONSE_CANCEL); + } +} + +void Prompter::on_entry_changed () { /* @@ -100,10 +128,11 @@ Prompter::on_entry_changed () button, nothing will happen at all. */ - if (entry.get_text() != "") { - set_response_sensitive (Gtk::RESPONSE_ACCEPT, true); - set_default_response (Gtk::RESPONSE_ACCEPT); + if (!entry.get_text().empty()) { + set_response_sensitive (Gtk::RESPONSE_ACCEPT, true); + set_default_response (Gtk::RESPONSE_ACCEPT); + can_accept_from_entry = true; } else { - set_response_sensitive (Gtk::RESPONSE_ACCEPT, false); + set_response_sensitive (Gtk::RESPONSE_ACCEPT, false); } } |