[anjuta] git: Add a popup menu to the Stash pane



commit c8fa5bf8a7db2d2fff13864c382bc00ee495d0f7
Author: James Liggett <jrliggett cox net>
Date:   Sun Jun 9 22:00:20 2013 -0700

    git: Add a popup menu to the Stash pane

 plugins/git/anjuta-git.xml   |    7 ++++++
 plugins/git/git-pane.c       |   19 ++++++++++++++++++
 plugins/git/git-pane.h       |    3 ++
 plugins/git/git-stash-pane.c |   29 +++++++++++++++++++++++++++-
 plugins/git/plugin.c         |   43 ++++++++++++++++++++++++++++++++++++++++++
 plugins/git/plugin.h         |    1 +
 6 files changed, 101 insertions(+), 1 deletions(-)
---
diff --git a/plugins/git/anjuta-git.xml b/plugins/git/anjuta-git.xml
index f91a89c..efcb7d2 100644
--- a/plugins/git/anjuta-git.xml
+++ b/plugins/git/anjuta-git.xml
@@ -27,4 +27,11 @@
                <menuitem name="Pull..." action="GitRemotePull" />
                <menuitem name="Fetch" action="GitRemoteFetch" />
        </popup>
+
+       <popup name="GitStashPopup">
+               <menuitem name="Apply" action="GitStashApply" />
+               <menuitem name="Apply and restore index" action="GitStashApplyIndex" />
+               <menuitem name="Diff" action="GitStashDiff" />
+               <menuitem name="Drop" action="GitStashDrop" />
+       </popup>
 </ui>
\ No newline at end of file
diff --git a/plugins/git/git-pane.c b/plugins/git/git-pane.c
index 4601350..95ff136 100644
--- a/plugins/git/git-pane.c
+++ b/plugins/git/git-pane.c
@@ -59,6 +59,25 @@ git_pane_remove_from_dock (GitPane *self)
                                 ANJUTA_DOCK_PANE (self));
 }
 
+void
+git_pane_popup_menu (GitPane *self, const gchar *menu_name, guint button, 
+                     guint32 time)
+{
+       gchar *path;
+       AnjutaPlugin *plugin;
+       AnjutaUI *ui;
+       GtkMenu *menu;
+
+       path = g_strconcat ("/", menu_name, NULL);
+       plugin = anjuta_dock_pane_get_plugin (ANJUTA_DOCK_PANE (self));
+       ui = anjuta_shell_get_ui (plugin->shell, NULL);
+       menu = GTK_MENU (gtk_ui_manager_get_widget (GTK_UI_MANAGER (ui),
+                                                   path));
+
+       g_free (path);
+       gtk_menu_popup (menu, NULL, NULL, NULL, NULL, button, time);
+}
+
 static void
 on_message_view_destroyed (Git* plugin, gpointer destroyed_view)
 {
diff --git a/plugins/git/git-pane.h b/plugins/git/git-pane.h
index 1be0f16..52a2e56 100644
--- a/plugins/git/git-pane.h
+++ b/plugins/git/git-pane.h
@@ -51,6 +51,9 @@ struct _GitPane
 GType git_pane_get_type (void) G_GNUC_CONST;
 void git_pane_remove_from_dock (GitPane *self);
 
+void git_pane_popup_menu (GitPane *self, const gchar *menu_name, guint button, 
+                          guint32 time);
+
 /* Static helper methods */
 void git_pane_create_message_view (Git *plugin);
 void git_pane_on_command_info_arrived (AnjutaCommand *command, Git *plugin);
diff --git a/plugins/git/git-stash-pane.c b/plugins/git/git-stash-pane.c
index f61a7ab..34f8e25 100644
--- a/plugins/git/git-stash-pane.c
+++ b/plugins/git/git-stash-pane.c
@@ -97,6 +97,26 @@ on_stash_list_command_data_arrived (AnjutaCommand *command,
        }
 }
 
