[anjuta/git-shell] git: Implement the Stash Changes pane



commit a5895ce190aa19cc11b2009456941d1b8257b80b
Author: James Liggett <jrliggett cox net>
Date:   Tue Jul 27 01:26:08 2010 -0700

    git: Implement the Stash Changes pane

 plugins/git/Makefile.am              |    4 +-
 plugins/git/anjuta-git.ui            |  117 +++++++++++++++++++++++++
 plugins/git/git-stash-changes-pane.c |  160 ++++++++++++++++++++++++++++++++++
 plugins/git/git-stash-changes-pane.h |   61 +++++++++++++
 plugins/git/plugin.c                 |   25 +++++-
 5 files changed, 365 insertions(+), 2 deletions(-)
---
diff --git a/plugins/git/Makefile.am b/plugins/git/Makefile.am
index e4ef386..4c1c994 100644
--- a/plugins/git/Makefile.am
+++ b/plugins/git/Makefile.am
@@ -203,7 +203,9 @@ libanjuta_git_la_SOURCES = \
 	git-delete-tags-pane.c \
 	git-delete-tags-pane.h \
 	git-stash-pane.h \
-	git-stash-pane.c
+	git-stash-pane.c \
+	git-stash-changes-pane.c \
+	git-stash-changes-pane.h
 
 libanjuta_git_la_LDFLAGS = $(ANJUTA_PLUGIN_LDFLAGS)
 
diff --git a/plugins/git/anjuta-git.ui b/plugins/git/anjuta-git.ui
index 91d16a5..74f1e86 100644
--- a/plugins/git/anjuta-git.ui
+++ b/plugins/git/anjuta-git.ui
@@ -2821,4 +2821,121 @@
       </packing>
     </child>
   </object>
+  <object class="GtkVBox" id="stash_changes_pane">
+    <property name="visible">True</property>
+    <property name="orientation">vertical</property>
+    <child>
+      <object class="GtkVBox" id="vbox2">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="GtkFrame" id="frame1">
+            <property name="visible">True</property>
+            <property name="label_xalign">0</property>
+            <property name="shadow_type">none</property>
+            <child>
+              <object class="GtkAlignment" id="alignment1">
+                <property name="visible">True</property>
+                <property name="left_padding">12</property>
+                <child>
+                  <object class="AnjutaColumnTextView" id="message_view">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="orientation">vertical</property>
+                  </object>
+                </child>
+              </object>
+            </child>
+            <child type="label">
+              <object class="GtkLabel" id="label1">
+                <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="frame2">
+            <property name="visible">True</property>
+            <property name="label_xalign">0</property>
+            <property name="shadow_type">none</property>
+            <child>
+              <object class="GtkAlignment" id="alignment2">
+                <property name="visible">True</property>
+                <property name="left_padding">12</property>
+                <child>
+                  <object class="GtkCheckButton" id="stash_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="label2">
+                <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">0</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkHButtonBox" id="hbuttonbox1">
+        <property name="visible">True</property>
+        <property name="spacing">5</property>
+        <property name="layout_style">end</property>
+        <child>
+          <object class="GtkButton" id="cancel_button">
+            <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="ok_button">
+            <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="fill">False</property>
+        <property name="position">1</property>
+      </packing>
+    </child>
+  </object>
 </interface>
