Commit 123603e7 authored by Alexander Mikhaylenko's avatar Alexander Mikhaylenko Committed by Adrien Plazas

glade: Support HdyPreferencesPage

This is mostly same as for HdyPrefrencesWindow.
Signed-off-by: Alexander Mikhaylenko's avatarAlexander Mikhaylenko <alexm@gnome.org>
parent ea57c785
/*
* Copyright (C) 2020 Alexander Mikhaylenko <alexm@gnome.org>
*
* SPDX-License-Identifier: LGPL-2.1+
*
* Based on
* glade-gtk-stack.c - GladeWidgetAdaptor for GtkStack
* Copyright (C) 2014 Red Hat, Inc.
*/
#include "glade-hdy-preferences-page.h"
#include <config.h>
#include <glib/gi18n-lib.h>
#include <gladeui/glade.h>
#include "glade-hdy-utils.h"
static GtkWidget *
get_child_by_title (GtkContainer *container,
const gchar *title)
{
g_autoptr (GList) children = gtk_container_get_children (container);
GList *l;
for (l = children; l; l = l->next) {
const gchar *child_title;
g_assert (HDY_IS_PREFERENCES_GROUP (l->data));
child_title = hdy_preferences_group_get_title (HDY_PREFERENCES_GROUP (l->data));
if (child_title && !strcmp (child_title, title))
return l->data;
}
return NULL;
}
static gchar *
get_unused_title (GtkContainer *container)
{
gint i = 1;
while (TRUE) {
g_autofree gchar *title = g_strdup_printf ("Group %d", i);
if (get_child_by_title (container, title) == NULL)
return g_steal_pointer (&title);
i++;
}
return NULL;
}
static void
add_group (GladeWidgetAdaptor *adaptor,
GObject *container)
{
GladeWidget *gwidget = glade_widget_get_from_gobject (container);
GladeWidget *gpage;
GladeWidgetAdaptor *page_adaptor;
g_autofree gchar *title = get_unused_title (GTK_CONTAINER (container));
page_adaptor = glade_widget_adaptor_get_by_type (HDY_TYPE_PREFERENCES_GROUP);
gpage = glade_widget_adaptor_create_widget (page_adaptor, FALSE,
"parent", gwidget,
"project", glade_widget_get_project (gwidget),
NULL);
glade_widget_property_set (gpage, "title", title);
glade_widget_add_child (gwidget, gpage, FALSE);
}
void
glade_hdy_preferences_page_post_create (GladeWidgetAdaptor *adaptor,
GObject *container,
GladeCreateReason reason)
{
if (reason == GLADE_CREATE_USER) {
add_group (adaptor, container);
add_group (adaptor, container);
add_group (adaptor, container);
}
}
gboolean
glade_hdy_preferences_page_add_verify (GladeWidgetAdaptor *adaptor,
GtkWidget *object,
GtkWidget *child,
gboolean user_feedback)
{
if (!HDY_IS_PREFERENCES_GROUP (child)) {
if (user_feedback) {
GladeWidgetAdaptor *page_adaptor =
glade_widget_adaptor_get_by_type (HDY_TYPE_PREFERENCES_GROUP);
glade_util_ui_message (glade_app_get_window (),
GLADE_UI_INFO, NULL,
ONLY_THIS_GOES_IN_THAT_MSG,
glade_widget_adaptor_get_title (page_adaptor),
glade_widget_adaptor_get_title (adaptor));
}
return FALSE;
}
return TRUE;
}
void
glade_hdy_preferences_page_add_child (GladeWidgetAdaptor *adaptor,
GObject *object,
GObject *child)
{
gtk_container_add (GTK_CONTAINER (object), GTK_WIDGET (child));
}
void
glade_hdy_preferences_page_remove_child (GladeWidgetAdaptor *adaptor,
GObject *object,
GObject *child)
{
gtk_container_remove (GTK_CONTAINER (object), GTK_WIDGET (child));
}
void
glade_hdy_preferences_page_replace_child (GladeWidgetAdaptor *adaptor,
GObject *object,
GObject *current,
GObject *new_widget)
{
gint index = glade_hdy_get_child_index (GTK_CONTAINER (object), GTK_WIDGET (current));
gtk_container_remove (GTK_CONTAINER (object), GTK_WIDGET (current));
gtk_container_add (GTK_CONTAINER (object), GTK_WIDGET (new_widget));
glade_hdy_reorder_child (GTK_CONTAINER (object), GTK_WIDGET (new_widget), index);
}
GList *
glade_hdy_preferences_page_get_children (GladeWidgetAdaptor *adaptor,
GObject *object)
{
return gtk_container_get_children (GTK_CONTAINER (object));
}
void
glade_hdy_preferences_page_action_activate (GladeWidgetAdaptor *adaptor,
GObject *object,
const gchar *action_path)
{
GladeWidget *parent = glade_widget_get_from_gobject (object);
if (!g_strcmp0 (action_path, "add_group")) {
g_autofree gchar *title = get_unused_title (GTK_CONTAINER (object));
GladeWidget *gchild;
glade_command_push_group (_("Add group to %s"),
glade_widget_get_name (parent));
gchild = glade_command_create (glade_widget_adaptor_get_by_type (HDY_TYPE_PREFERENCES_GROUP),
parent,
NULL,
glade_widget_get_project (parent));
glade_widget_property_set (gchild, "title", title);
glade_command_pop_group ();
} else {
GWA_GET_CLASS (GTK_TYPE_CONTAINER)->action_activate (adaptor,
object,
action_path);
}
}
void
glade_hdy_preferences_page_child_set_property (GladeWidgetAdaptor *adaptor,
GObject *container,
GObject *child,
const gchar *property_name,
const GValue *value)
{
if (!g_strcmp0 (property_name, "position")) {
GtkWidget *parent = gtk_widget_get_parent (GTK_WIDGET (child));
gtk_container_child_set_property (GTK_CONTAINER (parent),
GTK_WIDGET (child), property_name, value);
} else {
GWA_GET_CLASS (GTK_TYPE_CONTAINER)->child_set_property (adaptor,
container,
child,
property_name,
value);
}
}
void
glade_hdy_preferences_page_child_get_property (GladeWidgetAdaptor *adaptor,
GObject *container,
GObject *child,
const gchar *property_name,
GValue *value)
{
if (!g_strcmp0 (property_name, "position")) {
GtkWidget *parent = gtk_widget_get_parent (GTK_WIDGET (child));
gtk_container_child_get_property (GTK_CONTAINER (parent),
GTK_WIDGET (child), property_name, value);
} else {
GWA_GET_CLASS (GTK_TYPE_CONTAINER)->child_get_property (adaptor,
container,
child,
property_name,
value);
}
}
/*
* Copyright (C) 2019 Alexander Mikhaylenko <exalm7659@gmail.com>
*
* SPDX-License-Identifier: LGPL-2.1+
*/
#pragma once
#include <gladeui/glade.h>
#define HANDY_USE_UNSTABLE_API
#include <handy.h>
void glade_hdy_preferences_page_post_create (GladeWidgetAdaptor *adaptor,
GObject *container,
GladeCreateReason reason);
gboolean glade_hdy_preferences_page_add_verify (GladeWidgetAdaptor *adaptor,
GtkWidget *object,
GtkWidget *child,
gboolean user_feedback);
void glade_hdy_preferences_page_add_child (GladeWidgetAdaptor *adaptor,
GObject *container,
GObject *child);
void glade_hdy_preferences_page_remove_child (GladeWidgetAdaptor *adaptor,
GObject *container,
GObject *child);
void glade_hdy_preferences_page_replace_child (GladeWidgetAdaptor *adaptor,
GObject *container,
GObject *current,
GObject *new_widget);
GList *glade_hdy_preferences_page_get_children (GladeWidgetAdaptor *adaptor,
GObject *object);
void glade_hdy_preferences_page_action_activate (GladeWidgetAdaptor *adaptor,
GObject *object,
const gchar *action_path);
void glade_hdy_preferences_page_child_set_property (GladeWidgetAdaptor *adaptor,
GObject *container,
GObject *child,
const gchar *property_name,
const GValue *value);
void glade_hdy_preferences_page_child_get_property (GladeWidgetAdaptor *adaptor,
GObject *container,
GObject *child,
const gchar *property_name,
GValue *value);
......@@ -262,11 +262,32 @@
</properties>
</glade-widget-class>
<glade-widget-class name="HdyPreferencesGroup" generic-name="preferencesgroup" title="Preferences Group" since="0.0.10"/>
<glade-widget-class name="HdyPreferencesPage" generic-name="preferencespage" title="Preferences Page" since="0.0.10">
<glade-widget-class name="HdyPreferencesPage" generic-name="preferencespage" title="Preferences Page" since="0.0.10" use-placeholders="False">
<post-create-function>glade_hdy_preferences_page_post_create</post-create-function>
<add-child-verify-function>glade_hdy_preferences_page_add_verify</add-child-verify-function>
<add-child-function>glade_hdy_preferences_page_add_child</add-child-function>
<remove-child-function>glade_hdy_preferences_page_remove_child</remove-child-function>
<replace-child-function>glade_hdy_preferences_page_replace_child</replace-child-function>
<get-children-function>glade_hdy_preferences_page_get_children</get-children-function>
<child-set-property-function>glade_hdy_preferences_page_child_set_property</child-set-property-function>
<child-get-property-function>glade_hdy_preferences_page_child_get_property</child-get-property-function>
<action-activate-function>glade_hdy_preferences_page_action_activate</action-activate-function>
<packing-properties>
<property id="position" name="Position" default="-1" save="False">
<parameter-spec>
<type>GParamInt</type>
<min>-1</min>
</parameter-spec>
<tooltip>The position of the group in the preferences page</tooltip>
</property>
</packing-properties>
<properties>
<property id="icon-name" themed-icon="True" />
<property id="title" translatable="True" />
</properties>
<actions>
<action id="add_group" name="Add Group" stock="list-add" important="True"/>
</actions>
</glade-widget-class>
<glade-widget-class name="HdyPreferencesRow" generic-name="preferencesrow" title="Preferences Row" since="0.0.10"/>
<glade-widget-class name="HdyPreferencesWindow" generic-name="preferenceswindow" title="Preferences Window" since="0.0.10" use-placeholders="False">
......
......@@ -22,6 +22,7 @@ libglade_hdy_sources = [
'glade-hdy-header-bar.c',
'glade-hdy-header-group.c',
'glade-hdy-leaflet.c',
'glade-hdy-preferences-page.c',
'glade-hdy-preferences-window.c',
'glade-hdy-search-bar.c',
'glade-hdy-swipe-group.c',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment