[gspell/wip/choose-language-context-menu] text-view: add :language-menu boolean property



commit f1a3052e4008778360d8103172a9b6fd928be782
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sun May 8 17:59:25 2016 +0200

    text-view: add :language-menu boolean property
    
    https://bugzilla.gnome.org/show_bug.cgi?id=758415

 gspell/gspell-inline-checker-text-buffer.c |   13 +---
 gspell/gspell-inline-checker-text-buffer.h |    4 +
 gspell/gspell-text-view.c                  |   98 ++++++++++++++++++++++++++++
 gspell/gspell-text-view.h                  |    5 ++
 4 files changed, 110 insertions(+), 10 deletions(-)
---
diff --git a/gspell/gspell-inline-checker-text-buffer.c b/gspell/gspell-inline-checker-text-buffer.c
index 9fcfe78..f0e6788 100644
--- a/gspell/gspell-inline-checker-text-buffer.c
+++ b/gspell/gspell-inline-checker-text-buffer.c
@@ -876,10 +876,9 @@ get_suggestion_menu (GspellInlineCheckerTextBuffer *spell,
        return top_menu;
 }
 
-static void
-populate_popup_cb (GtkTextView                   *view,
-                  GtkMenu                       *menu,
-                  GspellInlineCheckerTextBuffer *spell)
+void
+_gspell_inline_checker_text_buffer_populate_popup (GspellInlineCheckerTextBuffer *spell,
+                                                  GtkMenu                       *menu)
 {
        GtkWidget *menu_item;
        GtkTextIter start;
@@ -1410,12 +1409,6 @@ _gspell_inline_checker_text_buffer_attach_view (GspellInlineCheckerTextBuffer *s
                                 0);
 
        g_signal_connect_object (view,
-                                "populate-popup",
-                                G_CALLBACK (populate_popup_cb),
-                                spell,
-                                0);
-
-       g_signal_connect_object (view,
                                 "draw",
                                 G_CALLBACK (draw_cb),
                                 spell,
diff --git a/gspell/gspell-inline-checker-text-buffer.h b/gspell/gspell-inline-checker-text-buffer.h
index 10063a6..988041b 100644
--- a/gspell/gspell-inline-checker-text-buffer.h
+++ b/gspell/gspell-inline-checker-text-buffer.h
@@ -48,6 +48,10 @@ G_GNUC_INTERNAL
 void   _gspell_inline_checker_text_buffer_detach_view          (GspellInlineCheckerTextBuffer *spell,
                                                                 GtkTextView                   *view);
 
+G_GNUC_INTERNAL
+void   _gspell_inline_checker_text_buffer_populate_popup       (GspellInlineCheckerTextBuffer *spell,
+                                                                GtkMenu                       *menu);
+
 /* For unit tests */
 
 G_GNUC_INTERNAL
diff --git a/gspell/gspell-text-view.c b/gspell/gspell-text-view.c
index 62386da..c5933d1 100644
--- a/gspell/gspell-text-view.c
+++ b/gspell/gspell-text-view.c
@@ -53,6 +53,7 @@ struct _GspellTextViewPrivate
 {
        GtkTextView *view;
        GspellInlineCheckerTextBuffer *inline_checker;
+       guint enable_language_menu : 1;
 };
 
 enum
@@ -60,6 +61,7 @@ enum
        PROP_0,
        PROP_VIEW,
        PROP_INLINE_SPELL_CHECKING,
+       PROP_ENABLE_LANGUAGE_MENU,
 };
 
 #define GSPELL_TEXT_VIEW_KEY "gspell-text-view-key"
@@ -121,6 +123,21 @@ notify_buffer_cb (GtkTextView    *gtk_view,
 }
 
 static void
+populate_popup_cb (GtkTextView    *gtk_view,
+                  GtkMenu        *menu,
+                  GspellTextView *gspell_view)
+{
+       GspellTextViewPrivate *priv;
+
+       priv = gspell_text_view_get_instance_private (gspell_view);
+
+       if (priv->inline_checker != NULL)
+       {
+               _gspell_inline_checker_text_buffer_populate_popup (priv->inline_checker, menu);
+       }
+}
+
+static void
 set_view (GspellTextView *gspell_view,
          GtkTextView    *gtk_view)
 {
@@ -141,6 +158,12 @@ set_view (GspellTextView *gspell_view,
                                 gspell_view,
                                 0);
 
+       g_signal_connect_object (priv->view,
+                                "populate-popup",
+                                G_CALLBACK (populate_popup_cb),
+                                gspell_view,
+                                0);
+
        g_object_notify (G_OBJECT (gspell_view), "view");
 }
 
@@ -162,6 +185,10 @@ gspell_text_view_get_property (GObject    *object,
                        g_value_set_boolean (value, gspell_text_view_get_inline_spell_checking (gspell_view));
                        break;
 
+               case PROP_ENABLE_LANGUAGE_MENU:
+                       g_value_set_boolean (value, gspell_text_view_get_enable_language_menu (gspell_view));
+                       break;
+
                default:
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                        break;
@@ -186,6 +213,10 @@ gspell_text_view_set_property (GObject      *object,
                        gspell_text_view_set_inline_spell_checking (gspell_view, g_value_get_boolean (value));
                        break;
 
+               case PROP_ENABLE_LANGUAGE_MENU:
+                       gspell_text_view_set_enable_language_menu (gspell_view, g_value_get_boolean (value));
+                       break;
+
                default:
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                        break;
@@ -248,6 +279,23 @@ gspell_text_view_class_init (GspellTextViewClass *klass)
                                                               FALSE,
                                                               G_PARAM_READWRITE |
                                                               G_PARAM_STATIC_STRINGS));
+
+       /**
+        * GspellTextView:enable-language-menu:
+        *
+        * When the context menu is shown, whether to add a sub-menu to select
+        * the language for the spell checking.
+        *
+        * Since: 1.2
+        */
+       g_object_class_install_property (object_class,
+                                        PROP_ENABLE_LANGUAGE_MENU,
+                                        g_param_spec_boolean ("enable-language-menu",
+                                                              "Enable Language Menu",
+                                                              "",
+                                                              FALSE,
+                                                              G_PARAM_READWRITE |
+                                                              G_PARAM_STATIC_STRINGS));
 }
 
 static void
