[gnome-games] ui: Prefer construct{} to construct property setters



commit cf1d6bf824fae083f23e4480302792420bbff8b4
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Thu Aug 22 02:13:41 2019 +0500

    ui: Prefer construct{} to construct property setters

 src/ui/collection-header-bar.vala                | 17 +++++++----------
 src/ui/collection-view.vala                      | 19 ++++++-------------
 src/ui/game-icon-view.vala                       | 22 +++++++++-------------
 src/ui/platform-list-item.vala                   | 11 ++++-------
 src/ui/preferences-page-platforms-retro-row.vala | 23 +++++++++--------------
 src/ui/preferences-sidebar-item.vala             | 11 ++++-------
 6 files changed, 39 insertions(+), 64 deletions(-)
---
diff --git a/src/ui/collection-header-bar.vala b/src/ui/collection-header-bar.vala
index 0d59fc67..2e11430c 100644
--- a/src/ui/collection-header-bar.vala
+++ b/src/ui/collection-header-bar.vala
@@ -27,16 +27,7 @@ private class Games.CollectionHeaderBar : Gtk.Bin {
                }
        }
 
-       private AdaptiveState _adaptive_state;
-       public AdaptiveState adaptive_state {
-               get { return _adaptive_state; }
-               construct {
-                       _adaptive_state = value;
-                       adaptive_state.notify["is-folded"].connect (update_subview);
-                       adaptive_state.notify["is-subview-open"].connect (update_subview);
-                       adaptive_state.notify["subview-title"].connect (update_subview_title);
-               }
-       }
+       public AdaptiveState adaptive_state { get; construct; }
 
        [GtkChild]
        private Gtk.Stack stack;
@@ -51,6 +42,12 @@ private class Games.CollectionHeaderBar : Gtk.Bin {
 
        private ulong viewstack_child_changed_id;
 
+       construct {
+               adaptive_state.notify["is-folded"].connect (update_subview);
+               adaptive_state.notify["is-subview-open"].connect (update_subview);
+               adaptive_state.notify["subview-title"].connect (update_subview_title);
+       }
+
        public CollectionHeaderBar (AdaptiveState adaptive_state) {
                Object (adaptive_state: adaptive_state);
        }
diff --git a/src/ui/collection-view.vala b/src/ui/collection-view.vala
index e383d41e..517164fb 100644
--- a/src/ui/collection-view.vala
+++ b/src/ui/collection-view.vala
@@ -33,19 +33,7 @@ private class Games.CollectionView : Object, UiView {
        }
 
        public Gtk.Window window { get; construct set; }
-
-       private ListModel _collection;
-       public ListModel collection {
-               get { return _collection; }
-               construct set {
-                       _collection = value;
-
-                       collection.items_changed.connect (() => {
-                               is_collection_empty = collection.get_n_items () == 0;
-                       });
-                       is_collection_empty = collection.get_n_items () == 0;
-               }
-       }
+       public ListModel collection { get; construct; }
 
        public bool loading_notification { get; set; }
        public bool search_mode { get; set; }
@@ -69,6 +57,11 @@ private class Games.CollectionView : Object, UiView {
                        game_activated (game);
                });
 
+               collection.items_changed.connect (() => {
+                       is_collection_empty = collection.get_n_items () == 0;
+               });
+               is_collection_empty = collection.get_n_items () == 0;
+
                header_bar.viewstack = box.viewstack;
                is_collection_empty = true;
 
