2 * Copyright (C) 1999 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include <gtkmm/stock.h>
23 #include "pbd/whitespace.h"
24 #include "widgets/prompter.h"
29 using namespace ArdourWidgets;
31 Prompter::Prompter (Gtk::Window& parent, bool modal)
32 : Gtk::Dialog ("", parent, modal)
34 , can_accept_from_entry (false)
39 Prompter::Prompter (bool modal)
40 : Gtk::Dialog ("", modal)
42 , can_accept_from_entry (false)
50 set_type_hint (Gdk::WINDOW_TYPE_HINT_DIALOG);
51 set_position (Gtk::WIN_POS_MOUSE);
52 set_name ("Prompter");
54 add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
57 Alas a generic 'affirmative' button seems a bit useless sometimes.
58 You will have to add your own.
60 set_response_sensitive (Gtk::RESPONSE_ACCEPT, false)
61 to prevent the RESPONSE_ACCEPT button from permitting blank strings.
64 entryLabel.set_line_wrap (true);
65 entryLabel.set_name ("PrompterLabel");
67 entryBox.set_homogeneous (false);
68 entryBox.set_spacing (5);
69 entryBox.set_border_width (10);
70 entryBox.pack_start (entryLabel, false, false);
71 entryBox.pack_start (entry, true, true);
73 get_vbox()->pack_start (entryBox);
80 /* don't connect to signals till shown, so that we don't change the
81 response sensitivity etc. when the setup of the dialog sets the text.
85 entry.signal_changed().connect (mem_fun (*this, &Prompter::on_entry_changed));
86 entry.signal_activate().connect (mem_fun (*this, &Prompter::entry_activated));
87 can_accept_from_entry = !entry.get_text().empty();
95 Prompter::change_labels (string /*okstr*/, string /*cancelstr*/)
97 // dynamic_cast<Gtk::Label*>(ok.get_child())->set_text (okstr);
98 // dynamic_cast<Gtk::Label*>(cancel.get_child())->set_text (cancelstr);
102 Prompter::get_result (string &str, bool strip)
104 str = entry.get_text ();
106 PBD::strip_whitespace_edges (str);
111 Prompter::entry_activated ()
113 if (can_accept_from_entry) {
114 response (Gtk::RESPONSE_ACCEPT);
116 response (Gtk::RESPONSE_CANCEL);
121 Prompter::on_entry_changed ()
124 This is set up so that entering text in the entry
125 field makes the RESPONSE_ACCEPT button active.
126 Of course if you haven't added a RESPONSE_ACCEPT
127 button, nothing will happen at all.
130 if (!entry.get_text().empty()) {
131 set_response_sensitive (Gtk::RESPONSE_ACCEPT, true);
132 set_default_response (Gtk::RESPONSE_ACCEPT);
133 can_accept_from_entry = true;
135 set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);