[gnome-builder] libide/tweaks: use buildable to extend objects
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide/tweaks: use buildable to extend objects
- Date: Sun, 31 Jul 2022 12:01:44 +0000 (UTC)
commit e1fbd089a2dba0b9bfec570418eb861168ff4130
Author: Christian Hergert <chergert redhat com>
Date: Sun Jul 31 04:15:40 2022 -0700
libide/tweaks: use buildable to extend objects
This relies on GNOME/gtk!4913 to work. But with that in place, we can
actually abuse the template expansion multiple times to merge various
UI elements into a single GtkBuilder.
src/libide/tweaks/ide-tweaks.c | 15 ++++++++++-----
src/libide/tweaks/test-tweaks.c | 12 ++++++++----
2 files changed, 18 insertions(+), 9 deletions(-)
---
diff --git a/src/libide/tweaks/ide-tweaks.c b/src/libide/tweaks/ide-tweaks.c
index 6192d63ae..b1d40cf0f 100644
--- a/src/libide/tweaks/ide-tweaks.c
+++ b/src/libide/tweaks/ide-tweaks.c
@@ -29,7 +29,8 @@
struct _IdeTweaks
{
- IdeTweaksItem parent_instance;
+ IdeTweaksItem parent_instance;
+ GtkBuilder *builder;
};
G_DEFINE_FINAL_TYPE (IdeTweaks, ide_tweaks, IDE_TYPE_TWEAKS_ITEM)
@@ -56,6 +57,8 @@ ide_tweaks_dispose (GObject *object)
{
IdeTweaks *self = (IdeTweaks *)object;
+ g_clear_object (&self->builder);
+
G_OBJECT_CLASS (ide_tweaks_parent_class)->dispose (object);
}
@@ -105,6 +108,8 @@ ide_tweaks_class_init (IdeTweaksClass *klass)
static void
ide_tweaks_init (IdeTweaks *self)
{
+ self->builder = gtk_builder_new ();
+ gtk_builder_set_current_object (self->builder, G_OBJECT (self));
}
IdeTweaks *
@@ -119,7 +124,6 @@ ide_tweaks_load_from_file (IdeTweaks *self,
GCancellable *cancellable,
GError **error)
{
- g_autoptr(GtkBuilder) builder = NULL;
g_autofree char *contents = NULL;
gsize length;
@@ -130,7 +134,8 @@ ide_tweaks_load_from_file (IdeTweaks *self,
if (!g_file_load_contents (file, cancellable, &contents, &length, NULL, error))
return FALSE;
- builder = gtk_builder_new ();
-
- return gtk_builder_extend_with_template (builder, G_OBJECT (self), IDE_TYPE_TWEAKS, contents, length,
error);
+ return gtk_builder_extend_with_template (self->builder,
+ G_OBJECT (self), G_OBJECT_TYPE (self),
+ contents, length,
+ error);
}
diff --git a/src/libide/tweaks/test-tweaks.c b/src/libide/tweaks/test-tweaks.c
index 050985e0d..f26decfe7 100644
--- a/src/libide/tweaks/test-tweaks.c
+++ b/src/libide/tweaks/test-tweaks.c
@@ -23,32 +23,36 @@
#include <libide-tweaks.h>
#include "ide-tweaks-init.h"
+#include "ide-tweaks-item-private.h"
int
main (int argc,
char *argv[])
{
g_autoptr(IdeTweaks) tweaks = NULL;
+ g_autoptr(GString) string = NULL;
_ide_tweaks_init ();
tweaks = ide_tweaks_new ();
+ string = g_string_new (NULL);
for (guint i = 1; i < argc; i++)
{
const char *path = argv[i];
g_autoptr(GFile) file = g_file_new_for_commandline_arg (path);
- g_autoptr(IdeTweaks) to_merge = ide_tweaks_new ();
g_autoptr(GError) error = NULL;
- if (!ide_tweaks_load_from_file (to_merge, file, NULL, &error))
+ if (!ide_tweaks_load_from_file (tweaks, file, NULL, &error))
{
g_printerr ("Failed to parse %s: %s\n", path, error->message);
return EXIT_FAILURE;
}
-
- g_print ("TODO: merge files\n");
}
+ _ide_tweaks_item_printf (IDE_TWEAKS_ITEM (tweaks), string, 0);
+
+ g_print ("%s", string->str);
+
return EXIT_SUCCESS;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]