[gnome-games] preferences-page-platforms: Replace custom ListboxRows with HdyActionRows



commit ee945798a38c553f506e5fb6491732f0c19bc215
Author: Neville <nevilleantony98 gmail com>
Date:   Sat May 9 20:03:15 2020 +0530

    preferences-page-platforms: Replace custom ListboxRows with HdyActionRows
    
    This will help reduce some abstractions and code as the following are no
    longer used and will be removed in the upcoming commit:
      - PreferencesPlatformsRow
      - PreferencesPlatformGenericRow
    
    Fixes #165

 data/ui/preferences-page-platforms-retro-row.ui  | 46 ++++--------------------
 data/ui/preferences-page-platforms.ui            |  1 -
 src/core/platform.vala                           |  2 +-
 src/dummy/dummy-platform.vala                    |  6 ++--
 src/generic/generic-platform.vala                |  6 ++--
 src/retro/retro-platform.vala                    |  2 +-
 src/ui/preferences-page-platforms-retro-row.vala | 17 ++++-----
 src/ui/preferences-page-platforms.vala           |  9 -----
 8 files changed, 24 insertions(+), 65 deletions(-)
---
diff --git a/data/ui/preferences-page-platforms-retro-row.ui b/data/ui/preferences-page-platforms-retro-row.ui
index bd89ae82..caa9d871 100644
--- a/data/ui/preferences-page-platforms-retro-row.ui
+++ b/data/ui/preferences-page-platforms-retro-row.ui
@@ -1,46 +1,14 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <requires lib="gtk+" version="3.24"/>
-  <template class="GamesPreferencesPagePlatformsRetroRow" parent="GtkListBoxRow">
+  <template class="GamesPreferencesPagePlatformsRetroRow" parent="HdyActionRow">
     <property name="visible">True</property>
-    <child>
-      <object class="GtkBox">
-        <property name="visible">True</property>
-        <property name="margin">10</property>
-        <property name="spacing">6</property>
-        <child>
-          <object class="GtkBox">
-            <property name="visible">True</property>
-            <property name="orientation">vertical</property>
-            <property name="hexpand">true</property>
-            <child>
-              <object class="GtkLabel" id="name_label">
-                <property name="visible">True</property>
-                <property name="ellipsize">end</property>
-                <property name="halign">start</property>
-                <property name="hexpand">true</property>
-              </object>
-            </child>
-            <child>
-              <object class="GtkLabel" id="core_label">
-                <property name="visible">True</property>
-                <property name="ellipsize">end</property>
-                <property name="halign">start</property>
-                <style>
-                  <class name="dim-label"/>
-                </style>
-              </object>
-            </child>
-          </object>
-        </child>
-        <child>
-          <object class="GtkImage" id="dropdown_arrow">
-            <property name="visible">False</property>
-            <property name="icon-name">pan-down-symbolic</property>
-          </object>
-        </child>
-      </object>
-    </child>
+      <child>
+        <object class="GtkImage" id="dropdown_arrow">
+          <property name="visible">False</property>
+          <property name="icon-name">pan-down-symbolic</property>
+        </object>
+      </child>
   </template>
   <object class="GtkPopover" id="details_popover">
     <property name="visible">False</property>
diff --git a/data/ui/preferences-page-platforms.ui b/data/ui/preferences-page-platforms.ui
index e1cb326f..b52f576f 100644
--- a/data/ui/preferences-page-platforms.ui
+++ b/data/ui/preferences-page-platforms.ui
@@ -7,7 +7,6 @@
       <object class="GtkListBox" id="list_box">
         <property name="selection-mode">none</property>
         <property name="visible">true</property>
-        <signal name="row-activated" handler="on_row_activated"/>
         <style>
           <class name="rounded"/>
           <class name="separators"/>
