[anjuta] git: Add stash support



commit ca70756b0391b014c45035701f9b5014bbcdb2d3
Author: James Liggett <jrliggett cox net>
Date:   Wed Jul 15 18:41:15 2009 -0700

    git: Add stash support

 plugins/git/Makefile.am                |    6 +-
 plugins/git/anjuta-git.ui              |  140 ++++++++++++++++++++++++++++++++
 plugins/git/anjuta-git.xml             |    5 +
 plugins/git/git-stash-changes-dialog.c |  118 +++++++++++++++++++++++++++
 plugins/git/git-stash-changes-dialog.h |   28 +++++++
 plugins/git/git-stash-save-command.c   |   96 ++++++++++++++++++++++
 plugins/git/git-stash-save-command.h   |   58 +++++++++++++
 plugins/git/plugin.c                   |   17 ++++
 8 files changed, 467 insertions(+), 1 deletions(-)
---
diff --git a/plugins/git/Makefile.am b/plugins/git/Makefile.am
index 7c26fa1..6693851 100644
--- a/plugins/git/Makefile.am
+++ b/plugins/git/Makefile.am
@@ -199,7 +199,11 @@ libanjuta_git_la_SOURCES = \
 	git-tag-delete-command.c \
 	git-tag-delete-command.h \
 	git-tag-list-command.c \
-	git-tag-list-command.h
+	git-tag-list-command.h \
+	git-stash-save-command.h \
+	git-stash-save-command.c \
+	git-stash-changes-dialog.c \
+	git-stash-changes-dialog.h
 
 libanjuta_git_la_LDFLAGS = $(ANJUTA_PLUGIN_LDFLAGS)
 
diff --git a/plugins/git/anjuta-git.ui b/plugins/git/anjuta-git.ui
index 6bb082f..ba4d9be 100644
--- a/plugins/git/anjuta-git.ui
+++ b/plugins/git/anjuta-git.ui
@@ -5088,4 +5088,144 @@
       <action-widget response="-5">button39</action-widget>
     </action-widgets>
   </object>
+  <object class="GtkDialog" id="stash_changes_dialog">
+    <property name="border_width">5</property>
+    <property name="title" translatable="yes">Stash Uncommitted Changes</property>
+    <property name="window_position">center</property>
+    <property name="type_hint">normal</property>
+    <property name="has_separator">False</property>
+    <child internal-child="vbox">
+      <object class="GtkVBox" id="dialog-vbox41">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child>
+          <object class="GtkVBox" id="vbox34">
+            <property name="visible">True</property>
+            <property name="orientation">vertical</property>
+            <child>
+              <object class="GtkFrame" id="frame54">
+                <property name="visible">True</property>
+                <property name="label_xalign">0</property>
+                <property name="shadow_type">none</property>
+                <child>
+                  <object class="GtkAlignment" id="alignment54">
+                    <property name="visible">True</property>
+                    <property name="left_padding">12</property>
+                    <child>
+                      <object class="GtkScrolledWindow" id="scrolledwindow13">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="hscrollbar_policy">automatic</property>
+                        <property name="vscrollbar_policy">automatic</property>
+                        <property name="shadow_type">in</property>
+                        <child>
+                          <object class="GtkTextView" id="stash_changes_message_view">
+                            <property name="width_request">600</property>
+                            <property name="height_request">100</property>
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+                <child type="label">
+                  <object class="GtkLabel" id="label65">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">&lt;b&gt;Stash Message (Optional)&lt;/b&gt;</property>
+                    <property name="use_markup">True</property>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkFrame" id="frame55">
+                <property name="visible">True</property>
+                <property name="label_xalign">0</property>
+                <property name="shadow_type">none</property>
+                <child>
+                  <object class="GtkAlignment" id="alignment55">
+                    <property name="visible">True</property>
+                    <property name="left_padding">12</property>
+                    <child>
+                      <object class="GtkCheckButton" id="stash_chnages_keep_index_check">
+                        <property name="label" translatable="yes">Stash indexed changes</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                        <property name="draw_indicator">True</property>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+                <child type="label">
+                  <object class="GtkLabel" id="label66">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">&lt;b&gt;Options&lt;/b&gt;</property>
+                    <property name="use_markup">True</property>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child internal-child="action_area">
+          <object class="GtkHButtonBox" id="dialog-action_area42">
+            <property name="visible">True</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="button40">
+                <property name="label">gtk-cancel</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="button41">
+                <property name="label">gtk-ok</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="-6">button40</action-widget>
+      <action-widget response="-5">button41</action-widget>
+    </action-widgets>
+  </object>
 </interface>
