[gnome-builder/wip/gtk4-port] plugins/buildui: include count in warnings/errors title
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port] plugins/buildui: include count in warnings/errors title
- Date: Mon, 13 Jun 2022 21:42:27 +0000 (UTC)
commit 2929a56f37d061ad835414e43d4d953288107c41
Author: Christian Hergert <chergert redhat com>
Date: Mon Jun 13 14:42:19 2022 -0700
plugins/buildui: include count in warnings/errors title
Now that we can rely on a n-items property from GTK models, we can more
easily bind these to titles.
src/plugins/buildui/gbp-buildui-status-popover.c | 45 +++++++++++++++++++++++
src/plugins/buildui/gbp-buildui-status-popover.ui | 10 ++---
2 files changed, 49 insertions(+), 6 deletions(-)
---
diff --git a/src/plugins/buildui/gbp-buildui-status-popover.c
b/src/plugins/buildui/gbp-buildui-status-popover.c
index 77b2a0b02..160548fd0 100644
--- a/src/plugins/buildui/gbp-buildui-status-popover.c
+++ b/src/plugins/buildui/gbp-buildui-status-popover.c
@@ -22,6 +22,8 @@
#include "config.h"
+#include <glib/gi18n.h>
+
#include <libide-editor.h>
#include <libide-foundry.h>
#include <libide-gui.h>
@@ -41,10 +43,40 @@ struct _GbpBuilduiStatusPopover
GtkStack *stack;
GtkCustomFilter *error_filter;
GtkCustomFilter *warning_filter;
+ GtkStackPage *errors;
+ GListModel *errors_model;
+ GtkStackPage *warnings;
+ GListModel *warnings_model;
};
G_DEFINE_FINAL_TYPE (GbpBuilduiStatusPopover, gbp_buildui_status_popover, GTK_TYPE_POPOVER)
+static gboolean
+warnings_title_cb (GBinding *binding,
+ const GValue *from_value,
+ GValue *to_value,
+ gpointer user_data)
+{
+ guint n_items = g_value_get_uint (from_value);
+ g_value_take_string (to_value,
+ /* translators: %u is replaced with the number of warnings */
+ g_strdup_printf (_("Warnings (%u)"), n_items));
+ return TRUE;
+}
+
+static gboolean
+errors_title_cb (GBinding *binding,
+ const GValue *from_value,
+ GValue *to_value,
+ gpointer user_data)
+{
+ guint n_items = g_value_get_uint (from_value);
+ g_value_take_string (to_value,
+ /* translators: %u is replaced with the number of errors */
+ g_strdup_printf (_("Errors (%u)"), n_items));
+ return TRUE;
+}
+
static void
gbp_buildui_status_popover_clear (GbpBuilduiStatusPopover *self)
{
@@ -188,8 +220,12 @@ gbp_buildui_status_popover_class_init (GbpBuilduiStatusPopoverClass *klass)
gtk_widget_class_set_template_from_resource (widget_class,
"/plugins/buildui/gbp-buildui-status-popover.ui");
gtk_widget_class_bind_template_child (widget_class, GbpBuilduiStatusPopover, diagnostics);
gtk_widget_class_bind_template_child (widget_class, GbpBuilduiStatusPopover, error_filter);
+ gtk_widget_class_bind_template_child (widget_class, GbpBuilduiStatusPopover, errors);
+ gtk_widget_class_bind_template_child (widget_class, GbpBuilduiStatusPopover, errors_model);
gtk_widget_class_bind_template_child (widget_class, GbpBuilduiStatusPopover, stack);
gtk_widget_class_bind_template_child (widget_class, GbpBuilduiStatusPopover, warning_filter);
+ gtk_widget_class_bind_template_child (widget_class, GbpBuilduiStatusPopover, warnings);
+ gtk_widget_class_bind_template_child (widget_class, GbpBuilduiStatusPopover, warnings_model);
gtk_widget_class_bind_template_callback (widget_class, gbp_buildui_status_popover_activate_cb);
g_type_ensure (IDE_TYPE_DIAGNOSTIC);
@@ -224,6 +260,15 @@ gbp_buildui_status_popover_init (GbpBuilduiStatusPopover *self)
G_CALLBACK (gbp_buildui_status_popover_add_diagnsotic),
self,
G_CONNECT_SWAPPED);
+
+ g_object_bind_property_full (self->warnings_model, "n-items",
+ self->warnings, "title",
+ G_BINDING_SYNC_CREATE,
+ warnings_title_cb, NULL, NULL, NULL);
+ g_object_bind_property_full (self->errors_model, "n-items",
+ self->errors, "title",
+ G_BINDING_SYNC_CREATE,
+ errors_title_cb, NULL, NULL, NULL);
}
static void
diff --git a/src/plugins/buildui/gbp-buildui-status-popover.ui
b/src/plugins/buildui/gbp-buildui-status-popover.ui
index a3d02bb53..6ceddbe0b 100644
--- a/src/plugins/buildui/gbp-buildui-status-popover.ui
+++ b/src/plugins/buildui/gbp-buildui-status-popover.ui
@@ -20,8 +20,7 @@
<property name="transition-duration">200</property>
<property name="transition-type">crossfade</property>
<child>
- <object class="GtkStackPage">
- <property name="title" translatable="yes">_Errors</property>
+ <object class="GtkStackPage" id="errors">
<property name="use-underline">true</property>
<property name="name">errors</property>
<property name="child">
@@ -46,7 +45,7 @@
<property name="model">
<object class="GtkNoSelection">
<property name="model">
- <object class="GtkFilterListModel">
+ <object class="GtkFilterListModel" id="errors_model">
<property name="model">diagnostics</property>
<property name="filter">error_filter</property>
</object>
@@ -60,8 +59,7 @@
</object>
</child>
<child>
- <object class="GtkStackPage">
- <property name="title" translatable="yes">_Warnings</property>
+ <object class="GtkStackPage" id="warnings">
<property name="use-underline">true</property>
<property name="name">warnings</property>
<property name="child">
@@ -86,7 +84,7 @@
<property name="model">
<object class="GtkNoSelection">
<property name="model">
- <object class="GtkFilterListModel">
+ <object class="GtkFilterListModel" id="warnings_model">
<property name="model">diagnostics</property>
<property name="filter">warning_filter</property>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]