+static gboolean
+on_stash_view_button_press_event (GtkWidget *stash_view, GdkEventButton *event,
+                                  GitStashPane *self)
+{
+       GtkTreeSelection *selection;
+
+       if (event->type == GDK_BUTTON_PRESS && event->button == 3)
+       {
+               selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (stash_view));
+
+               if (gtk_tree_selection_count_selected_rows (selection) > 0)
+               {
+                       git_pane_popup_menu (GIT_PANE (self), "GitStashPopup", event->button,
+                                            event->time);
+               }
+       }
+
+       return FALSE;
+}
+
 static void
 git_stash_pane_init (GitStashPane *self)
 {
@@ -104,10 +124,10 @@ git_stash_pane_init (GitStashPane *self)
                                                "stash_list_model",
                                                NULL};
        GError *error = NULL;
+       GtkWidget *stash_view;
        
        self->priv = g_new0 (GitStashPanePriv, 1);
        self->priv->builder = gtk_builder_new ();
-       
 
        if (!gtk_builder_add_objects_from_file (self->priv->builder, BUILDER_FILE, 
                                                objects, 
@@ -116,6 +136,13 @@ git_stash_pane_init (GitStashPane *self)
                g_warning ("Couldn't load builder file: %s", error->message);
                g_error_free (error);
        }
+
+       stash_view = GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
+                                                        "stash_view"));
+
+       g_signal_connect (G_OBJECT (stash_view), "button-press-event",
+                         G_CALLBACK (on_stash_view_button_press_event),
+                         self);
 }
 
 static void
diff --git a/plugins/git/plugin.c b/plugins/git/plugin.c
index 07f32ca..23f5416 100644
--- a/plugins/git/plugin.c
+++ b/plugins/git/plugin.c
@@ -597,6 +597,42 @@ static GtkActionEntry remote_menu_entries[] =
        }
 };
 
+static GtkActionEntry stash_menu_entries[] =
+{
+       {
+               "GitStashApply",
+               NULL,
+               N_("Apply"),
+               NULL,
+               NULL,
+               G_CALLBACK (on_apply_stash_button_clicked)
+       },
+       {
+               "GitStashApplyIndex",
+               NULL,
+               N_("Apply and restore index"),
+               NULL,
+               NULL,
+               G_CALLBACK (on_apply_stash_index_button_clicked)
+       },
+       {
+               "GitStashDiff",
+               NULL,
+               N_("Diff"),
+               NULL,
+               NULL,
+               G_CALLBACK (on_diff_stash_button_clicked)
+       },
+       {
+               "GitStashDrop",
+               NULL,
+               N_("Drop"),
+               NULL,
+               NULL,
+               G_CALLBACK (on_drop_stash_button_clicked)
+       }
+};
+
 static gpointer parent_class;
 
 static void
@@ -859,6 +895,12 @@ git_activate_plugin (AnjutaPlugin *plugin)
                                                                            remote_menu_entries,
                                                                            G_N_ELEMENTS 
(remote_menu_entries),
                                                                            GETTEXT_PACKAGE, FALSE, plugin);
+       git_plugin->stash_menu_group = anjuta_ui_add_action_group_entries (ui, "GitStashPopup",
+                                                                          _("Popup menu entries"),
+                                                                          stash_menu_entries,
+                                                                          G_N_ELEMENTS (stash_menu_entries),
+                                                                          GETTEXT_PACKAGE,
+                                                                          FALSE, plugin);
 
        
        /* Create the branch list commands. There are two commands because some 
@@ -1001,6 +1043,7 @@ git_deactivate_plugin (AnjutaPlugin *plugin)
        anjuta_ui_remove_action_group (ui, git_plugin->log_menu_group);
        anjuta_ui_remove_action_group (ui, git_plugin->branch_menu_group);
        anjuta_ui_remove_action_group (ui, git_plugin->remote_menu_group);
+       anjuta_ui_remove_action_group (ui, git_plugin->stash_menu_group);
        anjuta_ui_unmerge (ui, git_plugin->uiid);
 
        g_object_unref (git_plugin->local_branch_list_command);
diff --git a/plugins/git/plugin.h b/plugins/git/plugin.h
index f9bc5db..41325cf 100644
--- a/plugins/git/plugin.h
+++ b/plugins/git/plugin.h
@@ -83,6 +83,7 @@ struct _Git
        GtkActionGroup *log_menu_group;
        GtkActionGroup *branch_menu_group;
        GtkActionGroup *remote_menu_group;
+       GtkActionGroup *stash_menu_group;
 
        /* List commands for various panes. 
         * Keep them in the plugin so that the commands have the most direct


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