2005-05-13 16:47:18 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 1999 Paul Barton-Davis
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2006-01-13 14:48:55 -05:00
|
|
|
#include <pbd/whitespace.h>
|
|
|
|
|
2005-09-26 14:24:59 -04:00
|
|
|
#include <gtkmm/stock.h>
|
2005-05-13 16:47:18 -04:00
|
|
|
#include <gtkmm2ext/prompter.h>
|
|
|
|
|
|
|
|
#include "i18n.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace Gtkmm2ext;
|
|
|
|
|
2005-09-26 14:24:59 -04:00
|
|
|
Prompter::Prompter (Gtk::Window& parent, bool modal)
|
|
|
|
: Gtk::Dialog ("", parent, modal)
|
|
|
|
{
|
|
|
|
init ();
|
|
|
|
}
|
|
|
|
|
2005-05-13 16:47:18 -04:00
|
|
|
Prompter::Prompter (bool modal)
|
2005-09-26 14:24:59 -04:00
|
|
|
: Gtk::Dialog ("", modal)
|
|
|
|
{
|
|
|
|
init ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Prompter::init ()
|
2005-05-13 16:47:18 -04:00
|
|
|
{
|
2006-01-13 17:46:04 -05:00
|
|
|
set_type_hint (Gdk::WINDOW_TYPE_HINT_DIALOG);
|
2005-05-13 16:47:18 -04:00
|
|
|
set_position (Gtk::WIN_POS_MOUSE);
|
|
|
|
set_name ("Prompter");
|
2005-12-05 08:01:44 -05:00
|
|
|
|
2005-09-26 14:24:59 -04:00
|
|
|
add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
2006-04-19 16:42:17 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
Alas a generic 'affirmative' button seems a bit useless sometimes.
|
|
|
|
You will have to add your own.
|
2006-04-22 11:28:59 -04:00
|
|
|
After adding, use :
|
|
|
|
set_response_sensitive (Gtk::RESPONSE_ACCEPT, false)
|
|
|
|
to prevent the RESPONSE_ACCEPT button from permitting blank strings.
|
2006-04-19 16:42:17 -04:00
|
|
|
*/
|
2005-12-05 08:01:44 -05:00
|
|
|
|
2005-05-13 16:47:18 -04:00
|
|
|
entryLabel.set_line_wrap (true);
|
|
|
|
entryLabel.set_name ("PrompterLabel");
|
|
|
|
|
|
|
|
entryBox.set_homogeneous (false);
|
2005-12-05 07:43:54 -05:00
|
|
|
entryBox.set_spacing (5);
|
2005-05-13 16:47:18 -04:00
|
|
|
entryBox.set_border_width (10);
|
|
|
|
entryBox.pack_start (entryLabel);
|
|
|
|
entryBox.pack_start (entry, false, false);
|
|
|
|
|
2005-09-26 14:24:59 -04:00
|
|
|
get_vbox()->pack_start (entryBox);
|
2005-12-05 07:43:54 -05:00
|
|
|
show_all_children();
|
2006-04-22 11:28:59 -04:00
|
|
|
entry.signal_key_release_event().connect (mem_fun (*this, &Prompter::maybe_allow_response));
|
2005-09-26 14:24:59 -04:00
|
|
|
entry.signal_activate().connect (bind (mem_fun (*this, &Prompter::response), Gtk::RESPONSE_ACCEPT));
|
2005-05-13 16:47:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Prompter::change_labels (string okstr, string cancelstr)
|
|
|
|
{
|
2005-09-26 14:24:59 -04:00
|
|
|
// dynamic_cast<Gtk::Label*>(ok.get_child())->set_text (okstr);
|
|
|
|
// dynamic_cast<Gtk::Label*>(cancel.get_child())->set_text (cancelstr);
|
2005-05-13 16:47:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-01-13 14:48:55 -05:00
|
|
|
Prompter::get_result (string &str, bool strip)
|
2005-05-13 16:47:18 -04:00
|
|
|
{
|
|
|
|
str = entry.get_text ();
|
2006-01-13 14:48:55 -05:00
|
|
|
if (strip) {
|
2007-01-09 18:24:54 -05:00
|
|
|
PBD::strip_whitespace_edges (str);
|
2006-01-13 14:48:55 -05:00
|
|
|
}
|
2005-05-13 16:47:18 -04:00
|
|
|
}
|
2006-04-22 11:28:59 -04:00
|
|
|
|
|
|
|
bool
|
|
|
|
Prompter::maybe_allow_response (GdkEventKey* ev)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
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);
|
|
|
|
} else {
|
|
|
|
set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|