[gnome-chess/mcatanzaro/gtk4] progress



commit 8670343d6cfe68ccd0716e90ef5e4fd2a2026009
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Wed Dec 23 20:13:11 2020 -0600

    progress

 data/gnome-chess.ui  | 52 +++----------------------------
 src/gnome-chess.vala | 87 +++++++++++++++++++++++++++++++++-------------------
 2 files changed, 60 insertions(+), 79 deletions(-)
---
diff --git a/data/gnome-chess.ui b/data/gnome-chess.ui
index eeb14c9..73312ca 100644
--- a/data/gnome-chess.ui
+++ b/data/gnome-chess.ui
@@ -152,9 +152,9 @@
                     </style>
                     <child>
                       <object class="GtkButton" id="first_move_button">
+                       <property name="action-name">win.go-first</property>
                         <property name="sensitive">0</property>
                         <property name="tooltip-text" translatable="yes" comments="Tooltip on the show first 
move (i.e. game start) navigation button">Rewind to the game start</property>
-                        <signal name="clicked" handler="history_start_clicked_cb" swapped="no"/>
                         <style>
                           <class name="image-button"/>
                         </style>
@@ -165,24 +165,13 @@
                             <property name="icon-name">go-first-symbolic</property>
                           </object>
                         </child>
-                        <child>
-                          <object class='GtkShortcutController'>
-                            <property name='scope'>managed</property>
-                            <child>
-                              <object class='GtkShortcut'>
-                                <property name='trigger'>&lt;Alt&gt;&lt;Shift&gt;Left</property>
-                                <property name='action'>activate</property>
-                              </object>
-                            </child>
-                          </object>
-                        </child>
                       </object>
                     </child>
                     <child>
                       <object class="GtkButton" id="prev_move_button">
+                       <property name="action-name">win.go-previous</property>
                         <property name="sensitive">0</property>
                         <property name="tooltip-text" translatable="yes" comments="Tooltip on the show 
previous move navigation button">Show the previous move</property>
-                        <signal name="clicked" handler="history_previous_clicked_cb" swapped="no"/>
                         <style>
                           <class name="image-button"/>
                         </style>
@@ -193,24 +182,13 @@
                             <property name="icon-name">go-previous-symbolic</property>
                           </object>
                         </child>
-                        <child>
-                          <object class='GtkShortcutController'>
-                            <property name='scope'>managed</property>
-                            <child>
-                              <object class='GtkShortcut'>
-                                <property name='trigger'>&lt;Alt&gt;Left</property>
-                                <property name='action'>activate</property>
-                              </object>
-                            </child>
-                          </object>
-                        </child>
                       </object>
                     </child>
                     <child>
                       <object class="GtkButton" id="next_move_button">
+                       <property name="action-name">win.go-next</property>
                         <property name="sensitive">0</property>
                         <property name="tooltip-text" translatable="yes" comments="Tooltip on the show next 
move navigation button">Show the next move</property>
-                        <signal name="clicked" handler="history_next_clicked_cb" swapped="no"/>
                         <style>
                           <class name="image-button"/>
                         </style>
@@ -221,24 +199,13 @@
                             <property name="icon-name">go-next-symbolic</property>
                           </object>
                         </child>
-                        <child>
-                          <object class='GtkShortcutController'>
-                            <property name='scope'>managed</property>
-                            <child>
-                              <object class='GtkShortcut'>
-                                <property name='trigger'>&lt;Alt&gt;Right</property>
-                                <property name='action'>activate</property>
-                              </object>
-                            </child>
-                          </object>
-                        </child>
                       </object>
                     </child>
                     <child>
                       <object class="GtkButton" id="last_move_button">
+                       <property name="action-name">win.go-last</property>
                         <property name="sensitive">0</property>
                         <property name="tooltip-text" translatable="yes" comments="Tooltip on the show 
current move navigation button">Show the current move</property>
-                        <signal name="clicked" handler="history_latest_clicked_cb" swapped="no"/>
                         <style>
                           <class name="image-button"/>
                         </style>
