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; }
|
Gtk::Entry& the_entry() { return entry; }
|
||||||
|
|
||||||
void on_entry_changed ();
|
void on_entry_changed ();
|
||||||
|
void on_show ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Gtk::Entry entry;
|
Gtk::Entry entry;
|
||||||
Gtk::HBox entryBox;
|
Gtk::HBox entryBox;
|
||||||
Gtk::Label entryLabel;
|
Gtk::Label entryLabel;
|
||||||
|
bool first_show;
|
||||||
|
bool can_accept_from_entry;
|
||||||
|
|
||||||
void init ();
|
void init ();
|
||||||
|
void entry_activated ();
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace */
|
} /* namespace */
|
||||||
|
|
|
@ -32,12 +32,16 @@ using namespace Gtkmm2ext;
|
||||||
|
|
||||||
Prompter::Prompter (Gtk::Window& parent, bool modal)
|
Prompter::Prompter (Gtk::Window& parent, bool modal)
|
||||||
: Gtk::Dialog ("", parent, modal)
|
: Gtk::Dialog ("", parent, modal)
|
||||||
|
, first_show (true)
|
||||||
|
, can_accept_from_entry (false)
|
||||||
{
|
{
|
||||||
init ();
|
init ();
|
||||||
}
|
}
|
||||||
|
|
||||||
Prompter::Prompter (bool modal)
|
Prompter::Prompter (bool modal)
|
||||||
: Gtk::Dialog ("", modal)
|
: Gtk::Dialog ("", modal)
|
||||||
|
, first_show (true)
|
||||||
|
, can_accept_from_entry (false)
|
||||||
{
|
{
|
||||||
init ();
|
init ();
|
||||||
}
|
}
|
||||||
|
@ -70,10 +74,24 @@ Prompter::init ()
|
||||||
|
|
||||||
get_vbox()->pack_start (entryBox);
|
get_vbox()->pack_start (entryBox);
|
||||||
show_all_children();
|
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
|
void
|
||||||
Prompter::change_labels (string /*okstr*/, string /*cancelstr*/)
|
Prompter::change_labels (string /*okstr*/, string /*cancelstr*/)
|
||||||
{
|
{
|
||||||
|
@ -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
|
void
|
||||||
Prompter::on_entry_changed ()
|
Prompter::on_entry_changed ()
|
||||||
{
|
{
|
||||||
|
@ -100,10 +128,11 @@ Prompter::on_entry_changed ()
|
||||||
button, nothing will happen at all.
|
button, nothing will happen at all.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (entry.get_text() != "") {
|
if (!entry.get_text().empty()) {
|
||||||
set_response_sensitive (Gtk::RESPONSE_ACCEPT, true);
|
set_response_sensitive (Gtk::RESPONSE_ACCEPT, true);
|
||||||
set_default_response (Gtk::RESPONSE_ACCEPT);
|
set_default_response (Gtk::RESPONSE_ACCEPT);
|
||||||
|
can_accept_from_entry = true;
|
||||||
} else {
|
} else {
|
||||||
set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
|
set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user