[gtkmm] Builder demo: Make the keyboard shortcuts work
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm] Builder demo: Make the keyboard shortcuts work
- Date: Sun, 23 May 2021 07:20:52 +0000 (UTC)
commit f9ffcf01d705a9892f2a2274f538bce502a3fe1a
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date: Sun May 23 09:15:54 2021 +0200
Builder demo: Make the keyboard shortcuts work
demos/gtk-demo/example_builder.cc | 34 ++++++++++++++++++++++++++++++++++
demos/gtk-demo/example_builder.ui | 24 ++++++++++++++----------
2 files changed, 48 insertions(+), 10 deletions(-)
---
diff --git a/demos/gtk-demo/example_builder.cc b/demos/gtk-demo/example_builder.cc
index 3c2f58ce..52e22bbf 100644
--- a/demos/gtk-demo/example_builder.cc
+++ b/demos/gtk-demo/example_builder.cc
@@ -65,6 +65,40 @@ Example_Builder::Example_Builder(
refActions->add_action("cut", sigc::mem_fun(*this, &Example_Builder::on_not_implemented));
refActions->add_action("paste", sigc::mem_fun(*this, &Example_Builder::on_not_implemented));
insert_action_group("win", refActions);
+
+ auto controller = Gtk::ShortcutController::create();
+ controller->set_scope(Gtk::ShortcutScope::GLOBAL);
+ add_controller(controller);
+ controller->add_shortcut(Gtk::Shortcut::create(
+ Gtk::KeyvalTrigger::create(GDK_KEY_n, Gdk::ModifierType::CONTROL_MASK),
+ Gtk::NamedAction::create("win.new")));
+ controller->add_shortcut(Gtk::Shortcut::create(
+ Gtk::KeyvalTrigger::create(GDK_KEY_o, Gdk::ModifierType::CONTROL_MASK),
+ Gtk::NamedAction::create("win.open")));
+ controller->add_shortcut(Gtk::Shortcut::create(
+ Gtk::KeyvalTrigger::create(GDK_KEY_s, Gdk::ModifierType::CONTROL_MASK),
+ Gtk::NamedAction::create("win.save")));
+ controller->add_shortcut(Gtk::Shortcut::create(
+ Gtk::KeyvalTrigger::create(GDK_KEY_s, Gdk::ModifierType::CONTROL_MASK|Gdk::ModifierType::SHIFT_MASK),
+ Gtk::NamedAction::create("win.save-as")));
+ controller->add_shortcut(Gtk::Shortcut::create(
+ Gtk::KeyvalTrigger::create(GDK_KEY_q, Gdk::ModifierType::CONTROL_MASK),
+ Gtk::NamedAction::create("win.quit")));
+ controller->add_shortcut(Gtk::Shortcut::create(
+ Gtk::KeyvalTrigger::create(GDK_KEY_c, Gdk::ModifierType::CONTROL_MASK),
+ Gtk::NamedAction::create("win.copy")));
+ controller->add_shortcut(Gtk::Shortcut::create(
+ Gtk::KeyvalTrigger::create(GDK_KEY_x, Gdk::ModifierType::CONTROL_MASK),
+ Gtk::NamedAction::create("win.cut")));
+ controller->add_shortcut(Gtk::Shortcut::create(
+ Gtk::KeyvalTrigger::create(GDK_KEY_v, Gdk::ModifierType::CONTROL_MASK),
+ Gtk::NamedAction::create("win.paste")));
+ controller->add_shortcut(Gtk::Shortcut::create(
+ Gtk::KeyvalTrigger::create(GDK_KEY_F1),
+ Gtk::NamedAction::create("win.help")));
+ controller->add_shortcut(Gtk::Shortcut::create(
+ Gtk::KeyvalTrigger::create(GDK_KEY_F7),
+ Gtk::NamedAction::create("win.about")));
}
Example_Builder::~Example_Builder()
diff --git a/demos/gtk-demo/example_builder.ui b/demos/gtk-demo/example_builder.ui
index 9166cf23..427f1e7c 100644
--- a/demos/gtk-demo/example_builder.ui
+++ b/demos/gtk-demo/example_builder.ui
@@ -29,29 +29,24 @@
<item>
<attribute name="label" translatable="yes">_New</attribute>
<attribute name="action">win.new</attribute>
- <attribute name="accel"><Primary>n</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Open</attribute>
<attribute name="action">win.open</attribute>
- <attribute name="accel"><Primary>o</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Save</attribute>
<attribute name="action">win.save</attribute>
- <attribute name="accel"><Primary>s</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Save _As</attribute>
<attribute name="action">win.save-as</attribute>
- <attribute name="accel"><Primary>q</attribute>
</item>
</section>
<section>
<item>
<attribute name="label" translatable="yes">_Quit</attribute>
<attribute name="action">win.quit</attribute>
- <attribute name="accel"><Primary><Shift>s</attribute>
</item>
</section>
</submenu>
@@ -61,17 +56,14 @@
<item>
<attribute name="label" translatable="yes">_Copy</attribute>
<attribute name="action">win.copy</attribute>
- <attribute name="accel"><Primary>c</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Cut</attribute>
<attribute name="action">win.cut</attribute>
- <attribute name="accel"><Primary>x</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Paste</attribute>
<attribute name="action">win.paste</attribute>
- <attribute name="accel"><Primary>v</attribute>
</item>
</section>
</submenu>
@@ -81,12 +73,10 @@
<item>
<attribute name="label" translatable="yes">_Help</attribute>
<attribute name="action">win.help</attribute>
- <attribute name="accel">F1</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_About</attribute>
<attribute name="action">win.about</attribute>
- <attribute name="accel">F7</attribute>
</item>
</section>
</submenu>
@@ -106,15 +96,24 @@
<child>
<object class="GtkPopoverMenuBar" id="menubar1">
<property name="menu-model">menubar</property>
+ <accessibility>
+ <property name="label">Main Menu</property>
+ </accessibility>
</object>
</child>
<child>
<object class="GtkBox" id="toolbar1">
+ <property name="accessible-role">toolbar</property>
+ <property name="css-classes">toolbar</property>
+ <accessibility>
+ <property name="label">Toolbar</property>
+ </accessibility>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">New</property>
<property name="tooltip-text" translatable="yes">Create a new file</property>
<property name="icon-name">document-new</property>
+ <property name="action-name">win.new</property>
</object>
</child>
<child>
@@ -122,6 +121,7 @@
<property name="label" translatable="yes">Open</property>
<property name="tooltip-text" translatable="yes">Open a file</property>
<property name="icon-name">document-open</property>
+ <property name="action-name">win.open</property>
</object>
</child>
<child>
@@ -129,6 +129,7 @@
<property name="label" translatable="yes">Save</property>
<property name="tooltip-text" translatable="yes">Save a file</property>
<property name="icon-name">document-save</property>
+ <property name="action-name">win.save</property>
</object>
</child>
<child>
@@ -139,6 +140,7 @@
<property name="label" translatable="yes">Copy</property>
<property name="tooltip-text" translatable="yes">Copy selected object into the
clipboard</property>
<property name="icon-name">edit-copy</property>
+ <property name="action-name">win.copy</property>
</object>
</child>
<child>
@@ -146,6 +148,7 @@
<property name="label" translatable="yes">Cut</property>
<property name="tooltip-text" translatable="yes">Cut selected object into the
clipboard</property>
<property name="icon-name">edit-cut</property>
+ <property name="action-name">win.cut</property>
</object>
</child>
<child>
@@ -153,6 +156,7 @@
<property name="label" translatable="yes">Paste</property>
<property name="tooltip-text" translatable="yes">Paste object from the clipboard</property>
<property name="icon-name">edit-paste</property>
+ <property name="action-name">win.paste</property>
</object>
</child>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]