@@ -249,17 +216,6 @@
                             <property name="icon-name">go-last-symbolic</property>
                           </object>
                         </child>
-                        <child>
-                          <object class='GtkShortcutController'>
-                            <property name='scope'>managed</property>
-                            <child>
-                              <object class='GtkShortcut'>
-                                <property name='trigger'>&lt;Alt&gt;&lt;Shift&gt;Right</property>
-                                <property name='action'>activate</property>
-                              </object>
-                            </child>
-                          </object>
-                        </child>
                       </object>
                     </child>
                   </object>
diff --git a/src/gnome-chess.vala b/src/gnome-chess.vala
index 8e02ea4..4e281ca 100644
--- a/src/gnome-chess.vala
+++ b/src/gnome-chess.vala
@@ -95,6 +95,10 @@ Copyright © 2015–2016 Sahil Sareen""";
     private const string UNDO_MOVE_ACTION_NAME = "undo";
     private const string RESIGN_ACTION_NAME = "resign";
     private const string PAUSE_RESUME_ACTION_NAME = "pause-resume";
+    private const string HISTORY_GO_FIRST_ACTION_NAME = "go-first";
+    private const string HISTORY_GO_PREVIOUS_ACTION_NAME = "go-previous";
+    private const string HISTORY_GO_NEXT_ACTION_NAME = "go-next";
+    private const string HISTORY_GO_LAST_ACTION_NAME = "go-last";
 
     private const GLib.ActionEntry[] window_entries =
     {
@@ -105,6 +109,10 @@ Copyright © 2015–2016 Sahil Sareen""";
         { UNDO_MOVE_ACTION_NAME, undo_move_cb },
         { RESIGN_ACTION_NAME, resign_cb },
         { PAUSE_RESUME_ACTION_NAME, pause_resume_cb },
+        { HISTORY_GO_FIRST_ACTION_NAME, history_go_first_cb },
+        { HISTORY_GO_PREVIOUS_ACTION_NAME, history_go_previous_cb },
+        { HISTORY_GO_NEXT_ACTION_NAME, history_go_next_cb },
+        { HISTORY_GO_LAST_ACTION_NAME, history_go_last_cb },
     };
 
     private const OptionEntry[] option_entries =
@@ -179,13 +187,17 @@ Copyright © 2015–2016 Sahil Sareen""";
         update_pause_resume_button ();
 
         window.add_action_entries (window_entries, this);
-        set_accels_for_action ("win." + NEW_GAME_ACTION_NAME,       {        "<Control>n"       });
-        set_accels_for_action ("win." + OPEN_GAME_ACTION_NAME,      {        "<Control>o"       });
-        set_accels_for_action ("win." + SAVE_GAME_ACTION_NAME,      {        "<Control>s"       });
-        set_accels_for_action ("win." + SAVE_GAME_AS_ACTION_NAME,   { "<Shift><Control>s"       });
-        set_accels_for_action ("win." + UNDO_MOVE_ACTION_NAME,      {        "<Control>z"       });
-        set_accels_for_action ("win." + PAUSE_RESUME_ACTION_NAME,   {        "<Control>p",
-                                                                                      "Pause"   });
+        set_accels_for_action ("win." + NEW_GAME_ACTION_NAME,            {        "<Control>n"     });
+        set_accels_for_action ("win." + OPEN_GAME_ACTION_NAME,           {        "<Control>o"     });
+        set_accels_for_action ("win." + SAVE_GAME_ACTION_NAME,           {        "<Control>s"     });
+        set_accels_for_action ("win." + SAVE_GAME_AS_ACTION_NAME,        { "<Shift><Control>s"     });
+        set_accels_for_action ("win." + UNDO_MOVE_ACTION_NAME,           {        "<Control>z"     });
+        set_accels_for_action ("win." + PAUSE_RESUME_ACTION_NAME,        {        "<Control>p",
+                                                                                           "Pause" });
+        set_accels_for_action ("win." + HISTORY_GO_FIRST_ACTION_NAME,    {     "<Shift><Alt>Left"  });
+        set_accels_for_action ("win." + HISTORY_GO_PREVIOUS_ACTION_NAME, {            "<Alt>Left"  });
+        set_accels_for_action ("win." + HISTORY_GO_NEXT_ACTION_NAME,     {            "<Alt>Right" });
+        set_accels_for_action ("win." + HISTORY_GO_LAST_ACTION_NAME,     {     "<Shift><Alt>Right"  });
 
         window.notify["default-height"].connect (window_state_changed_cb);
         window.notify["default-width"].connect (window_state_changed_cb);
@@ -468,10 +480,27 @@ Copyright © 2015–2016 Sahil Sareen""";
         if (move_number < 0)
             move_number += 1 + n_moves;
 
