[gnome-control-center] search: Subclass AdwActionRow for CcSearchPanelRow



commit 41c9d956ae86b6e9d0d31a871c79f436ae975c5a
Author: Christopher Davis <christopherdavis gnome org>
Date:   Sat Jan 22 14:57:42 2022 -0800

    search: Subclass AdwActionRow for CcSearchPanelRow
    
    Also set the `icon-size` to large

 panels/search/cc-search-panel-row.c  | 16 +++----
 panels/search/cc-search-panel-row.h  |  2 +-
 panels/search/cc-search-panel-row.ui | 87 +++++++++++++++---------------------
 panels/search/cc-search-panel.c      | 25 ++++-------
 4 files changed, 50 insertions(+), 80 deletions(-)
---
diff --git a/panels/search/cc-search-panel-row.c b/panels/search/cc-search-panel-row.c
index f3cb3a199..933d2df59 100644
--- a/panels/search/cc-search-panel-row.c
+++ b/panels/search/cc-search-panel-row.c
@@ -21,12 +21,11 @@
 
 struct _CcSearchPanelRow
 {
-  AdwBin         parent_instance;
+  AdwActionRow   parent_instance;
 
   GAppInfo      *app_info;
 
   GtkImage      *icon;
-  GtkLabel      *app_name;
   GtkSwitch     *switcher;
 
   GtkListBox    *drag_widget;
@@ -34,7 +33,7 @@ struct _CcSearchPanelRow
   gdouble        drag_y;
 };
 
