[gnome-control-center] keyboard: Use HdyActionRow for shortcut/category



commit 959d530c443d23b068387820929e4789d71bca2e
Author: Ian Douglas Scott <idscott system76 com>
Date:   Thu Nov 12 12:10:06 2020 -0800

    keyboard: Use HdyActionRow for shortcut/category

 panels/keyboard/cc-keyboard-shortcut-dialog.c | 44 +++++--------------
 panels/keyboard/cc-keyboard-shortcut-row.c    |  8 ++--
 panels/keyboard/cc-keyboard-shortcut-row.h    |  3 +-
 panels/keyboard/cc-keyboard-shortcut-row.ui   | 61 +++++++++------------------
 4 files changed, 37 insertions(+), 79 deletions(-)
---
diff --git a/panels/keyboard/cc-keyboard-shortcut-dialog.c b/panels/keyboard/cc-keyboard-shortcut-dialog.c
index c41787eb3..a6814a3b2 100644
--- a/panels/keyboard/cc-keyboard-shortcut-dialog.c
+++ b/panels/keyboard/cc-keyboard-shortcut-dialog.c
@@ -25,7 +25,6 @@
  */
 
 #include <glib/gi18n.h>
-#define HANDY_USE_UNSTABLE_API
 #include <handy.h>
 
 #include "cc-keyboard-shortcut-dialog.h"
@@ -136,42 +135,21 @@ add_section (CcKeyboardShortcutDialog *self,
              const gchar     *section_id,
              const gchar     *section_title)
 {
-  GtkWidget *icon, *modified_label, *label, *box;
-  GtkListBoxRow *row;
+  GtkWidget *icon, *modified_label, *row;
 
-  icon = g_object_new (GTK_TYPE_IMAGE,
-                       "visible", 1,
-                       "icon_name", "go-next-symbolic",
-                       NULL);
+  icon = gtk_image_new_from_icon_name ("go-next-symbolic", GTK_ICON_SIZE_BUTTON);
   gtk_style_context_add_class (gtk_widget_get_style_context (icon), "dim-label");
 
-  modified_label = g_object_new (GTK_TYPE_LABEL,
-                                 "visible", 1,
-                                 NULL);
+  modified_label = gtk_label_new (NULL);
   gtk_style_context_add_class (gtk_widget_get_style_context (modified_label), "dim-label");
 
-  label = g_object_new (GTK_TYPE_LABEL,
-                        "visible", 1,
-                        "label", _(section_title),
-                        NULL);
-  gtk_style_context_add_class (gtk_widget_get_style_context (label), "row-label");
-
-  box = g_object_new (GTK_TYPE_BOX,
-                      "visible", 1,
-                      "spacing", 8,
-                      "margin_left", 12,
-                      "margin_right", 12,
-                      "margin_top", 8,
-                      "margin_bottom", 8,
-                      NULL);
-  gtk_container_add (GTK_CONTAINER (box), label);
-  gtk_box_pack_end (GTK_BOX (box), icon, FALSE, FALSE, 0);
-  gtk_box_pack_end (GTK_BOX (box), modified_label, FALSE, FALSE, 0);
-
-  row = g_object_new (GTK_TYPE_LIST_BOX_ROW,
-                      "visible", 1,
-                      NULL);
-  gtk_container_add (GTK_CONTAINER (row), box);
+  row = hdy_action_row_new ();
+  gtk_list_box_row_set_activatable (GTK_LIST_BOX_ROW (row), TRUE);
+  hdy_preferences_row_set_title (HDY_PREFERENCES_ROW (row), _(section_title));
+  gtk_container_add (GTK_CONTAINER (row), modified_label);
+  gtk_container_add (GTK_CONTAINER (row), icon);
+
+  gtk_widget_show_all (GTK_WIDGET (row));
 
   g_object_set_data_full (G_OBJECT (row),
                           "data",
@@ -181,7 +159,7 @@ add_section (CcKeyboardShortcutDialog *self,
   g_hash_table_insert (self->sections, g_strdup (section_id), row);
   gtk_container_add (GTK_CONTAINER (self->section_listbox), GTK_WIDGET (row));
 
-  return row;
+  return GTK_LIST_BOX_ROW (row);
 }
 
 static void
diff --git a/panels/keyboard/cc-keyboard-shortcut-row.c b/panels/keyboard/cc-keyboard-shortcut-row.c
index 6bb91d3ca..f8b901890 100644
--- a/panels/keyboard/cc-keyboard-shortcut-row.c
+++ b/panels/keyboard/cc-keyboard-shortcut-row.c
@@ -24,10 +24,9 @@
 
 struct _CcKeyboardShortcutRow
 {
-  GtkListBoxRow             parent_instance;
+  HdyActionRow              parent_instance;
 
   GtkLabel                 *accelerator_label;
-  GtkLabel                 *description_label;
   GtkButton                *reset_button;
 
   CcKeyboardItem           *item;
@@ -35,7 +34,7 @@ struct _CcKeyboardShortcutRow
   CcKeyboardShortcutEditor *shortcut_editor;
 };
 
-G_DEFINE_TYPE (CcKeyboardShortcutRow, cc_keyboard_shortcut_row, GTK_TYPE_LIST_BOX_ROW)
+G_DEFINE_TYPE (CcKeyboardShortcutRow, cc_keyboard_shortcut_row, HDY_TYPE_ACTION_ROW)
 
 static void
 reset_shortcut_cb (CcKeyboardShortcutRow *self)
@@ -50,7 +49,6 @@ cc_keyboard_shortcut_row_class_init (CcKeyboardShortcutRowClass *klass)
 
   gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/control-center/keyboard/cc-keyboard-shortcut-row.ui");
 
-  gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutRow, description_label);
   gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutRow, accelerator_label);
   gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutRow, reset_button);
 