-        first_move_button.sensitive = n_moves > 0 && move_number != 0 && !game.is_paused;
-        prev_move_button.sensitive = move_number > 0 && !game.is_paused;
-        next_move_button.sensitive = move_number < n_moves && !game.is_paused;
-        last_move_button.sensitive = n_moves > 0 && move_number != n_moves && !game.is_paused;
+        if (n_moves > 0 && move_number != 0 && !game.is_paused)
+            enable_window_action (HISTORY_GO_FIRST_ACTION_NAME);
+        else
+            disable_window_action (HISTORY_GO_FIRST_ACTION_NAME);
+
+
+        if (move_number > 0 && !game.is_paused)
+            enable_window_action (HISTORY_GO_PREVIOUS_ACTION_NAME);
+        else
+            disable_window_action (HISTORY_GO_PREVIOUS_ACTION_NAME);
+
+        if (move_number < n_moves && !game.is_paused)
+            enable_window_action (HISTORY_GO_NEXT_ACTION_NAME);
+        else
+            disable_window_action (HISTORY_GO_NEXT_ACTION_NAME);
+
+        if (n_moves > 0 && move_number != n_moves && !game.is_paused)
+            enable_window_action (HISTORY_GO_LAST_ACTION_NAME);
+        else
+            disable_window_action (HISTORY_GO_LAST_ACTION_NAME);
+
         history_combo.sensitive = !game.is_paused;
 
         /* Set move text for all moves (it may have changed format) */
@@ -1798,44 +1827,40 @@ Copyright © 2015–2016 Sahil Sareen""";
         scene.move_number = move_number;
     }
 
-    [CCode (cname = "history_latest_clicked_cb", instance_pos = -1)]
-    public void history_latest_clicked_cb (Widget widget)
+    private void history_go_first_cb ()
     {
-        scene.move_number = -1;
+        scene.move_number = 0;
     }
 
-    [CCode (cname = "history_next_clicked_cb", instance_pos = -1)]
-    public void history_next_clicked_cb (Widget widget)
+    private void history_go_previous_cb ()
     {
-        if (scene.move_number == -1)
+        if (scene.move_number == 0)
             return;
 
-        int move_number = scene.move_number + 1;
-        if (move_number >= game.n_moves)
-            scene.move_number = -1;
+        if (scene.move_number == -1)
+            scene.move_number = (int) game.n_moves - 1;
         else
-            scene.move_number = move_number;
+            scene.move_number = scene.move_number - 1;
     }
 
-    [CCode (cname = "history_previous_clicked_cb", instance_pos = -1)]
-    public void history_previous_clicked_cb (Widget widget)
+    private void history_go_next_cb ()
     {
-        if (scene.move_number == 0)
+        if (scene.move_number == -1)
             return;
 
-        if (scene.move_number == -1)
-            scene.move_number = (int) game.n_moves - 1;
+        int move_number = scene.move_number + 1;
+        if (move_number >= game.n_moves)
+            scene.move_number = -1;
         else
-            scene.move_number = scene.move_number - 1;
+            scene.move_number = move_number;
     }
 
-    [CCode (cname = "history_start_clicked_cb", instance_pos = -1)]
-    public void history_start_clicked_cb (Widget widget)
+    private void history_go_last_cb ()
     {
-        scene.move_number = 0;
+        scene.move_number = -1;
     }
 
-    public void preferences_response_cb (int response_id)
+    private void preferences_response_cb (int response_id)
     {
         preferences_dialog.hide ();
     }


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