[gnome-builder] glade: add undo/redo support
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] glade: add undo/redo support
- Date: Mon, 22 Oct 2018 05:37:39 +0000 (UTC)
commit 28fececffc0a68a0011e07fbaacaf1353464743c
Author: Christian Hergert <chergert redhat com>
Date: Sun Oct 21 22:37:21 2018 -0700
glade: add undo/redo support
This adds actions for undo/redo and wires up shortcuts to them. It also
adds menu entries for the document menu.
src/plugins/glade/gbp-glade-view-actions.c | 59 ++++++++++++++++++++++++++++
src/plugins/glade/gbp-glade-view-shortcuts.c | 24 +++++++++++
src/plugins/glade/gtk/menus.ui | 12 ++++++
3 files changed, 95 insertions(+)
---
diff --git a/src/plugins/glade/gbp-glade-view-actions.c b/src/plugins/glade/gbp-glade-view-actions.c
index 42170e368..33fbb725a 100644
--- a/src/plugins/glade/gbp-glade-view-actions.c
+++ b/src/plugins/glade/gbp-glade-view-actions.c
@@ -109,12 +109,64 @@ gbp_glade_view_action_pointer_mode (GSimpleAction *action,
glade_project_set_pointer_mode (project, value->value);
}
+static void
+gbp_glade_view_action_undo (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_undo (self->project);
+}
+
+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);
+}
+
static GActionEntry actions[] = {
+ { "redo", gbp_glade_view_action_redo },
+ { "undo", gbp_glade_view_action_undo },
{ "save", gbp_glade_view_action_save },
{ "preview", gbp_glade_view_action_preview },
{ "pointer-mode", gbp_glade_view_action_pointer_mode, "s" },
};
+static void
+gbp_glade_view_update_actions_cb (GbpGladeView *self,
+ GladeCommand *command,
+ gboolean execute,
+ GladeProject *project)
+{
+ GladeCommand *redo;
+ GladeCommand *undo;
+
+ g_assert (GBP_IS_GLADE_VIEW (self));
+ g_assert (!command || GLADE_IS_COMMAND (command));
+ g_assert (GLADE_IS_PROJECT (project));
+
+ redo = glade_project_next_redo_item (project);
+ undo = glade_project_next_undo_item (project);
+
+ dzl_gtk_widget_action_set (GTK_WIDGET (self), "glade-view", "undo",
+ "enabled", undo != NULL,
+ NULL);
+ dzl_gtk_widget_action_set (GTK_WIDGET (self), "glade-view", "redo",
+ "enabled", redo != NULL,
+ NULL);
+}
+
void
_gbp_glade_view_init_actions (GbpGladeView *self)
{
@@ -130,4 +182,11 @@ _gbp_glade_view_init_actions (GbpGladeView *self)
gtk_widget_insert_action_group (GTK_WIDGET (self),
"glade-view",
G_ACTION_GROUP (group));
+
+ g_signal_connect_object (self->project,
+ "changed",
+ G_CALLBACK (gbp_glade_view_update_actions_cb),
+ self,
+ G_CONNECT_SWAPPED);
+ gbp_glade_view_update_actions_cb (self, NULL, FALSE, self->project);
}
diff --git a/src/plugins/glade/gbp-glade-view-shortcuts.c b/src/plugins/glade/gbp-glade-view-shortcuts.c
index 19489c4be..a383282fc 100644
--- a/src/plugins/glade/gbp-glade-view-shortcuts.c
+++ b/src/plugins/glade/gbp-glade-view-shortcuts.c
@@ -42,6 +42,18 @@ static DzlShortcutEntry glade_view_shortcuts[] = {
NC_("shortcut window", "Glade shortcuts"),
NC_("shortcut window", "Designer"),
NC_("shortcut window", "Preview the interface design") },
+
+ { "org.gnome.builder.glade-view.undo",
+ 0, NULL,
+ NC_("shortcut window", "Glade shortcuts"),
+ NC_("shortcut window", "Designer"),
+ NC_("shortcut window", "Undo the last command") },
+
+ { "org.gnome.builder.glade-view.redo",
+ 0, NULL,
+ NC_("shortcut window", "Glade shortcuts"),
+ NC_("shortcut window", "Designer"),
+ NC_("shortcut window", "Redo the next command") },
};
void
@@ -65,6 +77,18 @@ _gbp_glade_view_init_shortcuts (GtkWidget *widget)
DZL_SHORTCUT_PHASE_BUBBLE,
I_("glade-view.preview"));
+ dzl_shortcut_controller_add_command_action (controller,
+ I_("org.gnome.builder.glade-view.undo"),
+ "<Control>z",
+ DZL_SHORTCUT_PHASE_BUBBLE,
+ I_("glade-view.undo"));
+
+ dzl_shortcut_controller_add_command_action (controller,
+ I_("org.gnome.builder.glade-view.redo"),
+ "<Control><Shift>z",
+ DZL_SHORTCUT_PHASE_BUBBLE,
+ I_("glade-view.redo"));
+
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 9fbac118d..29a5f0587 100644
--- a/src/plugins/glade/gtk/menus.ui
+++ b/src/plugins/glade/gtk/menus.ui
@@ -16,6 +16,18 @@
<attribute name="accel"><control><alt>p</attribute>
</item>
</section>
+ <section id="glade-undo-section">
+ <item>
+ <attribute name="action">glade-view.undo</attribute>
+ <attribute name="label" translatable="yes">Undo</attribute>
+ <attribute name="accel"><control>z</attribute>
+ </item>
+ <item>
+ <attribute name="action">glade-view.redo</attribute>
+ <attribute name="label" translatable="yes">Redo</attribute>
+ <attribute name="accel"><control><shift>z</attribute>
+ </item>
+ </section>
</menu>
<menu id="gb-project-tree-popup-menu">
<section id="gb-project-tree-open-section">
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]