[gnome-sudoku] Make undo and redo hide the value/earmark popovers



commit 5485cc3c555844ff33b952b0da87d71374572032
Author: shak-mar <shakmar openmailbox org>
Date:   Tue Jul 9 22:44:37 2019 +0200

    Make undo and redo hide the value/earmark popovers
    
    The bug fixed by this commit got a little bit more visible due to
    "89e7bc1 Handle earmarks properly in undo/redo (shak-mar, 2019-07-09)",
    because it is more apparent with the earmark popover;  however, the bug
    was also present before:
    
    1. Enter a value into a cell that was previously empty
    2. Open the value popover of the cell again (Now it shows a "clear"
       button)
    3. Press the undo button.  Now the value disappears from the cell, but
       the "clear" button remains, which is an inconsistent state.
    
    One way to fix this would be to update the popovers whenever things
    change underneath.  The other way, implemented by this commit, is to
    simply hide the popover whenever undo/redo is called.

 src/gnome-sudoku.vala | 2 ++
 src/sudoku-view.vala  | 9 ++++++++-
 2 files changed, 10 insertions(+), 1 deletion(-)
---
diff --git a/src/gnome-sudoku.vala b/src/gnome-sudoku.vala
index c87ed28..565c5c6 100644
--- a/src/gnome-sudoku.vala
+++ b/src/gnome-sudoku.vala
@@ -537,6 +537,7 @@ public class Sudoku : Gtk.Application
             return;
         game.undo ();
         undo_action.set_enabled (!game.is_undostack_null ());
+        view.hide_popovers ();
         view.queue_draw ();
     }
 
@@ -546,6 +547,7 @@ public class Sudoku : Gtk.Application
             return;
         game.redo ();
         redo_action.set_enabled (!game.is_redostack_null ());
+        view.hide_popovers ();
         view.queue_draw ();
     }
 
diff --git a/src/sudoku-view.vala b/src/sudoku-view.vala
index 88a4d18..9a46554 100644
--- a/src/sudoku-view.vala
+++ b/src/sudoku-view.vala
@@ -232,7 +232,7 @@ private class SudokuCellView : Gtk.DrawingArea
         }
     }
 
-    private void hide_both_popovers ()
+    public void hide_both_popovers ()
     {
         if (popover != null)
             popover.hide ();
@@ -676,4 +676,11 @@ public class SudokuView : Gtk.AspectFrame
             _highlighter = value;
         }
     }
+
+    public void hide_popovers ()
+    {
+        for (var i = 0; i < game.board.rows; i++)
+            for (var j = 0; j < game.board.cols; j++)
+                cells[i,j].hide_both_popovers ();
+    }
 }


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