[anjuta] git: Add stash drop support



commit 100647dffda46a4a5fd2643b641497b788e432d3
Author: James Liggett <jrliggett cox net>
Date:   Thu Jul 23 17:58:37 2009 -0700

    git: Add stash drop support

 plugins/git/Makefile.am              |    4 +-
 plugins/git/anjuta-git.ui            |    4 +-
 plugins/git/git-stash-drop-command.c |   94 ++++++++++++++++++++++++++++++++++
 plugins/git/git-stash-drop-command.h |   62 ++++++++++++++++++++++
 plugins/git/git-stash-widget.c       |   79 +++++++++++++++++++++++++---
 plugins/git/git-stash-widget.h       |    1 +
 6 files changed, 233 insertions(+), 11 deletions(-)
---
diff --git a/plugins/git/Makefile.am b/plugins/git/Makefile.am
index b9bcb63..f375813 100644
--- a/plugins/git/Makefile.am
+++ b/plugins/git/Makefile.am
@@ -215,7 +215,9 @@ libanjuta_git_la_SOURCES = \
 	git-apply-stash-dialog.c \
 	git-apply-stash-dialog.h \
 	git-stash-show-command.c \
-	git-stash-show-command.h
+	git-stash-show-command.h \
+	git-stash-drop-command.c \
+	git-stash-drop-command.h
 
 libanjuta_git_la_LDFLAGS = $(ANJUTA_PLUGIN_LDFLAGS)
 
diff --git a/plugins/git/anjuta-git.ui b/plugins/git/anjuta-git.ui
index a094205..6bd9958 100644
--- a/plugins/git/anjuta-git.ui
+++ b/plugins/git/anjuta-git.ui
@@ -5364,12 +5364,12 @@
       </packing>
     </child>
     <child>
-      <object class="GtkButton" id="stash_widget_delete_button">
+      <object class="GtkButton" id="stash_widget_drop_button">
         <property name="visible">True</property>
         <property name="sensitive">False</property>
         <property name="can_focus">True</property>
         <property name="receives_default">True</property>
-        <property name="tooltip_text" translatable="yes">Delete the selected stash</property>
+        <property name="tooltip_text" translatable="yes">Drop the selected stash</property>
         <child>
           <object class="GtkImage" id="image6">
             <property name="visible">True</property>
