[gnome-games/sudoku-vala] sudoku: Added displaying of note editor



commit 841b966165b89066ea4e35918f98e7bf3c4e155c
Author: LubomÃr SedlÃÅ <lubomir sedlar gmail com>
Date:   Thu Jun 30 21:43:26 2011 +0200

    sudoku: Added displaying of note editor
    
    Getting size of a not yet shown window does not work very reliably, so
    the window is displayed before moving to proper location.

 gnome-sudoku/src/sudoku-view.vala |   50 +++++++++++++++++++++++++++++++++---
 1 files changed, 45 insertions(+), 5 deletions(-)
---
diff --git a/gnome-sudoku/src/sudoku-view.vala b/gnome-sudoku/src/sudoku-view.vala
index 40560b4..b54d0c0 100644
--- a/gnome-sudoku/src/sudoku-view.vala
+++ b/gnome-sudoku/src/sudoku-view.vala
@@ -79,9 +79,9 @@ private class SudokuCellView : Gtk.DrawingArea
         }
 
         if (event.y / get_allocated_height () < 0.25)
-            stdout.printf("upper notes\n");
+            show_note_editor (0);
         else if (event.y / get_allocated_height () > 0.75)
-            stdout.printf("lower notes\n");
+            show_note_editor (1);
         else
             show_number_picker ();
 
@@ -112,7 +112,7 @@ private class SudokuCellView : Gtk.DrawingArea
                 
                 button.clicked.connect (() => {
                     cell.value = n;
-                    hide_number_picker ();
+                    hide_popup ();
                 });
 
                 if (n == 5)
@@ -128,7 +128,7 @@ private class SudokuCellView : Gtk.DrawingArea
         popup.show ();
     }
 
-    private void hide_number_picker ()
+    private void hide_popup ()
     {
         if (popup == null)
             return;
@@ -136,10 +136,50 @@ private class SudokuCellView : Gtk.DrawingArea
         popup = null;
     }
 
+    private bool editing_notes { get; set; default = false; }
+
+    private void show_note_editor (int top)
+    {
+        if (popup != null)
+            return;
+
+        editing_notes = true;
+        popup = new Gtk.Window (Gtk.WindowType.TOPLEVEL);
+        popup.decorated = false;
+        popup.resizable = false;
+        popup.skip_taskbar_hint = true;
+        popup.skip_pager_hint = true;
+        popup.set_type_hint (Gdk.WindowTypeHint.POPUP_MENU);
+        popup.set_size_request (get_allocated_width (), -1);
+
+        var entry = new Gtk.Entry ();
+        popup.add (entry);
+
+        entry.focus_out_event.connect (() => {
+            editing_notes = false;
+            hide_popup ();
+            return true;
+        });
+
+        entry.activate.connect (() => {
+            editing_notes = false;
+            stdout.printf ("activate");
+            hide_popup ();
+        });
+
+        int x, y, height;
+
+        get_window ().get_origin (out x, out y);
+        popup.show_all ();
+        popup.get_size (null, out height);
+        popup.move (x, y + top * (get_allocated_height () - height));
+    }
+
     private bool focus_out_cb (Gtk.Widget widget, Gdk.EventFocus event)
     {
+        if (editing_notes) return false;
         if (popup != null)
-            hide_number_picker ();
+            hide_popup ();
         return false;
     }
 



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