diff --git a/plugins/git/git-stash-changes-pane.c b/plugins/git/git-stash-changes-pane.c
new file mode 100644
index 0000000..afc7ab4
--- /dev/null
+++ b/plugins/git/git-stash-changes-pane.c
@@ -0,0 +1,160 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * git-shell-test
+ * Copyright (C) James Liggett 2010 <jrliggett cox net>
+ * 
+ * git-shell-test 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.
+ * 
+ * git-shell-test 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-pane.h"
+
+struct _GitStashChangesPanePriv
+{
+	GtkBuilder *builder;
+};
+
+G_DEFINE_TYPE (GitStashChangesPane, git_stash_changes_pane, GIT_TYPE_PANE);
+
+static void
+on_ok_button_clicked (GtkButton *button, GitStashChangesPane *self)
+{
+	Git *plugin;
+	AnjutaColumnTextView *message_view;
+	GtkToggleButton *stash_index_check;
+	gchar *message;
+	GitStashSaveCommand *save_command;
+
+	plugin = ANJUTA_PLUGIN_GIT (anjuta_dock_pane_get_plugin (ANJUTA_DOCK_PANE (self)));
+	message_view = ANJUTA_COLUMN_TEXT_VIEW (gtk_builder_get_object (self->priv->builder,
+	                                                                "message_view"));
+	stash_index_check = GTK_TOGGLE_BUTTON (gtk_builder_get_object (self->priv->builder,
+	                                                               "stash_index_check"));
+	message = anjuta_column_text_view_get_text (message_view);
+
+	/* Don't pass an empty message */
+	if (!g_utf8_strlen (message, -1))
+	{
+		g_free (message);
+		message = NULL;
+	}
+
+	save_command = git_stash_save_command_new (plugin->project_root_directory,
+	                                           gtk_toggle_button_get_active (stash_index_check),
+	                                           message);
+
+	g_free (message);
+
+	g_signal_connect (G_OBJECT (save_command), "command-finished",
+	                  G_CALLBACK (git_pane_report_errors),
+	                  plugin);
+
+
+	g_signal_connect (G_OBJECT (save_command), "command-finished",
+	                  G_CALLBACK (g_object_unref),
+	                  NULL);
+
+	anjuta_command_start (ANJUTA_COMMAND (save_command));
+	
+
+	git_pane_remove_from_dock (GIT_PANE (self));
+	                            
+}
+
+static void
+git_stash_changes_pane_init (GitStashChangesPane *self)
+{
+	gchar *objects[] = {"stash_changes_pane",
+						NULL};
+	GError *error = NULL;
+	GtkButton *ok_button;
+	GtkButton *cancel_button;
+
+	self->priv = g_new0 (GitStashChangesPanePriv, 1);
+	self->priv->builder = gtk_builder_new ();
+
+	if (!gtk_builder_add_objects_from_file (self->priv->builder, BUILDER_FILE, 
+	                                        objects, 
+	                                        &error))
+	{
+		g_warning ("Couldn't load builder file: %s", error->message);
+		g_error_free (error);
+	}
+
+	ok_button = GTK_BUTTON (gtk_builder_get_object (self->priv->builder, 
+	                                                "ok_button"));
+	cancel_button = GTK_BUTTON (gtk_builder_get_object (self->priv->builder,
+	                                                    "cancel_button"));
+
+	g_signal_connect (G_OBJECT (ok_button), "clicked",
+	                  G_CALLBACK (on_ok_button_clicked),
+	                  self);
+
+	g_signal_connect_swapped (G_OBJECT (cancel_button), "clicked",
+	                          G_CALLBACK (git_pane_remove_from_dock),
+	                          self);
+}
+
+static void
+git_stash_changes_pane_finalize (GObject *object)
+{
+	GitStashChangesPane *self;
+
+	self = GIT_STASH_CHANGES_PANE (object);
+
+	g_object_unref (self->priv->builder);
+	g_free (self->priv);
+
+	G_OBJECT_CLASS (git_stash_changes_pane_parent_class)->finalize (object);
+}
+
+static GtkWidget *
+get_widget (AnjutaDockPane *pane)
+{
+	GitStashChangesPane *self;
+
+	self = GIT_STASH_CHANGES_PANE (pane);
+
+	return GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
+	                                           "stash_changes_pane"));
+}
+
+static void
+git_stash_changes_pane_class_init (GitStashChangesPaneClass *klass)
+{
+	GObjectClass* object_class = G_OBJECT_CLASS (klass);
+	AnjutaDockPaneClass* pane_class = ANJUTA_DOCK_PANE_CLASS (klass);
+
+	object_class->finalize = git_stash_changes_pane_finalize;
+	pane_class->get_widget = get_widget;
+	pane_class->refresh = NULL;
+}
+
+
+AnjutaDockPane *
+git_stash_changes_pane_new (Git *plugin)
+{
+	return g_object_new (GIT_TYPE_STASH_CHANGES_PANE, "plugin", plugin, NULL);
+}
+
+void
+on_stash_changes_button_clicked (GtkAction *action, Git *plugin)
+{
+	AnjutaDockPane *stash_changes_pane;
+
+	stash_changes_pane = git_stash_changes_pane_new (plugin);
+
+	anjuta_dock_add_pane (ANJUTA_DOCK (plugin->dock), "StashChanges",
+	                      _("Stash Uncommitted Changes"), NULL, 
+	                      stash_changes_pane, GDL_DOCK_BOTTOM, NULL, 0, NULL);
+}
diff --git a/plugins/git/git-stash-changes-pane.h b/plugins/git/git-stash-changes-pane.h
new file mode 100644
index 0000000..6f6cdab
--- /dev/null
+++ b/plugins/git/git-stash-changes-pane.h
@@ -0,0 +1,61 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * git-shell-test
+ * Copyright (C) James Liggett 2010 <jrliggett cox net>
+ * 
+ * git-shell-test 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.
+ * 
+ * git-shell-test 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_PANE_H_
+#define _GIT_STASH_CHANGES_PANE_H_
+
+#include <glib-object.h>
+#include <libanjuta/anjuta-column-text-view.h>
+#include "git-pane.h"
+#include "git-stash-pane.h"
+#include "git-stash-save-command.h"
+
+G_BEGIN_DECLS
+
+#define GIT_TYPE_STASH_CHANGES_PANE             (git_stash_changes_pane_get_type ())
+#define GIT_STASH_CHANGES_PANE(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIT_TYPE_STASH_CHANGES_PANE, GitStashChangesPane))
+#define GIT_STASH_CHANGES_PANE_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), GIT_TYPE_STASH_CHANGES_PANE, GitStashChangesPaneClass))
+#define GIT_IS_STASH_CHANGES_PANE(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIT_TYPE_STASH_CHANGES_PANE))
+#define GIT_IS_STASH_CHANGES_PANE_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GIT_TYPE_STASH_CHANGES_PANE))
+#define GIT_STASH_CHANGES_PANE_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GIT_TYPE_STASH_CHANGES_PANE, GitStashChangesPaneClass))
+
+typedef struct _GitStashChangesPaneClass GitStashChangesPaneClass;
+typedef struct _GitStashChangesPane GitStashChangesPane;
+typedef struct _GitStashChangesPanePriv GitStashChangesPanePriv;
+
+struct _GitStashChangesPaneClass
+{
+	GitPaneClass parent_class;
+};
+
+struct _GitStashChangesPane
+{
+	GitPane parent_instance;
+
+	GitStashChangesPanePriv *priv;
+};
+
+GType git_stash_changes_pane_get_type (void) G_GNUC_CONST;
+AnjutaDockPane *git_stash_changes_pane_new (Git *plugin);
+void on_stash_changes_button_clicked (GtkAction *action, 
+                                      Git *plugin);
+
+G_END_DECLS
+
+#endif /* _GIT_STASH_CHANGES_PANE_H_ */
diff --git a/plugins/git/plugin.c b/plugins/git/plugin.c
index f6ff334..48a6d9d 100644
--- a/plugins/git/plugin.c
+++ b/plugins/git/plugin.c
@@ -44,6 +44,7 @@
 #include "git-create-tag-pane.h"
 #include "git-delete-tags-pane.h"
 #include "git-stash-pane.h"