diff --git a/plugins/git/anjuta-git.xml b/plugins/git/anjuta-git.xml
index 8e89261..a780cff 100644
--- a/plugins/git/anjuta-git.xml
+++ b/plugins/git/anjuta-git.xml
@@ -18,6 +18,11 @@
   				<menuitem name="Push..." action="ActionGitPush" />
   				<menuitem name="Pull..." action="ActionGitPull" />
   				<menuitem name="Diff uncommitted changes" action="ActionGitDiffUncommitted" />
+  				<placeholder name="PlaceholderStashMenu">
+  					<menu name="Stash" action="ActionMenuGitStash">
+  						<menuitem name="Stash uncomitted changes" action="ActionGitStashUncommitted" />
+  					</menu>
+  				</placeholder>
   				<separator />
 				<menuitem name="Add..." action="ActionGitAdd" />
 				<menuitem name="Remove..." action="ActionGitRemove" />
diff --git a/plugins/git/git-stash-changes-dialog.c b/plugins/git/git-stash-changes-dialog.c
new file mode 100644
index 0000000..21651af
--- /dev/null
+++ b/plugins/git/git-stash-changes-dialog.c
@@ -0,0 +1,118 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * anjuta
+ * Copyright (C) James Liggett 2009 <jrliggett cox net>
+ * 
+ * anjuta is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+ 
+#include "git-stash-changes-dialog.h"
+
+static void
+on_stash_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: Changes stored in a stash."), 5);
+	
+	git_report_errors (command, return_code);
+	
+	g_object_unref (command);
+}
+
+static void
+on_stash_changes_dialog_response (GtkDialog *dialog, gint response, 
+								  GitUIData *data)
+{
+	GtkWidget *stash_changes_message_view;
+	GtkWidget *stash_changes_keep_index_check;
+	gchar *message;
+	GitStashSaveCommand *stash_command;
+
+	if (response == GTK_RESPONSE_OK)
+	{
+		stash_changes_message_view = GTK_WIDGET (gtk_builder_get_object (data->bxml,
+																		 "stash_changes_message_view"));
+		stash_changes_keep_index_check = GTK_WIDGET (gtk_builder_get_object (data->bxml,
+																			 "stash_changes_keep_index_check"));
+
+		message = git_get_log_from_textview (stash_changes_message_view);
+
+		/* Don't pass empty messages */
+		if (!g_utf8_strlen (message, -1))
+		{
+			g_free (message);
+			message = NULL;
+		}
+
+		stash_command = git_stash_save_command_new (data->plugin->project_root_directory,
+													gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (stash_changes_keep_index_check)),
+													message);
+
+		git_create_message_view (data->plugin);
+
+		g_signal_connect (G_OBJECT (stash_command), "command-finished",
+						  G_CALLBACK (on_stash_command_finished),
+						  data->plugin);
+
+		g_signal_connect (G_OBJECT (stash_command), "data-arrived",
+						  G_CALLBACK (on_git_command_info_arrived),
+						  data->plugin);
+
+		anjuta_command_start (ANJUTA_COMMAND (stash_command));
+	}
+
+	git_ui_data_free (data);
+	gtk_widget_destroy (GTK_WIDGET (dialog));
+}
+
+static void
+stash_changes_dialog (Git *plugin)
+{
+	GtkBuilder *bxml;
+	gchar *objects[] = {"stash_changes_dialog", NULL};
+	GError *error;
+	GtkWidget *dialog;
+	GitUIData *data;
+
+	bxml = gtk_builder_new ();
+	error = NULL;
+
+	if (!gtk_builder_add_objects_from_file (bxml, BUILDER_FILE, objects, 
+	                                        &error))
+	{
+		g_warning ("Couldn't load builder file: %s", error->message);
+		g_error_free (error);
+	}
+
+	dialog = GTK_WIDGET (gtk_builder_get_object (bxml, "stash_changes_dialog"));
+
+	data = git_ui_data_new (plugin, bxml);
+
+	g_signal_connect (G_OBJECT (dialog), "response",
+					  G_CALLBACK (on_stash_changes_dialog_response),
+					  data);
+
+	gtk_widget_show_all (dialog);
+}
+
+void
+on_menu_git_stash_changes (GtkAction *action, Git *plugin)
+{
+	stash_changes_dialog (plugin);
+}
\ No newline at end of file
diff --git a/plugins/git/git-stash-changes-dialog.h b/plugins/git/git-stash-changes-dialog.h
new file mode 100644
index 0000000..ed2ee10
--- /dev/null
+++ b/plugins/git/git-stash-changes-dialog.h
@@ -0,0 +1,28 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * anjuta
+ * Copyright (C) James Liggett 2009 <jrliggett cox net>
+ * 
+ * anjuta is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+ 
+#ifndef _GIT_STASH_CHANGES_DIALOG_H
+#define _GIT_STASH_CHANGES_DIALOG_H
+
+#include "git-stash-save-command.h"
+#include "git-ui-utils.h"
+
+void on_menu_git_stash_changes (GtkAction *action, Git *plugin);
+
+#endif
\ No newline at end of file
diff --git a/plugins/git/git-stash-save-command.c b/plugins/git/git-stash-save-command.c
new file mode 100644
index 0000000..bb9bbe6
--- /dev/null
+++ b/plugins/git/git-stash-save-command.c
@@ -0,0 +1,96 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * anjuta
+ * Copyright (C) James Liggett 2009 <jrliggett cox net>
+ * 
+ * anjuta is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "git-stash-save-command.h"
+
+struct _GitStashSaveCommandPriv
+{
+	gboolean keep_index;
+	gchar *message;
+};
+
+G_DEFINE_TYPE (GitStashSaveCommand, git_stash_save_command, GIT_TYPE_COMMAND);
+
+static void
+git_stash_save_command_init (GitStashSaveCommand *self)
+{
+	self->priv = g_new0 (GitStashSaveCommandPriv, 1);
+}
+
+static void
+git_stash_save_command_finalize (GObject *object)
+{
+	GitStashSaveCommand *self;
+
+	self = GIT_STASH_SAVE_COMMAND (object);
+
+	g_free (self->priv->message);
+	g_free (self->priv);
+
+	G_OBJECT_CLASS (git_stash_save_command_parent_class)->finalize (object);
+}
+
+static guint
+git_stash_save_command_run (AnjutaCommand *command)
+{
+	GitStashSaveCommand *self;
+
+	self = GIT_STASH_SAVE_COMMAND (command);
+
+	git_command_add_arg (GIT_COMMAND (command), "stash");
+	git_command_add_arg (GIT_COMMAND (command), "save");
+
+	if (self->priv->keep_index)
+		git_command_add_arg (GIT_COMMAND (command), "--keep-index");
+
+	if (self->priv->message)
+		git_command_add_arg (GIT_COMMAND (command), self->priv->message);
+
+	return 0;
+}
+
+static void
+git_stash_save_command_class_init (GitStashSaveCommandClass *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_save_command_finalize;
+	parent_class->output_handler = git_command_send_output_to_info;
+	command_class->run = git_stash_save_command_run;
+}
+
+
+GitStashSaveCommand *
+git_stash_save_command_new (const gchar *working_directory, 
+							gboolean keep_index, const gchar *message)
+{
+	GitStashSaveCommand *self;
+
+	self = g_object_new (GIT_TYPE_STASH_SAVE_COMMAND, 
+						 "working-directory", working_directory,
+						 "single-line-output", TRUE,
+						 NULL);
+
+	self->priv->keep_index = keep_index;
+	self->priv->message = g_strdup (message);
+
+	return self;
+}
diff --git a/plugins/git/git-stash-save-command.h b/plugins/git/git-stash-save-command.h
new file mode 100644
index 0000000..2de5c41
--- /dev/null
+++ b/plugins/git/git-stash-save-command.h
@@ -0,0 +1,58 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * anjuta
+ * Copyright (C) James Liggett 2009 <jrliggett cox net>
+ * 
+ * anjuta is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _GIT_STASH_SAVE_COMMAND_H_
+#define _GIT_STASH_SAVE_COMMAND_H_
+
+#include <glib-object.h>
+#include "git-command.h"
+
+G_BEGIN_DECLS
+
+#define GIT_TYPE_STASH_SAVE_COMMAND             (git_stash_save_command_get_type ())
+#define GIT_STASH_SAVE_COMMAND(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIT_TYPE_STASH_SAVE_COMMAND, GitStashSaveCommand))
+#define GIT_STASH_SAVE_COMMAND_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), GIT_TYPE_STASH_SAVE_COMMAND, GitStashSaveCommandClass))
+#define GIT_IS_STASH_SAVE_COMMAND(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIT_TYPE_STASH_SAVE_COMMAND))
+#define GIT_IS_STASH_SAVE_COMMAND_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GIT_TYPE_STASH_SAVE_COMMAND))
+#define GIT_STASH_SAVE_COMMAND_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GIT_TYPE_STASH_SAVE_COMMAND, GitStashSaveCommandClass))
+
+typedef struct _GitStashSaveCommandClass GitStashSaveCommandClass;
+typedef struct _GitStashSaveCommand GitStashSaveCommand;
+typedef struct _GitStashSaveCommandPriv GitStashSaveCommandPriv;
+
+struct _GitStashSaveCommandClass
+{
+	GitCommandClass parent_class;
+};
+
+struct _GitStashSaveCommand
+{
+	GitCommand parent_instance;
+
+	GitStashSaveCommandPriv *priv;
+};
+
+GType git_stash_save_command_get_type (void) G_GNUC_CONST;
+GitStashSaveCommand *git_stash_save_command_new (const gchar *working_directory, 
+												 gboolean keep_index, 
+												 const gchar *message);
+
+G_END_DECLS
+
+#endif /* _GIT_STASH_SAVE_COMMAND_H_ */
diff --git a/plugins/git/plugin.c b/plugins/git/plugin.c
index a338cb0..09674a8 100644
--- a/plugins/git/plugin.c
+++ b/plugins/git/plugin.c
@@ -49,6 +49,7 @@
 #include "git-apply-mailbox-dialog.h"
 #include "git-cherry-pick-dialog.h"
 #include "git-delete-tag-dialog.h"
+#include "git-stash-changes-dialog.h"
 
 #define UI_FILE PACKAGE_DATA_DIR"/ui/anjuta-git.xml"
 
@@ -145,6 +146,22 @@ static GtkActionEntry actions_git[] =
 		G_CALLBACK (on_menu_git_diff)    /* action callback */
 	},
 	{
+		"ActionMenuGitStash",                       /* Action name */
+		NULL,                            /* Stock icon, if any */
+		N_("_Stash"),                     /* Display label */
+		NULL,                                     /* short-cut */
+		NULL,                      /* Tooltip */
+		NULL    /* action callback */
+	},
+	{
+		"ActionGitStashUncommitted",                       /* Action name */
+		NULL,                            /* Stock icon, if any */
+		N_("_Stash uncommitted changes..."),                     /* Display label */
+		NULL,                                     /* short-cut */
+		N_("Save ucommitted changes and re-apply them later"),                      /* Tooltip */
+		G_CALLBACK (on_menu_git_stash_changes)    /* action callback */
+	},
+	{
 		"ActionGitAdd",                       /* Action name */
 		GTK_STOCK_ADD,                            /* Stock icon, if any */
 		N_("_Add..."),                     /* Display label */



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