[gitg] Added basic spell checking support for commit message



commit 24635b5e0b3df50e9051783549414f27e48d14bb
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Sun Jul 7 12:39:52 2013 +0200

    Added basic spell checking support for commit message

 configure.ac                                  |    2 +
 data/org.gnome.gitg.gschema.xml.in.in         |    6 ++
 gitg/Makefile.am                              |    1 +
 gitg/commit/gitg-commit-dialog.vala           |   78 ++++++++++++++++++++++++-
 gitg/preferences/gitg-preferences-commit.vala |    8 +++
 gitg/resources/ui/gitg-preferences-commit.ui  |   44 ++++++++++-----
 6 files changed, 124 insertions(+), 15 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 5b66fb8..0049ddd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -170,12 +170,14 @@ AC_SUBST(LIBGITG_EXT_LIBS)
 
 LIBPEAS_REQUIRED_VERSION=1.5.0
 LIBPEAS_GTK_REQUIRED_VERSION=1.5.0
+GTKSPELL_REQUIRED_VERSION=3.0.3
 
 PKG_CHECK_MODULES(GITG, [
        gtksourceview-3.0 >= $GTKSOURCEVIEW_REQUIRED_VERSION
        gsettings-desktop-schemas
        libpeas-1.0 >= $LIBPEAS_REQUIRED_VERSION
        libpeas-gtk-1.0 >= $LIBPEAS_GTK_REQUIRED_VERSION
+       gtkspell3-3.0 >= $GTKSPELL_REQUIRED_VERSION
 ])
 
 GITG_CFLAGS="$LIBGITG_CFLAGS $GITG_CFLAGS"
diff --git a/data/org.gnome.gitg.gschema.xml.in.in b/data/org.gnome.gitg.gschema.xml.in.in
index 40718c2..554ff1d 100644
--- a/data/org.gnome.gitg.gschema.xml.in.in
+++ b/data/org.gnome.gitg.gschema.xml.in.in
@@ -113,6 +113,12 @@
         preference is set to TRUE.
       </_description>
     </key>
+    <key name="enable-spell-checking" type="b">
+      <default>true</default>
+    </key>
+    <key name="spell-checking-language" type="s">
+      <default>''</default>
+    </key>
   </schema>
   <schema gettext-domain="@GETTEXT_PACKAGE@" id="org.gnome.gitg.preferences.hidden" 
path="/org/gnome/gitg/preferences/hidden/">
     <key name="sign-tag" type="b">
diff --git a/gitg/Makefile.am b/gitg/Makefile.am
index b433cad..044c863 100644
--- a/gitg/Makefile.am
+++ b/gitg/Makefile.am
@@ -25,6 +25,7 @@ AM_VALAFLAGS = \
        --pkg gd-1.0                                            \
        --pkg webkit2gtk-3.0                                    \
        --pkg gtksourceview-3.0                                 \
+       --pkg GtkSpell-3.0                                      \
        --girdir "$(top_builddir)/libgd"                        \
        --girdir "$(top_builddir)/libgitg"                      \
        --girdir "$(top_builddir)/libgitg-ext"                  \
diff --git a/gitg/commit/gitg-commit-dialog.vala b/gitg/commit/gitg-commit-dialog.vala
index 900cb14..9384afe 100644
--- a/gitg/commit/gitg-commit-dialog.vala
+++ b/gitg/commit/gitg-commit-dialog.vala
@@ -23,6 +23,9 @@ namespace GitgCommit
 [GtkTemplate (ui = "/org/gnome/gitg/ui/gitg-commit-dialog.ui")]
 class Dialog : Gtk.Dialog
 {
+       // Do this to pull in config.h before glib.h (for gettext...)
+       private const string version = Gitg.Config.VERSION;
+
        [GtkChild (name = "source_view_message")]
        private GtkSource.View d_source_view_message;
 
@@ -70,6 +73,9 @@ class Dialog : Gtk.Dialog
        private Settings? d_message_settings;
        private Settings? d_font_settings;
        private Settings? d_commit_settings;
+       private bool d_enable_spell_checking;
+       private string? d_spell_checking_language;
+       private GtkSpell.Checker? d_spell_checker;
 
        public GtkSource.View source_view_message
        {
@@ -159,7 +165,6 @@ class Dialog : Gtk.Dialog
                default = true;
        }
 
-
        [Notify]
        public int right_margin_position
        {
@@ -200,6 +205,67 @@ class Dialog : Gtk.Dialog
                }
        }
 
