Make route group dialog resizable; make ArdourPrompter entries
[ardour.git] / libs / gtkmm2ext / prompter.cc
index d06204d35617f1e27a291678db29ffa3348efed1..4c3ff43a73a00fff070a39b59c081c4d217118b1 100644 (file)
@@ -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 ();
 }
@@ -65,17 +69,32 @@ Prompter::init ()
        entryBox.set_homogeneous (false);
        entryBox.set_spacing (5);
        entryBox.set_border_width (10);
-       entryBox.pack_start (entryLabel);
-       entryBox.pack_start (entry, false, false);
+       entryBox.pack_start (entryLabel, false, false);
+       entryBox.pack_start (entry, true, true);
 
        get_vbox()->pack_start (entryBox);
        show_all_children();
-       entry.signal_key_release_event().connect (mem_fun (*this, &Prompter::maybe_allow_response));
-       entry.signal_activate().connect (bind (mem_fun (*this, &Prompter::response), Gtk::RESPONSE_ACCEPT));
 }      
 
 void
-Prompter::change_labels (string okstr, string cancelstr)
+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));
+               can_accept_from_entry = !entry.get_text().empty();
+               first_show = false;
+       }
+
+       Dialog::on_show ();
+}
+
+void
+Prompter::change_labels (string /*okstr*/, string /*cancelstr*/)
 {
        // dynamic_cast<Gtk::Label*>(ok.get_child())->set_text (okstr);
        // dynamic_cast<Gtk::Label*>(cancel.get_child())->set_text (cancelstr);
@@ -90,22 +109,31 @@ Prompter::get_result (string &str, bool strip)
        }
 }
 
-bool
-Prompter::maybe_allow_response (GdkEventKey* ev)
+void
+Prompter::entry_activated ()
+{
+       if (can_accept_from_entry) {
+               response (Gtk::RESPONSE_ACCEPT);
+       } else {
+               response (Gtk::RESPONSE_CANCEL);
+       }
+}              
+
+void
+Prompter::on_entry_changed ()
 {
-        /* 
+       /* 
           This is set up so that entering text in the entry 
           field makes the RESPONSE_ACCEPT button active. 
           Of course if you haven't added a RESPONSE_ACCEPT 
           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);
        }
-       return true;
 }
-