[gnome-builder] glade: add various clipboard commands



commit 32e5d6cc154039733b6aa8e8b08a7b141187082b
Author: Christian Hergert <chergert redhat com>
Date:   Mon Oct 22 09:52:44 2018 -0700

    glade: add various clipboard commands

 src/plugins/glade/gbp-glade-view-actions.c   | 43 ++++++++++++++++++----------
 src/plugins/glade/gbp-glade-view-shortcuts.c | 24 ++++++++++++++++
 src/plugins/glade/gtk/menus.ui               | 22 ++++++++++++++
 3 files changed, 74 insertions(+), 15 deletions(-)
---
diff --git a/src/plugins/glade/gbp-glade-view-actions.c b/src/plugins/glade/gbp-glade-view-actions.c
index 33fbb725a..143b3b38e 100644
--- a/src/plugins/glade/gbp-glade-view-actions.c
+++ b/src/plugins/glade/gbp-glade-view-actions.c
@@ -110,32 +110,45 @@ gbp_glade_view_action_pointer_mode (GSimpleAction *action,
 }
 
 static void
-gbp_glade_view_action_undo (GSimpleAction *action,
-                            GVariant      *param,
-                            gpointer       user_data)
+gbp_glade_view_action_paste (GSimpleAction *action,
+                             GVariant      *param,
+                             gpointer       user_data)
 {
   GbpGladeView *self = user_data;
+  GtkWidget *placeholder;
 
   g_assert (G_IS_SIMPLE_ACTION (action));
   g_assert (GBP_IS_GLADE_VIEW (self));
 
-  glade_project_undo (self->project);
+  placeholder = glade_util_get_placeholder_from_pointer (GTK_CONTAINER (self));
+  glade_project_command_paste (self->project, placeholder ? GLADE_PLACEHOLDER (placeholder) : NULL);
 }
 
-static void
-gbp_glade_view_action_redo (GSimpleAction *action,
-                            GVariant      *param,
-                            gpointer       user_data)
-{
-  GbpGladeView *self = user_data;
-
-  g_assert (G_IS_SIMPLE_ACTION (action));
-  g_assert (GBP_IS_GLADE_VIEW (self));
-
-  glade_project_redo (self->project);
+#define WRAP_PROJECT_ACTION(name, func)                 \
+static void                                             \
+gbp_glade_view_action_##name (GSimpleAction *action,    \
+                              GVariant      *param,     \
+                              gpointer       user_data) \
+{                                                       \
+  GbpGladeView *self = user_data;                       \
+                                                        \
+  g_assert (G_IS_SIMPLE_ACTION (action));               \
+  g_assert (GBP_IS_GLADE_VIEW (self));                  \
+                                                        \
+  glade_project_##func (self->project);                 \
 }
 
+WRAP_PROJECT_ACTION (cut, command_cut)
+WRAP_PROJECT_ACTION (copy, copy_selection)
+WRAP_PROJECT_ACTION (delete, command_delete)
+WRAP_PROJECT_ACTION (redo, redo)
+WRAP_PROJECT_ACTION (undo, undo)
+
 static GActionEntry actions[] = {
+  { "cut", gbp_glade_view_action_cut },
+  { "copy", gbp_glade_view_action_copy },
+  { "paste", gbp_glade_view_action_paste },
+  { "delete", gbp_glade_view_action_delete },
   { "redo", gbp_glade_view_action_redo },
   { "undo", gbp_glade_view_action_undo },
   { "save", gbp_glade_view_action_save },
diff --git a/src/plugins/glade/gbp-glade-view-shortcuts.c b/src/plugins/glade/gbp-glade-view-shortcuts.c
index a383282fc..d4cf2c39c 100644
--- a/src/plugins/glade/gbp-glade-view-shortcuts.c
+++ b/src/plugins/glade/gbp-glade-view-shortcuts.c
@@ -89,6 +89,30 @@ _gbp_glade_view_init_shortcuts (GtkWidget *widget)
                                               DZL_SHORTCUT_PHASE_BUBBLE,
                                               I_("glade-view.redo"));
 
+  dzl_shortcut_controller_add_command_action (controller,
+                                              I_("org.gnome.builder.glade-view.copy"),
+                                              "<Primary>c",
+                                              DZL_SHORTCUT_PHASE_BUBBLE,
+                                              I_("glade-view.copy"));
+
+  dzl_shortcut_controller_add_command_action (controller,
+                                              I_("org.gnome.builder.glade-view.cut"),
+                                              "<Primary>x",
+                                              DZL_SHORTCUT_PHASE_BUBBLE,
+                                              I_("glade-view.cut"));
+
+  dzl_shortcut_controller_add_command_action (controller,
+                                              I_("org.gnome.builder.glade-view.paste"),
+                                              "<Primary>v",
+                                              DZL_SHORTCUT_PHASE_BUBBLE,
+                                              I_("glade-view.paste"));
+
+  dzl_shortcut_controller_add_command_action (controller,
+                                              I_("org.gnome.builder.glade-view.delete"),
+                                              "Delete",
+                                              DZL_SHORTCUT_PHASE_BUBBLE,
+                                              I_("glade-view.delete"));
+
   dzl_shortcut_manager_add_shortcut_entries (NULL,
                                              glade_view_shortcuts,
                                              G_N_ELEMENTS (glade_view_shortcuts),
diff --git a/src/plugins/glade/gtk/menus.ui b/src/plugins/glade/gtk/menus.ui
index 29a5f0587..2c7eba481 100644
--- a/src/plugins/glade/gtk/menus.ui
+++ b/src/plugins/glade/gtk/menus.ui
@@ -16,6 +16,28 @@
         <attribute name="accel">&lt;control&gt;&lt;alt&gt;p</attribute>
       </item>
     </section>
+    <section id="glade-clipboard-section">
+      <item>
+        <attribute name="action">glade-view.cut</attribute>
+        <attribute name="label" translatable="yes">Cut</attribute>
+        <attribute name="accel">&lt;primary&gt;x</attribute>
+      </item>
+      <item>
+        <attribute name="action">glade-view.copy</attribute>
+        <attribute name="label" translatable="yes">Copy</attribute>
+        <attribute name="accel">&lt;primary&gt;c</attribute>
+      </item>
+      <item>
+        <attribute name="action">glade-view.paste</attribute>
+        <attribute name="label" translatable="yes">Paste</attribute>
+        <attribute name="accel">&lt;primary&gt;v</attribute>
+      </item>
+      <item>
+        <attribute name="action">glade-view.delete</attribute>
+        <attribute name="label" translatable="yes">Delete</attribute>
+        <attribute name="accel">Delete</attribute>
+      </item>
+    </section>
     <section id="glade-undo-section">
       <item>
         <attribute name="action">glade-view.undo</attribute>


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