2003-09-02 10:29:05 +00:00
|
|
|
/**
|
2003-10-08 11:31:51 +00:00
|
|
|
* \file gtk/Alert_pimpl.C
|
2003-09-02 10:29:05 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Huang Ying
|
|
|
|
*
|
2003-09-02 17:02:32 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-09-02 10:29:05 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "frontends/Alert.h"
|
|
|
|
#include "frontends/Alert_pimpl.h"
|
|
|
|
|
2004-09-26 18:36:07 +00:00
|
|
|
#include <gtkmm.h>
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
using std::string;
|
|
|
|
|
2003-09-02 10:29:05 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
|
|
string translateShortcut(string const & str)
|
|
|
|
{
|
|
|
|
string::size_type i = str.find_first_of("&");
|
|
|
|
if (i == string::npos || i == str.length() - 1)
|
|
|
|
return str;
|
|
|
|
string tstr = str;
|
|
|
|
tstr[i] = '_';
|
|
|
|
return tstr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void warning_pimpl(string const &, string const & message)
|
|
|
|
{
|
|
|
|
Gtk::MessageDialog dlg(Glib::locale_to_utf8(message),
|
2004-09-26 16:48:30 +00:00
|
|
|
true, Gtk::MESSAGE_WARNING,
|
|
|
|
Gtk::BUTTONS_CLOSE, true);
|
2003-09-02 10:29:05 +00:00
|
|
|
dlg.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void error_pimpl(string const &, string const & message)
|
|
|
|
{
|
|
|
|
Gtk::MessageDialog dlg(Glib::locale_to_utf8(message),
|
2004-09-26 16:48:30 +00:00
|
|
|
true, Gtk::MESSAGE_ERROR,
|
|
|
|
Gtk::BUTTONS_CLOSE, true);
|
2003-09-02 10:29:05 +00:00
|
|
|
dlg.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void information_pimpl(string const &, string const & message)
|
|
|
|
{
|
|
|
|
Gtk::MessageDialog dlg(Glib::locale_to_utf8(message),
|
2004-09-26 16:48:30 +00:00
|
|
|
true, Gtk::MESSAGE_INFO,
|
|
|
|
Gtk::BUTTONS_CLOSE, true);
|
2003-09-02 10:29:05 +00:00
|
|
|
dlg.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int prompt_pimpl(string const &, string const & question,
|
|
|
|
int defaultButton, int /*escapeButton*/,
|
|
|
|
string const & b1, string const & b2, string const & b3)
|
|
|
|
{
|
|
|
|
Glib::ustring gb1 = Glib::locale_to_utf8(translateShortcut(b1));
|
|
|
|
Glib::ustring gb2 = Glib::locale_to_utf8(translateShortcut(b2));
|
|
|
|
Glib::ustring gb3;
|
|
|
|
if (!b3.empty())
|
|
|
|
gb3 = Glib::locale_to_utf8(translateShortcut(b3));
|
|
|
|
Gtk::MessageDialog dlg(Glib::locale_to_utf8(question),
|
2004-09-26 16:48:30 +00:00
|
|
|
true, Gtk::MESSAGE_QUESTION,
|
|
|
|
Gtk::BUTTONS_NONE, true);
|
2003-09-02 10:29:05 +00:00
|
|
|
dlg.add_button(gb1, 0);
|
|
|
|
dlg.add_button(gb2, 1);
|
|
|
|
if (!b3.empty())
|
|
|
|
dlg.add_button(gb3, 2);
|
|
|
|
dlg.set_default_response(defaultButton);
|
|
|
|
return dlg.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::pair<bool, string> const askForText_pimpl(string const & msg,
|
|
|
|
string const & dflt)
|
|
|
|
{
|
|
|
|
Gtk::MessageDialog dlg(Glib::locale_to_utf8(msg),
|
2004-09-26 16:48:30 +00:00
|
|
|
true, Gtk::MESSAGE_QUESTION,
|
2003-09-02 10:29:05 +00:00
|
|
|
Gtk::BUTTONS_OK_CANCEL,
|
2004-09-26 16:48:30 +00:00
|
|
|
true);
|
2003-09-02 10:29:05 +00:00
|
|
|
Gtk::Entry entry;
|
|
|
|
entry.set_text(Glib::locale_to_utf8(dflt));
|
|
|
|
entry.set_position(-1);
|
|
|
|
entry.show();
|
|
|
|
dlg.get_vbox()->children().push_back(
|
|
|
|
Gtk::Box_Helpers::Element(entry));
|
|
|
|
int response = dlg.run();
|
|
|
|
if (response == Gtk::RESPONSE_OK) {
|
|
|
|
string str = Glib::locale_from_utf8(entry.get_text());
|
|
|
|
return std::make_pair<bool, string>(true, str);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return std::make_pair<bool, string>(false, string());
|
|
|
|
}
|