[gtkmm-documentation] Main menu example: Make the keyboard shortcuts work
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm-documentation] Main menu example: Make the keyboard shortcuts work
- Date: Thu, 27 May 2021 13:20:31 +0000 (UTC)
commit 6888538cd6428a4db5c90efc2d70cf551e6e34e7
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date: Thu May 27 15:18:22 2021 +0200
Main menu example: Make the keyboard shortcuts work
examples/book/builder/basic/basic.glade | 2 +-
examples/book/builder/derived/derived.glade | 2 +-
examples/book/menus/main_menu/exampleapplication.cc | 5 +++++
examples/book/menus_and_toolbars/examplewindow.cc | 11 +----------
4 files changed, 8 insertions(+), 12 deletions(-)
---
diff --git a/examples/book/builder/basic/basic.glade b/examples/book/builder/basic/basic.glade
index 6b0e17b..f97c225 100644
--- a/examples/book/builder/basic/basic.glade
+++ b/examples/book/builder/basic/basic.glade
@@ -5,7 +5,7 @@
<property name="can_focus">False</property>
<property name="title" translatable="yes">Basic Builder example</property>
<property name="default_width">250</property>
- <property name="default_height">100</property>
+ <property name="default_height">120</property>
<property name="hide_on_close">True</property>
<child internal-child="content_area">
<object class="GtkBox" id="dialog-vbox2">
diff --git a/examples/book/builder/derived/derived.glade b/examples/book/builder/derived/derived.glade
index 29457fc..be276cd 100644
--- a/examples/book/builder/derived/derived.glade
+++ b/examples/book/builder/derived/derived.glade
@@ -5,7 +5,7 @@
<property name="can_focus">False</property>
<property name="title" translatable="yes">Derived Builder example</property>
<property name="default_width">250</property>
- <property name="default_height">100</property>
+ <property name="default_height">120</property>
<property name="hide_on_close">True</property>
<child internal-child="content_area">
<object class="GtkBox" id="dialog-vbox2">
diff --git a/examples/book/menus/main_menu/exampleapplication.cc
b/examples/book/menus/main_menu/exampleapplication.cc
index 1569aca..47d1cbf 100644
--- a/examples/book/menus/main_menu/exampleapplication.cc
+++ b/examples/book/menus/main_menu/exampleapplication.cc
@@ -52,6 +52,11 @@ void ExampleApplication::on_startup()
//Help menu:
add_action("about", sigc::mem_fun(*this, &ExampleApplication::on_menu_help_about));
+ // Set accelerator keys:
+ set_accel_for_action("app.newstandard", "<Primary>n");
+ set_accel_for_action("app.quit", "<Primary>q");
+ set_accel_for_action("win.copy", "<Primary>c");
+ set_accel_for_action("win.paste", "<Primary>v");
m_refBuilder = Gtk::Builder::create();
//Layout the actions in a menubar and a menu:
diff --git a/examples/book/menus_and_toolbars/examplewindow.cc
b/examples/book/menus_and_toolbars/examplewindow.cc
index 6803848..da0cc21 100644
--- a/examples/book/menus_and_toolbars/examplewindow.cc
+++ b/examples/book/menus_and_toolbars/examplewindow.cc
@@ -62,12 +62,10 @@ ExampleWindow::ExampleWindow(const Glib::RefPtr<Gtk::Application>& app)
" <item>"
" <attribute name='label' translatable='yes'>_New</attribute>"
" <attribute name='action'>example.new</attribute>"
- " <attribute name='accel'><Primary>n</attribute>"
" </item>"
" <item>"
" <attribute name='label' translatable='yes'>_Open</attribute>"
" <attribute name='action'>example.open</attribute>"
- " <attribute name='accel'><Primary>o</attribute>"
" </item>"
" </section>"
" <section>"
@@ -80,7 +78,6 @@ ExampleWindow::ExampleWindow(const Glib::RefPtr<Gtk::Application>& app)
" <item>"
" <attribute name='label' translatable='yes'>_Quit</attribute>"
" <attribute name='action'>example.quit</attribute>"
- " <attribute name='accel'><Primary>q</attribute>"
" </item>"
" </section>"
" </submenu>"
@@ -89,26 +86,20 @@ ExampleWindow::ExampleWindow(const Glib::RefPtr<Gtk::Application>& app)
" <item>"
" <attribute name='label' translatable='yes'>_Cut</attribute>"
" <attribute name='action'>example.cut</attribute>"
- " <attribute name='accel'><Primary>x</attribute>"
" </item>"
" <item>"
" <attribute name='label' translatable='yes'>_Copy</attribute>"
" <attribute name='action'>example.copy</attribute>"
- " <attribute name='accel'><Primary>c</attribute>"
" </item>"
" <item>"
" <attribute name='label' translatable='yes'>_Paste</attribute>"
" <attribute name='action'>example.paste</attribute>"
- " <attribute name='accel'><Primary>v</attribute>"
" </item>"
" </submenu>"
" </menu>"
"</interface>";
- // When the menubar is a child of a Gtk::Window, keyboard accelerators are not
- // automatically fetched from the Gio::Menu.
- // See the examples/book/menus/main_menu example for an alternative way of
- // adding the menubar when using Gtk::ApplicationWindow.
+ // Set accelerator keys:
app->set_accel_for_action("example.new", "<Primary>n");
app->set_accel_for_action("example.open", "<Primary>o");
app->set_accel_for_action("example.quit", "<Primary>q");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]