[gnome-builder/wip/gtk4-port: 1081/1774] plugins/buildui: add warning/error status indicator




commit e1d56f8d3c876e8a40b3679c1f88fe022a80e3d7
Author: Christian Hergert <chergert redhat com>
Date:   Fri May 20 11:48:43 2022 -0700

    plugins/buildui: add warning/error status indicator
    
    This is currently placed in a menu button which does nothing, but the next
    step here is to add a popover with various display items. That might allow
    us to remove the info from the omnibar at some point.
    
    More importantly, I want to make the process of "show issues, jump to
    next warning/error" a bit more keyboard friendly w/o moving panels around.

 src/plugins/buildui/buildui.gresource.xml          |   1 +
 src/plugins/buildui/gbp-buildui-status-indicator.c | 104 +++++++++++++++++++++
 src/plugins/buildui/gbp-buildui-status-indicator.h |  35 +++++++
 .../buildui/gbp-buildui-status-indicator.ui        |  42 +++++++++
 src/plugins/buildui/gbp-buildui-workspace-addin.c  |  17 ++++
 src/plugins/buildui/meson.build                    |   1 +
 6 files changed, 200 insertions(+)
---
diff --git a/src/plugins/buildui/buildui.gresource.xml b/src/plugins/buildui/buildui.gresource.xml
index 9740f9bba..6c0b4bf0f 100644
--- a/src/plugins/buildui/buildui.gresource.xml
+++ b/src/plugins/buildui/buildui.gresource.xml
@@ -7,6 +7,7 @@
     <file preprocess="xml-stripblanks">gbp-buildui-omni-bar-section.ui</file>
     <file preprocess="xml-stripblanks">gbp-buildui-pane.ui</file>
     <file preprocess="xml-stripblanks">gbp-buildui-stage-row.ui</file>
+    <file preprocess="xml-stripblanks">gbp-buildui-status-indicator.ui</file>
     <file preprocess="xml-stripblanks">gbp-buildui-targets-dialog.ui</file>
     <file preprocess="xml-stripblanks">gtk/menus.ui</file>
   </gresource>
diff --git a/src/plugins/buildui/gbp-buildui-status-indicator.c 
b/src/plugins/buildui/gbp-buildui-status-indicator.c
new file mode 100644
index 000000000..707994ab8
--- /dev/null
+++ b/src/plugins/buildui/gbp-buildui-status-indicator.c
@@ -0,0 +1,104 @@
+/* gbp-buildui-status-indicator.c
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-buildui-status-indicator"
+
+#include "config.h"
+
+#include <libide-foundry.h>
+
+#include "gbp-buildui-status-indicator.h"
+
+struct _GbpBuilduiStatusIndicator
+{
+  GtkWidget parent_instance;
+
+  GtkWidget *box;
+  GtkWidget *error_label;
+  GtkWidget *warning_label;
+};
+
+G_DEFINE_FINAL_TYPE (GbpBuilduiStatusIndicator, gbp_buildui_status_indicator, GTK_TYPE_WIDGET)
+
+static void
+gbp_buildui_status_indicator_dispose (GObject *object)
+{
+  GbpBuilduiStatusIndicator *self = (GbpBuilduiStatusIndicator *)object;
+
+  g_clear_pointer (&self->box, gtk_widget_unparent);
+
+  G_OBJECT_CLASS (gbp_buildui_status_indicator_parent_class)->dispose (object);
+}
+
+static void
+gbp_buildui_status_indicator_class_init (GbpBuilduiStatusIndicatorClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  object_class->dispose = gbp_buildui_status_indicator_dispose;
+
+  gtk_widget_class_set_template_from_resource (widget_class, 
"/plugins/buildui/gbp-buildui-status-indicator.ui");
+  gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
+  gtk_widget_class_bind_template_child (widget_class, GbpBuilduiStatusIndicator, box);
+  gtk_widget_class_bind_template_child (widget_class, GbpBuilduiStatusIndicator, error_label);
+  gtk_widget_class_bind_template_child (widget_class, GbpBuilduiStatusIndicator, warning_label);
+}
+
+static void
+gbp_buildui_status_indicator_init (GbpBuilduiStatusIndicator *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+static void
+gbp_buildui_status_indicator_connect (GbpBuilduiStatusIndicator *self,
+                                      IdeContext                *context)
+{
+  IdeBuildManager *build_manager;
+
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_BUILDUI_STATUS_INDICATOR (self));
+  g_assert (IDE_IS_CONTEXT (context));
+
+  build_manager = ide_build_manager_from_context (context);
+
+  g_assert (IDE_IS_BUILD_MANAGER (build_manager));
+
+  g_object_bind_property (build_manager, "error-count", self->error_label, "label", G_BINDING_SYNC_CREATE);
+  g_object_bind_property (build_manager, "warning-count", self->warning_label, "label", 
G_BINDING_SYNC_CREATE);
+
+  IDE_EXIT;
+}
+
+GbpBuilduiStatusIndicator *
+gbp_buildui_status_indicator_new (IdeContext *context)
+{
+  GbpBuilduiStatusIndicator *self;
+
+  g_return_val_if_fail (IDE_IS_CONTEXT (context), NULL);
+  g_return_val_if_fail (ide_context_has_project (context), NULL);
+
+  self = g_object_new (GBP_TYPE_BUILDUI_STATUS_INDICATOR, NULL);
+  gbp_buildui_status_indicator_connect (self, context);
+
+  return self;
+}
diff --git a/src/plugins/buildui/gbp-buildui-status-indicator.h 
b/src/plugins/buildui/gbp-buildui-status-indicator.h
new file mode 100644
index 000000000..4217d94ff
--- /dev/null
+++ b/src/plugins/buildui/gbp-buildui-status-indicator.h
@@ -0,0 +1,35 @@
+/* gbp-buildui-status-indicator.h
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+
+#include <libide-core.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_BUILDUI_STATUS_INDICATOR (gbp_buildui_status_indicator_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpBuilduiStatusIndicator, gbp_buildui_status_indicator, GBP, 
BUILDUI_STATUS_INDICATOR, GtkWidget)
+
+GbpBuilduiStatusIndicator *gbp_buildui_status_indicator_new (IdeContext *context);
+
+G_END_DECLS
diff --git a/src/plugins/buildui/gbp-buildui-status-indicator.ui 
b/src/plugins/buildui/gbp-buildui-status-indicator.ui
new file mode 100644
index 000000000..730d8398f
--- /dev/null
+++ b/src/plugins/buildui/gbp-buildui-status-indicator.ui
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="GbpBuilduiStatusIndicator" parent="GtkWidget">
+    <child>
+      <object class="GtkBox" id="box">
+        <property name="spacing">6</property>
+        <child>
+          <object class="GtkBox">
+            <property name="spacing">3</property>
+            <child>
+              <object class="GtkImage">
+                <property name="icon-name">dialog-warning-symbolic</property>
+                <property name="pixel-size">12</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkLabel" id="warning_label">
+                <property name="label">0</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkBox">
+            <property name="spacing">3</property>
+            <child>
+              <object class="GtkImage">
+                <property name="icon-name">dialog-error-symbolic</property>
+                <property name="pixel-size">12</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkLabel" id="error_label">
+                <property name="label">0</property>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/plugins/buildui/gbp-buildui-workspace-addin.c 
b/src/plugins/buildui/gbp-buildui-workspace-addin.c
index 7f3d0e636..c21c2c603 100644
--- a/src/plugins/buildui/gbp-buildui-workspace-addin.c
+++ b/src/plugins/buildui/gbp-buildui-workspace-addin.c
@@ -30,6 +30,7 @@
 #include "gbp-buildui-log-pane.h"
 #include "gbp-buildui-omni-bar-section.h"
 #include "gbp-buildui-pane.h"
+#include "gbp-buildui-status-indicator.h"
 #include "gbp-buildui-targets-dialog.h"
 #include "gbp-buildui-workspace-addin.h"
 
@@ -47,6 +48,8 @@ struct _GbpBuilduiWorkspaceAddin
   GtkLabel                 *error_label;
   GtkImage                 *warning_image;
   GtkLabel                 *warning_label;
+  GbpBuilduiStatusIndicator *status_indicator;
+  GtkMenuButton             *status_button;
 
   /* Owned references */
   IdeSignalGroup           *build_manager_signals;
