[gnome-builder/wip/gtk4-port: 218/1774] plugins/newcomers: port to GTK 4
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port: 218/1774] plugins/newcomers: port to GTK 4
- Date: Mon, 11 Jul 2022 22:31:03 +0000 (UTC)
commit 3d65716658b8d9ce3cef08c788db241614fa1e31
Author: Christian Hergert <chergert redhat com>
Date: Wed Mar 30 15:57:34 2022 -0700
plugins/newcomers: port to GTK 4
src/plugins/newcomers/gbp-newcomers-project.c | 12 +-
src/plugins/newcomers/gbp-newcomers-section.c | 115 +++++--------
src/plugins/newcomers/gbp-newcomers-section.h | 2 +-
src/plugins/newcomers/gbp-newcomers-section.ui | 227 ++++++++++++-------------
4 files changed, 154 insertions(+), 202 deletions(-)
---
diff --git a/src/plugins/newcomers/gbp-newcomers-project.c b/src/plugins/newcomers/gbp-newcomers-project.c
index 3653fa16f..f7eb01eae 100644
--- a/src/plugins/newcomers/gbp-newcomers-project.c
+++ b/src/plugins/newcomers/gbp-newcomers-project.c
@@ -20,7 +20,7 @@
#define G_LOG_DOMAIN "gbp-newcomers-project"
-#include <dazzle.h>
+#include "config.h"
#include "gbp-newcomers-project.h"
@@ -60,13 +60,13 @@ gbp_newcomers_project_constructed (GObject *object)
}
static void
-gbp_newcomers_project_destroy (GtkWidget *widget)
+gbp_newcomers_project_dispose (GObject *object)
{
- GbpNewcomersProject *self = GBP_NEWCOMERS_PROJECT (widget);
+ GbpNewcomersProject *self = (GbpNewcomersProject *)object;
g_clear_object (&self->project_info);
- GTK_WIDGET_CLASS (gbp_newcomers_project_parent_class)->destroy (widget);
+ G_OBJECT_CLASS (gbp_newcomers_project_parent_class)->dispose (object);
}
static void
@@ -135,14 +135,12 @@ static void
gbp_newcomers_project_class_init (GbpNewcomersProjectClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->constructed = gbp_newcomers_project_constructed;
+ object_class->dispose = gbp_newcomers_project_dispose;
object_class->get_property = gbp_newcomers_project_get_property;
object_class->set_property = gbp_newcomers_project_set_property;
- widget_class->destroy = gbp_newcomers_project_destroy;
-
properties [PROP_ICON_NAME] =
g_param_spec_string ("icon-name",
"Icon Name",
diff --git a/src/plugins/newcomers/gbp-newcomers-section.c b/src/plugins/newcomers/gbp-newcomers-section.c
index d4d8d83b6..c7769052f 100644
--- a/src/plugins/newcomers/gbp-newcomers-section.c
+++ b/src/plugins/newcomers/gbp-newcomers-section.c
@@ -28,7 +28,8 @@
struct _GbpNewcomersSection
{
- GtkBin parent_instance;
+ GtkWidget parent_instance;
+ GtkBox *box;
GtkListBox *list_box;
};
@@ -65,94 +66,52 @@ gbp_newcomers_section_get_priority (IdeGreeterSection *section)
return 100;
}
-static void
-gbp_newcomers_section_filter_child (GtkWidget *child,
- gpointer user_data)
-{
- struct {
- DzlPatternSpec *spec;
- gboolean found;
- } *filter = user_data;
- gboolean match = TRUE;
-
- g_assert (GBP_IS_NEWCOMERS_PROJECT (child));
- g_assert (user_data != NULL);
-
- if (filter->spec != NULL)
- {
- const gchar *name;
-
- name = gbp_newcomers_project_get_name (GBP_NEWCOMERS_PROJECT (child));
- match = dzl_pattern_spec_match (filter->spec, name);
- }
-
- gtk_widget_set_visible (child, match);
-
- filter->found |= match;
-}
-
static gboolean
gbp_newcomers_section_filter (IdeGreeterSection *section,
- DzlPatternSpec *spec)
+ IdePatternSpec *spec)
{
GbpNewcomersSection *self = (GbpNewcomersSection *)section;
- struct {
- DzlPatternSpec *spec;
- gboolean found;
- } filter = { spec, FALSE };
+ gboolean found = FALSE;
g_assert (GBP_IS_NEWCOMERS_SECTION (self));
- gtk_container_foreach (GTK_CONTAINER (self->list_box),
- gbp_newcomers_section_filter_child,
- &filter);
-
- return filter.found;
-}
-
-static void
-gbp_newcomers_section_activate_cb (GtkWidget *widget,
- gpointer user_data)
-{
- GbpNewcomersProject *project = (GbpNewcomersProject *)widget;
- struct {
- GbpNewcomersSection *self;
- gboolean handled;
- } *activate = user_data;
-
- g_assert (GBP_IS_NEWCOMERS_PROJECT (project));
- g_assert (activate != NULL);
- g_assert (GBP_IS_NEWCOMERS_SECTION (activate->self));
+ for (GtkWidget *child = gtk_widget_get_first_child (GTK_WIDGET (self->list_box));
+ child != NULL;
+ child = gtk_widget_get_next_sibling (GTK_WIDGET (self->list_box)))
+ {
+ if (GBP_IS_NEWCOMERS_PROJECT (child))
+ {
+ const char *name = gbp_newcomers_project_get_name (GBP_NEWCOMERS_PROJECT (child));
+ gboolean match = spec == NULL || ide_pattern_spec_match (spec, name);
- if (activate->handled || !gtk_widget_get_visible (widget))
- return;
+ gtk_widget_set_visible (child, match);
- gbp_newcomers_section_row_activated (activate->self,
- project,
- activate->self->list_box);
+ found |= match;
+ }
+ }
- activate->handled = TRUE;
+ return found;
}
static gboolean
gbp_newcomers_section_activate_first (IdeGreeterSection *section)
{
GbpNewcomersSection *self = (GbpNewcomersSection *)section;
- struct {
- GbpNewcomersSection *self;
- gboolean handled;
- } activate;
g_assert (GBP_IS_NEWCOMERS_SECTION (self));
- activate.self = self;
- activate.handled = FALSE;
-
- gtk_container_foreach (GTK_CONTAINER (self->list_box),
- gbp_newcomers_section_activate_cb,
- &activate);
+ for (GtkWidget *child = gtk_widget_get_first_child (GTK_WIDGET (self->list_box));
+ child != NULL;
+ child = gtk_widget_get_next_sibling (GTK_WIDGET (self->list_box)))
+ {
+ if (GBP_IS_NEWCOMERS_PROJECT (child))
+ {
+ gbp_newcomers_section_row_activated (self, GBP_NEWCOMERS_PROJECT (child), self->list_box);
+ return TRUE;
+ }
+ }
- return activate.handled;
+ return FALSE;
}
static void
@@ -171,9 +130,8 @@ greeter_section_iface_init (IdeGreeterSectionInterface *iface)
iface->set_selection_mode = gbp_newcomers_section_set_selection_mode;
}
-G_DEFINE_FINAL_TYPE_WITH_CODE (GbpNewcomersSection, gbp_newcomers_section, GTK_TYPE_BIN,
- G_IMPLEMENT_INTERFACE (IDE_TYPE_GREETER_SECTION,
- greeter_section_iface_init))
+G_DEFINE_FINAL_TYPE_WITH_CODE (GbpNewcomersSection, gbp_newcomers_section, GTK_TYPE_WIDGET,
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_GREETER_SECTION, greeter_section_iface_init))
static gboolean
clear_selection_from_timeout (gpointer data)
@@ -248,6 +206,16 @@ gbp_newcomers_section_row_activated (GbpNewcomersSection *self,
delayed_activate_free);
}
+static void
+gbp_newcomers_section_dispose (GObject *object)
+{
+ GbpNewcomersSection *self = (GbpNewcomersSection *)object;
+
+ g_clear_pointer ((GtkWidget **)&self->box, gtk_widget_unparent);
+
+ G_OBJECT_CLASS (gbp_newcomers_section_parent_class)->dispose (object);
+}
+
static void
gbp_newcomers_section_get_property (GObject *object,
guint prop_id,
@@ -271,6 +239,7 @@ gbp_newcomers_section_class_init (GbpNewcomersSectionClass *klass)
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->dispose = gbp_newcomers_section_dispose;
object_class->get_property = gbp_newcomers_section_get_property;
g_object_class_install_property (object_class,
@@ -280,7 +249,9 @@ gbp_newcomers_section_class_init (GbpNewcomersSectionClass *klass)
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
gtk_widget_class_set_css_name (widget_class, "newcomers");
+ gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
gtk_widget_class_set_template_from_resource (widget_class, "/plugins/newcomers/gbp-newcomers-section.ui");
+ gtk_widget_class_bind_template_child (widget_class, GbpNewcomersSection, box);
gtk_widget_class_bind_template_child (widget_class, GbpNewcomersSection, list_box);
g_type_ensure (GBP_TYPE_NEWCOMERS_PROJECT);
diff --git a/src/plugins/newcomers/gbp-newcomers-section.h b/src/plugins/newcomers/gbp-newcomers-section.h
index 72e33f294..7c944c740 100644
--- a/src/plugins/newcomers/gbp-newcomers-section.h
+++ b/src/plugins/newcomers/gbp-newcomers-section.h
@@ -26,6 +26,6 @@ G_BEGIN_DECLS
#define GBP_TYPE_NEWCOMERS_SECTION (gbp_newcomers_section_get_type())
-G_DECLARE_FINAL_TYPE (GbpNewcomersSection, gbp_newcomers_section, GBP, NEWCOMERS_SECTION, GtkBin)
+G_DECLARE_FINAL_TYPE (GbpNewcomersSection, gbp_newcomers_section, GBP, NEWCOMERS_SECTION, GtkWidget)
G_END_DECLS
diff --git a/src/plugins/newcomers/gbp-newcomers-section.ui b/src/plugins/newcomers/gbp-newcomers-section.ui
index 6c75030e2..31eab9b41 100644
--- a/src/plugins/newcomers/gbp-newcomers-section.ui
+++ b/src/plugins/newcomers/gbp-newcomers-section.ui
@@ -1,19 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
- <template class="GbpNewcomersSection" parent="GtkBin">
+ <template class="GbpNewcomersSection" parent="GtkWidget">
<property name="halign">center</property>
<property name="hexpand">true</property>
<child>
- <object class="GtkBox">
+ <object class="GtkBox" id="box">
<property name="orientation">vertical</property>
<property name="spacing">6</property>
- <property name="visible">true</property>
<property name="width-request">600</property>
<property name="halign">center</property>
<property name="valign">start</property>
<child>
<object class="GtkLabel">
- <property name="visible">true</property>
<property name="xalign">0.0</property>
<property name="label" translatable="yes">Suggested GNOME Projects</property>
<style>
@@ -25,126 +23,111 @@
</object>
</child>
<child>
- <object class="GtkFrame">
- <property name="shadow-type">in</property>
- <property name="visible">true</property>
+ <object class="GtkListBox" id="list_box">
+ <property name="selection-mode">browse</property>
+ <style>
+ <class name="boxed-list"/>
+ </style>
+ <child>
+ <object class="GbpNewcomersProject">
+ <property name="name" translatable="yes">Boxes</property>
+ <property name="description" translatable="yes">A simple GNOME 3 application to access
remote or virtual systems</property>
+ <property name="icon-name">org.gnome.Boxes</property>
+ <property name="uri">https://gitlab.gnome.org/GNOME/gnome-boxes.git</property>
+ <property name="languages">Vala</property>
+ </object>
+ </child>
<child>
- <object class="GtkListBox" id="list_box">
- <property name="visible">true</property>
- <property name="selection-mode">browse</property>
- <child>
- <object class="GbpNewcomersProject">
- <property name="name" translatable="yes">Boxes</property>
- <property name="description" translatable="yes">A simple GNOME 3 application to access
remote or virtual systems</property>
- <property name="icon-name">org.gnome.Boxes</property>
- <property name="uri">https://gitlab.gnome.org/GNOME/gnome-boxes.git</property>
- <property name="visible">true</property>
- <property name="languages">Vala</property>
- </object>
- </child>
- <child>
- <object class="GbpNewcomersProject">
- <property name="name" translatable="yes">Builder</property>
- <property name="description" translatable="yes">An IDE for writing GNOME-based
software</property>
- <property name="icon-name">org.gnome.Builder</property>
- <property name="uri">https://gitlab.gnome.org/GNOME/gnome-builder.git</property>
- <property name="visible">true</property>
- <property name="languages">C
+ <object class="GbpNewcomersProject">
+ <property name="name" translatable="yes">Builder</property>
+ <property name="description" translatable="yes">An IDE for writing GNOME-based
software</property>
+ <property name="icon-name">org.gnome.Builder</property>
+ <property name="uri">https://gitlab.gnome.org/GNOME/gnome-builder.git</property>
+ <property name="languages">C
Python</property>
- </object>
- </child>
- <child>
- <object class="GbpNewcomersProject">
- <property name="name" translatable="yes">Calendar</property>
- <property name="description" translatable="yes">Calendar application for GNOME</property>
- <property name="icon-name">org.gnome.Calendar</property>
- <property name="uri">https://gitlab.gnome.org/GNOME/gnome-calendar.git</property>
- <property name="visible">true</property>
- <property name="languages">C</property>
- </object>
- </child>
- <child>
- <object class="GbpNewcomersProject">
- <property name="name" translatable="yes">Clocks</property>
- <property name="description" translatable="yes">A simple clock application for
GNOME</property>
- <property name="icon-name">org.gnome.clocks</property>
- <property name="uri">http://gitlab.gnome.org/gnome/gnome-clocks.git</property>
- <property name="visible">true</property>
- <property name="languages">Vala</property>
- </object>
- </child>
- <child>
- <object class="GbpNewcomersProject">
- <property name="name" translatable="yes">Gitg</property>
- <property name="description" translatable="yes">Gitg is a graphical Git client</property>
- <property name="icon-name">org.gnome.gitg</property>
- <property name="uri">https://gitlab.gnome.org/GNOME/gitg.git</property>
- <property name="visible">true</property>
- <property name="languages">Vala</property>
- </object>
- </child>
- <child>
- <object class="GbpNewcomersProject">
- <property name="name" translatable="yes">Maps</property>
- <property name="description" translatable="yes">A simple GNOME 3 maps
application</property>
- <property name="icon-name">org.gnome.Maps</property>
- <property name="uri">https://gitlab.gnome.org/GNOME/gnome-maps.git</property>
- <property name="visible">true</property>
- <property name="languages">C
- JavaScript</property>
- </object>
- </child>
- <child>
- <object class="GbpNewcomersProject">
- <property name="name" translatable="yes">Music</property>
- <property name="description" translatable="yes">Music player and management
application</property>
- <property name="icon-name">org.gnome.Music</property>
- <property name="uri">https://gitlab.gnome.org/GNOME/gnome-music.git</property>
- <property name="visible">true</property>
- <property name="languages">Python</property>
- </object>
- </child>
- <child>
- <object class="GbpNewcomersProject">
- <property name="name" translatable="yes">Nautilus</property>
- <property name="description" translatable="yes">Default file manager for GNOME</property>
- <property name="icon-name">org.gnome.Nautilus</property>
- <property name="uri">https://gitlab.gnome.org/GNOME/nautilus.git</property>
- <property name="visible">true</property>
- <property name="languages">C</property>
- </object>
- </child>
- <child>
- <object class="GbpNewcomersProject">
- <property name="name" translatable="yes">Photos</property>
- <property name="description" translatable="yes">Access, organize and share your photos
on GNOME</property>
- <property name="icon-name">org.gnome.Photos</property>
- <property name="uri">https://gitlab.gnome.org/GNOME/gnome-photos.git</property>
- <property name="visible">true</property>
- <property name="languages">C</property>
- </object>
- </child>
- <child>
- <object class="GbpNewcomersProject">
- <property name="name" translatable="yes">Polari</property>
- <property name="description" translatable="yes">An IRC Client for GNOME</property>
- <property name="icon-name">org.gnome.Polari</property>
- <property name="uri">https://gitlab.gnome.org/GNOME/polari.git</property>
- <property name="visible">true</property>
- <property name="languages">C
- JavaScript</property>
- </object>
- </child>
- <child>
- <object class="GbpNewcomersProject">
- <property name="name" translatable="yes">Sound Recorder</property>
- <property name="description" translatable="yes">A simple and modern sound
recorder</property>
- <property name="icon-name">org.gnome.SoundRecorder</property>
- <property name="uri">https://gitlab.gnome.org/GNOME/gnome-sound-recorder.git</property>
- <property name="visible">true</property>
- <property name="languages">JavaScript</property>
- </object>
- </child>
+ </object>
+ </child>
+ <child>
+ <object class="GbpNewcomersProject">
+ <property name="name" translatable="yes">Calendar</property>
+ <property name="description" translatable="yes">Calendar application for GNOME</property>
+ <property name="icon-name">org.gnome.Calendar</property>
+ <property name="uri">https://gitlab.gnome.org/GNOME/gnome-calendar.git</property>
+ <property name="languages">C</property>
+ </object>
+ </child>
+ <child>
+ <object class="GbpNewcomersProject">
+ <property name="name" translatable="yes">Clocks</property>
+ <property name="description" translatable="yes">A simple clock application for
GNOME</property>
+ <property name="icon-name">org.gnome.clocks</property>
+ <property name="uri">http://gitlab.gnome.org/gnome/gnome-clocks.git</property>
+ <property name="languages">Vala</property>
+ </object>
+ </child>
+ <child>
+ <object class="GbpNewcomersProject">
+ <property name="name" translatable="yes">Gitg</property>
+ <property name="description" translatable="yes">Gitg is a graphical Git client</property>
+ <property name="icon-name">org.gnome.gitg</property>
+ <property name="uri">https://gitlab.gnome.org/GNOME/gitg.git</property>
+ <property name="languages">Vala</property>
+ </object>
+ </child>
+ <child>
+ <object class="GbpNewcomersProject">
+ <property name="name" translatable="yes">Maps</property>
+ <property name="description" translatable="yes">A simple GNOME 3 maps application</property>
+ <property name="icon-name">org.gnome.Maps</property>
+ <property name="uri">https://gitlab.gnome.org/GNOME/gnome-maps.git</property>
+ <property name="languages">C
+JavaScript</property>
+ </object>
+ </child>
+ <child>
+ <object class="GbpNewcomersProject">
+ <property name="name" translatable="yes">Music</property>
+ <property name="description" translatable="yes">Music player and management
application</property>
+ <property name="icon-name">org.gnome.Music</property>
+ <property name="uri">https://gitlab.gnome.org/GNOME/gnome-music.git</property>
+ <property name="languages">Python</property>
+ </object>
+ </child>
+ <child>
+ <object class="GbpNewcomersProject">
+ <property name="name" translatable="yes">Nautilus</property>
+ <property name="description" translatable="yes">Default file manager for GNOME</property>
+ <property name="icon-name">org.gnome.Nautilus</property>
+ <property name="uri">https://gitlab.gnome.org/GNOME/nautilus.git</property>
+ <property name="languages">C</property>
+ </object>
+ </child>
+ <child>
+ <object class="GbpNewcomersProject">
+ <property name="name" translatable="yes">Photos</property>
+ <property name="description" translatable="yes">Access, organize and share your photos on
GNOME</property>
+ <property name="icon-name">org.gnome.Photos</property>
+ <property name="uri">https://gitlab.gnome.org/GNOME/gnome-photos.git</property>
+ <property name="languages">C</property>
+ </object>
+ </child>
+ <child>
+ <object class="GbpNewcomersProject">
+ <property name="name" translatable="yes">Polari</property>
+ <property name="description" translatable="yes">An IRC Client for GNOME</property>
+ <property name="icon-name">org.gnome.Polari</property>
+ <property name="uri">https://gitlab.gnome.org/GNOME/polari.git</property>
+ <property name="languages">C
+JavaScript</property>
+ </object>
+ </child>
+ <child>
+ <object class="GbpNewcomersProject">
+ <property name="name" translatable="yes">Sound Recorder</property>
+ <property name="description" translatable="yes">A simple and modern sound recorder</property>
+ <property name="icon-name">org.gnome.SoundRecorder</property>
+ <property name="uri">https://gitlab.gnome.org/GNOME/gnome-sound-recorder.git</property>
+ <property name="languages">JavaScript</property>
</object>
</child>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]