gplugin/gplugin

Toggle plugin details when the row is activated

2021-12-06, Elliott Sales de Andrade
101652e352e8
Parents 0a057bd05094
Children 37f9d0575d3c
Toggle plugin details when the row is activated
--- a/gplugin-gtk4/data/plugin-row.ui Mon Dec 06 22:37:09 2021 -0600
+++ b/gplugin-gtk4/data/plugin-row.ui Mon Dec 06 22:37:09 2021 -0600
@@ -104,7 +104,7 @@
<child>
<object class="GtkRevealer" id="revealer">
<property name="can-focus">0</property>
- <property name="reveal-child" bind-source="expander" bind-property="expanded" bind-flags="sync-create"/>
+ <property name="reveal-child" bind-source="expander" bind-property="expanded" bind-flags="bidirectional|sync-create"/>
<property name="child">
<object class="GtkBox">
<property name="can-focus">0</property>
--- a/gplugin-gtk4/data/view.ui Mon Dec 06 22:37:09 2021 -0600
+++ b/gplugin-gtk4/data/view.ui Mon Dec 06 22:37:09 2021 -0600
@@ -28,6 +28,7 @@
<object class="GtkListBox" id="list_box">
<property name="selection-mode">none</property>
<property name="show-separators">1</property>
+ <signal name="row-activated" handler="gplugin_gtk_view_row_activated"/>
<child type="placeholder">
<object class="GtkLabel">
<property name="label" translatable="yes">No plugins found</property>
--- a/gplugin-gtk4/gplugin-gtk-plugin-row.c Mon Dec 06 22:37:09 2021 -0600
+++ b/gplugin-gtk4/gplugin-gtk-plugin-row.c Mon Dec 06 22:37:09 2021 -0600
@@ -43,6 +43,7 @@
GtkWidget *summary;
GtkWidget *version;
GtkWidget *config;
+ GtkWidget *revealer;
/* Details */
GtkWidget *description;
@@ -64,6 +65,7 @@
enum {
PROP_ZERO,
PROP_PLUGIN,
+ PROP_EXPANDED,
N_PROPERTIES,
};
static GParamSpec *properties[N_PROPERTIES] = {
@@ -247,6 +249,9 @@
case PROP_PLUGIN:
gplugin_gtk_plugin_row_set_plugin(row, g_value_get_object(value));
break;
+ case PROP_EXPANDED:
+ gplugin_gtk_plugin_row_set_expanded(row, g_value_get_boolean(value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec);
break;
@@ -266,6 +271,9 @@
case PROP_PLUGIN:
g_value_set_object(value, gplugin_gtk_plugin_row_get_plugin(row));
break;
+ case PROP_EXPANDED:
+ g_value_set_boolean(value, gplugin_gtk_plugin_row_get_expanded(row));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec);
break;
@@ -311,6 +319,12 @@
"The GPluginPlugin whose info should be displayed",
G_TYPE_OBJECT,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
+ properties[PROP_EXPANDED] = g_param_spec_boolean(
+ "expanded",
+ "expanded",
+ "Whether the row has been opened to show details",
+ FALSE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
/* template stuff */
gtk_widget_class_set_template_from_resource(
@@ -338,6 +352,10 @@
widget_class,
GPluginGtkPluginRow,
config);
+ gtk_widget_class_bind_template_child(
+ widget_class,
+ GPluginGtkPluginRow,
+ revealer);
/* Details */
gtk_widget_class_bind_template_child(
@@ -459,6 +477,37 @@
}
/**
+ * gplugin_gtk_plugin_row_get_expanded:
+ * @row: The plugin row instance.
+ *
+ * Returns whether the plugin row is showing detailed information.
+ *
+ * Returns: %TRUE if the plugin row is expanded, %FALSE otherwise.
+ */
+gboolean
+gplugin_gtk_plugin_row_get_expanded(GPluginGtkPluginRow *row)
+{
+ g_return_val_if_fail(GPLUGIN_GTK_IS_PLUGIN_ROW(row), FALSE);
+
+ return gtk_revealer_get_reveal_child(GTK_REVEALER(row->revealer));
+}
+
+/**
+ * gplugin_gtk_plugin_row_set_expanded:
+ * @row: The plugin row instance.
+ * @expanded: Whether the plugin row is expanded.
+ *
+ * Sets whether the plugin row is showing detailed information.
+ */
+void
+gplugin_gtk_plugin_row_set_expanded(GPluginGtkPluginRow *row, gboolean expanded)
+{
+ g_return_if_fail(GPLUGIN_GTK_IS_PLUGIN_ROW(row));
+
+ gtk_revealer_set_reveal_child(GTK_REVEALER(row->revealer), expanded);
+}
+
+/**
* gplugin_gtk_plugin_row_get_sort_key:
* @row: The plugin row instance.
*
--- a/gplugin-gtk4/gplugin-gtk-plugin-row.h Mon Dec 06 22:37:09 2021 -0600
+++ b/gplugin-gtk4/gplugin-gtk-plugin-row.h Mon Dec 06 22:37:09 2021 -0600
@@ -46,6 +46,8 @@
GPluginGtkPluginRow *row,
GPluginPlugin *plugin);
GPluginPlugin *gplugin_gtk_plugin_row_get_plugin(GPluginGtkPluginRow *row);
+gboolean gplugin_gtk_plugin_row_get_expanded(GPluginGtkPluginRow *row);
+void gplugin_gtk_plugin_row_set_expanded(GPluginGtkPluginRow *row, gboolean expanded);
gchar *gplugin_gtk_plugin_row_get_sort_key(GPluginGtkPluginRow *row);
gboolean gplugin_gtk_plugin_row_matches_search(
GPluginGtkPluginRow *row,
--- a/gplugin-gtk4/gplugin-gtk-view.c Mon Dec 06 22:37:09 2021 -0600
+++ b/gplugin-gtk4/gplugin-gtk-view.c Mon Dec 06 22:37:09 2021 -0600
@@ -58,6 +58,17 @@
* Helpers
*****************************************************************************/
static void
+gplugin_gtk_view_row_activated(G_GNUC_UNUSED GtkListBox *box,
+ GtkListBoxRow *row, G_GNUC_UNUSED gpointer data)
+{
+ GPluginGtkPluginRow *plugin_row = GPLUGIN_GTK_PLUGIN_ROW(row);
+
+ gplugin_gtk_plugin_row_set_expanded(
+ plugin_row,
+ !gplugin_gtk_plugin_row_get_expanded(plugin_row));
+}
+
+static void
gplugin_gtk_view_add_plugins_to_list(
G_GNUC_UNUSED const gchar *id,
GSList *plugins,
@@ -218,6 +229,9 @@
gtk_widget_class_bind_template_callback(
widget_class,
+ gplugin_gtk_view_row_activated);
+ gtk_widget_class_bind_template_callback(
+ widget_class,
gplugin_gtk_view_search_changed);
/* properties */