@@ -243,6 +246,7 @@ gbp_buildui_workspace_addin_load (IdeWorkspaceAddin *addin,
   g_autoptr(IdePanelPosition) log_position = NULL;
   PangoAttrList *small_attrs = NULL;
   IdeBuildManager *build_manager;
+  PanelStatusbar *statusbar;
   IdeWorkbench *workbench;
   IdeOmniBar *omnibar;
   IdeContext *context;
@@ -262,6 +266,13 @@ gbp_buildui_workspace_addin_load (IdeWorkspaceAddin *addin,
   context = ide_workbench_get_context (workbench);
   build_manager = ide_build_manager_from_context (context);
 
+  statusbar = ide_workspace_get_statusbar (workspace);
+  self->status_indicator = gbp_buildui_status_indicator_new (context);
+  self->status_button = g_object_new (GTK_TYPE_MENU_BUTTON,
+                                      "child", self->status_indicator,
+                                      NULL);
+  panel_statusbar_add_prefix (statusbar, 1000, GTK_WIDGET (self->status_button));
+
   small_attrs = pango_attr_list_new ();
   pango_attr_list_insert (small_attrs, pango_attr_scale_new (0.833333));
 
@@ -375,10 +386,16 @@ gbp_buildui_workspace_addin_unload (IdeWorkspaceAddin *addin,
                                     IdeWorkspace      *workspace)
 {
   GbpBuilduiWorkspaceAddin *self = (GbpBuilduiWorkspaceAddin *)addin;
+  PanelStatusbar *statusbar;
 
   g_assert (GBP_IS_BUILDUI_WORKSPACE_ADDIN (self));
   g_assert (IDE_IS_PRIMARY_WORKSPACE (workspace));
 
+  statusbar = ide_workspace_get_statusbar (workspace);
+  panel_statusbar_remove (statusbar, GTK_WIDGET (self->status_button));
+  self->status_button = NULL;
+  self->status_indicator = NULL;
+
   for (guint i = 0; i < G_N_ELEMENTS (actions); i++)
     g_action_map_remove_action (G_ACTION_MAP (workspace), actions[i].name);
 
diff --git a/src/plugins/buildui/meson.build b/src/plugins/buildui/meson.build
index b741aedf5..c33ad6e1f 100644
--- a/src/plugins/buildui/meson.build
+++ b/src/plugins/buildui/meson.build
@@ -10,6 +10,7 @@ plugins_sources += files([
   'gbp-buildui-runtime-categories.c',
   'gbp-buildui-runtime-row.c',
   'gbp-buildui-stage-row.c',
+  'gbp-buildui-status-indicator.c',
   'gbp-buildui-targets-dialog.c',
   'gbp-buildui-tree-addin.c',
   'gbp-buildui-workspace-addin.c',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]