@@ -115,7 +113,7 @@ cc_keyboard_shortcut_row_new (CcKeyboardItem *item,
   self->manager = manager;
   self->shortcut_editor = shortcut_editor;
 
-  gtk_label_set_text (self->description_label, cc_keyboard_item_get_description (item));
+  hdy_preferences_row_set_title (HDY_PREFERENCES_ROW (self), cc_keyboard_item_get_description (item));
 
   g_object_bind_property_full (item,
                                "key-combos",
diff --git a/panels/keyboard/cc-keyboard-shortcut-row.h b/panels/keyboard/cc-keyboard-shortcut-row.h
index d11143f73..919d2acdc 100644
--- a/panels/keyboard/cc-keyboard-shortcut-row.h
+++ b/panels/keyboard/cc-keyboard-shortcut-row.h
@@ -21,6 +21,7 @@
 #pragma once
 
 #include <gtk/gtk.h>
+#include <handy.h>
 #include "cc-keyboard-item.h"
 #include "cc-keyboard-manager.h"
 #include "cc-keyboard-shortcut-editor.h"
@@ -29,7 +30,7 @@ G_BEGIN_DECLS
 
 #define CC_TYPE_KEYBOARD_SHORTCUT_ROW (cc_keyboard_shortcut_row_get_type())
 
-G_DECLARE_FINAL_TYPE (CcKeyboardShortcutRow, cc_keyboard_shortcut_row, CC, KEYBOARD_SHORTCUT_ROW, 
GtkListBoxRow)
+G_DECLARE_FINAL_TYPE (CcKeyboardShortcutRow, cc_keyboard_shortcut_row, CC, KEYBOARD_SHORTCUT_ROW, 
HdyActionRow)
 
 
 CcKeyboardShortcutRow *cc_keyboard_shortcut_row_new (CcKeyboardItem*, CcKeyboardManager*, 
CcKeyboardShortcutEditor*, GtkSizeGroup*);
diff --git a/panels/keyboard/cc-keyboard-shortcut-row.ui b/panels/keyboard/cc-keyboard-shortcut-row.ui
index 87a52d77a..7a79db6d7 100644
--- a/panels/keyboard/cc-keyboard-shortcut-row.ui
+++ b/panels/keyboard/cc-keyboard-shortcut-row.ui
@@ -1,57 +1,38 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
-  <template class="CcKeyboardShortcutRow" parent="GtkListBoxRow">
+  <template class="CcKeyboardShortcutRow" parent="HdyActionRow">
     <property name="visible">True</property>
     <property name="selectable">False</property>
     <property name="activatable">True</property>
     <child>
-      <object class="GtkBox">
+      <object class="GtkLabel" id="accelerator_label">
         <property name="visible">True</property>
-        <property name="spacing">18</property>
-        <property name="margin-start">6</property>
-        <property name="margin-end">6</property>
-        <property name="margin-bottom">4</property>
-        <property name="margin-top">4</property>
-        <child>
-          <object class="GtkLabel" id="description_label">
-            <property name="visible">True</property>
-            <property name="xalign">0.0</property>
-           <property name="wrap">True</property>
-           <property name="wrap-mode">word-char</property>
-            <property name="hexpand">True</property>
-         </object>
-        </child>
+        <property name="xalign">0.0</property>
+        <property name="use-markup">True</property>
+        <style>
+          <class name="dim-label" />
+        </style>
+      </object>
+    </child>
+    <child>
+      <object class="GtkButton" id="reset_button">
+        <property name="visible">True</property>
+        <property name="valign">center</property>
+        <property name="relief">none</property>
+        <property name="tooltip-text" translatable="yes">Reset the shortcut to its default value</property>
+        <signal name="clicked" handler="reset_shortcut_cb" swapped="true"/>
         <child>
-          <object class="GtkLabel" id="accelerator_label">
+          <object class="GtkImage">
             <property name="visible">True</property>
-            <property name="xalign">0.0</property>
-            <property name="use-markup">True</property>
+            <property name="icon-name">edit-clear-symbolic</property>
+            <property name="icon-size">1</property>
             <style>
-              <class name="dim-label" />
-           </style>
-         </object>
-        </child>
-        <child>
-          <object class="GtkButton" id="reset_button">
-            <property name="visible">True</property>
-            <property name="valign">center</property>
-            <property name="relief">none</property>
-           <property name="tooltip-text" translatable="yes">Reset the shortcut to its default 
value</property>
-           <child>
-              <object class="GtkImage">
-               <property name="visible">True</property>
-               <property name="icon-name">edit-clear-symbolic</property>
-               <property name="icon-size">1</property>
-             </object>
-           </child>
-           <style>
               <class name="flat" />
               <class name="circular" />
               <class name="reset-shortcut-button" />
-           </style>
-           <signal name="clicked" handler="reset_shortcut_cb" swapped="true"/>
-         </object>
+            </style>
+          </object>
         </child>
       </object>
     </child>


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