[tepl] Edit menu: implement cut, copy, paste and delete GActions



commit 032b5965ce5997e710226d5ef8f94d0b363aa9ed
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Thu Jul 13 09:52:44 2017 +0200

    Edit menu: implement cut, copy, paste and delete GActions
    
    Without caring about the GAction:enabled property for now.

 tepl/tepl-application-window-actions.c |   71 +++++++++++++++++++++++++++++++-
 tepl/tepl-application-window.c         |    4 ++
 tepl/tepl-application.c                |   24 ++++++----
 3 files changed, 88 insertions(+), 11 deletions(-)
---
diff --git a/tepl/tepl-application-window-actions.c b/tepl/tepl-application-window-actions.c
index b4fa79d..260c02f 100644
--- a/tepl/tepl-application-window-actions.c
+++ b/tepl/tepl-application-window-actions.c
@@ -28,6 +28,70 @@
  */
 
 static void
+cut_cb (GSimpleAction *action,
+       GVariant      *parameter,
+       gpointer       user_data)
+{
+       TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+       TeplView *active_view;
+
+       active_view = tepl_tab_group_get_active_view (TEPL_TAB_GROUP (tepl_window));
+
+       if (active_view != NULL)
+       {
+               tepl_view_cut_clipboard (active_view);
+       }
+}
+
+static void
+copy_cb (GSimpleAction *action,
+        GVariant      *parameter,
+        gpointer       user_data)
+{
+       TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+       TeplView *active_view;
+
+       active_view = tepl_tab_group_get_active_view (TEPL_TAB_GROUP (tepl_window));
+
+       if (active_view != NULL)
+       {
+               tepl_view_copy_clipboard (active_view);
+       }
+}
+
+static void
+paste_cb (GSimpleAction *action,
+         GVariant      *parameter,
+         gpointer       user_data)
+{
+       TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+       TeplView *active_view;
+
+       active_view = tepl_tab_group_get_active_view (TEPL_TAB_GROUP (tepl_window));
+
+       if (active_view != NULL)
+       {
+               tepl_view_paste_clipboard (active_view);
+       }
+}
+
+static void
+delete_cb (GSimpleAction *action,
+          GVariant      *parameter,
+          gpointer       user_data)
+{
+       TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+       TeplView *active_view;
+
+       active_view = tepl_tab_group_get_active_view (TEPL_TAB_GROUP (tepl_window));
+
+       if (active_view != NULL)
+       {
+               tepl_view_delete_selection (active_view);
+       }
+}
+
+static void
 select_all_cb (GSimpleAction *action,
               GVariant      *parameter,
               gpointer       user_data)
@@ -52,9 +116,14 @@ _tepl_application_window_add_actions (TeplApplicationWindow *tepl_window)
         * application or other libraries.
         *
         * Do not forget to document each action in the TeplApplicationWindow
-        * class description.
+        * class description, and to add the corresponding TeplActionInfoEntry
+        * in tepl-application.c.
         */
        const GActionEntry entries[] = {
+               { "tepl-cut", cut_cb },
+               { "tepl-copy", copy_cb },
+               { "tepl-paste", paste_cb },
+               { "tepl-delete", delete_cb },
                { "tepl-select-all", select_all_cb },
        };
 
diff --git a/tepl/tepl-application-window.c b/tepl/tepl-application-window.c
index 2cc84b1..0b95b55 100644
--- a/tepl/tepl-application-window.c
+++ b/tepl/tepl-application-window.c
@@ -47,6 +47,10 @@
  * # GActions # {#tepl-application-window-gactions}
  *
  * This class adds the following #GAction's to the #GtkApplicationWindow:
+ * - `"win.tepl-cut"`: calls tepl_view_cut_clipboard() on the active view.
+ * - `"win.tepl-copy"`: calls tepl_view_copy_clipboard() on the active view.
+ * - `"win.tepl-paste"`: calls tepl_view_paste_clipboard() on the active view.
+ * - `"win.tepl-delete"`: calls tepl_view_delete_selection() on the active view.
  * - `"win.tepl-select-all"`: calls tepl_view_select_all() on the active view.
  *
  * Corresponding #TeplActionInfo's are available with
diff --git a/tepl/tepl-application.c b/tepl/tepl-application.c
index ea11a27..902f05c 100644
--- a/tepl/tepl-application.c
+++ b/tepl/tepl-application.c
@@ -71,13 +71,20 @@ init_tepl_action_info_store (TeplApplication *tepl_app)
 {
        const TeplActionInfoEntry entries[] =
        {
-               /* When adding an item to this array, do not forget to update
-                * the documentation of
-                * tepl_application_get_tepl_action_info_store().
-                */
-
                /* action, icon, label, accel, tooltip */
 
+               { "win.tepl-cut", "edit-cut", N_("Cu_t"), "<Control>x",
+                 N_("Cut the selection") },
+
+               { "win.tepl-copy", "edit-copy", N_("_Copy"), "<Control>c",
+                 N_("Copy the selection") },
+
+               { "win.tepl-paste", "edit-paste", N_("_Paste"), "<Control>v",
+                 N_("Paste the clipboard") },
+
+               { "win.tepl-delete", "edit-delete", N_("_Delete"), NULL,
+                 N_("Delete the selected text") },
+
                { "win.tepl-select-all", "edit-select-all", N_("Select _All"), "<Control>a",
                  N_("Select all the text") },
        };
@@ -279,11 +286,8 @@ tepl_application_get_app_action_info_store (TeplApplication *tepl_app)
  * tepl_application_get_tepl_action_info_store:
  * @tepl_app: a #TeplApplication.
  *
- * The returned #TeplActionInfoStore contains #TeplActionInfo's for the
- * following actions:
- * - `"win.tepl-select-all"`
- *
- * To know what the #GAction's do, see the [class description of
+ * The returned #TeplActionInfoStore contains #TeplActionInfo's for all the
+ * #GAction's listed  in the [class description of
  * TeplApplicationWindow][tepl-application-window-gactions].
  *
  * Returns: (transfer none): the #TeplActionInfoStore of the Tepl library.


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