[latexila] MainWindowEdit: bind some Tepl GActions to latexila GtkActions



commit 8acda9cac07083c20dd83d64e4234bb7b033bf51
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Mon Aug 14 07:19:00 2017 +0200

    MainWindowEdit: bind some Tepl GActions to latexila GtkActions

 src/main_window.vala      |    6 ++--
 src/main_window_edit.vala |   79 +++++++++-----------------------------------
 2 files changed, 19 insertions(+), 66 deletions(-)
---
diff --git a/src/main_window.vala b/src/main_window.vala
index c7b8055..0b0d64d 100644
--- a/src/main_window.vala
+++ b/src/main_window.vala
@@ -155,6 +155,9 @@ public class MainWindow : ApplicationWindow
         Object (application: app);
         this.title = "LaTeXila";
 
+        Tepl.ApplicationWindow tepl_window =
+            Tepl.ApplicationWindow.get_from_gtk_application_window (this);
+
         initialize_ui_manager ();
 
         _main_window_file = new MainWindowFile (this, _ui_manager);
@@ -230,9 +233,6 @@ public class MainWindow : ApplicationWindow
         // Documents panel
         init_documents_panel ();
         docs_vgrid.add (_documents_panel);
-
-        Tepl.ApplicationWindow tepl_window =
-            Tepl.ApplicationWindow.get_from_gtk_application_window (this);
         tepl_window.set_tab_group (_documents_panel);
 
         // Goto Line
diff --git a/src/main_window_edit.vala b/src/main_window_edit.vala
index 96186ed..3a3d26c 100644
--- a/src/main_window_edit.vala
+++ b/src/main_window_edit.vala
@@ -36,23 +36,23 @@ public class MainWindowEdit
             N_("Redo the last undone action"), on_redo },
 
         { "EditCut", "edit-cut", N_("Cu_t"), "<Control>X",
-            N_("Cut the selection"), on_cut },
+            N_("Cut the selection") },
 
         { "EditCopy", "edit-copy", N_("_Copy"), "<Control>C",
-            N_("Copy the selection"), on_copy },
+            N_("Copy the selection") },
 
         // No shortcut here because if the shortcut is null, Ctrl+V is used for _all_
         // the window. In this case Ctrl+V in the search text entry would be broken (the
         // text is pasted in the document instead of the entry).
         // Anyway if we press Ctrl+V when the cursor is in the document, no problem.
         { "EditPaste", "edit-paste", N_("_Paste"), "",
-            N_("Paste the clipboard"), on_paste },
+            N_("Paste the clipboard") },
 
         { "EditDelete", "edit-delete", N_("_Delete"), null,
-            N_("Delete the selected text"), on_delete },
+            N_("Delete the selected text") },
 
         { "EditSelectAll", "edit-select-all", N_("Select _All"), "<Control>A",
-            N_("Select the entire document"), on_select_all },
+            N_("Select the entire document") },
 
         { "EditIndent", "format-indent-more", N_("_Indent"), "Tab",
             N_("Indent the selected lines"), on_indent },
@@ -87,6 +87,17 @@ public class MainWindowEdit
         _action_group.add_actions (_action_entries, this);
 
         ui_manager.insert_action_group (_action_group, 0);
+
+        Amtk.utils_bind_g_action_to_gtk_action (main_window, "tepl-cut",
+            _action_group, "EditCut");
+        Amtk.utils_bind_g_action_to_gtk_action (main_window, "tepl-copy",
+            _action_group, "EditCopy");
+        Amtk.utils_bind_g_action_to_gtk_action (main_window, "tepl-paste",
+            _action_group, "EditPaste");
+        Amtk.utils_bind_g_action_to_gtk_action (main_window, "tepl-delete",
+            _action_group, "EditDelete");
+        Amtk.utils_bind_g_action_to_gtk_action (main_window, "tepl-select-all",
+            _action_group, "EditSelectAll");
     }
 
     /* Sensitivity */
@@ -99,7 +110,6 @@ public class MainWindowEdit
 
         if (sensitive)
         {
-            set_has_selection_sensitivity ();
             set_undo_sensitivity ();
             set_redo_sensitivity ();
         }
@@ -111,11 +121,6 @@ public class MainWindowEdit
         {
             "EditUndo",
             "EditRedo",
-            "EditCut",
-            "EditCopy",
-            "EditPaste",
-            "EditDelete",
-            "EditSelectAll",
             "EditIndent",
             "EditUnindent",
             "EditComment",
@@ -130,28 +135,6 @@ public class MainWindowEdit
         }
     }
 
-    private void set_has_selection_sensitivity ()
-    {
-        bool has_selection = false;
-
-        if (_main_window.active_tab != null)
-            has_selection = _main_window.active_document.has_selection;
-
-        // Actions that must be insensitive if there is no selection.
-        string[] action_names =
-        {
-            "EditCut",
-            "EditCopy",
-            "EditDelete"
-        };
-
-        foreach (string action_name in action_names)
-        {
-            Gtk.Action action = _action_group.get_action (action_name);
-            action.sensitive = has_selection;
-        }
-    }
-
     private void set_undo_sensitivity ()
     {
         bool can_undo = false;
@@ -200,36 +183,6 @@ public class MainWindowEdit
         }
     }
 
-    public void on_cut ()
-    {
-        return_if_fail (_main_window.active_tab != null);
-        _main_window.active_view.cut_clipboard ();
-    }
-
-    public void on_copy ()
-    {
-        return_if_fail (_main_window.active_tab != null);
-        _main_window.active_view.copy_clipboard ();
-    }
-
-    public void on_paste ()
-    {
-        return_if_fail (_main_window.active_tab != null);
-        _main_window.active_view.paste_clipboard ();
-    }
-
-    public void on_delete ()
-    {
-        return_if_fail (_main_window.active_tab != null);
-        _main_window.active_view.delete_selection ();
-    }
-
-    public void on_select_all ()
-    {
-        return_if_fail (_main_window.active_tab != null);
-        _main_window.active_view.select_all ();
-    }
-
     public void on_indent ()
     {
         DocumentTab? tab = _main_window.active_tab;


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