-G_DEFINE_TYPE (CcSearchPanelRow, cc_search_panel_row, ADW_TYPE_BIN)
+G_DEFINE_TYPE (CcSearchPanelRow, cc_search_panel_row, ADW_TYPE_ACTION_ROW)
 
 enum
 {
@@ -98,7 +97,6 @@ drag_begin_cb (GtkDragSource    *source,
   CcSearchPanelRow *panel_row;
   GtkAllocation alloc;
   GtkWidget *drag_icon;
-  GtkWidget *row;
 
   gtk_widget_get_allocation (GTK_WIDGET (self), &alloc);
 
@@ -108,10 +106,8 @@ drag_begin_cb (GtkDragSource    *source,
   panel_row = cc_search_panel_row_new (self->app_info);
   gtk_switch_set_active (panel_row->switcher, gtk_switch_get_active (self->switcher));
 
-  row = gtk_list_box_row_new ();
-  gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (row), GTK_WIDGET (panel_row));
-  gtk_list_box_append (GTK_LIST_BOX (self->drag_widget), row);
-  gtk_list_box_drag_highlight_row (self->drag_widget, GTK_LIST_BOX_ROW (row));
+  gtk_list_box_append (GTK_LIST_BOX (self->drag_widget), GTK_WIDGET (panel_row));
+  gtk_list_box_drag_highlight_row (self->drag_widget, GTK_LIST_BOX_ROW (panel_row));
 
   drag_icon = gtk_drag_icon_get_for_drag (drag);
   gtk_drag_icon_set_child (GTK_DRAG_ICON (drag_icon), GTK_WIDGET (self->drag_widget));
@@ -152,7 +148,6 @@ cc_search_panel_row_class_init (CcSearchPanelRowClass *klass)
   gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/control-center/search/cc-search-panel-row.ui");
 
   gtk_widget_class_bind_template_child (widget_class, CcSearchPanelRow, icon);
-  gtk_widget_class_bind_template_child (widget_class, CcSearchPanelRow, app_name);
   gtk_widget_class_bind_template_child (widget_class, CcSearchPanelRow, switcher);
 
   gtk_widget_class_bind_template_callback (widget_class, move_up_button_clicked);
@@ -205,7 +200,8 @@ cc_search_panel_row_new (GAppInfo *app_info)
     g_object_ref (gicon);
   gtk_image_set_from_gicon (self->icon, gicon);
 
-  gtk_label_set_text (self->app_name, g_app_info_get_name (app_info));
+  adw_preferences_row_set_title (ADW_PREFERENCES_ROW (self),
+                                 g_app_info_get_name (app_info));
 
   return self;
 }
diff --git a/panels/search/cc-search-panel-row.h b/panels/search/cc-search-panel-row.h
index c9c83cb2c..f7bae837a 100644
--- a/panels/search/cc-search-panel-row.h
+++ b/panels/search/cc-search-panel-row.h
@@ -26,7 +26,7 @@ G_BEGIN_DECLS
 
 #define CC_TYPE_SEARCH_PANEL_ROW (cc_search_panel_row_get_type())
 
-G_DECLARE_FINAL_TYPE (CcSearchPanelRow, cc_search_panel_row, CC, SEARCH_PANEL_ROW, AdwBin)
+G_DECLARE_FINAL_TYPE (CcSearchPanelRow, cc_search_panel_row, CC, SEARCH_PANEL_ROW, AdwActionRow)
 
 
 CcSearchPanelRow *cc_search_panel_row_new          (GAppInfo *app_info);
diff --git a/panels/search/cc-search-panel-row.ui b/panels/search/cc-search-panel-row.ui
index 3a50d06f1..2fb7f3b73 100644
--- a/panels/search/cc-search-panel-row.ui
+++ b/panels/search/cc-search-panel-row.ui
@@ -1,59 +1,42 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
-  <!-- interface-requires gtk+ 3.0 -->
-  <template class="CcSearchPanelRow" parent="AdwBin">
-    <child>
-      <object class="GtkBox">
-        <property name="spacing">12</property>
+  <template class="CcSearchPanelRow" parent="AdwActionRow">
+    <child type="prefix">
+      <object class="GtkImage" id="icon">
+        <property name="icon-size">large</property>
+        <style>
+          <class name="lowres-icon"/>
+        </style>
+      </object>
+    </child>
+    <child type="prefix">
+      <object class="GtkImage">
+        <property name="icon-name">list-drag-handle-symbolic</property>
+        <style>
+          <class name="drag-handle"/>
+        </style>
+      </object>
+    </child>
+    <child type="suffix">
+      <object class="GtkSwitch" id="switcher">
+        <property name="valign">center</property>
+      </object>
+    </child>
+    <child type="suffix">
+      <object class="GtkSeparator">
+        <property name="orientation">vertical</property>
         <property name="margin-top">12</property>
         <property name="margin-bottom">12</property>
-        <property name="margin-start">12</property>
-        <property name="margin-end">12</property>
-        <child>
-          <object class="GtkImage">
-            <property name="icon-name">list-drag-handle-symbolic</property>
-            <style>
-              <class name="drag-handle"/>
-            </style>
-          </object>
-        </child>
-        <child>
-          <object class="GtkImage" id="icon">
-            <style>
-              <class name="lowres-icon"/>
-            </style>
-          </object>
-        </child>
-        <child>
-          <object class="GtkLabel" id="app_name">
-            <property name="hexpand">True</property>
-            <property name="ellipsize">end</property>
-            <property name="xalign">0.0</property>
-          </object>
-        </child>
-        <child>
-          <object class="GtkSwitch" id="switcher">
-            <property name="valign">center</property>
-          </object>
-        </child>
-        <child>
-          <object class="GtkSeparator">
-            <property name="orientation">vertical</property>
-          </object>
-        </child>
-        <child>
-          <object class="GtkMenuButton">
-            <property name="popover">move_row_menu</property>
-            <style>
-              <class name="flat"/>
-            </style>
-            <child>
-              <object class="GtkImage">
-                <property name="icon-name">view-more-symbolic</property>
-              </object>
-            </child>
-          </object>
-        </child>
+      </object>
+    </child>
+    <child type="suffix">
+      <object class="GtkMenuButton">
+        <property name="valign">center</property>
+        <property name="icon-name">view-more-symbolic</property>
+        <property name="popover">move_row_menu</property>
+        <style>
+          <class name="flat"/>
+        </style>
       </object>
     </child>
   </template>
diff --git a/panels/search/cc-search-panel.c b/panels/search/cc-search-panel.c
index b9227d439..661a74272 100644
--- a/panels/search/cc-search-panel.c
+++ b/panels/search/cc-search-panel.c
@@ -52,16 +52,13 @@ list_sort_func (gconstpointer a,
                 gpointer user_data)
 {
   CcSearchPanel *self = user_data;
-  GtkWidget *panel_row_a, *panel_row_b;
   GAppInfo *app_a, *app_b;
   const gchar *id_a, *id_b;
   gint idx_a, idx_b;
   gpointer lookup;
 
-  panel_row_a = gtk_list_box_row_get_child (GTK_LIST_BOX_ROW ((gpointer*)a));
-  panel_row_b = gtk_list_box_row_get_child (GTK_LIST_BOX_ROW ((gpointer*)b));
-  app_a = cc_search_panel_row_get_app_info (CC_SEARCH_PANEL_ROW (panel_row_a));
-  app_b = cc_search_panel_row_get_app_info (CC_SEARCH_PANEL_ROW (panel_row_b));
+  app_a = cc_search_panel_row_get_app_info (CC_SEARCH_PANEL_ROW ((gpointer*)a));
+  app_b = cc_search_panel_row_get_app_info (CC_SEARCH_PANEL_ROW ((gpointer*)b));
 
   id_a = g_app_info_get_id (app_a);
   id_b = g_app_info_get_id (app_b);
@@ -161,7 +158,6 @@ search_panel_move_selected (CcSearchPanel *self,
   GAppInfo *app_info, *other_app_info;
   const gchar *app_id, *other_app_id;
   const gchar *last_good_app, *target_app;
-  GtkWidget *panel_row;
   GtkWidget *aux;
   gint idx, other_idx;
   gpointer idx_ptr;
@@ -173,12 +169,11 @@ search_panel_move_selected (CcSearchPanel *self,
   /* The assertions are valid only as long as we don't move the first
      or the last item. */
 
-  aux = gtk_widget_get_parent (GTK_WIDGET (self->selected_row));
+  aux = GTK_WIDGET (self->selected_row);
   other_row = down ? GTK_LIST_BOX_ROW (gtk_widget_get_next_sibling (aux)) :
                      GTK_LIST_BOX_ROW (gtk_widget_get_prev_sibling (aux));
 
-  panel_row = gtk_list_box_row_get_child (GTK_LIST_BOX_ROW (other_row));
-  other_app_info = cc_search_panel_row_get_app_info (CC_SEARCH_PANEL_ROW (panel_row));
+  other_app_info = cc_search_panel_row_get_app_info (CC_SEARCH_PANEL_ROW (other_row));
   other_app_id = g_app_info_get_id (other_app_info);
 
   g_assert (other_app_id != NULL);
@@ -204,8 +199,7 @@ search_panel_move_selected (CcSearchPanel *self,
           break;
         }
 
-      panel_row = gtk_list_box_row_get_child (GTK_LIST_BOX_ROW (aux));
-      tmp = cc_search_panel_row_get_app_info (CC_SEARCH_PANEL_ROW (panel_row));
+      tmp = cc_search_panel_row_get_app_info (CC_SEARCH_PANEL_ROW (aux));
       tmp_id = g_app_info_get_id (tmp);
 
       last_good_app = tmp_id;
@@ -238,8 +232,7 @@ search_panel_move_selected (CcSearchPanel *self,
       GAppInfo *tmp;
       const char *tmp_id;
 
-      panel_row = gtk_list_box_row_get_child (GTK_LIST_BOX_ROW (aux));
-      tmp = cc_search_panel_row_get_app_info (CC_SEARCH_PANEL_ROW (panel_row));
+      tmp = cc_search_panel_row_get_app_info (CC_SEARCH_PANEL_ROW (aux));
       tmp_id = g_app_info_get_id (tmp);
 
       g_hash_table_replace (self->sort_order, g_strdup (tmp_id), GINT_TO_POINTER (idx));
@@ -263,10 +256,8 @@ row_moved_cb (CcSearchPanel    *self,
               CcSearchPanelRow *dest_row,
               CcSearchPanelRow *row)
 {
-  GtkWidget *dest_listbox_row = gtk_widget_get_parent (GTK_WIDGET (dest_row));
-  GtkWidget *listbox_row = gtk_widget_get_parent (GTK_WIDGET (row));
-  gint source_idx = gtk_list_box_row_get_index (GTK_LIST_BOX_ROW (listbox_row));
-  gint dest_idx = gtk_list_box_row_get_index (GTK_LIST_BOX_ROW (dest_listbox_row));
+  gint source_idx = gtk_list_box_row_get_index (GTK_LIST_BOX_ROW (row));
+  gint dest_idx = gtk_list_box_row_get_index (GTK_LIST_BOX_ROW (dest_row));
   gboolean down;
 
   self->selected_row = row;


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