[gnome-builder/wip/gtk4-port: 132/736] libide/gui: port environment editor to gtk 4
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port: 132/736] libide/gui: port environment editor to gtk 4
- Date: Tue, 26 Apr 2022 01:46:16 +0000 (UTC)
commit 6abf7a4cab29a4f5c1f35a93bf51e5b65b830ecc
Author: Christian Hergert <chergert redhat com>
Date: Mon Mar 28 17:40:24 2022 -0700
libide/gui: port environment editor to gtk 4
src/libide/gui/ide-environment-editor.c | 60 +++++++++++++++++++++------------
src/libide/gui/ide-environment-editor.h | 15 ++++++---
2 files changed, 48 insertions(+), 27 deletions(-)
---
diff --git a/src/libide/gui/ide-environment-editor.c b/src/libide/gui/ide-environment-editor.c
index 13c016af7..bfe95cfb0 100644
--- a/src/libide/gui/ide-environment-editor.c
+++ b/src/libide/gui/ide-environment-editor.c
@@ -29,14 +29,16 @@
struct _IdeEnvironmentEditor
{
- GtkListBox parent_instance;
- IdeEnvironment *environment;
- GtkWidget *dummy_row;
+ GtkWidget parent_instance;
+
+ GtkListBox *list_box;
+ IdeEnvironment *environment;
+ GtkWidget *dummy_row;
IdeEnvironmentVariable *dummy;
};
-G_DEFINE_FINAL_TYPE (IdeEnvironmentEditor, ide_environment_editor, GTK_TYPE_LIST_BOX)
+G_DEFINE_FINAL_TYPE (IdeEnvironmentEditor, ide_environment_editor, GTK_TYPE_WIDGET)
enum {
PROP_0,
@@ -113,7 +115,7 @@ ide_environment_editor_disconnect (IdeEnvironmentEditor *self)
g_assert (IDE_IS_ENVIRONMENT_EDITOR (self));
g_assert (IDE_IS_ENVIRONMENT (self->environment));
- gtk_list_box_bind_model (GTK_LIST_BOX (self), NULL, NULL, NULL, NULL);
+ gtk_list_box_bind_model (self->list_box, NULL, NULL, NULL, NULL);
g_clear_object (&self->dummy);
}
@@ -124,12 +126,12 @@ ide_environment_editor_connect (IdeEnvironmentEditor *self)
g_assert (IDE_IS_ENVIRONMENT_EDITOR (self));
g_assert (IDE_IS_ENVIRONMENT (self->environment));
- gtk_list_box_bind_model (GTK_LIST_BOX (self),
+ gtk_list_box_bind_model (self->list_box,
G_LIST_MODEL (self->environment),
ide_environment_editor_create_row, self, NULL);
self->dummy_row = ide_environment_editor_create_dummy_row (self);
- gtk_container_add (GTK_CONTAINER (self), self->dummy_row);
+ gtk_list_box_append (self->list_box, self->dummy_row);
}
static void
@@ -167,17 +169,24 @@ find_row (IdeEnvironmentEditor *self,
g_assert (IDE_IS_ENVIRONMENT_EDITOR (self));
g_assert (IDE_IS_ENVIRONMENT_VARIABLE (variable));
- gtk_container_foreach (GTK_CONTAINER (self), find_row_cb, &lookup);
+ for (GtkWidget *child = gtk_widget_get_first_child (GTK_WIDGET (self->list_box));
+ child != NULL;
+ child = gtk_widget_get_next_sibling (child))
+ {
+ find_row_cb (child, &lookup);
+ if (lookup.row)
+ return lookup.row;
+ }
return lookup.row;
}
static void
-ide_environment_editor_row_activated (GtkListBox *list_box,
- GtkListBoxRow *row)
+ide_environment_editor_row_activated (IdeEnvironmentEditor *self,
+ GtkListBoxRow *row,
+ GtkListBox *list_box)
{
- IdeEnvironmentEditor *self = (IdeEnvironmentEditor *)list_box;
-
+ g_assert (IDE_IS_ENVIRONMENT_EDITOR (self));
g_assert (GTK_IS_LIST_BOX (list_box));
g_assert (GTK_IS_LIST_BOX_ROW (row));
@@ -195,13 +204,14 @@ ide_environment_editor_row_activated (GtkListBox *list_box,
}
static void
-ide_environment_editor_destroy (GtkWidget *widget)
+ide_environment_editor_dispose (GObject *object)
{
- IdeEnvironmentEditor *self = (IdeEnvironmentEditor *)widget;
-
- GTK_WIDGET_CLASS (ide_environment_editor_parent_class)->destroy (widget);
+ IdeEnvironmentEditor *self = (IdeEnvironmentEditor *)object;
+ g_clear_pointer ((GtkWidget **)&self->list_box, gtk_widget_unparent);
g_clear_object (&self->environment);
+
+ G_OBJECT_CLASS (ide_environment_editor_parent_class)->dispose (object);
}
static void
@@ -247,15 +257,11 @@ ide_environment_editor_class_init (IdeEnvironmentEditorClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
- GtkListBoxClass *list_box_class = GTK_LIST_BOX_CLASS (klass);
+ object_class->dispose = ide_environment_editor_dispose;
object_class->get_property = ide_environment_editor_get_property;
object_class->set_property = ide_environment_editor_set_property;
- widget_class->destroy = ide_environment_editor_destroy;
-
- list_box_class->row_activated = ide_environment_editor_row_activated;
-
properties [PROP_ENVIRONMENT] =
g_param_spec_object ("environment",
"Environment",
@@ -264,12 +270,22 @@ ide_environment_editor_class_init (IdeEnvironmentEditorClass *klass)
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_properties (object_class, LAST_PROP, properties);
+
+ gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
}
static void
ide_environment_editor_init (IdeEnvironmentEditor *self)
{
- gtk_list_box_set_selection_mode (GTK_LIST_BOX (self), GTK_SELECTION_NONE);
+ self->list_box = g_object_new (GTK_TYPE_LIST_BOX,
+ "selection-mode", GTK_SELECTION_NONE,
+ NULL);
+ g_signal_connect_object (self->list_box,
+ "row-activated",
+ G_CALLBACK (ide_environment_editor_row_activated),
+ self,
+ G_CONNECT_SWAPPED);
+ gtk_widget_set_parent (GTK_WIDGET (self->list_box), GTK_WIDGET (self));
}
GtkWidget *
diff --git a/src/libide/gui/ide-environment-editor.h b/src/libide/gui/ide-environment-editor.h
index 2a5731da2..c999a8bac 100644
--- a/src/libide/gui/ide-environment-editor.h
+++ b/src/libide/gui/ide-environment-editor.h
@@ -20,7 +20,12 @@
#pragma once
+#if !defined (IDE_GUI_INSIDE) && !defined (IDE_GUI_COMPILATION)
+# error "Only <libide-gui.h> can be included directly."
+#endif
+
#include <gtk/gtk.h>
+
#include <libide-core.h>
#include <libide-threading.h>
@@ -28,14 +33,14 @@ G_BEGIN_DECLS
#define IDE_TYPE_ENVIRONMENT_EDITOR (ide_environment_editor_get_type())
-IDE_AVAILABLE_IN_3_32
-G_DECLARE_FINAL_TYPE (IdeEnvironmentEditor, ide_environment_editor, IDE, ENVIRONMENT_EDITOR, GtkListBox)
+IDE_AVAILABLE_IN_ALL
+G_DECLARE_FINAL_TYPE (IdeEnvironmentEditor, ide_environment_editor, IDE, ENVIRONMENT_EDITOR, GtkWidget)
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
GtkWidget *ide_environment_editor_new (void);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
IdeEnvironment *ide_environment_editor_get_environment (IdeEnvironmentEditor *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
void ide_environment_editor_set_environment (IdeEnvironmentEditor *self,
IdeEnvironment *environment);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]