[anjuta] git: Add support for applying stashes from the stash widget
- From: James Liggett <jrliggett src gnome org>
- To: svn-commits-list gnome org
- Subject: [anjuta] git: Add support for applying stashes from the stash widget
- Date: Fri, 24 Jul 2009 01:49:23 +0000 (UTC)
commit f994b5e2c0ea70f6bf79f9600f07d6213bf9ab9d
Author: James Liggett <jrliggett cox net>
Date: Mon Jul 20 19:25:33 2009 -0700
git: Add support for applying stashes from the stash widget
plugins/git/Makefile.am | 4 +-
plugins/git/git-stash-apply-command.c | 95 +++++++++++++++++++++++++++++++++
plugins/git/git-stash-apply-command.h | 58 ++++++++++++++++++++
plugins/git/git-stash-widget.c | 48 +++++++++++++++++
plugins/git/git-stash-widget.h | 1 +
plugins/git/git-ui-utils.c | 16 ++++++
plugins/git/git-ui-utils.h | 2 +
7 files changed, 223 insertions(+), 1 deletions(-)
---
diff --git a/plugins/git/Makefile.am b/plugins/git/Makefile.am
index 84e6d49..30927d6 100644
--- a/plugins/git/Makefile.am
+++ b/plugins/git/Makefile.am
@@ -209,7 +209,9 @@ libanjuta_git_la_SOURCES = \
git-stash.c \
git-stash.h \
git-stash-list-command.c \
- git-stash-list-command.h
+ git-stash-list-command.h \
+ git-stash-apply-command.c \
+ git-stash-apply-command.h
libanjuta_git_la_LDFLAGS = $(ANJUTA_PLUGIN_LDFLAGS)
diff --git a/plugins/git/git-stash-apply-command.c b/plugins/git/git-stash-apply-command.c
new file mode 100644
index 0000000..481611a
--- /dev/null
+++ b/plugins/git/git-stash-apply-command.c
@@ -0,0 +1,95 @@
+/* -*- 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-apply-command.h"
+
+struct _GitStashApplyCommandPriv
+{
+ gboolean restore_index;
+ gchar *stash;
+};
+
+G_DEFINE_TYPE (GitStashApplyCommand, git_stash_apply_command, GIT_TYPE_COMMAND);
+
+static void
+git_stash_apply_command_init (GitStashApplyCommand *self)
+{
+ self->priv = g_new0 (GitStashApplyCommandPriv, 1);
+}
+
+static void
+git_stash_apply_command_finalize (GObject *object)
+{
+ GitStashApplyCommand *self;
+
+ self = GIT_STASH_APPLY_COMMAND (object);
+
+ g_free (self->priv->stash);
+ g_free (self->priv);
+
+ G_OBJECT_CLASS (git_stash_apply_command_parent_class)->finalize (object);
+}
+
+static guint
+git_stash_apply_command_run (AnjutaCommand *command)
+{
+ GitStashApplyCommand *self;
+
+ self = GIT_STASH_APPLY_COMMAND (command);
+
+ git_command_add_arg (GIT_COMMAND (command), "stash");
+ git_command_add_arg (GIT_COMMAND (command), "apply");
+
+ if (self->priv->restore_index)
+ git_command_add_arg (GIT_COMMAND (command), "--index");
+
+ git_command_add_arg (GIT_COMMAND (command), self->priv->stash);
+
+ return 0;
+}
+
+static void
+git_stash_apply_command_class_init (GitStashApplyCommandClass *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_apply_command_finalize;
+ parent_class->output_handler = git_command_send_output_to_info;
+ command_class->run = git_stash_apply_command_run;
+}
+
+
+GitStashApplyCommand *
+git_stash_apply_command_new (const gchar *working_directory,
+ gboolean restore_index, const gchar *stash)
+{
+ GitStashApplyCommand *self;
+
+ self = g_object_new (GIT_TYPE_STASH_APPLY_COMMAND,
+ "working-directory", working_directory,
+ "single-line-output", TRUE,
+ NULL);
+
+ self->priv->restore_index = restore_index;
+ self->priv->stash = g_strdup (stash);
+
+ return self;
+}
diff --git a/plugins/git/git-stash-apply-command.h b/plugins/git/git-stash-apply-command.h
new file mode 100644
index 0000000..f653970
--- /dev/null
+++ b/plugins/git/git-stash-apply-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_APPLY_COMMAND_H_
+#define _GIT_STASH_APPLY_COMMAND_H_
+
+#include <glib-object.h>
+#include "git-command.h"
+
+G_BEGIN_DECLS
+
+#define GIT_TYPE_STASH_APPLY_COMMAND (git_stash_apply_command_get_type ())
+#define GIT_STASH_APPLY_COMMAND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIT_TYPE_STASH_APPLY_COMMAND, GitStashApplyCommand))
+#define GIT_STASH_APPLY_COMMAND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIT_TYPE_STASH_APPLY_COMMAND, GitStashApplyCommandClass))
+#define GIT_IS_STASH_APPLY_COMMAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIT_TYPE_STASH_APPLY_COMMAND))
+#define GIT_IS_STASH_APPLY_COMMAND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIT_TYPE_STASH_APPLY_COMMAND))
+#define GIT_STASH_APPLY_COMMAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIT_TYPE_STASH_APPLY_COMMAND, GitStashApplyCommandClass))
+
+typedef struct _GitStashApplyCommandClass GitStashApplyCommandClass;
+typedef struct _GitStashApplyCommand GitStashApplyCommand;
+typedef struct _GitStashApplyCommandPriv GitStashApplyCommandPriv;
+
+struct _GitStashApplyCommandClass
+{
+ GitCommandClass parent_class;
+};
+
+struct _GitStashApplyCommand
+{
+ GitCommand parent_instance;
+
+ GitStashApplyCommandPriv *priv;
+};
+
+GType git_stash_apply_command_get_type (void) G_GNUC_CONST;
+GitStashApplyCommand *git_stash_apply_command_new (const gchar *working_directory,
+ gboolean restore_index,
+ const gchar *stash);
+
+G_END_DECLS
+
+#endif /* _GIT_STASH_APPLY_COMMAND_H_ */
diff --git a/plugins/git/git-stash-widget.c b/plugins/git/git-stash-widget.c
index 6416396..0416248 100644
--- a/plugins/git/git-stash-widget.c
+++ b/plugins/git/git-stash-widget.c
@@ -98,6 +98,47 @@ on_stash_widget_save_button_clicked (GtkButton *button, GitUIData *data)
}
+static void
+on_stash_widget_apply_button_clicked (GtkButton *button, GitUIData *data)
+{
+ GtkWidget *stash_widget_view;
+ GtkListStore *stash_list_model;
+ GtkTreeSelection *selection;
+ GtkTreeIter iter;
+ gchar *stash;
+ GitStashApplyCommand *apply_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);
+
+ apply_command = git_stash_apply_command_new (data->plugin->project_root_directory,
+ FALSE, stash);
+
+ g_free (stash);
+
+ git_create_message_view (data->plugin);
+
+ g_signal_connect (G_OBJECT (apply_command), "data-arrived",
+ G_CALLBACK (on_git_command_info_arrived),
+ data->plugin);
+
+ g_signal_connect (G_CALLBACK (apply_command), "command-finished",
+ G_CALLBACK (on_git_stash_apply_command_finished),
+ data->plugin);
+
+ anjuta_command_start (ANJUTA_COMMAND (apply_command));
+ }
+
+}
+
void
git_stash_widget_create (Git *plugin, GtkWidget **stash_widget,
GtkWidget **stash_widget_grip)
@@ -112,6 +153,7 @@ git_stash_widget_create (Git *plugin, GtkWidget **stash_widget,
GtkWidget *stash_widget_view;
GtkWidget *stash_widget_grip_hbox;
GtkWidget *stash_widget_save_button;
+ GtkWidget *stash_widget_apply_button;
GtkTreeSelection *selection;
bxml = gtk_builder_new ();
@@ -133,6 +175,8 @@ git_stash_widget_create (Git *plugin, GtkWidget **stash_widget,
"stash_widget_grip_hbox"));
stash_widget_save_button = GTK_WIDGET (gtk_builder_get_object (bxml,
"stash_widget_save_button"));
+ stash_widget_apply_button = GTK_WIDGET (gtk_builder_get_object (bxml,
+ "stash_widget_apply_button"));
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (stash_widget_view));
gtk_tree_selection_set_select_function (selection,
@@ -143,6 +187,10 @@ git_stash_widget_create (Git *plugin, GtkWidget **stash_widget,
G_CALLBACK (on_stash_widget_save_button_clicked),
data);
+ g_signal_connect (G_OBJECT (stash_widget_apply_button), "clicked",
+ G_CALLBACK (on_stash_widget_apply_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 d047738..ce62860 100644
--- a/plugins/git/git-stash-widget.h
+++ b/plugins/git/git-stash-widget.h
@@ -22,6 +22,7 @@
#include "git-ui-utils.h"
#include "git-stash-save-command.h"
+#include "git-stash-apply-command.h"
void git_stash_widget_create (Git *plugin, GtkWidget **stash_widget,
GtkWidget **stash_widget_grip);
diff --git a/plugins/git/git-ui-utils.c b/plugins/git/git-ui-utils.c
index c7ee7c1..81e3eae 100644
--- a/plugins/git/git-ui-utils.c
+++ b/plugins/git/git-ui-utils.c
@@ -476,6 +476,22 @@ on_git_stash_save_command_finished (AnjutaCommand *command, guint return_code,
}
void
+on_git_stash_apply_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: Stashed changes applied."), 5);
+
+ git_report_errors (command, return_code);
+
+ g_object_unref (command);
+}
+
+void
git_select_all_status_items (GtkButton *select_all_button,
AnjutaVcsStatusTreeView *tree_view)
{
diff --git a/plugins/git/git-ui-utils.h b/plugins/git/git-ui-utils.h
index 362d3cd..67be4b6 100644
--- a/plugins/git/git-ui-utils.h
+++ b/plugins/git/git-ui-utils.h
@@ -85,6 +85,8 @@ void on_git_list_stash_command_data_arrived (AnjutaCommand *command,
GtkListStore *stash_list_model);
void on_git_stash_save_command_finished (AnjutaCommand *command,
guint return_code, Git *plugin);
+void on_git_stash_apply_command_finished (AnjutaCommand *command,
+ guint return_code, Git *plugin);
void git_select_all_status_items (GtkButton *select_all_button,
AnjutaVcsStatusTreeView *tree_view);
void git_clear_all_status_selections (GtkButton *clear_button,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]