diff --git a/plugins/git/git-stash-drop-command.c b/plugins/git/git-stash-drop-command.c
new file mode 100644
index 0000000..6e2dab2
--- /dev/null
+++ b/plugins/git/git-stash-drop-command.c
@@ -0,0 +1,94 @@
+/* -*- 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-drop-command.h"
+
+struct _GitStashDropCommandPriv
+{
+	gchar *stash;
+};
+
+G_DEFINE_TYPE (GitStashDropCommand, git_stash_drop_command, 
+			   GIT_TYPE_COMMAND);
+
+static void
+git_stash_drop_command_init (GitStashDropCommand *self)
+{
+	self->priv = g_new0 (GitStashDropCommandPriv, 1);
+}
+
+static void
+git_stash_drop_command_finalize (GObject *object)
+{
+	GitStashDropCommand *self;
+	
+	self = GIT_STASH_DROP_COMMAND (object);
+	
+	g_free (self->priv->stash);
+	g_free (self->priv);
+
+	G_OBJECT_CLASS (git_stash_drop_command_parent_class)->finalize (object);
+}
+
+static guint
+git_stash_drop_command_run (AnjutaCommand *command)
+{	
+	GitStashDropCommand *self;
+	
+	self = GIT_STASH_DROP_COMMAND (command);
+	
+	git_command_add_arg (GIT_COMMAND (command), "stash");
+	git_command_add_arg (GIT_COMMAND (command), "drop");
+	git_command_add_arg (GIT_COMMAND (command), self->priv->stash);
+	
+	return 0;
+}
+
+static void
+git_stash_drop_command_class_init (GitStashDropCommandClass *klass)
+{
+	GObjectClass* object_class = G_OBJECT_CLASS (klass);
+	GitCommandClass *parent_class = GIT_COMMAND_CLASS (klass);
+	AnjutaCommandClass *command_class = ANJUTA_COMMAND_CLASS (klass);
+
+	object_class->finalize = git_stash_drop_command_finalize;
+	parent_class->output_handler = git_command_send_output_to_info;
+	command_class->run = git_stash_drop_command_run;
+}
+
+
+GitStashDropCommand *
+git_stash_drop_command_new (const gchar *working_directory, const gchar *stash)
+{
+	GitStashDropCommand *self;
+	
+	self =  g_object_new (GIT_TYPE_STASH_DROP_COMMAND, 
+						  "working-directory", working_directory,
+						  NULL);
+	
+	self->priv->stash = g_strdup (stash);
+	
+	return self;
+}
+
diff --git a/plugins/git/git-stash-drop-command.h b/plugins/git/git-stash-drop-command.h
new file mode 100644
index 0000000..86b30a4
--- /dev/null
+++ b/plugins/git/git-stash-drop-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_DROP_COMMAND_H_
+#define _GIT_STASH_DROP_COMMAND_H_
+
+#include <glib-object.h>
+#include "git-command.h"
+
+G_BEGIN_DECLS
+
+#define GIT_TYPE_STASH_DROP_COMMAND             (git_stash_drop_command_get_type ())
+#define GIT_STASH_DROP_COMMAND(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIT_TYPE_STASH_DROP_COMMAND, GitStashDropCommand))
+#define GIT_STASH_DROP_COMMAND_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), GIT_TYPE_STASH_DROP_COMMAND, GitStashDropCommandClass))
+#define GIT_IS_STASH_DROP_COMMAND(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIT_TYPE_STASH_DROP_COMMAND))
+#define GIT_IS_STASH_DROP_COMMAND_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GIT_TYPE_STASH_DROP_COMMAND))
+#define GIT_STASH_DROP_COMMAND_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GIT_TYPE_STASH_DROP_COMMAND, GitStashDropCommandClass))
+
+typedef struct _GitStashDropCommandClass GitStashDropCommandClass;
+typedef struct _GitStashDropCommand GitStashDropCommand;
+typedef struct _GitStashDropCommandPriv GitStashDropCommandPriv;
+
+struct _GitStashDropCommandClass
+{
+	GitCommandClass parent_class;
+};
+
+struct _GitStashDropCommand
+{
+	GitCommand parent_instance;
+	
+	GitStashDropCommandPriv *priv;
+};
+
+GType git_stash_drop_command_get_type (void) G_GNUC_CONST;
+GitStashDropCommand *git_stash_drop_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 7a7b335..0c353c8 100644
--- a/plugins/git/git-stash-widget.c
+++ b/plugins/git/git-stash-widget.c
@@ -57,20 +57,20 @@ on_stash_widget_view_row_selected (GtkTreeSelection *selection,
 {
 	GtkWidget *stash_widget_apply_button;
 	GtkWidget *stash_widget_show_button;
-	GtkWidget *stash_widget_delete_button;
+	GtkWidget *stash_widget_drop_button;
 
 	stash_widget_apply_button = GTK_WIDGET (gtk_builder_get_object (data->bxml,
 																	"stash_widget_apply_button"));
 	stash_widget_show_button = GTK_WIDGET (gtk_builder_get_object (data->bxml,
 																   "stash_widget_show_button"));
-	stash_widget_delete_button = GTK_WIDGET (gtk_builder_get_object (data->bxml,
-																	 "stash_widget_delete_button"));
+	stash_widget_drop_button = GTK_WIDGET (gtk_builder_get_object (data->bxml,
+																   "stash_widget_drop_button"));
 
 	gtk_widget_set_sensitive (stash_widget_apply_button, 
 							  !path_currently_selected);
 	gtk_widget_set_sensitive (stash_widget_show_button,
 							  !path_currently_selected);
-	gtk_widget_set_sensitive (stash_widget_delete_button,
+	gtk_widget_set_sensitive (stash_widget_drop_button,
 							  !path_currently_selected);
 
 	return TRUE;
@@ -193,6 +193,62 @@ on_stash_widget_show_button_clicked (GtkButton *button, GitUIData *data)
 	}
 }
 
+static void
+on_stash_drop_command_finished (AnjutaCommand *command, guint return_code,
+                            	Git *plugin)
+{
+	AnjutaStatus *status;
+	
+	status = anjuta_shell_get_status (ANJUTA_PLUGIN (plugin)->shell,
+									  NULL);
+	
+	anjuta_status (status, _("Git: Stash dropped."), 5);
+	
+	git_report_errors (command, return_code);
+	
+	g_object_unref (command);
+}
+
+static void
+on_stash_widget_drop_button_clicked (GtkButton *button, GitUIData *data)
+{
+	GtkWidget *stash_widget_view;
+	GtkListStore *stash_list_model;
+	GtkTreeSelection *selection;
+	GtkTreeIter iter;
+	gchar *stash;
+	GitStashDropCommand *drop_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);
+
+		drop_command = git_stash_drop_command_new (data->plugin->project_root_directory,
+												   stash);
+
+		g_free (stash);
+
+		git_create_message_view (data->plugin);
+
+		g_signal_connect (G_OBJECT (drop_command), "data-arrived",
+						  G_CALLBACK (on_git_command_info_arrived),
+						  data->plugin);
+
+		g_signal_connect (G_CALLBACK (drop_command), "command-finished",
+						  G_CALLBACK (on_stash_drop_command_finished),
+						  data->plugin);
+
+		anjuta_command_start (ANJUTA_COMMAND (drop_command));
+	}
+}
+
 void
 git_stash_widget_create (Git *plugin, GtkWidget **stash_widget, 
 						 GtkWidget **stash_widget_grip)
@@ -209,6 +265,7 @@ git_stash_widget_create (Git *plugin, GtkWidget **stash_widget,
 	GtkWidget *stash_widget_save_button;
 	GtkWidget *stash_widget_apply_button;
 	GtkWidget *stash_widget_show_button;
+	GtkWidget *stash_widget_drop_button;
 	GtkTreeSelection *selection;
 
 	bxml = gtk_builder_new ();
@@ -234,6 +291,8 @@ git_stash_widget_create (Git *plugin, GtkWidget **stash_widget,
 																	"stash_widget_apply_button"));
 	stash_widget_show_button = GTK_WIDGET (gtk_builder_get_object (bxml,
 	                                                           	   "stash_widget_show_button"));
+	stash_widget_drop_button = GTK_WIDGET (gtk_builder_get_object (bxml,
+	                                                           	   "stash_widget_drop_button"));
 	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (stash_widget_view));
 
 	gtk_tree_selection_set_select_function (selection, 
@@ -252,6 +311,10 @@ git_stash_widget_create (Git *plugin, GtkWidget **stash_widget,
 					  G_CALLBACK (on_stash_widget_show_button_clicked),
 					  data);
 
+	g_signal_connect (G_OBJECT (stash_widget_drop_button), "clicked",
+					  G_CALLBACK (on_stash_widget_drop_button_clicked),
+					  data);
+
 	g_object_set_data_full (G_OBJECT (stash_widget_scrolled_window), "ui-data",
 							data, (GDestroyNotify) git_ui_data_free);
 
@@ -304,7 +367,7 @@ git_stash_widget_clear (Git *plugin)
 	GtkListStore *stash_list_model;
 	GtkWidget *stash_widget_apply_button;
 	GtkWidget *stash_widget_show_button;
-	GtkWidget *stash_widget_delete_button;
+	GtkWidget *stash_widget_drop_button;
 
 	data = g_object_get_data (G_OBJECT (plugin->stash_widget), "ui-data");
 	stash_list_model = GTK_LIST_STORE (gtk_builder_get_object (data->bxml,
@@ -313,14 +376,14 @@ git_stash_widget_clear (Git *plugin)
 																	"stash_widget_apply_button"));
 	stash_widget_show_button = GTK_WIDGET (gtk_builder_get_object (data->bxml,
 																   "stash_widget_show_button"));
-	stash_widget_delete_button = GTK_WIDGET (gtk_builder_get_object (data->bxml,
-																	 "stash_widget_delete_button"));
+	stash_widget_drop_button = GTK_WIDGET (gtk_builder_get_object (data->bxml,
+																   "stash_widget_drop_button"));
 
 	gtk_list_store_clear (stash_list_model);
 
 	gtk_widget_set_sensitive (stash_widget_apply_button, FALSE);
 	gtk_widget_set_sensitive (stash_widget_show_button, FALSE);
-	gtk_widget_set_sensitive (stash_widget_delete_button, FALSE);
+	gtk_widget_set_sensitive (stash_widget_drop_button, FALSE);
 }
 
 GFileMonitor *
diff --git a/plugins/git/git-stash-widget.h b/plugins/git/git-stash-widget.h
index ce35985..26975ee 100644
--- a/plugins/git/git-stash-widget.h
+++ b/plugins/git/git-stash-widget.h
@@ -24,6 +24,7 @@
 #include "git-stash-save-command.h"
 #include "git-stash-apply-command.h"
 #include "git-stash-show-command.h"
+#include "git-stash-drop-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]