[gnome-builder/wip/gtk4-port: 510/1774] plugins/spellcheck: add action to add word to dictionary
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port: 510/1774] plugins/spellcheck: add action to add word to dictionary
- Date: Mon, 11 Jul 2022 22:31:14 +0000 (UTC)
commit 2e08e698a5ce47719ae3292ddae4b2a33e718726
Author: Christian Hergert <chergert redhat com>
Date: Thu Apr 7 17:16:58 2022 -0700
plugins/spellcheck: add action to add word to dictionary
src/plugins/spellcheck/gbp-spell-buffer-addin.c | 17 ++++++++
src/plugins/spellcheck/gbp-spell-buffer-addin.h | 3 ++
.../spellcheck/gbp-spell-editor-page-addin.c | 48 ++++++++++++++++++++--
3 files changed, 64 insertions(+), 4 deletions(-)
---
diff --git a/src/plugins/spellcheck/gbp-spell-buffer-addin.c b/src/plugins/spellcheck/gbp-spell-buffer-addin.c
index fab471ccb..c601555de 100644
--- a/src/plugins/spellcheck/gbp-spell-buffer-addin.c
+++ b/src/plugins/spellcheck/gbp-spell-buffer-addin.c
@@ -146,3 +146,20 @@ static void
gbp_spell_buffer_addin_init (GbpSpellBufferAddin *self)
{
}
+
+void
+gbp_spell_buffer_addin_add_word (GbpSpellBufferAddin *self,
+ const char *word)
+{
+ IDE_ENTRY;
+
+ g_return_if_fail (GBP_IS_SPELL_BUFFER_ADDIN (self));
+
+ if (word == NULL || word[0] == 0)
+ IDE_EXIT;
+
+ editor_spell_checker_add_word (self->checker, word);
+ editor_text_buffer_spell_adapter_invalidate_all (self->adapter);
+
+ IDE_EXIT;
+}
diff --git a/src/plugins/spellcheck/gbp-spell-buffer-addin.h b/src/plugins/spellcheck/gbp-spell-buffer-addin.h
index 97d1617f7..dafcbc838 100644
--- a/src/plugins/spellcheck/gbp-spell-buffer-addin.h
+++ b/src/plugins/spellcheck/gbp-spell-buffer-addin.h
@@ -28,4 +28,7 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (GbpSpellBufferAddin, gbp_spell_buffer_addin, GBP, SPELL_BUFFER_ADDIN, GObject)
+void gbp_spell_buffer_addin_add_word (GbpSpellBufferAddin *self,
+ const char *word);
+
G_END_DECLS
diff --git a/src/plugins/spellcheck/gbp-spell-editor-page-addin.c
b/src/plugins/spellcheck/gbp-spell-editor-page-addin.c
index 2b305c2ef..1c0a0b79a 100644
--- a/src/plugins/spellcheck/gbp-spell-editor-page-addin.c
+++ b/src/plugins/spellcheck/gbp-spell-editor-page-addin.c
@@ -31,9 +31,34 @@
struct _GbpSpellEditorPageAddin
{
- GObject parent_instance;
+ GObject parent_instance;
GbpSpellBufferAddin *buffer_addin;
- GMenuModel *menu;
+ GMenuModel *menu;
+ GSimpleActionGroup *actions;
+};
+
+static void
+gbp_spell_editor_page_addin_add (GSimpleAction *action,
+ GVariant *param,
+ gpointer user_data)
+{
+ GbpSpellEditorPageAddin *self = user_data;
+ const char *word;
+
+ IDE_ENTRY;
+
+ g_assert (G_IS_SIMPLE_ACTION (action));
+ g_assert (param != NULL);
+ g_assert (g_variant_is_of_type (param, G_VARIANT_TYPE_STRING));
+
+ word = g_variant_get_string (param, NULL);
+ gbp_spell_buffer_addin_add_word (self->buffer_addin, word);
+
+ IDE_EXIT;
+}
+
+static const GActionEntry actions[] = {
+ { "add", gbp_spell_editor_page_addin_add, "s" },
};
static void
@@ -41,6 +66,7 @@ gbp_spell_editor_page_addin_load (IdeEditorPageAddin *addin,
IdeEditorPage *page)
{
GbpSpellEditorPageAddin *self = (GbpSpellEditorPageAddin *)addin;
+ IdeBufferAddin *buffer_addin;
IdeSourceView *view;
IdeBuffer *buffer;
@@ -52,11 +78,21 @@ gbp_spell_editor_page_addin_load (IdeEditorPageAddin *addin,
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 ();
+ buffer_addin = ide_buffer_addin_find_by_module_name (buffer, "spellcheck");
+ self->buffer_addin = GBP_SPELL_BUFFER_ADDIN (buffer_addin);
+ self->menu = editor_spell_menu_new ();
ide_source_view_append_menu (view, self->menu);
+ self->actions = g_simple_action_group_new ();
+ g_action_map_add_action_entries (G_ACTION_MAP (self->actions),
+ actions,
+ G_N_ELEMENTS (actions),
+ self);
+ gtk_widget_insert_action_group (GTK_WIDGET (page),
+ "spelling",
+ G_ACTION_GROUP (self->actions));
+
IDE_EXIT;
}
@@ -72,9 +108,13 @@ gbp_spell_editor_page_addin_unload (IdeEditorPageAddin *addin,
g_assert (GBP_IS_SPELL_EDITOR_PAGE_ADDIN (self));
g_assert (IDE_IS_EDITOR_PAGE (page));
+ gtk_widget_insert_action_group (GTK_WIDGET (page), "spelling", NULL);
+
view = ide_editor_page_get_view (page);
ide_source_view_remove_menu (view, self->menu);
+
g_clear_object (&self->menu);
+ g_clear_object (&self->actions);
self->buffer_addin = NULL;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]