@@ -355,4 +403,54 @@ gspell_text_view_set_inline_spell_checking (GspellTextView *gspell_view,
        g_object_notify (G_OBJECT (gspell_view), "inline-spell-checking");
 }
 
+/**
+ * gspell_text_view_get_enable_language_menu:
+ * @gspell_view: a #GspellTextView.
+ *
+ * Returns: whether the language context menu is enabled.
+ * Since: 1.2
+ */
+gboolean
+gspell_text_view_get_enable_language_menu (GspellTextView *gspell_view)
+{
+       GspellTextViewPrivate *priv;
+
+       g_return_val_if_fail (GSPELL_IS_TEXT_VIEW (gspell_view), FALSE);
+
+       priv = gspell_text_view_get_instance_private (gspell_view);
+       return priv->enable_language_menu;
+}
+
+/**
+ * gspell_text_view_set_enable_language_menu:
+ * @gspell_view: a #GspellTextView.
+ * @enable_language_menu: whether to enable the language context menu.
+ *
+ * Sets whether to enable the language context menu. If enabled, doing a right
+ * click on the #GtkTextView will show a sub-menu to choose the language for the
+ * spell checking. If another language is chosen, it changes the
+ * #GspellChecker:language property of the #GspellTextBuffer:spell-checker of
+ * the #GtkTextView:buffer of the #GspellTextView:view.
+ *
+ * Since: 1.2
+ */
+void
+gspell_text_view_set_enable_language_menu (GspellTextView *gspell_view,
+                                          gboolean        enable_language_menu)
+{
+       GspellTextViewPrivate *priv;
+
+       g_return_if_fail (GSPELL_IS_TEXT_VIEW (gspell_view));
+
+       priv = gspell_text_view_get_instance_private (gspell_view);
+
+       enable_language_menu = enable_language_menu != FALSE;
+
+       if (priv->enable_language_menu != enable_language_menu)
+       {
+               priv->enable_language_menu = enable_language_menu;
+               g_object_notify (G_OBJECT (gspell_view), "enable-language-menu");
+       }
+}
+
 /* ex:set ts=8 noet: */
diff --git a/gspell/gspell-text-view.h b/gspell/gspell-text-view.h
index b11e554..be764f6 100644
--- a/gspell/gspell-text-view.h
+++ b/gspell/gspell-text-view.h
@@ -50,6 +50,11 @@ gboolean             gspell_text_view_get_inline_spell_checking      (GspellTextView 
*gspell_vie
 void                   gspell_text_view_set_inline_spell_checking      (GspellTextView *gspell_view,
                                                                         gboolean        enable);
 
+gboolean               gspell_text_view_get_enable_language_menu       (GspellTextView *gspell_view);
+
+void                   gspell_text_view_set_enable_language_menu       (GspellTextView *gspell_view,
+                                                                        gboolean        
enable_language_menu);
+
 G_END_DECLS
 
 #endif /* GSPELL_TEXT_VIEW_H */


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