[gnome-text-editor] spellcheck: stub out menus for spell checking



commit 282b211a2fb017d1e3257a809c71cce4891c1924
Author: Christian Hergert <chergert redhat com>
Date:   Fri Jun 25 14:53:01 2021 -0700

    spellcheck: stub out menus for spell checking

 src/editor-page.c       | 15 ++++++++++++
 src/editor-spell-menu.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/editor-spell-menu.h | 33 ++++++++++++++++++++++++++
 src/meson.build         |  2 ++
 4 files changed, 112 insertions(+)
---
diff --git a/src/editor-page.c b/src/editor-page.c
index d28ee8f..620d2b9 100644
--- a/src/editor-page.c
+++ b/src/editor-page.c
@@ -25,9 +25,11 @@
 #include <glib/gi18n.h>
 
 #include "editor-info-bar-private.h"
+#include "editor-joined-menu-private.h"
 #include "editor-page-private.h"
 #include "editor-sidebar-model-private.h"
 #include "editor-session-private.h"
+#include "editor-spell-menu.h"
 #include "editor-utils-private.h"
 
 enum {
@@ -600,11 +602,24 @@ editor_page_class_init (EditorPageClass *klass)
 static void
 editor_page_init (EditorPage *self)
 {
+  g_autoptr(GMenuModel) spelling_menu = NULL;
+  g_autoptr(EditorJoinedMenu) joined = NULL;
+  GMenuModel *extra_menu;
   GtkDropTarget *dest;
 
   gtk_widget_init_template (GTK_WIDGET (self));
   editor_page_tweak_gutter_spacing (self);
 
+  joined = editor_joined_menu_new ();
+  extra_menu = gtk_text_view_get_extra_menu (GTK_TEXT_VIEW (self->view));
+  editor_joined_menu_append_menu (joined, extra_menu);
+
+  spelling_menu = editor_spell_menu_new ();
+  editor_joined_menu_append_menu (joined, spelling_menu);
+
+  gtk_text_view_set_extra_menu (GTK_TEXT_VIEW (self->view),
+                                G_MENU_MODEL (joined));
+
   g_object_bind_property (self, "document", self->infobar, "document", 0);
 
   g_signal_connect_object (self->view,
diff --git a/src/editor-spell-menu.c b/src/editor-spell-menu.c
new file mode 100644
index 0000000..68a6cad
--- /dev/null
+++ b/src/editor-spell-menu.c
@@ -0,0 +1,62 @@
+/* editor-spell-menu.c
+ *
+ * Copyright 2021 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
+ */
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+
+#include "editor-spell-menu.h"
+
+GMenuModel *
+editor_spell_menu_new (void)
+{
+  g_autoptr(GMenu) menu = g_menu_new ();
+  g_autoptr(GMenu) corrections_menu = g_menu_new ();
+  g_autoptr(GMenu) corrections_section = g_menu_new ();
+  g_autoptr(GMenu) languages_menu = g_menu_new ();
+  g_autoptr(GMenuItem) languages_item = g_menu_item_new_submenu (_("Languages"), G_MENU_MODEL 
(languages_menu));
+  g_autoptr(GMenuItem) add_item = g_menu_item_new (_("Add to Dictionary"), "spellcheck.add");
+  g_autoptr(GMenuItem) ignore_item = g_menu_item_new (_("Ignore"), "spellcheck.ignore");
+  g_autoptr(GMenuItem) check_item = g_menu_item_new (_("Check Spelling"), "spellcheck.enabled");
+
+  g_menu_item_set_attribute (add_item, "hidden-when", "s", "action-disabled");
+  g_menu_item_set_attribute (ignore_item, "hidden-when", "s", "action-disabled");
+  g_menu_item_set_attribute (check_item, "role", "s", "check");
+  g_menu_item_set_attribute (languages_item, "submenu-action", "s", "spellcheck.enabled");
+
+  g_menu_append_section (corrections_section, NULL, G_MENU_MODEL (corrections_menu));
+  g_menu_append_item (corrections_section, add_item);
+  g_menu_append_item (corrections_section, ignore_item);
+  g_menu_append_section (menu, NULL, G_MENU_MODEL (corrections_section));
+  g_menu_append_item (menu, languages_item);
+  g_menu_append_item (menu, check_item);
+
+  g_object_set_data_full (G_OBJECT (menu),
+                          "LANGUAGES_MENU",
+                          g_object_ref (languages_menu),
+                          g_object_unref);
+
+  g_object_set_data_full (G_OBJECT (menu),
+                          "CORRECTIONS_MENU",
+                          g_object_ref (corrections_menu),
+                          g_object_unref);
+
+  return G_MENU_MODEL (g_steal_pointer (&menu));
+}
diff --git a/src/editor-spell-menu.h b/src/editor-spell-menu.h
new file mode 100644
index 0000000..b079719
--- /dev/null
+++ b/src/editor-spell-menu.h
@@ -0,0 +1,33 @@
+/* editor-spell-menu.h
+ *
+ * Copyright 2021 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 "editor-types.h"
+
+G_BEGIN_DECLS
+
+GMenuModel *editor_spell_menu_new          (void);
+void        editor_spell_menu_set_language (GMenuModel          *menu,
+                                            EditorSpellLanguage *language);
+void        editor_spell_menu_set_word     (GMenuModel          *menu,
+                                            const char          *word);
+
+G_END_DECLS
diff --git a/src/meson.build b/src/meson.build
index c4e462b..b047762 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -7,6 +7,7 @@ editor_sources = [
   'editor-document.c',
   'editor-info-bar.c',
   'editor-frame-source.c',
+  'editor-joined-menu.c',
   'editor-language-dialog.c',
   'editor-language-row.c',
   'editor-open-popover.c',
@@ -32,6 +33,7 @@ editor_sources = [
   'editor-signal-group.c',
   'editor-spell-checker.c',
   'editor-spell-language.c',
+  'editor-spell-menu.c',
   'editor-spell-provider.c',
   'editor-theme-selector.c',
   'editor-utils.c',


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