[anjuta] git: Add a context menu to the log pane



commit 74794bb224031b5a8440fdcaca0bf3ddca2b42ae
Author: James Liggett <jrliggett cox net>
Date:   Mon May 27 16:02:13 2013 -0700

    git: Add a context menu to the log pane

 plugins/git/anjuta-git.xml         |    8 ++++++
 plugins/git/git-cherry-pick-pane.c |   33 +++++++++++++++++++++++-
 plugins/git/git-cherry-pick-pane.h |    2 +
 plugins/git/git-log-pane.c         |   34 ++++++++++++++++++++++++
 plugins/git/git-reset-pane.c       |   50 +++++++++++++++++++++++++++++++++--
 plugins/git/git-reset-pane.h       |    3 ++
 plugins/git/git-revert-pane.c      |   30 +++++++++++++++++++++
 plugins/git/git-revert-pane.h      |    2 +
 plugins/git/plugin.c               |   43 +++++++++++++++++++++++++++++++
 plugins/git/plugin.h               |    1 +
 10 files changed, 202 insertions(+), 4 deletions(-)
---
diff --git a/plugins/git/anjuta-git.xml b/plugins/git/anjuta-git.xml
index 1d20b48..a960c7e 100644
--- a/plugins/git/anjuta-git.xml
+++ b/plugins/git/anjuta-git.xml
@@ -7,4 +7,12 @@
     <popup name="GitStatusCommitPopup">
         <menuitem name="Unstage" action="GitStatusUnstage" />    
     </popup>
+
+       <popup name="GitLogPopup">
+               <menuitem name="Show commit diff" action="GitLogShowDiff" />
+               <menuitem name="Cherry pick" action="GitLogCherryPick" />
+               <separator />
+               <menuitem name="Revert" action="GitLogRevert" />
+               <menuitem name="Reset..." action="GitLogReset" />
+       </popup>
 </ui>
\ No newline at end of file
diff --git a/plugins/git/git-cherry-pick-pane.c b/plugins/git/git-cherry-pick-pane.c
index 53893bb..e4cc01c 100644
--- a/plugins/git/git-cherry-pick-pane.c
+++ b/plugins/git/git-cherry-pick-pane.c
@@ -175,4 +175,35 @@ on_cherry_pick_button_clicked (GtkAction *action, Git *plugin)
        anjuta_dock_replace_command_pane (ANJUTA_DOCK (plugin->dock), "CherryPick", 
                                          _("Cherry Pick"), NULL, pane, GDL_DOCK_BOTTOM, NULL, 
                                          0, NULL);
-}
\ No newline at end of file
+}
+
+void
+on_git_log_cherry_pick_activated (GtkAction *action, Git *plugin)
+{
+       GitRevision *revision;
+       gchar *sha;
+       GitCherryPickCommand *cherry_pick_command;
+
+       revision = git_log_pane_get_selected_revision (GIT_LOG_PANE (plugin->log_pane));
+
+       if (revision)
+       {
+               sha = git_revision_get_sha (revision);
+               cherry_pick_command = git_cherry_pick_command_new (plugin->project_root_directory,
+                                                                  sha, FALSE, FALSE, 
+                                                                  FALSE);
+
+               g_signal_connect (G_OBJECT (cherry_pick_command), "command-finished",
+                                 G_CALLBACK (git_pane_report_errors),
+                                 plugin);
+
+               g_signal_connect (G_OBJECT (cherry_pick_command), "command-finished",
+                                 G_CALLBACK (g_object_unref),
+                                 NULL);
+
+               anjuta_command_start (ANJUTA_COMMAND (cherry_pick_command));
+
+               g_free (sha);
+               g_object_unref (revision);
+       }
+}
diff --git a/plugins/git/git-cherry-pick-pane.h b/plugins/git/git-cherry-pick-pane.h
index 8c21138..0d23991 100644
--- a/plugins/git/git-cherry-pick-pane.h
+++ b/plugins/git/git-cherry-pick-pane.h
@@ -25,6 +25,7 @@
 #include "git-pane.h"
 #include "plugin.h"
 #include "git-cherry-pick-command.h"
+#include "git-log-pane.h"
 
 G_BEGIN_DECLS
 
@@ -54,6 +55,7 @@ struct _GitCherryPickPane
 GType git_cherry_pick_pane_get_type (void) G_GNUC_CONST;
 AnjutaDockPane *git_cherry_pick_pane_new (Git *plugin);
 void on_cherry_pick_button_clicked (GtkAction *action, Git *plugin);
+void on_git_log_cherry_pick_activated (GtkAction *action, Git *plugin);
 
 G_END_DECLS
 
diff --git a/plugins/git/git-log-pane.c b/plugins/git/git-log-pane.c
index e9f5531..e159214 100644
--- a/plugins/git/git-log-pane.c
+++ b/plugins/git/git-log-pane.c
@@ -801,6 +801,35 @@ on_path_entry_icon_release (GtkEntry *entry,
        }
 }
 
