[gnome-builder/wip/gtk4-port] plugins/editorui: use workspace addin to add statusbar widgets



commit b6a2e69b24d9a8923e923cc53042fab3c539341f
Author: Christian Hergert <chergert redhat com>
Date:   Sat Apr 2 03:10:42 2022 -0700

    plugins/editorui: use workspace addin to add statusbar widgets
    
    The goal here is for the statusbar widgets related to the editor to be
    shown based on page changes. We still need actions for everything and
    also need to be able to ignore focus changes where the widget has not
    been destroyed or clicking on the menus will clear them.

 src/plugins/editorui/editorui-plugin.c             |   4 +
 src/plugins/editorui/editorui.gresource.xml        |   1 +
 .../editorui/gbp-editorui-workspace-addin.c        | 134 +++++++++++++++++++++
 .../editorui/gbp-editorui-workspace-addin.h        |  31 +++++
 src/plugins/editorui/gtk/menus.ui                  |  60 +++++++++
 src/plugins/editorui/meson.build                   |   1 +
 6 files changed, 231 insertions(+)
---
diff --git a/src/plugins/editorui/editorui-plugin.c b/src/plugins/editorui/editorui-plugin.c
index 015d0a924..a5013ff9e 100644
--- a/src/plugins/editorui/editorui-plugin.c
+++ b/src/plugins/editorui/editorui-plugin.c
@@ -27,6 +27,7 @@
 #include <libide-gui.h>
 
 #include "gbp-editorui-workbench-addin.h"
+#include "gbp-editorui-workspace-addin.h"
 #include "gbp-editorui-resources.h"
 
 _IDE_EXTERN void
@@ -37,4 +38,7 @@ _gbp_editorui_register_types (PeasObjectModule *module)
   peas_object_module_register_extension_type (module,
                                               IDE_TYPE_WORKBENCH_ADDIN,
                                               GBP_TYPE_EDITORUI_WORKBENCH_ADDIN);
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_WORKSPACE_ADDIN,
+                                              GBP_TYPE_EDITORUI_WORKSPACE_ADDIN);
 }
diff --git a/src/plugins/editorui/editorui.gresource.xml b/src/plugins/editorui/editorui.gresource.xml
index 1a4e739e9..7651fc6fb 100644
--- a/src/plugins/editorui/editorui.gresource.xml
+++ b/src/plugins/editorui/editorui.gresource.xml
@@ -2,5 +2,6 @@
 <gresources>
   <gresource prefix="/plugins/editorui">
     <file>editorui.plugin</file>
+    <file preprocess="xml-stripblanks">gtk/menus.ui</file>
   </gresource>
 </gresources>
