[anjuta] git: Add the ability to show stash diffs



commit 229093f7122985bac65b6d5521c06c58e80d434b
Author: James Liggett <jrliggett cox net>
Date:   Tue Jul 21 23:58:45 2009 -0700

    git: Add the ability to show stash diffs

 plugins/git/Makefile.am              |    4 +-
 plugins/git/git-stash-show-command.c |   93 ++++++++++++++++++++++++++++++++++
 plugins/git/git-stash-show-command.h |   62 ++++++++++++++++++++++
 plugins/git/git-stash-widget.c       |   58 +++++++++++++++++++++
 plugins/git/git-stash-widget.h       |    1 +
 5 files changed, 217 insertions(+), 1 deletions(-)
---
diff --git a/plugins/git/Makefile.am b/plugins/git/Makefile.am
index ee2195b..b9bcb63 100644
--- a/plugins/git/Makefile.am
+++ b/plugins/git/Makefile.am
@@ -213,7 +213,9 @@ libanjuta_git_la_SOURCES = \
 	git-stash-apply-command.c \
 	git-stash-apply-command.h \
 	git-apply-stash-dialog.c \
-	git-apply-stash-dialog.h
+	git-apply-stash-dialog.h \
+	git-stash-show-command.c \
+	git-stash-show-command.h
 
 libanjuta_git_la_LDFLAGS = $(ANJUTA_PLUGIN_LDFLAGS)
 
diff --git a/plugins/git/git-stash-show-command.c b/plugins/git/git-stash-show-command.c
new file mode 100644
index 0000000..66f9a4a
--- /dev/null
+++ b/plugins/git/git-stash-show-command.c
@@ -0,0 +1,93 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * anjuta
+ * Copyright (C) James Liggett 2008 <jrliggett cox net>
+ * 
+ * anjuta is free software.
+ * 
+ * You may redistribute it and/or modify it under the terms of the
+ * GNU General Public License, as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ * 
+ * anjuta is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with anjuta.  If not, write to:
+ * 	The Free Software Foundation, Inc.,
+ * 	51 Franklin Street, Fifth Floor
+ * 	Boston, MA  02110-1301, USA.
+ */
+
+#include "git-stash-show-command.h"
+
+struct _GitStashShowCommandPriv
+{
+	gchar *stash;
+};
+
+G_DEFINE_TYPE (GitStashShowCommand, git_stash_show_command, 
+			   GIT_TYPE_RAW_OUTPUT_COMMAND);
+
+static void
+git_stash_show_command_init (GitStashShowCommand *self)
+{
+	self->priv = g_new0 (GitStashShowCommandPriv, 1);
+}
+
+static void
+git_stash_show_command_finalize (GObject *object)
+{
+	GitStashShowCommand *self;
+	
+	self = GIT_STASH_SHOW_COMMAND (object);
+	
+	g_free (self->priv->stash);
+	g_free (self->priv);
+
+	G_OBJECT_CLASS (git_stash_show_command_parent_class)->finalize (object);
+}
+
+static guint
+git_stash_show_command_run (AnjutaCommand *command)
+{	
+	GitStashShowCommand *self;
+	
+	self = GIT_STASH_SHOW_COMMAND (command);
+	
+	git_command_add_arg (GIT_COMMAND (command), "stash");
+	git_command_add_arg (GIT_COMMAND (command), "show");
+	git_command_add_arg (GIT_COMMAND (command), "-p");
+	git_command_add_arg (GIT_COMMAND (command), self->priv->stash);
+	
+	return 0;
+}
+
+static void
+git_stash_show_command_class_init (GitStashShowCommandClass *klass)
+{
+	GObjectClass* object_class = G_OBJECT_CLASS (klass);
+	AnjutaCommandClass *command_class = ANJUTA_COMMAND_CLASS (klass);
+
+	object_class->finalize = git_stash_show_command_finalize;
+	command_class->run = git_stash_show_command_run;
+}
+
+
+GitStashShowCommand *
+git_stash_show_command_new (const gchar *working_directory, const gchar *stash)
+{
+	GitStashShowCommand *self;
+	
+	self =  g_object_new (GIT_TYPE_STASH_SHOW_COMMAND, 
+						  "working-directory", working_directory,
+						  NULL);
+	
+	self->priv->stash = g_strdup (stash);
+	
+	return self;
+}
+
diff --git a/plugins/git/git-stash-show-command.h b/plugins/git/git-stash-show-command.h
new file mode 100644
index 0000000..f72e93c
--- /dev/null
+++ b/plugins/git/git-stash-show-command.h
@@ -0,0 +1,62 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * anjuta
+ * Copyright (C) James Liggett 2008 <jrliggett cox net>
+ * 
+ * anjuta is free software.
+ * 
+ * You may redistribute it and/or modify it under the terms of the
+ * GNU General Public License, as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ * 
+ * anjuta is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with anjuta.  If not, write to:
+ * 	The Free Software Foundation, Inc.,
+ * 	51 Franklin Street, Fifth Floor
+ * 	Boston, MA  02110-1301, USA.
+ */
+
+#ifndef _GIT_STASH_SHOW_COMMAND_H_
+#define _GIT_STASH_SHOW_COMMAND_H_
+
+#include <glib-object.h>
+#include "git-raw-output-command.h"
+
+G_BEGIN_DECLS
+
+#define GIT_TYPE_STASH_SHOW_COMMAND             (git_stash_show_command_get_type ())
+#define GIT_STASH_SHOW_COMMAND(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIT_TYPE_STASH_SHOW_COMMAND, GitStashShowCommand))
+#define GIT_STASH_SHOW_COMMAND_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), GIT_TYPE_STASH_SHOW_COMMAND, GitStashShowCommandClass))
+#define GIT_IS_STASH_SHOW_COMMAND(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIT_TYPE_STASH_SHOW_COMMAND))
+#define GIT_IS_STASH_SHOW_COMMAND_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GIT_TYPE_STASH_SHOW_COMMAND))
+#define GIT_STASH_SHOW_COMMAND_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GIT_TYPE_STASH_SHOW_COMMAND, GitStashShowCommandClass))
+
+typedef struct _GitStashShowCommandClass GitStashShowCommandClass;
+typedef struct _GitStashShowCommand GitStashShowCommand;
+typedef struct _GitStashShowCommandPriv GitStashShowCommandPriv;
+
+struct _GitStashShowCommandClass
+{
+	GitRawOutputCommandClass parent_class;
+};
+
+struct _GitStashShowCommand
+{
+	GitRawOutputCommand parent_instance;
+	
+	GitStashShowCommandPriv *priv;
+};
+
+GType git_stash_show_command_get_type (void) G_GNUC_CONST;
+GitStashShowCommand *git_stash_show_command_new (const gchar *working_directory,
+												 const gchar *stash);
+
+G_END_DECLS
+
+#endif /* _GIT_CAT_BLOB_COMMAND_H_ */
diff --git a/plugins/git/git-stash-widget.c b/plugins/git/git-stash-widget.c
index a1aacbd..02c286a 100644
--- a/plugins/git/git-stash-widget.c
+++ b/plugins/git/git-stash-widget.c
@@ -139,6 +139,57 @@ on_stash_widget_apply_button_clicked (GtkButton *button, GitUIData *data)
 	
 }
 