+static gboolean
+on_log_view_button_press_event (GtkWidget *log_view, GdkEventButton *event,
+                                GitLogPane *self)
+{
+       GtkMenu *menu;
+       GtkTreeSelection *selection;
+       AnjutaPlugin *plugin;
+       AnjutaUI *ui;
+
+       if (event->type == GDK_BUTTON_PRESS && event->button == 3)
+       {
+               selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (log_view));
+
+               if (gtk_tree_selection_count_selected_rows (selection) > 0)
+               {
+                       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),
+                                                                   "/GitLogPopup"));
+
+                       gtk_menu_popup (menu, NULL, NULL, NULL, NULL, event->button, 
+                                       event->time);
+               }
+       }
+
+       return FALSE;
+}
+
 static void
 git_log_pane_init (GitLogPane *self)
 {
@@ -966,6 +995,11 @@ git_log_pane_init (GitLogPane *self)
                          G_CALLBACK (on_log_pane_drag_drop),
                          self);
 
+       /* Pop up menu */
+       g_signal_connect (G_OBJECT (log_view), "button-press-event",
+                         G_CALLBACK (on_log_view_button_press_event),
+                         self);
+
        /* The loading view always has one row. Cache a copy of its iter for easy
         * access. */
        gtk_tree_model_get_iter_first (GTK_TREE_MODEL (self->priv->log_loading_model), 
diff --git a/plugins/git/git-reset-pane.c b/plugins/git/git-reset-pane.c
index aa7945e..b902754 100644
--- a/plugins/git/git-reset-pane.c
+++ b/plugins/git/git-reset-pane.c
@@ -154,6 +154,29 @@ git_reset_pane_new (Git *plugin)
        return g_object_new (GIT_TYPE_RESET_PANE, "plugin", plugin, NULL);
 }
 
+AnjutaDockPane *
+git_reset_pane_new_with_sha (Git *plugin, const gchar *sha)
+{
+       GitResetPane *self;
+       AnjutaEntry *reset_revision_entry;
+
+       self = g_object_new (GIT_TYPE_RESET_PANE, "plugin", plugin, NULL);
+       reset_revision_entry = ANJUTA_ENTRY (gtk_builder_get_object (self->priv->builder,
+                                                                    "reset_revision_entry"));
+
+       anjuta_entry_set_text (reset_revision_entry, sha);
+
+       return ANJUTA_DOCK_PANE (self);
+}
+
+static void
+add_pane (AnjutaDockPane *pane, Git *plugin)
+{
+       anjuta_dock_replace_command_pane (ANJUTA_DOCK (plugin->dock), "Reset", 
+                                         _("Reset"), NULL, pane, GDL_DOCK_BOTTOM, 
+                                         NULL, 0, NULL);
+}
+
 void
 on_reset_button_clicked (GtkAction *action, Git *plugin)
 {
@@ -161,7 +184,28 @@ on_reset_button_clicked (GtkAction *action, Git *plugin)
 
        pane = git_reset_pane_new (plugin);
 
-       anjuta_dock_replace_command_pane (ANJUTA_DOCK (plugin->dock), "Reset", 
-                                         _("Reset"), NULL, pane, GDL_DOCK_BOTTOM, NULL, 0,
-                                         NULL);
+       add_pane (pane, plugin);
+
+       
+}
+
+void
+on_git_log_reset_activated (GtkAction *action, Git *plugin)
+{
+       GitRevision *revision;
+       gchar *sha;
+       AnjutaDockPane *pane;
+
+       revision = git_log_pane_get_selected_revision (GIT_LOG_PANE (plugin->log_pane));
+
+       if (revision)
+       {
+               sha = git_revision_get_sha (revision);
+               pane = git_reset_pane_new_with_sha (plugin, sha);
+
+               add_pane (pane, plugin);
+
+               g_free (sha);
+               g_object_unref (revision);
+       }
 }
\ No newline at end of file
diff --git a/plugins/git/git-reset-pane.h b/plugins/git/git-reset-pane.h
index 5f0d0e5..395eb8a 100644
--- a/plugins/git/git-reset-pane.h
+++ b/plugins/git/git-reset-pane.h
@@ -25,6 +25,7 @@
 #include "git-pane.h"
 #include "plugin.h"
 #include "git-reset-tree-command.h"
+#include "git-log-pane.h"
 
 G_BEGIN_DECLS
 
@@ -53,7 +54,9 @@ struct _GitResetPane
 
 GType git_reset_pane_get_type (void) G_GNUC_CONST;
 AnjutaDockPane *git_reset_pane_new (Git *plugin);
+AnjutaDockPane *git_reset_pane_new_with_sha (Git *plugin, const gchar *sha);
 void on_reset_button_clicked (GtkAction *action, Git *plugin);
+void on_git_log_reset_activated (GtkAction *action, Git *plugin);
 
 G_END_DECLS
 