diff --git a/src/plugins/editorui/gbp-editorui-workspace-addin.c 
b/src/plugins/editorui/gbp-editorui-workspace-addin.c
new file mode 100644
index 000000000..ebd485711
--- /dev/null
+++ b/src/plugins/editorui/gbp-editorui-workspace-addin.c
@@ -0,0 +1,134 @@
+/* gbp-editorui-workspace-addin.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-editorui-workspace-addin"
+
+#include "config.h"
+
+#include <libide-editor.h>
+
+#include "gbp-editorui-workspace-addin.h"
+
+struct _GbpEditoruiWorkspaceAddin
+{
+  GObject        parent_instance;
+
+  IdeWorkspace  *workspace;
+
+  GtkMenuButton *indentation;
+};
+
+#define clear_from_statusbar(s,w) clear_from_statusbar(s, (GtkWidget **)w)
+
+static void
+(clear_from_statusbar) (PanelStatusbar  *statusbar,
+                        GtkWidget      **widget)
+{
+  if (*widget)
+    {
+      panel_statusbar_remove (statusbar, *widget);
+      *widget = NULL;
+    }
+}
+
+static void
+gbp_editorui_workspace_addin_load (IdeWorkspaceAddin *addin,
+                                   IdeWorkspace      *workspace)
+{
+  GbpEditoruiWorkspaceAddin *self = (GbpEditoruiWorkspaceAddin *)addin;
+  PanelStatusbar *statusbar;
+  GMenu *menu;
+
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_EDITORUI_WORKSPACE_ADDIN (self));
+  g_assert (IDE_IS_WORKSPACE (workspace));
+
+  self->workspace = workspace;
+
+  statusbar = ide_workspace_get_statusbar (workspace);
+
+  menu = ide_application_get_menu_by_id (IDE_APPLICATION_DEFAULT, "editor-indentation");
+  self->indentation = g_object_new (GTK_TYPE_MENU_BUTTON,
+                                    "menu-model", menu,
+                                    "direction", GTK_ARROW_UP,
+                                    "visible", FALSE,
+                                    NULL);
+  panel_statusbar_add_suffix (statusbar, GTK_WIDGET (self->indentation));
+
+  IDE_EXIT;
+}
+
+static void
+gbp_editorui_workspace_addin_unload (IdeWorkspaceAddin *addin,
+                                     IdeWorkspace      *workspace)
+{
+  GbpEditoruiWorkspaceAddin *self = (GbpEditoruiWorkspaceAddin *)addin;
+  PanelStatusbar *statusbar;
+
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_EDITORUI_WORKSPACE_ADDIN (self));
+  g_assert (IDE_IS_WORKSPACE (workspace));
+
+  statusbar = ide_workspace_get_statusbar (workspace);
+
+  clear_from_statusbar (statusbar, &self->indentation);
+
+  self->workspace = NULL;
+
+  IDE_EXIT;
+}
+
+static void
+gbp_editorui_workspace_addin_page_changed (IdeWorkspaceAddin *addin,
+                                           IdePage           *page)
+{
+  GbpEditoruiWorkspaceAddin *self = (GbpEditoruiWorkspaceAddin *)addin;
+
+  g_assert (GBP_IS_EDITORUI_WORKSPACE_ADDIN (self));
+  g_assert (!page || IDE_IS_PAGE (page));
+
+  if (!IDE_IS_EDITOR_PAGE (page))
+    page = NULL;
+
+  gtk_widget_set_visible (GTK_WIDGET (self->indentation), page != NULL);
+}
+
+static void
+workspace_addin_iface_init (IdeWorkspaceAddinInterface *iface)
+{
+  iface->load = gbp_editorui_workspace_addin_load;
+  iface->unload = gbp_editorui_workspace_addin_unload;
+  iface->page_changed = gbp_editorui_workspace_addin_page_changed;
+}
+
+G_DEFINE_TYPE_WITH_CODE (GbpEditoruiWorkspaceAddin, gbp_editorui_workspace_addin, G_TYPE_OBJECT,
+                         G_IMPLEMENT_INTERFACE (IDE_TYPE_WORKSPACE_ADDIN, workspace_addin_iface_init))
+
+static void
+gbp_editorui_workspace_addin_class_init (GbpEditoruiWorkspaceAddinClass *klass)
+{
+}
+
+static void
+gbp_editorui_workspace_addin_init (GbpEditoruiWorkspaceAddin *self)
+{
+}
diff --git a/src/plugins/editorui/gbp-editorui-workspace-addin.h 
b/src/plugins/editorui/gbp-editorui-workspace-addin.h
new file mode 100644
index 000000000..9c2d1e551
--- /dev/null
+++ b/src/plugins/editorui/gbp-editorui-workspace-addin.h
@@ -0,0 +1,31 @@
+/* gbp-editorui-workspace-addin.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 <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_EDITORUI_WORKSPACE_ADDIN (gbp_editorui_workspace_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpEditoruiWorkspaceAddin, gbp_editorui_workspace_addin, GBP, 
EDITORUI_WORKSPACE_ADDIN, GObject)
+
+G_END_DECLS
diff --git a/src/plugins/editorui/gtk/menus.ui b/src/plugins/editorui/gtk/menus.ui
new file mode 100644
index 000000000..e1f3d80f5
--- /dev/null
+++ b/src/plugins/editorui/gtk/menus.ui
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <menu id="editor-indentation">
+    <section>
+      <attribute name="label" translatable="yes">Indentation</attribute>
+      <item>
+        <attribute name="label" translatable="yes">Tabs</attribute>
+        <attribute name="action">indent.style('tabs')</attribute>
+        <attribute name="role">radio</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">Spaces</attribute>
+        <attribute name="action">indent.style('spaces')</attribute>
+        <attribute name="role">radio</attribute>
+      </item>
+    </section>
+    <section>
+      <submenu>
+        <attribute name="label" translatable="yes">Spaces per Tab</attribute>
+        <section>
+          <item>
+            <attribute name="label" translatable="yes">2</attribute>
+          </item>
+          <item>
+            <attribute name="label" translatable="yes">3</attribute>
+          </item>
+          <item>
+            <attribute name="label" translatable="yes">4</attribute>
+          </item>
+          <item>
+            <attribute name="label" translatable="yes">5</attribute>
+          </item>
+          <item>
+            <attribute name="label" translatable="yes">8</attribute>
+          </item>
+        </section>
+      </submenu>
+      <submenu>
+        <attribute name="label" translatable="yes">Indentation Size</attribute>
+        <section>
+          <item>
+            <attribute name="label" translatable="yes">2</attribute>
+          </item>
+          <item>
+            <attribute name="label" translatable="yes">3</attribute>
+          </item>
+          <item>
+            <attribute name="label" translatable="yes">4</attribute>
+          </item>
+          <item>
+            <attribute name="label" translatable="yes">5</attribute>
+          </item>
+          <item>
+            <attribute name="label" translatable="yes">8</attribute>
+          </item>
+        </section>
+      </submenu>
+    </section>
+  </menu>
+</interface>
diff --git a/src/plugins/editorui/meson.build b/src/plugins/editorui/meson.build
index 15ac96dea..62926aec3 100644
--- a/src/plugins/editorui/meson.build
+++ b/src/plugins/editorui/meson.build
@@ -1,6 +1,7 @@
 plugins_sources += files([
   'editorui-plugin.c',
   'gbp-editorui-workbench-addin.c',
+  'gbp-editorui-workspace-addin.c',
 ])
 
 plugin_editorui_resources = gnome.compile_resources(


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