[gnome-builder/wip/gtk4-port: 524/736] plugins/spellcheck: start on editor page addin for menus




commit bc0a891ef7ad24b9923ea13adeadeb3c6d73edaf
Author: Christian Hergert <chergert redhat com>
Date:   Thu Apr 7 17:08:13 2022 -0700

    plugins/spellcheck: start on editor page addin for menus

 .../spellcheck/gbp-spell-editor-page-addin.c       | 102 +++++++++++++++++++++
 .../spellcheck/gbp-spell-editor-page-addin.h       |  31 +++++++
 src/plugins/spellcheck/meson.build                 |   1 +
 src/plugins/spellcheck/spellcheck-plugin.c         |   5 +
 4 files changed, 139 insertions(+)
---
diff --git a/src/plugins/spellcheck/gbp-spell-editor-page-addin.c 
b/src/plugins/spellcheck/gbp-spell-editor-page-addin.c
new file mode 100644
index 000000000..2b305c2ef
--- /dev/null
+++ b/src/plugins/spellcheck/gbp-spell-editor-page-addin.c
@@ -0,0 +1,102 @@
+/* gbp-spell-editor-page-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-spell-editor-page-addin"
+
+#include "config.h"
+
+#include <libide-editor.h>
+
+#include "editor-spell-menu.h"
+
+#include "gbp-spell-buffer-addin.h"
+#include "gbp-spell-editor-page-addin.h"
+
+struct _GbpSpellEditorPageAddin
+{
+  GObject parent_instance;
+  GbpSpellBufferAddin *buffer_addin;
+  GMenuModel *menu;
+};
+
+static void
+gbp_spell_editor_page_addin_load (IdeEditorPageAddin *addin,
+                                  IdeEditorPage      *page)
+{
+  GbpSpellEditorPageAddin *self = (GbpSpellEditorPageAddin *)addin;
+  IdeSourceView *view;
+  IdeBuffer *buffer;
+
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_SPELL_EDITOR_PAGE_ADDIN (self));
+  g_assert (IDE_IS_EDITOR_PAGE (page));
+
+  buffer = ide_editor_page_get_buffer (page);
+  view = ide_editor_page_get_view (page);
+
+  self->buffer_addin = GBP_SPELL_BUFFER_ADDIN (ide_buffer_addin_find_by_module_name (buffer, "spellcheck"));
+  self->menu = editor_spell_menu_new ();
+
+  ide_source_view_append_menu (view, self->menu);
+
+  IDE_EXIT;
+}
+
+static void
+gbp_spell_editor_page_addin_unload (IdeEditorPageAddin *addin,
+                                    IdeEditorPage      *page)
+{
+  GbpSpellEditorPageAddin *self = (GbpSpellEditorPageAddin *)addin;
+  IdeSourceView *view;
+
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_SPELL_EDITOR_PAGE_ADDIN (self));
+  g_assert (IDE_IS_EDITOR_PAGE (page));
+
+  view = ide_editor_page_get_view (page);
+  ide_source_view_remove_menu (view, self->menu);
+  g_clear_object (&self->menu);
+
+  self->buffer_addin = NULL;
+
+  IDE_EXIT;
+}
+
+static void
+editor_page_addin_iface_init (IdeEditorPageAddinInterface *iface)
+{
+  iface->load = gbp_spell_editor_page_addin_load;
+  iface->unload = gbp_spell_editor_page_addin_unload;
+}
+
+G_DEFINE_FINAL_TYPE_WITH_CODE (GbpSpellEditorPageAddin, gbp_spell_editor_page_addin, G_TYPE_OBJECT,
+                               G_IMPLEMENT_INTERFACE (IDE_TYPE_EDITOR_PAGE_ADDIN, 
editor_page_addin_iface_init))
+
+static void
+gbp_spell_editor_page_addin_class_init (GbpSpellEditorPageAddinClass *klass)
+{
+}
+
+static void
+gbp_spell_editor_page_addin_init (GbpSpellEditorPageAddin *self)
+{
+}
diff --git a/src/plugins/spellcheck/gbp-spell-editor-page-addin.h 
b/src/plugins/spellcheck/gbp-spell-editor-page-addin.h
new file mode 100644
index 000000000..b52a48898
--- /dev/null
+++ b/src/plugins/spellcheck/gbp-spell-editor-page-addin.h
@@ -0,0 +1,31 @@
+/* gbp-spell-editor-page-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_SPELL_EDITOR_PAGE_ADDIN (gbp_spell_editor_page_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpSpellEditorPageAddin, gbp_spell_editor_page_addin, GBP, SPELL_EDITOR_PAGE_ADDIN, 
GObject)
+
+G_END_DECLS
diff --git a/src/plugins/spellcheck/meson.build b/src/plugins/spellcheck/meson.build
index b2dc68744..48794211d 100644
--- a/src/plugins/spellcheck/meson.build
+++ b/src/plugins/spellcheck/meson.build
@@ -13,6 +13,7 @@ plugins_sources += files([
   'editor-spell-provider.c',
   'editor-text-buffer-spell-adapter.c',
   'gbp-spell-buffer-addin.c',
+  'gbp-spell-editor-page-addin.c',
   'spellcheck-plugin.c',
 ])
 
diff --git a/src/plugins/spellcheck/spellcheck-plugin.c b/src/plugins/spellcheck/spellcheck-plugin.c
index 894eef24c..e07005f4c 100644
--- a/src/plugins/spellcheck/spellcheck-plugin.c
+++ b/src/plugins/spellcheck/spellcheck-plugin.c
@@ -22,9 +22,11 @@
 
 #include <libpeas/peas.h>
 
+#include <libide-code.h>
 #include <libide-editor.h>
 
 #include "gbp-spell-buffer-addin.h"
+#include "gbp-spell-editor-page-addin.h"
 
 _IDE_EXTERN void
 _gbp_spellcheck_register_types (PeasObjectModule *module)
@@ -32,4 +34,7 @@ _gbp_spellcheck_register_types (PeasObjectModule *module)
   peas_object_module_register_extension_type (module,
                                               IDE_TYPE_BUFFER_ADDIN,
                                               GBP_TYPE_SPELL_BUFFER_ADDIN);
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_EDITOR_PAGE_ADDIN,
+                                              GBP_TYPE_SPELL_EDITOR_PAGE_ADDIN);
 }


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