+static void
+on_stash_widget_show_button_clicked (GtkButton *button, GitUIData *data)
+{
+	GtkWidget *stash_widget_view;
+	GtkListStore *stash_list_model;
+	GtkTreeSelection *selection;
+	GtkTreeIter iter;
+	gchar *stash;
+	gchar *editor_name;
+	IAnjutaDocumentManager *document_manager;
+	IAnjutaEditor *editor;
+	GitStashShowCommand *show_command;
+
+	stash_widget_view = GTK_WIDGET (gtk_builder_get_object (data->bxml,
+															"stash_widget_view"));
+	stash_list_model = GTK_LIST_STORE (gtk_builder_get_object (data->bxml,
+															   "stash_list_model"));
+	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (stash_widget_view));
+
+	if (gtk_tree_selection_get_selected (selection, NULL, &iter))
+	{
+		gtk_tree_model_get (GTK_TREE_MODEL (stash_list_model), &iter, 0, 
+							&stash, -1);
+
+		show_command = git_stash_show_command_new (data->plugin->project_root_directory,
+												   stash);
+
+		editor_name = g_strdup_printf ("%s.diff", stash);
+
+		document_manager = anjuta_shell_get_interface (ANJUTA_PLUGIN (data->plugin)->shell,
+		                                               IAnjutaDocumentManager, 
+		                                               NULL);
+		editor = ianjuta_document_manager_add_buffer (document_manager, 
+		                                              editor_name,
+		                                              "", NULL);
+
+		g_free (stash);
+		g_free (editor_name);
+
+		g_signal_connect (G_OBJECT (show_command), "data-arrived",
+						  G_CALLBACK (git_send_raw_command_output_to_editor),
+						  editor);
+
+		g_signal_connect (G_CALLBACK (show_command), "command-finished",
+						  G_CALLBACK (on_git_command_finished),
+						  data->plugin);
+
+		anjuta_command_start (ANJUTA_COMMAND (show_command));
+	}
+}
+
 void
 git_stash_widget_create (Git *plugin, GtkWidget **stash_widget, 
 						 GtkWidget **stash_widget_grip)
@@ -154,6 +205,7 @@ git_stash_widget_create (Git *plugin, GtkWidget **stash_widget,
 	GtkWidget *stash_widget_grip_hbox;
 	GtkWidget *stash_widget_save_button;
 	GtkWidget *stash_widget_apply_button;
+	GtkWidget *stash_widget_show_button;
 	GtkTreeSelection *selection;
 
 	bxml = gtk_builder_new ();
@@ -177,6 +229,8 @@ git_stash_widget_create (Git *plugin, GtkWidget **stash_widget,
 																   "stash_widget_save_button"));
 	stash_widget_apply_button = GTK_WIDGET (gtk_builder_get_object (bxml,
 																	"stash_widget_apply_button"));
+	stash_widget_show_button = GTK_WIDGET (gtk_builder_get_object (bxml,
+	                                                           	   "stash_widget_show_button"));
 	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (stash_widget_view));
 
 	gtk_tree_selection_set_select_function (selection, 
@@ -191,6 +245,10 @@ git_stash_widget_create (Git *plugin, GtkWidget **stash_widget,
 					  G_CALLBACK (on_stash_widget_apply_button_clicked),
 					  data);
 
+	g_signal_connect (G_OBJECT (stash_widget_show_button), "clicked",
+					  G_CALLBACK (on_stash_widget_show_button_clicked),
+					  data);
+
 	g_object_set_data_full (G_OBJECT (stash_widget_scrolled_window), "ui-data",
 							data, (GDestroyNotify) git_ui_data_free);
 
diff --git a/plugins/git/git-stash-widget.h b/plugins/git/git-stash-widget.h
index 61048bc..ce35985 100644
--- a/plugins/git/git-stash-widget.h
+++ b/plugins/git/git-stash-widget.h
@@ -23,6 +23,7 @@
 #include "git-ui-utils.h"
 #include "git-stash-save-command.h"
 #include "git-stash-apply-command.h"
+#include "git-stash-show-command.h"
 
 void git_stash_widget_create (Git *plugin, GtkWidget **stash_widget,
 							  GtkWidget **stash_widget_grip);



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