[hitori/jbicha/hitori-keyboard-shortcuts] shortcuts: fix Ctrl+N and add Ctrl+Q and Ctrl+W as quit actions



commit 40bbe8ed658d3a5a5656fe3b8591ac33e36c256f
Author: Jeremy Bicha <jbicha ubuntu com>
Date:   Tue Feb 19 16:36:38 2019 -0500

    shortcuts: fix Ctrl+N and add Ctrl+Q and Ctrl+W as quit actions
    
    The Ctrl+N keyboard shortcut didn't work.
    
    Support both Ctrl+Q and Ctrl+W to quit the app.
    
    (Tweaked by Philip Withnall to fix redo shortcut.)

 data/hitori.ui  |  5 -----
 src/interface.c | 23 +++++++++++++++++++++++
 2 files changed, 23 insertions(+), 5 deletions(-)
---
diff --git a/data/hitori.ui b/data/hitori.ui
index c53515a..fb49e26 100644
--- a/data/hitori.ui
+++ b/data/hitori.ui
@@ -7,7 +7,6 @@
                        <item>
                                <attribute name="action">app.new-game</attribute>
                                <attribute name="label" translatable="yes">_New Game</attribute>
-                               <attribute name="accel">&lt;Primary&gt;n</attribute>
                        </item>
                        <submenu id="board_size_menu">
                                <attribute name="label" translatable="yes">Board _Size</attribute>
@@ -49,7 +48,6 @@
                        <item>
                                <attribute name="action">app.help</attribute>
                                <attribute name="label" translatable="yes">_Help</attribute>
-                               <attribute name="accel">F1</attribute>
                        </item>
                        <item>
                                <attribute name="action">app.about</attribute>
@@ -80,7 +78,6 @@
                                                                <property name="can_focus">True</property>
                                                                <property 
name="focus_on_click">False</property>
                                                                <property 
name="action_name">win.undo</property>
-                                                               <accelerator key="Z" signal="activate" 
modifiers="GDK_CONTROL_MASK"/>
                                                                <property name="tooltip_text" 
translatable="yes">Undo your last move</property>
                                                                <style>
                                                                        <class name="image-button"/>
@@ -102,7 +99,6 @@
                                                                <property name="can_focus">True</property>
                                                                <property 
name="focus_on_click">False</property>
                                                                <property 
name="action_name">win.redo</property>
-                                                               <accelerator key="Z" signal="activate" 
modifiers="GDK_CONTROL_MASK | GDK_SHIFT_MASK"/>
                                                                <property name="tooltip_text" 
translatable="yes">Redo a move</property>
                                                                <style>
                                                                        <class name="image-button"/>
@@ -148,7 +144,6 @@
                                                <property name="can_focus">True</property>
                                                <property name="focus_on_click">False</property>
                                                <property name="action_name">win.hint</property>
-                                               <accelerator key="H" signal="activate" 
modifiers="GDK_CONTROL_MASK"/>
                                                <property name="tooltip_text" translatable="yes">Get a hint 
for your next move</property>
                                                <style>
                                                        <class name="image-button"/>
diff --git a/src/interface.c b/src/interface.c
index 0dc8c77..be9c7af 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -44,6 +44,7 @@ void hitori_destroy_cb (GtkWindow *window, Hitori *hitori);
 void hitori_window_state_event_cb (GtkWindow *window, GdkEventWindowState *event, Hitori *hitori);
 static void new_game_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data);
 static void hint_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data);
+static void quit_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data);
 static void undo_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data);
 static void redo_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data);
 static void help_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data);
@@ -54,6 +55,7 @@ static GActionEntry app_entries[] = {
        { "new-game", new_game_cb, NULL, NULL, NULL },
        { "about", about_cb, NULL, NULL, NULL },
        { "help", help_cb, NULL, NULL, NULL },
+       { "quit", quit_cb, NULL, NULL, NULL },
 };
 
 static GActionEntry win_entries[] = {
@@ -96,6 +98,20 @@ hitori_create_interface (Hitori *hitori)
        hitori->redo_action = G_SIMPLE_ACTION (g_action_map_lookup_action (G_ACTION_MAP (hitori->window), 
"redo"));
        hitori->hint_action = G_SIMPLE_ACTION (g_action_map_lookup_action (G_ACTION_MAP (hitori->window), 
"hint"));
 
+       const gchar *vaccels_help[] = {"F1", NULL};
+       const gchar *vaccels_hint[] = {"<Primary>h", NULL};
+       const gchar *vaccels_new[] = {"<Primary>n", NULL};
+       const gchar *vaccels_quit[] = {"<Primary>q", "<Primary>w", NULL};
+       const gchar *vaccels_redo[] = {"<Primary><Shift>z", NULL};
+       const gchar *vaccels_undo[] = {"<Primary>z", NULL};
+
+       gtk_application_set_accels_for_action (GTK_APPLICATION (hitori), "app.help", vaccels_help);
+       gtk_application_set_accels_for_action (GTK_APPLICATION (hitori), "win.hint", vaccels_hint);
+       gtk_application_set_accels_for_action (GTK_APPLICATION (hitori), "app.new-game", vaccels_new);
+       gtk_application_set_accels_for_action (GTK_APPLICATION (hitori), "app.quit", vaccels_quit);
+       gtk_application_set_accels_for_action (GTK_APPLICATION (hitori), "win.redo", vaccels_redo);
+       gtk_application_set_accels_for_action (GTK_APPLICATION (hitori), "win.undo", vaccels_undo);
+
        /* Set up font descriptions for the drawing area */
        style_context = gtk_widget_get_style_context (hitori->drawing_area);
        gtk_style_context_get (style_context,
@@ -411,6 +427,13 @@ hitori_destroy_cb (GtkWindow *window, Hitori *hitori)
        hitori_quit (hitori);
 }
 
+static void
+quit_cb (GSimpleAction *action, GVariant *parameters, gpointer user_data)
+{
+       HitoriApplication *self = HITORI_APPLICATION (user_data);
+       hitori_quit (self);
+}
+
 void
 hitori_window_state_event_cb (GtkWindow *window, GdkEventWindowState *event, Hitori *hitori)
 {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]