22 #include <libgtkcrnmm_config.h>
29 #ifndef CRN_USING_GTKMM3
30 # define get_content_area get_vbox
34 using namespace GtkCRN;
36 Gtk::Window*& App::internal_main_window() {
static Gtk::Window *main =
nullptr;
return main; }
38 #ifdef CRN_USING_GTKMM3
41 actions(Gio::SimpleActionGroup::create())
43 actions->add_action(
"file-menu");
44 actions->add_action(
"quit", sigc::bind(sigc::hide_return(sigc::mem_fun(
this, &
App::ask_for_quit)), (GdkEventAny*)
nullptr));
45 actions->add_action(
"help-menu");
49 signal_realize().connect(sigc::bind(sigc::mem_fun(
this, &Gtk::Widget::insert_action_group),
"app",
actions));
56 ui_manager(Gtk::UIManager::create()),
57 actions(Gtk::ActionGroup::create(
"GtkCRN::App actions"))
59 actions->add(Gtk::Action::create(
"app-file-menu",
_(
"_File"),
_(
"File")));
60 actions->add(Gtk::Action::create(
"app-quit", Gtk::Stock::QUIT), sigc::bind(sigc::hide_return(sigc::mem_fun(
this, &
App::ask_for_quit)), (GdkEventAny*)
nullptr));
61 actions->add(Gtk::Action::create(
"app-help-menu", Gtk::StockID(
"corenum-icon-circle"),
_(
"_?"),
_(
"?")));
62 actions->add(Gtk::Action::create(
"app-help", Gtk::Stock::HELP), sigc::mem_fun(
this, &
App::help));
63 actions->add(Gtk::Action::create(
"app-about", Gtk::Stock::ABOUT), sigc::mem_fun(
this, &
App::about));
78 Gtk::MessageDialog dial(*
this,
_(
"Are you sure you want to quit?"),
false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO,
true);
79 if (dial.run() == Gtk::RESPONSE_YES)
81 #ifdef CRN_USING_GTKMM3
98 #ifdef CRN_USING_GTKMM3
99 Gtk::Dialog dial(
"", *
this,
true);
101 Gtk::Dialog dial(
"", *
this,
true,
false);
103 dial.set_position(Gtk::WIN_POS_CENTER_ON_PARENT);
106 dial.get_content_area()->pack_start(lab,
false,
true, 2);
108 ent.set_activates_default();
109 ent.set_text(defval);
111 dial.get_content_area()->pack_start(ent,
false,
true, 2);
112 #ifdef CRN_USING_GTKMM3
113 dial.add_button(
_(
"_Cancel"), Gtk::RESPONSE_REJECT);
114 dial.add_button(
_(
"_OK"), Gtk::RESPONSE_ACCEPT);
116 dial.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_REJECT);
117 dial.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT);
118 std::vector<int> altbut;
119 altbut.push_back(Gtk::RESPONSE_ACCEPT);
120 altbut.push_back(Gtk::RESPONSE_CANCEL);
121 dial.set_alternative_button_order_from_array(altbut);
123 dial.set_default_response(Gtk::RESPONSE_ACCEPT);
124 if (dial.run() == Gtk::RESPONSE_ACCEPT)
125 return ent.get_text();
133 Glib::ustring message;
134 Gtk::MessageType mtype;
136 static gboolean do_show_message(mesg *message)
138 Gtk::MessageDialog md(message->message,
false, message->mtype, Gtk::BUTTONS_OK,
true);
151 mesg *msg =
new mesg;
152 msg->message = message;
154 g_idle_add(GSourceFunc(do_show_message), msg);
164 gboolean display_exception(exc_data *ex)
166 Gtk::MessageDialog md(ex->message.CStr(),
false, ex->kill ? Gtk::MESSAGE_ERROR : Gtk::MESSAGE_WARNING, Gtk::BUTTONS_OK,
true);
167 if (ex->stack.IsNotEmpty())
169 Gtk::Expander *expd = Gtk::manage(
new Gtk::Expander(
_(
"Advanced details")));
170 md.get_content_area()->pack_start(*expd,
true,
true, 0);
171 Gtk::ScrolledWindow *sw = Gtk::manage(
new Gtk::ScrolledWindow);
173 Gtk::TextView *lab = Gtk::manage(
new Gtk::TextView);
174 lab->get_buffer()->set_text(ex->stack.CStr());
176 expd->set_expanded(
false);
179 md.set_resizable(
true);
180 md.set_default_size(500, -1);
197 exc_data *msg =
new exc_data;
198 msg->message =
_(
"Unhandled exception caught.");
199 msg->kill = kill_app;
200 g_idle_add(GSourceFunc(display_exception), msg);
209 exc_data *msg =
new exc_data;
212 msg->kill = kill_app;
213 g_idle_add(GSourceFunc(display_exception), msg);
222 exc_data *msg =
new exc_data;
223 msg->message = ex.what();
224 msg->kill = kill_app;
225 g_idle_add(GSourceFunc(display_exception), msg);
Glib::RefPtr< Gtk::ActionGroup > actions
Glib::RefPtr< Gtk::UIManager > ui_manager
const std::string & GetMessage() const noexcept
String containing a description of the exception.
Glib::ustring ask_for_string(const Glib::ustring &msg, const Glib::ustring &defval="")
Shows a dialog asking for a single string.
const std::string & GetContext() const noexcept
String containing the call stack at the moment of throw.
virtual void help()
Displays help (overloadable)
static void show_message(const Glib::ustring &message, Gtk::MessageType mtype)
Displays a message.
virtual void about()
Displays credits (overloadable)
static void show_exception(crn::Exception &ex, bool kill_app=true)
Displays an exception.
App()
Constructor. Creates Actions and adds them to UI manager.
A character string class.
Base class for exceptions.
virtual bool ask_for_quit(GdkEventAny *event)
Callback for application quit event (overloadable)