keyboard: Use HdyActionRow for shortcut/category

This commit is contained in:
Ian Douglas Scott 2020-11-12 12:10:06 -08:00
parent a7d526f70b
commit 959d530c44
4 changed files with 36 additions and 78 deletions

View file

@ -25,7 +25,6 @@
*/ */
#include <glib/gi18n.h> #include <glib/gi18n.h>
#define HANDY_USE_UNSTABLE_API
#include <handy.h> #include <handy.h>
#include "cc-keyboard-shortcut-dialog.h" #include "cc-keyboard-shortcut-dialog.h"
@ -136,42 +135,21 @@ add_section (CcKeyboardShortcutDialog *self,
const gchar *section_id, const gchar *section_id,
const gchar *section_title) const gchar *section_title)
{ {
GtkWidget *icon, *modified_label, *label, *box; GtkWidget *icon, *modified_label, *row;
GtkListBoxRow *row;
icon = g_object_new (GTK_TYPE_IMAGE, icon = gtk_image_new_from_icon_name ("go-next-symbolic", GTK_ICON_SIZE_BUTTON);
"visible", 1,
"icon_name", "go-next-symbolic",
NULL);
gtk_style_context_add_class (gtk_widget_get_style_context (icon), "dim-label"); gtk_style_context_add_class (gtk_widget_get_style_context (icon), "dim-label");
modified_label = g_object_new (GTK_TYPE_LABEL, modified_label = gtk_label_new (NULL);
"visible", 1,
NULL);
gtk_style_context_add_class (gtk_widget_get_style_context (modified_label), "dim-label"); gtk_style_context_add_class (gtk_widget_get_style_context (modified_label), "dim-label");
label = g_object_new (GTK_TYPE_LABEL, row = hdy_action_row_new ();
"visible", 1, gtk_list_box_row_set_activatable (GTK_LIST_BOX_ROW (row), TRUE);
"label", _(section_title), hdy_preferences_row_set_title (HDY_PREFERENCES_ROW (row), _(section_title));
NULL); gtk_container_add (GTK_CONTAINER (row), modified_label);
gtk_style_context_add_class (gtk_widget_get_style_context (label), "row-label"); gtk_container_add (GTK_CONTAINER (row), icon);
box = g_object_new (GTK_TYPE_BOX, gtk_widget_show_all (GTK_WIDGET (row));
"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);
g_object_set_data_full (G_OBJECT (row), g_object_set_data_full (G_OBJECT (row),
"data", "data",
@ -181,7 +159,7 @@ add_section (CcKeyboardShortcutDialog *self,
g_hash_table_insert (self->sections, g_strdup (section_id), row); g_hash_table_insert (self->sections, g_strdup (section_id), row);
gtk_container_add (GTK_CONTAINER (self->section_listbox), GTK_WIDGET (row)); gtk_container_add (GTK_CONTAINER (self->section_listbox), GTK_WIDGET (row));
return row; return GTK_LIST_BOX_ROW (row);
} }
static void static void

View file

@ -24,10 +24,9 @@
struct _CcKeyboardShortcutRow struct _CcKeyboardShortcutRow
{ {
GtkListBoxRow parent_instance; HdyActionRow parent_instance;
GtkLabel *accelerator_label; GtkLabel *accelerator_label;
GtkLabel *description_label;
GtkButton *reset_button; GtkButton *reset_button;
CcKeyboardItem *item; CcKeyboardItem *item;
@ -35,7 +34,7 @@ struct _CcKeyboardShortcutRow
CcKeyboardShortcutEditor *shortcut_editor; 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 static void
reset_shortcut_cb (CcKeyboardShortcutRow *self) 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_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, accelerator_label);
gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutRow, reset_button); 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->manager = manager;
self->shortcut_editor = shortcut_editor; 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, g_object_bind_property_full (item,
"key-combos", "key-combos",

View file

@ -21,6 +21,7 @@
#pragma once #pragma once
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <handy.h>
#include "cc-keyboard-item.h" #include "cc-keyboard-item.h"
#include "cc-keyboard-manager.h" #include "cc-keyboard-manager.h"
#include "cc-keyboard-shortcut-editor.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()) #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*); CcKeyboardShortcutRow *cc_keyboard_shortcut_row_new (CcKeyboardItem*, CcKeyboardManager*, CcKeyboardShortcutEditor*, GtkSizeGroup*);

View file

@ -1,57 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<interface> <interface>
<!-- interface-requires gtk+ 3.0 --> <!-- interface-requires gtk+ 3.0 -->
<template class="CcKeyboardShortcutRow" parent="GtkListBoxRow"> <template class="CcKeyboardShortcutRow" parent="HdyActionRow">
<property name="visible">True</property> <property name="visible">True</property>
<property name="selectable">False</property> <property name="selectable">False</property>
<property name="activatable">True</property> <property name="activatable">True</property>
<child> <child>
<object class="GtkBox"> <object class="GtkLabel" id="accelerator_label">
<property name="visible">True</property> <property name="visible">True</property>
<property name="spacing">18</property> <property name="xalign">0.0</property>
<property name="margin-start">6</property> <property name="use-markup">True</property>
<property name="margin-end">6</property> <style>
<property name="margin-bottom">4</property> <class name="dim-label" />
<property name="margin-top">4</property> </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> <child>
<object class="GtkLabel" id="description_label"> <object class="GtkImage">
<property name="visible">True</property> <property name="visible">True</property>
<property name="xalign">0.0</property> <property name="icon-name">edit-clear-symbolic</property>
<property name="wrap">True</property> <property name="icon-size">1</property>
<property name="wrap-mode">word-char</property>
<property name="hexpand">True</property>
</object>
</child>
<child>
<object class="GtkLabel" id="accelerator_label">
<property name="visible">True</property>
<property name="xalign">0.0</property>
<property name="use-markup">True</property>
<style> <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="flat" />
<class name="circular" /> <class name="circular" />
<class name="reset-shortcut-button" /> <class name="reset-shortcut-button" />
</style> </style>
<signal name="clicked" handler="reset_shortcut_cb" swapped="true"/> </object>
</object>
</child> </child>
</object> </object>
</child> </child>