diff --git a/plugins/git/git-revert-pane.c b/plugins/git/git-revert-pane.c
index 7746891..5f5a32a 100644
--- a/plugins/git/git-revert-pane.c
+++ b/plugins/git/git-revert-pane.c
@@ -162,4 +162,34 @@ on_revert_button_clicked (GtkAction *action, Git *plugin)
        anjuta_dock_replace_command_pane (ANJUTA_DOCK (plugin->dock), "Revert", 
                                          _("Revert"), NULL, pane, GDL_DOCK_BOTTOM, NULL, 0,
                                          NULL);
+}
+
+void
+on_git_log_revert_activated (GtkAction *action, Git *plugin)
+{
+       GitRevision *revision;
+       gchar *sha;
+       GitRevertCommand *revert_command;
+
+       revision = git_log_pane_get_selected_revision (GIT_LOG_PANE (plugin->log_pane));
+
+       if (revision)
+       {
+               sha = git_revision_get_sha (revision);
+               revert_command = git_revert_command_new (plugin->project_root_directory,
+                                                        sha, FALSE);
+
+               g_signal_connect (G_OBJECT (revert_command), "command-finished",
+                                 G_CALLBACK (git_pane_report_errors),
+                                 plugin);
+
+               g_signal_connect (G_OBJECT (revert_command), "command-finished",
+                                 G_CALLBACK (g_object_unref),
+                                 NULL);
+
+               anjuta_command_start (ANJUTA_COMMAND (revert_command));
+
+               g_free (sha);
+               g_object_unref (revision);
+       }
 }
\ No newline at end of file
diff --git a/plugins/git/git-revert-pane.h b/plugins/git/git-revert-pane.h
index 92dca1f..47df14a 100644
--- a/plugins/git/git-revert-pane.h
+++ b/plugins/git/git-revert-pane.h
@@ -25,6 +25,7 @@
 #include "git-pane.h"
 #include "plugin.h"
 #include "git-revert-command.h"
+#include "git-log-pane.h"
 
 G_BEGIN_DECLS
 
@@ -54,6 +55,7 @@ struct _GitRevertPane
 GType git_revert_pane_get_type (void) G_GNUC_CONST;
 AnjutaDockPane *git_revert_pane_new (Git *plugin);
 void on_revert_button_clicked (GtkAction *action, Git *plugin);
+void on_git_log_revert_activated (GtkAction *action, Git *plugin);
 
 G_END_DECLS
 
diff --git a/plugins/git/plugin.c b/plugins/git/plugin.c
index 90cd4cf..0b1801a 100644
--- a/plugins/git/plugin.c
+++ b/plugins/git/plugin.c
@@ -505,6 +505,42 @@ static GtkActionEntry status_menu_entries[] =
        }
 };
 
+static GtkActionEntry log_menu_entries[] =
+{
+       {
+               "GitLogShowDiff",
+               NULL,
+               N_("Show commit diff"),
+               NULL,
+               NULL,
+               G_CALLBACK (on_commit_diff_button_clicked)
+       },
+       {
+               "GitLogCherryPick",
+               NULL,
+               N_("Cherry pick"),
+               NULL,
+               NULL,
+               G_CALLBACK (on_git_log_cherry_pick_activated)
+       },
+       {
+               "GitLogRevert",
+               NULL,
+               N_("Revert"),
+               NULL,
+               NULL,
+               G_CALLBACK (on_git_log_revert_activated)
+       },
+       {
+               "GitLogReset",
+               NULL,
+               N_("Reset..."),
+               NULL,
+               NULL,
+               G_CALLBACK (on_git_log_reset_activated)
+       }
+};
+
 static gpointer parent_class;
 
 static void
@@ -750,6 +786,12 @@ git_activate_plugin (AnjutaPlugin *plugin)
                                                                            status_menu_entries, 
                                                                            G_N_ELEMENTS 
(status_menu_entries), 
                                                                            GETTEXT_PACKAGE, FALSE, plugin);
+       git_plugin->log_menu_group = anjuta_ui_add_action_group_entries (ui, "GitLogPopup",
+                                                                        _("Log popup menu"),
+                                                                        log_menu_entries,
+                                                                        G_N_ELEMENTS (log_menu_entries),
+                                                                        GETTEXT_PACKAGE,
+                                                                        FALSE, plugin);
 
        
        /* Create the branch list commands. There are two commands because some 
@@ -889,6 +931,7 @@ git_deactivate_plugin (AnjutaPlugin *plugin)
 
        ui = anjuta_shell_get_ui (plugin->shell, NULL);
        anjuta_ui_remove_action_group (ui, git_plugin->status_menu_group);
+       anjuta_ui_remove_action_group (ui, git_plugin->log_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 4b3074b..008f9b4 100644
--- a/plugins/git/plugin.h
+++ b/plugins/git/plugin.h
@@ -80,6 +80,7 @@ struct _Git
        /* Popup menu action groups */
        gint uiid;
        GtkActionGroup *status_menu_group;
+       GtkActionGroup *log_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]