[gnome-klotski] Compile with --enable-experimental-non-null.



commit d6d59754dfbb32a38699a9ca45cd599f24f37d18
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sun Feb 9 02:11:58 2020 +0100

    Compile with --enable-experimental-non-null.

 src/gnome-klotski.vala  | 15 +++++++++------
 src/klotski-window.vala |  8 ++++++--
 src/meson.build         |  1 +
 src/puzzle-view.vala    | 22 +++++++++++++---------
 4 files changed, 29 insertions(+), 17 deletions(-)
---
diff --git a/src/gnome-klotski.vala b/src/gnome-klotski.vala
index 48426d9..3dccae9 100644
--- a/src/gnome-klotski.vala
+++ b/src/gnome-klotski.vala
@@ -24,6 +24,8 @@ private class Klotski : Gtk.Application
     /* Translators: application name, as used in the window manager, the window title, the about dialog... */
     internal const string PROGRAM_NAME = _("Klotski");
 
+    private KlotskiWindow window;
+
     private const OptionEntry [] option_entries =
     {
         /* Translators: command-line option description, see 'gnome-klotski --help' */
@@ -81,7 +83,8 @@ private class Klotski : Gtk.Application
 
         add_action_entries (action_entries, this);
 
-        add_window (new KlotskiWindow ());
+        window = new KlotskiWindow ();
+        add_window (window);
 
         set_accels_for_action ("win.prev-puzzle",   {"Up"});        // TODO
         set_accels_for_action ("win.next-puzzle",   {"Down"});      // TODO a weird behaviour exists when 
you first change puzzle pack, then go to
@@ -101,7 +104,7 @@ private class Klotski : Gtk.Application
 
     protected override void activate ()
     {
-        get_active_window ().present ();
+        window.present ();
     }
 
     /*\
@@ -110,14 +113,14 @@ private class Klotski : Gtk.Application
 
     private void scores_cb ()
     {
-        ((KlotskiWindow) get_active_window ()).show_scores ();
+        window.show_scores ();
     }
 
     private void help_cb ()
     {
         try
         {
-            show_uri (get_active_window ().get_screen (), "help:gnome-klotski", get_current_event_time ());
+            show_uri (window.get_screen (), "help:gnome-klotski", get_current_event_time ());
         }
         catch (Error e)
         {
@@ -143,7 +146,7 @@ private class Klotski : Gtk.Application
         /* Translators: text crediting a documenter, in the about dialog */
         string [] documenters = { _("Andrew Sobala") };
 
-        show_about_dialog (get_active_window (),
+        show_about_dialog (window,
                            /* Translators: name of the program, seen in the About dialog */
                            "program-name", PROGRAM_NAME,
 
@@ -173,6 +176,6 @@ private class Klotski : Gtk.Application
 
     private void quit_cb ()
     {
-        get_active_window ().destroy ();
+        window.destroy ();
     }
 }
diff --git a/src/klotski-window.vala b/src/klotski-window.vala
index a2fe684..e3234d9 100644
--- a/src/klotski-window.vala
+++ b/src/klotski-window.vala
@@ -517,7 +517,9 @@ private class KlotskiWindow : ApplicationWindow
     {
         CssProvider css_provider = new CssProvider ();
         css_provider.load_from_resource ("/org/gnome/Klotski/ui/klotski.css");
-        StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), css_provider, 
STYLE_PROVIDER_PRIORITY_APPLICATION);
+        Gdk.Screen? gdk_screen = Gdk.Screen.get_default ();
+        if (gdk_screen != null) // else..?
+            StyleContext.add_provider_for_screen ((!) gdk_screen, css_provider, 
STYLE_PROVIDER_PRIORITY_APPLICATION);
 
         settings = new GLib.Settings ("org.gnome.Klotski");
         set_default_size (settings.get_int ("window-width"), settings.get_int ("window-height"));
@@ -685,7 +687,9 @@ private class KlotskiWindow : ApplicationWindow
     private void start_puzzle_cb ()
     {
         TreeView tree = ((TreeView) (((ScrolledWindow) (stack_puzzles.get_children ().nth_data 
(current_pack))).get_child ()));
-        TreeModel model = tree.get_model ();
+        TreeModel? model = tree.get_model ();
+        if (model == null)
+            assert_not_reached ();
         TreeIter iter;
 
         if (tree.get_selection ().get_selected (out model, out iter))
diff --git a/src/meson.build b/src/meson.build
index 1e72eea..ba0949f 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -15,6 +15,7 @@ executable(meson.project_name(),[
     vala_args: [
         '--gresources', resource_files,
         '--target-glib', '2.44',
+        '--enable-experimental-non-null',
         '--vapidir', join_paths(meson.current_source_dir(), 'vapi')
     ],
     dependencies: [
diff --git a/src/puzzle-view.vala b/src/puzzle-view.vala
index 1ae7e07..dbdac41 100644
--- a/src/puzzle-view.vala
+++ b/src/puzzle-view.vala
@@ -44,19 +44,22 @@ private class PuzzleView : Gtk.DrawingArea
     private double kx = 0;
     private double ky = 0;
 
-    private Rsvg.Handle tiles_handle = null;
-    private File image_file = null;
-    private Cairo.Surface surface = null;
-
-    private Puzzle? _puzzle = null;
-    internal Puzzle? puzzle
+    private bool tiles_handle_init_done = false;
+    private Rsvg.Handle tiles_handle;
+    private File image_file;
+    private Cairo.Surface surface;
+
+    private bool puzzle_init_done = false;
+    private Puzzle _puzzle;
+    internal Puzzle puzzle
     {
-        private  get { return _puzzle; }
+        private  get { if (!puzzle_init_done) assert_not_reached (); return _puzzle; }
         internal set
         {
-            if (_puzzle != null)
+            if (puzzle_init_done)
                 SignalHandler.disconnect_by_func (_puzzle, null, this);
             _puzzle = value;
+            puzzle_init_done = true;
             _puzzle.changed.connect (puzzle_changed_cb);
             piece_x = 0;
             piece_y = 0;
@@ -113,13 +116,14 @@ private class PuzzleView : Gtk.DrawingArea
             stderr.printf ("%s %s\n", "Error in puzzle-view.vala load image:", e.message);
             Posix.exit (Posix.EXIT_FAILURE);
         }
+        tiles_handle_init_done = true;
     }
 
     protected override bool draw (Cairo.Context cr)
     {
         if (tile_size != render_size)
         {
-            if (tiles_handle != null)
+            if (tiles_handle_init_done)
             {
                 int height = tile_size * 2;
                 int width = tile_size * THEME_TILE_SEGMENTS;


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