[gnome-mines] Reduce code duplication when changing button state



commit 33b540768e2d45259f37240e5d4147668e882210
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Sun Feb 16 10:43:50 2014 -0600

    Reduce code duplication when changing button state

 src/gnome-mines.vala |   45 +++++++++++++++++++++++++++++----------------
 1 files changed, 29 insertions(+), 16 deletions(-)
---
diff --git a/src/gnome-mines.vala b/src/gnome-mines.vala
index 8c77fc5..c7b7f54 100644
--- a/src/gnome-mines.vala
+++ b/src/gnome-mines.vala
@@ -203,7 +203,7 @@ public class Mines : Gtk.Application
         play_pause_button.valign = Gtk.Align.CENTER;
         play_pause_button.halign = Gtk.Align.CENTER;
         play_pause_button.relief = Gtk.ReliefStyle.NONE;
-        play_pause_button.action_name = "app.new-game";
+        display_new_game_button ();
         buttons_box.pack_end (play_pause_button, false, false, 0);
         size.add_widget (play_pause_button);
     }
@@ -487,8 +487,7 @@ public class Mines : Gtk.Application
         new_game_screen.show ();
         window.resize (window_width, window_height);
 
-        play_pause_button.action_name = "app.new-game";
-        play_pause_image.icon_name = "view-refresh-symbolic";
+        display_new_game_button ();
 
         new_game_action.set_enabled (false);
         repeat_size_action.set_enabled (false);
@@ -594,17 +593,12 @@ public class Mines : Gtk.Application
         if (minefield.paused)
         {
             hint_action.set_enabled (false);
-
-            if (play_pause_button.get_direction () == Gtk.TextDirection.RTL)
-                play_pause_image.icon_name = "media-playback-start-rtl-symbolic";
-            else
-                play_pause_image.icon_name = "media-playback-start-symbolic";
-
+            display_unpause_button ();
         }
         else if (minefield.elapsed > 0)
         {
             hint_action.set_enabled (true);
-            play_pause_image.icon_name = "media-playback-pause-symbolic";
+            display_pause_button ();
         }
     }
 
@@ -615,8 +609,7 @@ public class Mines : Gtk.Application
 
     private void explode_cb (Minefield minefield)
     {
-        play_pause_button.action_name = "app.new-game";
-        play_pause_image.icon_name = "view-refresh-symbolic";
+        display_new_game_button ();
         hint_action.set_enabled (false);
         pause_action.set_enabled (false);
         clock_label.hide ();
@@ -634,8 +627,7 @@ public class Mines : Gtk.Application
             show_new_game_screen ();
         else
         {
-            play_pause_button.action_name = "app.new-game";
-            play_pause_image.icon_name = "view-refresh-symbolic";
+            display_new_game_button ();
             hint_action.set_enabled (false);
             pause_action.set_enabled (false);
             clock_label.hide ();
@@ -644,8 +636,7 @@ public class Mines : Gtk.Application
 
     private void clock_started_cb ()
     {
-        play_pause_image.icon_name = "media-playback-pause-symbolic";
-        play_pause_button.action_name = "app.pause";
+        display_pause_button ();
         clock_label.show ();
     }
 
@@ -906,6 +897,28 @@ public class Mines : Gtk.Application
         }
     }
 
+    private void display_new_game_button ()
+    {
+        play_pause_button.action_name = "app.new-game";
+        play_pause_image.icon_name = "view-refresh-symbolic";
+    }
+
+    private void display_pause_button ()
+    {
+        play_pause_button.action_name = "app.pause";
+        play_pause_image.icon_name = "media-playback-pause-symbolic";
+    }
+
+    private void display_unpause_button ()
+    {
+        play_pause_button.action_name = "app.pause";
+
+        if (play_pause_button.get_direction () == Gtk.TextDirection.RTL)
+            play_pause_image.icon_name = "media-playback-start-rtl-symbolic";
+        else
+            play_pause_image.icon_name = "media-playback-start-symbolic";
+    }
+
     public static int main (string[] args)
     {
         Intl.setlocale (LocaleCategory.ALL, "");


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