+       [Notify]
+       public string? spell_checking_language
+       {
+               get { return d_spell_checking_language; }
+
+               set
+               {
+                       d_spell_checking_language = value;
+                       set_spell_language();
+               }
+       }
+
+       [Notify]
+       public bool enable_spell_checking
+       {
+               get { return d_enable_spell_checking; }
+               set
+               {
+                       d_enable_spell_checking = value;
+
+                       if (d_enable_spell_checking)
+                       {
+                               if (d_spell_checker == null)
+                               {
+                                       d_spell_checker = new GtkSpell.Checker();
+                                       d_spell_checker.attach(d_source_view_message);
+
+                                       set_spell_language();
+
+                                       d_spell_checker.language_changed.connect(() => {
+                                               spell_checking_language = d_spell_checker.get_language();
+                                       });
+                               }
+                       }
+                       else
+                       {
+                               if (d_spell_checker != null)
+                               {
+                                       d_spell_checker.detach();
+                                       d_spell_checker = null;
+                               }
+                       }
+               }
+       }
+
+       private void set_spell_language()
+       {
+               if (d_spell_checker != null && d_spell_checking_language != "")
+               {
+                       try
+                       {
+                               d_spell_checker.set_language(d_spell_checking_language);
+                       }
+                       catch
+                       {
+                               warning(_("Cannot set spell checking language: %s"), 
d_spell_checking_language);
+                               d_spell_checking_language = "";
+                       }
+               }
+       }
+
        private void load_author_info()
        {
                if (d_cancel_avatar != null)
@@ -313,6 +379,16 @@ class Dialog : Gtk.Dialog
                                        "subject-margin-position",
                                        SettingsBindFlags.GET);
 
+               d_message_settings.bind("enable-spell-checking",
+                                       this,
+                                       "enable-spell-checking",
+                                       SettingsBindFlags.GET | SettingsBindFlags.SET);
+
+               d_message_settings.bind("spell-checking-language",
+                                       this,
+                                       "spell-checking-language",
+                                       SettingsBindFlags.GET | SettingsBindFlags.SET);
+
                d_constructed = true;
 
                init_message_area();
diff --git a/gitg/preferences/gitg-preferences-commit.vala b/gitg/preferences/gitg-preferences-commit.vala
index 82e8e53..ecf5535 100644
--- a/gitg/preferences/gitg-preferences-commit.vala
+++ b/gitg/preferences/gitg-preferences-commit.vala
@@ -48,6 +48,9 @@ public class PreferencesCommit : Gtk.Grid, GitgExt.Preferences
        [GtkChild (name = "spin_button_right_margin")]
        private Gtk.SpinButton d_spin_button_right_margin;
 
+       [GtkChild (name = "enable_spell_checking")]
+       private Gtk.CheckButton d_enable_spell_checking;
+
        construct
        {
                var settings = new Settings("org.gnome.gitg.preferences.commit.message");
@@ -91,6 +94,11 @@ public class PreferencesCommit : Gtk.Grid, GitgExt.Preferences
                              d_spin_button_right_margin,
                              "value",
                              SettingsBindFlags.GET | SettingsBindFlags.SET);
+
+               settings.bind("enable-spell-checking",
+                             d_enable_spell_checking,
+                             "active",
+                             SettingsBindFlags.GET | SettingsBindFlags.SET);
        }
 
        public Gtk.Widget widget
diff --git a/gitg/resources/ui/gitg-preferences-commit.ui b/gitg/resources/ui/gitg-preferences-commit.ui
index 8314d18..418b385 100644
--- a/gitg/resources/ui/gitg-preferences-commit.ui
+++ b/gitg/resources/ui/gitg-preferences-commit.ui
@@ -1,6 +1,18 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
+  <object class="GtkAdjustment" id="spin_button_right_margin_adjustment">
+    <property name="lower">1</property>
+    <property name="upper">160</property>
+    <property name="value">72</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
+  </object>
+  <object class="GtkAdjustment" id="spin_button_subject_margin_adjustment">
+    <property name="upper">100</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
+  </object>
   <template class="GitgPreferencesCommit" parent="GtkGrid">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
@@ -64,8 +76,6 @@
                         <property name="can_focus">False</property>
                         <property name="has_focus">False</property>
                         <property name="is_focus">False</property>
-                        <property name="hexpand">True</property>
-                        <property name="vexpand">True</property>
                         <property name="row_spacing">6</property>
                         <property name="column_spacing">6</property>
                         <child>
@@ -184,6 +194,24 @@
                     <property name="height">1</property>
                   </packing>
                 </child>
+                <child>
+                  <object class="GtkCheckButton" id="enable_spell_checking">
+                    <property name="label" translatable="yes">Enable spell checking</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="has_focus">False</property>
+                    <property name="is_focus">False</property>
+                    <property name="receives_default">False</property>
+                    <property name="xalign">0</property>
+                    <property name="draw_indicator">True</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">2</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
               </object>
             </child>
           </object>
@@ -222,16 +250,4 @@
       </packing>
     </child>
   </template>
-  <object class="GtkAdjustment" id="spin_button_right_margin_adjustment">
-    <property name="lower">1</property>
-    <property name="upper">160</property>
-    <property name="value">72</property>
-    <property name="step_increment">1</property>
-    <property name="page_increment">10</property>
-  </object>
-  <object class="GtkAdjustment" id="spin_button_subject_margin_adjustment">
-    <property name="upper">100</property>
-    <property name="step_increment">1</property>
-    <property name="page_increment">10</property>
-  </object>
 </interface>


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