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
This commit is contained in:
parent
28c721bbfe
commit
b504c8cc90
@ -58,13 +58,17 @@ class Prompter : public Gtk::Dialog
|
||||
Gtk::Entry& the_entry() { return entry; }
|
||||
|
||||
void on_entry_changed ();
|
||||
void on_show ();
|
||||
|
||||
private:
|
||||
Gtk::Entry entry;
|
||||
Gtk::HBox entryBox;
|
||||
Gtk::Label entryLabel;
|
||||
bool first_show;
|
||||
bool can_accept_from_entry;
|
||||
|
||||
void init ();
|
||||
void entry_activated ();
|
||||
};
|
||||
|
||||
} /* namespace */
|
||||
|
@ -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,8 +74,22 @@ Prompter::init ()
|
||||
|
||||
get_vbox()->pack_start (entryBox);
|
||||
show_all_children();
|
||||
}
|
||||
|
||||
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 (bind (mem_fun (*this, &Prompter::response), Gtk::RESPONSE_ACCEPT));
|
||||
entry.signal_activate().connect (mem_fun (*this, &Prompter::entry_activated));
|
||||
first_show = false;
|
||||
}
|
||||
|
||||
Dialog::on_show ();
|
||||
}
|
||||
|
||||
void
|
||||
@ -90,6 +108,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,9 +128,10 @@ Prompter::on_entry_changed ()
|
||||
button, nothing will happen at all.
|
||||
*/
|
||||
|
||||
if (entry.get_text() != "") {
|
||||
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user