[latexila/wip/gspell: 2/3] spell: create the Tools menu for the spell checking actions



commit 66924fd0431e0dd62638e9cb7077d650f4ded637
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Tue Sep 15 10:24:21 2015 +0200

    spell: create the Tools menu for the spell checking actions
    
    It's the standard location for a tool like the spell checking.
    It was in the Edit menu because there was only one menu item, but in the
    near future there will be more items.

 src/Makefile.am            |    1 +
 src/main_window.vala       |    2 +
 src/main_window_edit.vala  |   31 -----------------
 src/main_window_tools.vala |   77 ++++++++++++++++++++++++++++++++++++++++++++
 src/ui/ui.xml              |    6 ++-
 5 files changed, 84 insertions(+), 33 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index c77224a..24d982f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -42,6 +42,7 @@ vala_files =                          \
        main_window_edit.vala           \
        main_window_file.vala           \
        main_window_structure.vala      \
+       main_window_tools.vala          \
        main_window.vala                \
        menu_in_toolbar.vala            \
        most_used_symbols.vala          \
diff --git a/src/main_window.vala b/src/main_window.vala
index b5bc6b4..c4724dd 100644
--- a/src/main_window.vala
+++ b/src/main_window.vala
@@ -101,6 +101,7 @@ public class MainWindow : Window
     private MainWindowBuildTools _main_window_build_tools;
     private MainWindowStructure _main_window_structure;
     private MainWindowDocuments _main_window_documents;
+    private MainWindowTools _main_window_tools;
 
     // context id for the statusbar
     private uint _tip_message_cid;
@@ -159,6 +160,7 @@ public class MainWindow : Window
         _main_window_build_tools = new MainWindowBuildTools (this, _ui_manager);
         _main_window_documents = new MainWindowDocuments (this, _ui_manager);
         _main_window_structure = new MainWindowStructure (_ui_manager);
+        _main_window_tools = new MainWindowTools (this, _ui_manager);
 
         show_images_in_menu ();
         set_file_actions_sensitivity (false);
diff --git a/src/main_window_edit.vala b/src/main_window_edit.vala
index 414be85..ef48883 100644
--- a/src/main_window_edit.vala
+++ b/src/main_window_edit.vala
@@ -75,12 +75,6 @@ public class MainWindowEdit
             N_("Configure the application"), on_open_preferences }
     };
 
-    private const ToggleActionEntry[] _toggle_action_entries =
-    {
-        { "EditSpellChecking", "tools-check-spelling", N_("_Spell Check"), null,
-            N_("Activate or disable the spell checking"), on_spell_checking }
-    };
-
     private unowned MainWindow _main_window;
     private Gtk.ActionGroup _action_group;
 
@@ -91,20 +85,8 @@ public class MainWindowEdit
         _action_group = new Gtk.ActionGroup ("EditMenuActionGroup");
         _action_group.set_translation_domain (Config.GETTEXT_PACKAGE);
         _action_group.add_actions (_action_entries, this);
-        _action_group.add_toggle_actions (_toggle_action_entries, this);
 
         ui_manager.insert_action_group (_action_group, 0);
-
-        /* Bind spell checking setting */
-
-        ToggleAction spell_checking_action =
-            _action_group.get_action ("EditSpellChecking") as ToggleAction;
-
-        GLib.Settings editor_settings =
-            new GLib.Settings ("org.gnome.latexila.preferences.editor");
-
-        editor_settings.bind ("spell-checking", spell_checking_action, "active",
-            SettingsBindFlags.DEFAULT);
     }
 
     /* Sensitivity */
@@ -290,19 +272,6 @@ public class MainWindowEdit
         _main_window.active_view.show_completion ();
     }
 
-    public void on_spell_checking (Gtk.Action action)
-    {
-        bool activate = (action as ToggleAction).active;
-
-        foreach (DocumentView view in _main_window.get_views ())
-        {
-            if (activate)
-                view.activate_spell_checking ();
-            else
-                view.disable_spell_checking ();
-        }
-    }
-
     public void on_open_preferences ()
     {
         PreferencesDialog.show_me (_main_window);
diff --git a/src/main_window_tools.vala b/src/main_window_tools.vala
new file mode 100644
index 0000000..0edd4da
--- /dev/null
+++ b/src/main_window_tools.vala
@@ -0,0 +1,77 @@
+/*
+ * This file is part of LaTeXila.
+ *
+ * Copyright © 2015 Sébastien Wilmet
+ *
+ * LaTeXila 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.
+ *
+ * LaTeXila 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 LaTeXila.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using Gtk;
+
+// The Tools menu of a MainWindow
+
+public class MainWindowTools
+{
+    private const Gtk.ActionEntry[] _action_entries =
+    {
+        { "Tools", null, N_("_Tools") }
+    };
+
+    private const ToggleActionEntry[] _toggle_action_entries =
+    {
+        { "ToolsInlineSpellChecker", "tools-check-spelling", N_("_Highlight Misspelled Words"), null,
+            N_("Highlight misspelled words in the document"), on_inline_spell_checker }
+    };
+
+    private unowned MainWindow _main_window;
+    private Gtk.ActionGroup _action_group;
+
+    public MainWindowTools (MainWindow main_window, UIManager ui_manager)
+    {
+        _main_window = main_window;
+
+        _action_group = new Gtk.ActionGroup ("ToolsMenuActionGroup");
+        _action_group.set_translation_domain (Config.GETTEXT_PACKAGE);
+        _action_group.add_actions (_action_entries, this);
+        _action_group.add_toggle_actions (_toggle_action_entries, this);
+
+        ui_manager.insert_action_group (_action_group, 0);
+
+        /* Bind spell checking setting */
+
+        ToggleAction spell_checking_action =
+            _action_group.get_action ("ToolsInlineSpellChecker") as ToggleAction;
+
+        GLib.Settings editor_settings =
+            new GLib.Settings ("org.gnome.latexila.preferences.editor");
+
+        editor_settings.bind ("spell-checking", spell_checking_action, "active",
+            SettingsBindFlags.DEFAULT);
+    }
+
+    /* Gtk.Action callbacks */
+
+    public void on_inline_spell_checker (Gtk.Action action)
+    {
+        bool activate = (action as ToggleAction).active;
+
+        foreach (DocumentView view in _main_window.get_views ())
+        {
+            if (activate)
+                view.activate_spell_checking ();
+            else
+                view.disable_spell_checking ();
+        }
+    }
+}
diff --git a/src/ui/ui.xml b/src/ui/ui.xml
index d095d85..61e0538 100644
--- a/src/ui/ui.xml
+++ b/src/ui/ui.xml
@@ -53,8 +53,6 @@ along with LaTeXila.  If not, see <http://www.gnu.org/licenses/>.
       <separator />
       <menuitem action="EditCompletion" />
       <separator />
-      <menuitem action="EditSpellChecking" />
-      <separator />
       <menuitem action="EditPreferences" />
     </menu>
 
@@ -372,6 +370,10 @@ along with LaTeXila.  If not, see <http://www.gnu.org/licenses/>.
       <menuitem action="ProjectsManage" />
     </menu>
 
+    <menu action="Tools">
+      <menuitem action="ToolsInlineSpellChecker" />
+    </menu>
+
     <menu action="Structure">
       <menuitem action="StructureCut" />
       <menuitem action="StructureCopy" />


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