[gnome-sudoku] Simplify warnings
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-sudoku] Simplify warnings
- Date: Sun, 13 Jul 2014 19:25:52 +0000 (UTC)
commit 224b6e924438d151c4b559c874d24c28046d0008
Author: Parin Porecha <parinporecha gmail com>
Date: Sat Jul 12 19:22:41 2014 +0200
Simplify warnings
Merge the Unfillable squares warning and duplicate numbers'
red highlight into one single setting.
https://bugzilla.gnome.org/show_bug.cgi?id=616462
data/gnome-sudoku-menu.ui | 4 +-
data/org.gnome.sudoku.gschema.xml | 8 +++---
src/gnome-sudoku.vala | 6 ++--
src/sudoku-view.vala | 42 +++++++-----------------------------
4 files changed, 17 insertions(+), 43 deletions(-)
---
diff --git a/data/gnome-sudoku-menu.ui b/data/gnome-sudoku-menu.ui
index 91cd314..de03917 100644
--- a/data/gnome-sudoku-menu.ui
+++ b/data/gnome-sudoku-menu.ui
@@ -19,8 +19,8 @@
</section>
<section>
<item>
- <attribute name="label" translatable="yes">_Warn About Unfillable Squares</attribute>
- <attribute name="action">app.unfillable-squares-warning</attribute>
+ <attribute name="label" translatable="yes">_Show Warnings</attribute>
+ <attribute name="action">app.show-warnings</attribute>
</item>
</section>
<section>
diff --git a/data/org.gnome.sudoku.gschema.xml b/data/org.gnome.sudoku.gschema.xml
index 8aead64..6d837c3 100644
--- a/data/org.gnome.sudoku.gschema.xml
+++ b/data/org.gnome.sudoku.gschema.xml
@@ -17,10 +17,10 @@
<summary>Number of Sudokus to print</summary>
<description>Set the number of sudokus you want to print</description>
</key>
- <key name="unfillable-squares-warning" type="b">
- <default>false</default>
- <summary>Warn about unfillable squares</summary>
- <description>Displays a big red X in a square if it cannot possibly be filled by any
number</description>
+ <key name="show-warnings" type="b">
+ <default>true</default>
+ <summary>Warn about unfillable squares and duplicate numbers</summary>
+ <description>Displays a big red X in a square if it cannot possibly be filled by any number and
duplicate numbers are highlighted in red</description>
</key>
</schema>
</schemalist>
diff --git a/src/gnome-sudoku.vala b/src/gnome-sudoku.vala
index c1514a2..8a69b41 100644
--- a/src/gnome-sudoku.vala
+++ b/src/gnome-sudoku.vala
@@ -99,9 +99,9 @@ public class Sudoku : Gtk.Application
add_action_entries (action_entries, this);
settings = new GLib.Settings ("org.gnome.sudoku");
- var action = settings.create_action ("unfillable-squares-warning");
+ var action = settings.create_action ("show-warnings");
action.notify["state"].connect (() =>
- view.show_warnings = settings.get_boolean ("unfillable-squares-warning"));
+ view.show_warnings = settings.get_boolean ("show-warnings"));
add_action (action);
add_accelerator ("<Primary>z", "app.undo", null);
@@ -217,7 +217,7 @@ public class Sudoku : Gtk.Application
view = new SudokuView (game);
view.show_possibilities = show_possibilities;
- view.show_warnings = settings.get_boolean ("unfillable-squares-warning");
+ view.show_warnings = settings.get_boolean ("show-warnings");
view.show ();
grid_box.pack_start (view);
diff --git a/src/sudoku-view.vala b/src/sudoku-view.vala
index bd26c9f..eb7fef4 100644
--- a/src/sudoku-view.vala
+++ b/src/sudoku-view.vala
@@ -81,12 +81,12 @@ private class SudokuCellView : Gtk.DrawingArea
}
}
- private bool _warn_about_unfillable_squares = false;
- public bool warn_about_unfillable_squares
+ private bool _show_warnings = true;
+ public bool show_warnings
{
- get { return _warn_about_unfillable_squares; }
+ get { return _show_warnings; }
set {
- _warn_about_unfillable_squares = value;
+ _show_warnings = value;
queue_draw ();
}
}
@@ -329,7 +329,7 @@ private class SudokuCellView : Gtk.DrawingArea
int glyph_width, glyph_height;
layout.get_pixel_size (out glyph_width, out glyph_height);
- if (game.board.broken_coords.contains(Coord(row, col)))
+ if (_show_warnings && game.board.broken_coords.contains(Coord(row, col)))
{
c.set_source_rgb (1.0, 0.0, 0.0);
}
@@ -399,7 +399,7 @@ private class SudokuCellView : Gtk.DrawingArea
if (is_fixed)
return false;
- if (_warn_about_unfillable_squares)
+ if (_show_warnings && (value == 0 && game.board.count_possibilities (_row, _col) == 0))
{
string warning = "X";
Cairo.TextExtents extents;
@@ -546,25 +546,10 @@ public class SudokuView : Gtk.AspectFrame
cell.notify["value"].connect((s, p)=> {
/* The board needs redrawing if it was/is broken, or if the possibilities are being
displayed */
if (_show_possibilities || _show_warnings || game.board.broken ||
previous_board_broken_state) {
- for (var i = 0; i < game.board.rows; i++)
- {
- for (var j = 0; j < game.board.cols; j++)
- {
- if (_show_warnings && cells[i,j].value == 0 &&
game.board.count_possibilities (cells[i,j].row, cells[i,j].col) == 0) {
- if (!cells[i,j].warn_about_unfillable_squares) {
- cells[i,j].warn_about_unfillable_squares = true;
- }
- }
- else
- {
- cells[i,j].warn_about_unfillable_squares = false;
- }
- }
- }
+ this.queue_draw ();
previous_board_broken_state = game.board.broken;
}
cell_value_changed_event(cell_row, cell_col);
- queue_draw ();
});
}
@@ -608,19 +593,8 @@ public class SudokuView : Gtk.AspectFrame
set {
_show_warnings = value;
for (var i = 0; i < game.board.rows; i++)
- {
for (var j = 0; j < game.board.cols; j++)
- {
- if (_show_warnings && cells[i,j].value == 0 && game.board.count_possibilities
(cells[i,j].row, cells[i,j].col) == 0)
- {
- cells[i,j].warn_about_unfillable_squares = true;
- }
- else
- {
- cells[i,j].warn_about_unfillable_squares = false;
- }
- }
- }
+ cells[i,j].show_warnings = _show_warnings;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]