diff --git a/src/ui/game-icon-view.vala b/src/ui/game-icon-view.vala
index a8e7f273..afad2058 100644
--- a/src/ui/game-icon-view.vala
+++ b/src/ui/game-icon-view.vala
@@ -2,24 +2,20 @@
 
 [GtkTemplate (ui = "/org/gnome/Games/ui/game-icon-view.ui")]
 private class Games.GameIconView : Gtk.Box {
-       private Game _game;
-       public Game game {
-               get { return _game; }
-               construct {
-                       _game = value;
-
-                       thumbnail.uid = game.get_uid ();
-                       thumbnail.icon = game.get_icon ();
-                       thumbnail.cover = game.get_cover ();
-                       title.label = game.name;
-               }
-       }
-
        [GtkChild]
        private GameThumbnail thumbnail;
        [GtkChild]
        private Gtk.Label title;
 
+       public Game game { get; construct; }
+
+       construct {
+               thumbnail.uid = game.get_uid ();
+               thumbnail.icon = game.get_icon ();
+               thumbnail.cover = game.get_cover ();
+               title.label = game.name;
+       }
+
        public GameIconView (Game game) {
                Object (game: game);
        }
diff --git a/src/ui/platform-list-item.vala b/src/ui/platform-list-item.vala
index ff4c9837..3fd6c13e 100644
--- a/src/ui/platform-list-item.vala
+++ b/src/ui/platform-list-item.vala
@@ -5,13 +5,10 @@ private class Games.PlatformListItem : Gtk.ListBoxRow {
        [GtkChild]
        protected Gtk.Label label;
 
-       private Platform _platform;
-       public Platform platform {
-               get { return _platform; }
-               construct {
-                       _platform = value;
-                       label.label = value.get_name ();
-               }
+       public Platform platform { get; construct; }
+
+       construct {
+               label.label = platform.get_name ();
        }
 
        public PlatformListItem (Platform platform) {
diff --git a/src/ui/preferences-page-platforms-retro-row.vala 
b/src/ui/preferences-page-platforms-retro-row.vala
index 49ca9c56..5404bf25 100644
--- a/src/ui/preferences-page-platforms-retro-row.vala
+++ b/src/ui/preferences-page-platforms-retro-row.vala
@@ -18,24 +18,19 @@ private class Games.PreferencesPagePlatformsRetroRow : PreferencesPagePlatformsR
        private HashTable<Gtk.Widget, Retro.CoreDescriptor> row_cores;
        private int num_cores;
 
-       private RetroPlatform _platform;
-       public RetroPlatform platform {
-               get { return _platform; }
-               construct {
-                       _platform = value;
-                       name_label.label = value.get_name ();
+       public RetroPlatform platform { get; construct; }
 
-                       refresh_cores ();
+       construct {
+               list_box.set_header_func (update_header);
 
-                       var path = "/org/gnome/Games/platforms/%s/".printf (value.get_id ());
-                       settings = new Settings.with_path ("org.gnome.Games.platforms", path);
+               name_label.label = platform.get_name ();
 
-                       settings.changed.connect (update_label);
-               }
-       }
+               refresh_cores ();
 
-       construct {
-               list_box.set_header_func (update_header);
+               var path = "/org/gnome/Games/platforms/%s/".printf (platform.get_id ());
+               settings = new Settings.with_path ("org.gnome.Games.platforms", path);
+
+               settings.changed.connect (update_label);
        }
 
        public PreferencesPagePlatformsRetroRow (RetroPlatform platform) {
diff --git a/src/ui/preferences-sidebar-item.vala b/src/ui/preferences-sidebar-item.vala
index f0ec8ede..35e2b9c2 100644
--- a/src/ui/preferences-sidebar-item.vala
+++ b/src/ui/preferences-sidebar-item.vala
@@ -5,13 +5,10 @@ private class Games.PreferencesSidebarItem : Gtk.ListBoxRow {
        [GtkChild]
        private Gtk.Label label;
 
-       private PreferencesPage _preferences_page;
-       public PreferencesPage preferences_page {
-               get { return _preferences_page; }
-               construct {
-                       _preferences_page = value;
-                       label.label = value.title;
-               }
+       public PreferencesPage preferences_page { get; construct; }
+
+       construct {
+               label.label = preferences_page.title;
        }
 
        public PreferencesSidebarItem (PreferencesPage preferences_page) {


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