[gnome-sudoku] Disable Clear Board button when there's nothing to clear



commit fca0a5d4338380e885d8cdaf10e20ebfb787c03b
Author: Parin Porecha <parinporecha gmail com>
Date:   Tue Jul 22 19:16:03 2014 +0200

    Disable Clear Board button when there's nothing to clear
    
    https://bugzilla.gnome.org/show_bug.cgi?id=733454

 lib/sudoku-board.vala |   11 +++++++++++
 src/gnome-sudoku.vala |    4 ++++
 2 files changed, 15 insertions(+), 0 deletions(-)
---
diff --git a/lib/sudoku-board.vala b/lib/sudoku-board.vala
index 80a3ade..13cc824 100644
--- a/lib/sudoku-board.vala
+++ b/lib/sudoku-board.vala
@@ -62,11 +62,19 @@ public class SudokuBoard : Object
         get { return _filled; }
     }
 
+    /* the number of fixed squares on the board */
+    public int fixed { get; private set; }
+
     public bool complete
     {
         get { return _filled == _cols * _rows && !broken; }
     }
 
+    public bool is_empty ()
+    {
+        return _filled == fixed;
+    }
+
     public double difficulty_rating;
 
     private bool in_range (float[] range)
@@ -193,6 +201,7 @@ public class SudokuBoard : Object
         board.possible_in_col = possible_in_col;
         board.possible_in_block = possible_in_block;
         board._filled = _filled;
+        board.fixed = fixed;
         board.broken_coords.add_all (broken_coords);
         board.earmarks = earmarks;
 
@@ -291,6 +300,8 @@ public class SudokuBoard : Object
         cells[row, col] = val;
         this.is_fixed[row, col] = is_fixed;
         _filled++;
+        if (is_fixed)
+            fixed++;
 
         if (!possible_in_row[row, val - 1]) // If val was not possible in this row
         {
diff --git a/src/gnome-sudoku.vala b/src/gnome-sudoku.vala
index f21d300..8aee4fa 100644
--- a/src/gnome-sudoku.vala
+++ b/src/gnome-sudoku.vala
@@ -28,6 +28,7 @@ public class Sudoku : Gtk.Application
 
     private SimpleAction undo_action;
     private SimpleAction redo_action;
+    private SimpleAction clear_action;
     private SimpleAction print_action;
 
     private string header_bar_subtitle;
@@ -136,6 +137,7 @@ public class Sudoku : Gtk.Application
 
         undo_action = (SimpleAction) lookup_action ("undo");
         redo_action = (SimpleAction) lookup_action ("redo");
+        clear_action = (SimpleAction) lookup_action ("reset");
         print_action = (SimpleAction) lookup_action ("print");
 
         sudoku_store = new SudokuStore ();
@@ -171,6 +173,7 @@ public class Sudoku : Gtk.Application
         debug ("\n%s", rating.to_string ());
         undo_action.set_enabled (false);
         redo_action.set_enabled (false);
+        clear_action.set_enabled (!board.is_empty ());
 
         if (view != null) {
             grid_box.remove (view);
@@ -194,6 +197,7 @@ public class Sudoku : Gtk.Application
         game.cell_changed.connect (() => {
             undo_action.set_enabled (!game.is_undostack_null ());
             redo_action.set_enabled (!game.is_redostack_null ());
+            clear_action.set_enabled (!game.board.is_empty ());
         });
 
         game.board.completed.connect (() => {


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