[gtk/matthiasc/for-master: 5/6] gtk-demo: Improve the builder demo
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/matthiasc/for-master: 5/6] gtk-demo: Improve the builder demo
- Date: Mon, 14 Sep 2020 21:33:56 +0000 (UTC)
commit a3dcfafba689dd646513587930371f9a7384bf11
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Sep 14 17:06:34 2020 -0400
gtk-demo: Improve the builder demo
Make the keyboard shortcuts work.
demos/gtk-demo/builder.c | 36 ++++++++++++++++++++++++++++++++++++
demos/gtk-demo/demo.ui | 16 ++++++----------
2 files changed, 42 insertions(+), 10 deletions(-)
---
diff --git a/demos/gtk-demo/builder.c b/demos/gtk-demo/builder.c
index 7699b3d0f6..3574b3dbeb 100644
--- a/demos/gtk-demo/builder.c
+++ b/demos/gtk-demo/builder.c
@@ -105,6 +105,7 @@ do_builder (GtkWidget *do_widget)
GtkBuilder *builder;
GtkWidget *about;
GtkWidget *status;
+ GtkEventController *controller;
builder = gtk_builder_new_from_resource ("/builder/demo.ui");
@@ -118,6 +119,41 @@ do_builder (GtkWidget *do_widget)
window);
gtk_widget_insert_action_group (window, "win", actions);
+ controller = gtk_shortcut_controller_new ();
+ gtk_shortcut_controller_set_scope (GTK_SHORTCUT_CONTROLLER (controller),
+ GTK_SHORTCUT_SCOPE_GLOBAL);
+ gtk_widget_add_controller (window, controller);
+ gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller),
+ gtk_shortcut_new (gtk_keyval_trigger_new (GDK_KEY_n, GDK_CONTROL_MASK),
+ gtk_named_action_new ("win.new")));
+ gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller),
+ gtk_shortcut_new (gtk_keyval_trigger_new (GDK_KEY_o, GDK_CONTROL_MASK),
+ gtk_named_action_new ("win.open")));
+ gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller),
+ gtk_shortcut_new (gtk_keyval_trigger_new (GDK_KEY_s, GDK_CONTROL_MASK),
+ gtk_named_action_new ("win.save")));
+ gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller),
+ gtk_shortcut_new (gtk_keyval_trigger_new (GDK_KEY_s, GDK_CONTROL_MASK|GDK_SHIFT_MASK),
+ gtk_named_action_new ("win.save-as")));
+ gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller),
+ gtk_shortcut_new (gtk_keyval_trigger_new (GDK_KEY_q, GDK_CONTROL_MASK),
+ gtk_named_action_new ("win.quit")));
+ gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller),
+ gtk_shortcut_new (gtk_keyval_trigger_new (GDK_KEY_c, GDK_CONTROL_MASK),
+ gtk_named_action_new ("win.copy")));
+ gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller),
+ gtk_shortcut_new (gtk_keyval_trigger_new (GDK_KEY_x, GDK_CONTROL_MASK),
+ gtk_named_action_new ("win.cut")));
+ gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller),
+ gtk_shortcut_new (gtk_keyval_trigger_new (GDK_KEY_v, GDK_CONTROL_MASK),
+ gtk_named_action_new ("win.paste")));
+ gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller),
+ gtk_shortcut_new (gtk_keyval_trigger_new (GDK_KEY_F1, 0),
+ gtk_named_action_new ("win.help")));
+ gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller),
+ gtk_shortcut_new (gtk_keyval_trigger_new (GDK_KEY_F7, 0),
+ gtk_named_action_new ("win.about")));
+
about = GTK_WIDGET (gtk_builder_get_object (builder, "aboutdialog1"));
gtk_window_set_transient_for (GTK_WINDOW (about), GTK_WINDOW (window));
gtk_window_set_hide_on_close (GTK_WINDOW (about), TRUE);
diff --git a/demos/gtk-demo/demo.ui b/demos/gtk-demo/demo.ui
index bd541040dd..01847f8b92 100644
--- a/demos/gtk-demo/demo.ui
+++ b/demos/gtk-demo/demo.ui
@@ -29,29 +29,24 @@
<item>
<attribute name="label" translatable="yes">_New</attribute>
<attribute name="action">win.new</attribute>
- <attribute name="accel"><Control>n</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Open</attribute>
<attribute name="action">win.open</attribute>
- <attribute name="accel"><Control>o</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Save</attribute>
<attribute name="action">win.save</attribute>
- <attribute name="accel"><Control>s</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Save _As</attribute>
<attribute name="action">win.save-as</attribute>
- <attribute name="accel"><Control>q</attribute>
</item>
</section>
<section>
<item>
<attribute name="label" translatable="yes">_Quit</attribute>
<attribute name="action">win.quit</attribute>
- <attribute name="accel"><Control><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"><Control>c</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Cut</attribute>
<attribute name="action">win.cut</attribute>
- <attribute name="accel"><Control>x</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Paste</attribute>
<attribute name="action">win.paste</attribute>
- <attribute name="accel"><Control>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>
@@ -118,6 +108,7 @@
<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>
@@ -125,6 +116,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>
@@ -132,6 +124,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>
@@ -142,6 +135,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>
@@ -149,6 +143,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>
@@ -156,6 +151,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]