+#include "git-stash-changes-pane.h"
 
 AnjutaCommandBarEntry branch_entries[] =
 {
@@ -247,6 +248,27 @@ AnjutaCommandBarEntry remotes_entries[] =
 	
 };
 
+AnjutaCommandBarEntry stash_entries[] =
+{
+	{
+		ANJUTA_COMMAND_BAR_ENTRY_FRAME,
+		"NULL",
+		N_("Stash tools"),
+		NULL,
+		NULL,
+		NULL
+	},
+	{
+		ANJUTA_COMMAND_BAR_ENTRY_BUTTON,
+		"StashChanges",
+		N_("Stash uncommitted changes"),
+		N_("Save uncommitted changes without committing them"),
+		GTK_STOCK_SAVE,
+		G_CALLBACK (on_stash_changes_button_clicked)
+	},
+	
+};
+
 static gpointer parent_class;
 
 static void
@@ -530,7 +552,8 @@ git_activate_plugin (AnjutaPlugin *plugin)
 	git_plugin->stash_pane = git_stash_pane_new (git_plugin);
 	anjuta_dock_add_pane (ANJUTA_DOCK (git_plugin->dock), "Stash", 
 	                      _("Stash"), NULL, git_plugin->stash_pane,
-	                      GDL_DOCK_CENTER, NULL, 0, NULL);
+	                      GDL_DOCK_CENTER, stash_entries, 
+	                      G_N_ELEMENTS (stash_entries), git_plugin);
 
 	
 	/* Add watches */



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