[gtkmm-documentation] App_and_win_menus example: Add a menu item that sends a Gio::Notification
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm-documentation] App_and_win_menus example: Add a menu item that sends a Gio::Notification
- Date: Tue, 28 Jan 2014 09:13:23 +0000 (UTC)
commit 682f3bfcb9e1b63805f1daf8ccc1a353d1be5297
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date: Tue Jan 28 10:08:41 2014 +0100
App_and_win_menus example: Add a menu item that sends a Gio::Notification
* examples/book/application/app_and_win_menus/exampleapplication.[h|cc]:
Add on_action_print(). Add actions and menu items for a Gio::Notification.
* examples/book/application/app_and_win_menus/examplewindow.[h|cc]:
Add on_action_send_notification() and on_action_withdraw_notification().
.../app_and_win_menus/exampleapplication.cc | 21 ++++++++++++++++++-
.../app_and_win_menus/exampleapplication.h | 1 +
.../application/app_and_win_menus/examplewindow.cc | 22 ++++++++++++++++++++
.../application/app_and_win_menus/examplewindow.h | 3 +-
4 files changed, 45 insertions(+), 2 deletions(-)
---
diff --git a/examples/book/application/app_and_win_menus/exampleapplication.cc
b/examples/book/application/app_and_win_menus/exampleapplication.cc
index c823763..97e3aa1 100644
--- a/examples/book/application/app_and_win_menus/exampleapplication.cc
+++ b/examples/book/application/app_and_win_menus/exampleapplication.cc
@@ -61,14 +61,28 @@ void ExampleApplication::on_startup()
submenu_edit->append("_Cut", "win.cut");
Glib::RefPtr<Gio::MenuItem> item = Gio::MenuItem::create("_Copy", "win.copy");
//Setting "accel" works, but might be deprecated soon: See
https://bugzilla.gnome.org/show_bug.cgi?id=708908
+ //When it is deprecated, use Gtk::Application::add_accelerator() instead.
item->set_attribute_value("accel", Glib::Variant<Glib::ustring>::create("<Primary>c"));
submenu_edit->append_item(item);
- item = Gio::MenuItem::create("_Copy", "win.paste");
+ item = Gio::MenuItem::create("_Paste", "win.paste");
item->set_attribute_value("accel", Glib::Variant<Glib::ustring>::create("<Primary>v"));
submenu_edit->append_item(item);
win_menu->append_submenu("Edit", submenu_edit);
+ Glib::RefPtr<Gio::Menu> submenu_notification = Gio::Menu::create();
+ submenu_notification->append("_Send", "win.send-note");
+ submenu_notification->append("_Withdraw", "win.withdraw-note");
+ win_menu->append_submenu("Notification", submenu_notification);
+
set_menubar(win_menu);
+
+ //Create an action with a parameter. This action can be activated from
+ //a Gio::Notification, sent by the Notification/win.send-note menu selection.
+ Glib::RefPtr<Gio::SimpleAction> action_print =
+ Gio::SimpleAction::create("print", Glib::VARIANT_TYPE_STRING);
+ action_print->signal_activate().connect(
+ sigc::mem_fun(*this, &ExampleApplication::on_action_print));
+ add_action(action_print);
}
void ExampleApplication::create_window()
@@ -111,3 +125,8 @@ void ExampleApplication::on_action_quit()
std::cout << G_STRFUNC << std::endl;
quit();
}
+
+void ExampleApplication::on_action_print(const Glib::VariantBase& parameter)
+{
+ std::cout << G_STRFUNC << " Parameter=" << parameter.print() << std::endl;
+}
diff --git a/examples/book/application/app_and_win_menus/exampleapplication.h
b/examples/book/application/app_and_win_menus/exampleapplication.h
index bedd301..c8b6bd9 100644
--- a/examples/book/application/app_and_win_menus/exampleapplication.h
+++ b/examples/book/application/app_and_win_menus/exampleapplication.h
@@ -38,6 +38,7 @@ private:
void on_window_hide(Gtk::Window* window);
void on_action_something();
void on_action_quit();
+ void on_action_print(const Glib::VariantBase& parameter);
};
#endif /* GTKMM_EXAMPLEAPPLICATION_H */
diff --git a/examples/book/application/app_and_win_menus/examplewindow.cc
b/examples/book/application/app_and_win_menus/examplewindow.cc
index 344e070..6a39ee0 100644
--- a/examples/book/application/app_and_win_menus/examplewindow.cc
+++ b/examples/book/application/app_and_win_menus/examplewindow.cc
@@ -36,6 +36,10 @@ ExampleWindow::ExampleWindow()
sigc::mem_fun(*this, &ExampleWindow::on_action_something) );
add_action("paste",
sigc::mem_fun(*this, &ExampleWindow::on_action_something) );
+ add_action("send-note",
+ sigc::mem_fun(*this, &ExampleWindow::on_action_send_notification) );
+ add_action("withdraw-note",
+ sigc::mem_fun(*this, &ExampleWindow::on_action_withdraw_notification) );
}
void ExampleWindow::on_action_something()
@@ -49,3 +53,21 @@ void ExampleWindow::on_action_close()
hide();
}
+
+void ExampleWindow::on_action_send_notification()
+{
+ std::cout << G_STRFUNC << std::endl;
+
+ Glib::RefPtr<Gio::Notification> note = Gio::Notification::create("Unimportant message!");
+ note->set_body("Notification from " + Glib::get_application_name());
+ note->add_button("Print", "app.print", Glib::ustring("Hello, world!"));
+ note->add_button("Quit Application", "app.quit");
+ get_application()->send_notification("note", note);
+}
+
+void ExampleWindow::on_action_withdraw_notification()
+{
+ std::cout << G_STRFUNC << std::endl;
+
+ get_application()->withdraw_notification("note");
+}
diff --git a/examples/book/application/app_and_win_menus/examplewindow.h
b/examples/book/application/app_and_win_menus/examplewindow.h
index 4e719b9..d0f00be 100644
--- a/examples/book/application/app_and_win_menus/examplewindow.h
+++ b/examples/book/application/app_and_win_menus/examplewindow.h
@@ -22,12 +22,13 @@
class ExampleWindow: public Gtk::ApplicationWindow
{
public:
-
explicit ExampleWindow();
private:
void on_action_something();
void on_action_close();
+ void on_action_send_notification();
+ void on_action_withdraw_notification();
};
#endif /* GTKMM_EXAMPLEWINDOW_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]