[gnome-sudoku] Allow earmarking numbers using Ctrl+number
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-sudoku] Allow earmarking numbers using Ctrl+number
- Date: Thu, 5 Jun 2014 13:38:15 +0000 (UTC)
commit bbf1e52d77bcd5c42c0e1daa9cded0e6430bf9a2
Author: Parin Porecha <parinporecha gmail com>
Date: Thu Jun 5 17:18:22 2014 +0530
Allow earmarking numbers using Ctrl+number
https://bugzilla.gnome.org/show_bug.cgi?id=731222
src/number-picker.vala | 21 +++++++++++++--------
src/sudoku-view.vala | 14 ++++++++++++--
2 files changed, 25 insertions(+), 10 deletions(-)
---
diff --git a/src/number-picker.vala b/src/number-picker.vala
index a6bf8aa..4b53774 100644
--- a/src/number-picker.vala
+++ b/src/number-picker.vala
@@ -44,10 +44,10 @@ private class NumberPicker : Gtk.Grid
var toggle_active = toggle_button.get_active ();
earmark_state_changed (n, toggle_active);
earmarks_active = toggle_active ? earmarks_active + 1 : earmarks_active - 1;
- if (earmarks_active >= EARMARKS_MAX_ALLOWED)
- set_toggle_sensitive (false);
- else if (earmarks_active == (EARMARKS_MAX_ALLOWED - 1))
+ if (earmarks_active < EARMARKS_MAX_ALLOWED)
set_toggle_sensitive (true);
+ else
+ set_toggle_sensitive (false);
});
}
@@ -88,11 +88,16 @@ private class NumberPicker : Gtk.Grid
public void set_earmarks (int row, int col)
{
for (var i = 0; i < board.max_val; i++)
- if (board.earmarks[row, col, i])
- {
- var button = (ToggleButton) this.get_child_at (i % board.block_cols, i / board.block_rows);
- button.set_active (board.earmarks[row, col, i]);
- }
+ set_earmark (row, col, i, board.earmarks[row, col, i]);
+ }
+
+ public bool set_earmark (int row, int col, int index, bool state)
+ {
+ if (state && earmarks_active >= EARMARKS_MAX_ALLOWED)
+ return false;
+ var button = (ToggleButton) this.get_child_at (index % board.block_cols, index / board.block_rows);
+ button.set_active (state);
+ return true;
}
private void set_toggle_sensitive (bool state)
diff --git a/src/sudoku-view.vala b/src/sudoku-view.vala
index b3a26cc..263d37d 100644
--- a/src/sudoku-view.vala
+++ b/src/sudoku-view.vala
@@ -161,6 +161,7 @@ private class SudokuCellView : Gtk.DrawingArea
this.game.board.earmarks[row, col, number-1] = state;
queue_draw ();
});
+ earmark_picker.set_earmarks (row, col);
earmark_popover = new Popover (this);
earmark_popover.add (earmark_picker);
@@ -231,7 +232,6 @@ private class SudokuCellView : Gtk.DrawingArea
{
if (!is_fixed)
{
- earmark_picker.set_earmarks (_row, _col);
popover.hide ();
earmark_popover.show ();
}
@@ -280,7 +280,17 @@ private class SudokuCellView : Gtk.DrawingArea
k_no = key_map_keypad (k_name);
if (k_no >= 1 && k_no <= 9)
{
- value = k_no;
+ if ((event.state & ModifierType.CONTROL_MASK) > 0 && !is_fixed)
+ {
+ var new_state = !game.board.earmarks[_row, _col, k_no-1];
+ if (earmark_picker.set_earmark (_row, _col, k_no-1, new_state))
+ {
+ game.board.earmarks[_row, _col, k_no-1] = new_state;
+ queue_draw ();
+ }
+ }
+ else
+ value = k_no;
return true;
}
if (k_no == 0 || k_name == "BackSpace" || k_name == "Delete")
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]