diff --git a/src/core/platform.vala b/src/core/platform.vala
index 966be821..7350ca34 100644
--- a/src/core/platform.vala
+++ b/src/core/platform.vala
@@ -7,7 +7,7 @@ public interface Games.Platform : Object {
 
        public abstract string get_uid_prefix ();
 
-       public abstract PreferencesPagePlatformsRow get_row ();
+       public abstract Hdy.ActionRow get_row ();
 
        public abstract Type get_snapshot_type ();
 
diff --git a/src/dummy/dummy-platform.vala b/src/dummy/dummy-platform.vala
index 9eb40fb4..5c080482 100644
--- a/src/dummy/dummy-platform.vala
+++ b/src/dummy/dummy-platform.vala
@@ -13,8 +13,10 @@ public class Games.DummyPlatform : Object, Platform {
                return "unknown";
        }
 
-       public PreferencesPagePlatformsRow get_row () {
-               return new PreferencesPagePlatformsGenericRow (_("Unknown"));
+       public Hdy.ActionRow get_row () {
+               var generic_row = new Hdy.ActionRow ();
+               generic_row.title = _("Unknown");
+               return generic_row;
        }
 
        public Type get_snapshot_type () {
diff --git a/src/generic/generic-platform.vala b/src/generic/generic-platform.vala
index 5c3e4c47..e9d254e7 100644
--- a/src/generic/generic-platform.vala
+++ b/src/generic/generic-platform.vala
@@ -23,8 +23,10 @@ public class Games.GenericPlatform : Object, Platform {
                return uid_prefix;
        }
 
-       public PreferencesPagePlatformsRow get_row () {
-               return new PreferencesPagePlatformsGenericRow (name);
+       public Hdy.ActionRow get_row () {
+               var generic_row = new Hdy.ActionRow ();
+               generic_row.title = name;
+               return generic_row;
        }
 
        public Type get_snapshot_type () {
diff --git a/src/retro/retro-platform.vala b/src/retro/retro-platform.vala
index 90e816fd..f2bf34d1 100644
--- a/src/retro/retro-platform.vala
+++ b/src/retro/retro-platform.vala
@@ -29,7 +29,7 @@ public class Games.RetroPlatform : Object, Platform {
                return mime_types;
        }
 
-       public PreferencesPagePlatformsRow get_row () {
+       public Hdy.ActionRow get_row () {
                return new PreferencesPagePlatformsRetroRow (this);
        }
 
diff --git a/src/ui/preferences-page-platforms-retro-row.vala 
b/src/ui/preferences-page-platforms-retro-row.vala
index 52ebe035..19a8a05f 100644
--- a/src/ui/preferences-page-platforms-retro-row.vala
+++ b/src/ui/preferences-page-platforms-retro-row.vala
@@ -1,11 +1,7 @@
 // This file is part of GNOME Games. License: GPL-3.0+.
 
 [GtkTemplate (ui = "/org/gnome/Games/ui/preferences-page-platforms-retro-row.ui")]
-private class Games.PreferencesPagePlatformsRetroRow : PreferencesPagePlatformsRow, Gtk.ListBoxRow {
-       [GtkChild]
-       private Gtk.Label name_label;
-       [GtkChild]
-       private Gtk.Label core_label;
+private class Games.PreferencesPagePlatformsRetroRow : Hdy.ActionRow {
        [GtkChild]
        private Gtk.Popover details_popover;
        [GtkChild]
@@ -23,7 +19,7 @@ private class Games.PreferencesPagePlatformsRetroRow : PreferencesPagePlatformsR
        construct {
                list_box.set_header_func (update_header);
 
-               name_label.label = platform.get_name ();
+               title = platform.get_name ();
 
                refresh_cores ();
 
@@ -45,17 +41,17 @@ private class Games.PreferencesPagePlatformsRetroRow : PreferencesPagePlatformsR
                        /* Translators: This is displayed under the platform name when no
                         * core is available for this platform. To see this message, click
                         * on the hamburger menu, click on Preferences, then on Platforms */
-                       core_label.label = _("None");
+                       subtitle = _("None");
                else {
                        try {
-                               core_label.label = preferred_core.get_name ();
+                               subtitle = preferred_core.get_name ();
                        }
                        catch (Error e) {
                                critical (e.message);
                        /* Translators: This is displayed under the platform name when no
                         * core is available for this platform. To see this message, click
                         * on the hamburger menu, click on Preferences, then on Platforms */
-                               core_label.label = _("None");
+                               subtitle = _("None");
                        }
                }
        }
@@ -68,6 +64,7 @@ private class Games.PreferencesPagePlatformsRetroRow : PreferencesPagePlatformsR
 
                sensitive = (num_cores > 0);
                dropdown_arrow.visible = (num_cores > 1);
+               activatable = (num_cores > 1);
 
                row_cores = new HashTable<Gtk.Widget, Retro.CoreDescriptor> (null, null);
 
@@ -93,7 +90,7 @@ private class Games.PreferencesPagePlatformsRetroRow : PreferencesPagePlatformsR
                update_label ();
        }
 
-       public void on_activated () {
+       public override void activate () {
                if (num_cores <= 1)
                        return;
 
diff --git a/src/ui/preferences-page-platforms.vala b/src/ui/preferences-page-platforms.vala
index 9dc33d1c..833780e5 100644
--- a/src/ui/preferences-page-platforms.vala
+++ b/src/ui/preferences-page-platforms.vala
@@ -18,13 +18,4 @@ private class Games.PreferencesPagePlatforms : PreferencesPage {
                        list_box.add (row);
                }
        }
-
-       [GtkCallback]
-       private void on_row_activated (Gtk.ListBoxRow row) {
-               assert (row is PreferencesPagePlatformsRow);
-
-               var platforms_row = row as PreferencesPagePlatformsRow;
-
-               platforms_row.on_activated ();
-       }
 }


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