[anjuta/git-shell: 23/26] git: Add some basic branch actions



commit bda6a6f0892c3edc40bac00ee78a3e11d1ff0529
Author: James Liggett <jrliggett cox net>
Date:   Mon May 17 16:46:31 2010 -0700

    git: Add some basic branch actions
    
    Add create/delete branches and branch switching.

 plugins/git/Makefile.am                |    8 +-
 plugins/git/git-create-branch-pane.c   |  194 ++++++++++++++++++++++++++++++++
 plugins/git/git-create-branch-pane.h   |   59 ++++++++++
 plugins/git/git-delete-branches-pane.c |  191 +++++++++++++++++++++++++++++++
 plugins/git/git-delete-branches-pane.h |   61 ++++++++++
 plugins/git/git-switch-branch-pane.c   |   44 +++++++
 plugins/git/git-switch-branch-pane.h   |   29 +++++
 plugins/git/plugin.c                   |   47 +++++++-
 plugins/git/plugin.h                   |    3 +
 9 files changed, 631 insertions(+), 5 deletions(-)
---
diff --git a/plugins/git/Makefile.am b/plugins/git/Makefile.am
index 4ebf617..2b4f061 100644
--- a/plugins/git/Makefile.am
+++ b/plugins/git/Makefile.am
@@ -163,7 +163,13 @@ libanjuta_git_la_SOURCES = \
 	git-pane.c \
 	git-pane.h \
 	git-branches-pane.c \
-	git-branches-pane.h
+	git-branches-pane.h \
+	git-create-branch-pane.c \
+	git-create-branch-pane.h \
+	git-delete-branches-pane.c \
+	git-delete-branch-pane.h \
+	git-switch-branch-pane.c \
+	git-switch-branch-pane.h
 
 libanjuta_git_la_LDFLAGS = $(ANJUTA_PLUGIN_LDFLAGS)
 
diff --git a/plugins/git/git-create-branch-pane.c b/plugins/git/git-create-branch-pane.c
new file mode 100644
index 0000000..49c8d4a
--- /dev/null
+++ b/plugins/git/git-create-branch-pane.c
@@ -0,0 +1,194 @@
+/* -*- 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-create-branch-pane.h"
+
+struct _GitCreateBranchPanePriv
+{
+	GtkBuilder *builder;
+};
+
+G_DEFINE_TYPE (GitCreateBranchPane, git_create_branch_pane, GIT_TYPE_PANE);
+
+static void
+on_ok_button_clicked (GtkButton *button, GitCreateBranchPane *self)
+{
+	Git *plugin;
+	GtkEntry *name_entry;
+	GtkToggleButton *revision_radio;
+	GtkEntry *revision_entry;
+	GtkToggleButton *checkout_check;
+	gchar *name;
+	gchar *revision;
+	GitBranchCreateCommand *create_command;
+
+	plugin = ANJUTA_PLUGIN_GIT (anjuta_dock_pane_get_plugin (ANJUTA_DOCK_PANE (self)));
+	name_entry = GTK_ENTRY (gtk_builder_get_object (self->priv->builder,
+	                                                "name_entry"));
+	revision_radio = GTK_TOGGLE_BUTTON (gtk_builder_get_object (self->priv->builder,
+	                                                            "revision_radio"));
+	revision_entry = GTK_ENTRY (gtk_builder_get_object (self->priv->builder,
+	                                                    "revision_entry"));
+	checkout_check = GTK_TOGGLE_BUTTON (gtk_builder_get_object (self->priv->builder,
+	                                                            "checkout_check"));
+	name = gtk_editable_get_chars (GTK_EDITABLE (name_entry), 0, -1);
+	revision = NULL;
+
+	if (gtk_toggle_button_get_active (revision_radio))
+	{
+		revision = gtk_editable_get_chars (GTK_EDITABLE (revision_entry), 0, 
+		                                   -1);
+	}
+
+	create_command = git_branch_create_command_new (plugin->project_root_directory,
+	                                                name,
+	                                                revision,
+	                                                gtk_toggle_button_get_active (checkout_check));
+
+	g_signal_connect (G_OBJECT (create_command), "command-finished",
+	                  G_CALLBACK (g_object_unref),
+	                  NULL);
+
+	anjuta_command_start (ANJUTA_COMMAND (create_command));
+
+
+	g_free (name);
+	g_free (revision);
+
+	anjuta_dock_remove_pane (ANJUTA_DOCK (plugin->dock), 
+	                         ANJUTA_DOCK_PANE (self));
+}
+
+static void
+on_cancel_button_clicked (GtkButton *button, GitCreateBranchPane *self)
+{
+	Git *plugin;
+
+	plugin = ANJUTA_PLUGIN_GIT (anjuta_dock_pane_get_plugin (ANJUTA_DOCK_PANE (self)));
+
+	anjuta_dock_remove_pane (ANJUTA_DOCK (plugin->dock),
+	                         ANJUTA_DOCK_PANE (self));
+}
+
+static void
+on_revision_radio_toggled (GtkToggleButton *button, GitCreateBranchPane *self)
+{
+	GtkWidget *revision_entry;
+
+	revision_entry = GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
+	                                                     "revision_entry"));
+
+	gtk_widget_set_sensitive (revision_entry,
+	                          gtk_toggle_button_get_active (button));
+}
+
+static void
+git_create_branch_pane_init (GitCreateBranchPane *self)
+{
+	gchar *objects[] = {"create_branch_pane",
+						NULL};
+	GError *error = NULL;
+	GtkWidget *ok_button;
+	GtkWidget *cancel_button;
+	GtkWidget *revision_radio;
+
+	self->priv = g_new0 (GitCreateBranchPanePriv, 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_WIDGET (gtk_builder_get_object (self->priv->builder, 
+	                                                "ok_button"));
+	cancel_button = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, 
+	                                                    "cancel_button"));
+	revision_radio = GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
+	                                                     "revision_radio"));
+
+	g_signal_connect (G_OBJECT (ok_button), "clicked",
+	                  G_CALLBACK (on_ok_button_clicked),
+	                  self);
+
+	g_signal_connect (G_OBJECT (cancel_button), "clicked",
+	                  G_CALLBACK (on_cancel_button_clicked),
+	                  self);
+
+	g_signal_connect (G_OBJECT (revision_radio), "toggled",
+	                  G_CALLBACK (on_revision_radio_toggled),
+	                  self);
+}
+
+static void
+git_create_branch_pane_finalize (GObject *object)
+{
+	GitCreateBranchPane *self;
+
+	self = GIT_CREATE_BRANCH_PANE (object);
+
+	g_object_unref (self->priv->builder);
+	g_free (self->priv);
+
+	G_OBJECT_CLASS (git_create_branch_pane_parent_class)->finalize (object);
+}
+
+static GtkWidget *
+git_create_branch_pane_get_widget (AnjutaDockPane *pane)
+{
+	GitCreateBranchPane *self;
+
+	self = GIT_CREATE_BRANCH_PANE (pane);
+
+	return GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
+	                                           "create_branch_pane"));
+}
+
+static void
+git_create_branch_pane_class_init (GitCreateBranchPaneClass *klass)
+{
+	GObjectClass* object_class = G_OBJECT_CLASS (klass);
+	AnjutaDockPaneClass *pane_class = ANJUTA_DOCK_PANE_CLASS (klass);
+
+	object_class->finalize = git_create_branch_pane_finalize;
+	pane_class->get_widget = git_create_branch_pane_get_widget;
+	pane_class->refresh = NULL;
+}
+
+
+AnjutaDockPane *
+git_create_branch_pane_new (Git *plugin)
+{
+	return g_object_new (GIT_TYPE_CREATE_BRANCH_PANE, "plugin", plugin, NULL);
+}
+
+void
+on_create_branch_button_clicked (GtkAction *action, Git *plugin)
+{
+	AnjutaDockPane *pane;
+
+	pane = git_create_branch_pane_new (plugin);
+
+	anjuta_dock_add_pane (ANJUTA_DOCK (plugin->dock), "CreateBranch", 
+	                      "Create Branch", NULL, pane, GDL_DOCK_BOTTOM, NULL, 0,
+	                      NULL);
+}
\ No newline at end of file
diff --git a/plugins/git/git-create-branch-pane.h b/plugins/git/git-create-branch-pane.h
new file mode 100644
index 0000000..1e08e3f
--- /dev/null
+++ b/plugins/git/git-create-branch-pane.h
@@ -0,0 +1,59 @@
+/* -*- 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_CREATE_BRANCH_PANE_H_
+#define _GIT_CREATE_BRANCH_PANE_H_
+
+#include <glib-object.h>
+#include "git-pane.h"
+#include "plugin.h"
+#include "git-branch-create-command.h"
+
+G_BEGIN_DECLS
+
+#define GIT_TYPE_CREATE_BRANCH_PANE             (git_create_branch_pane_get_type ())
+#define GIT_CREATE_BRANCH_PANE(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIT_TYPE_CREATE_BRANCH_PANE, GitCreateBranchPane))
+#define GIT_CREATE_BRANCH_PANE_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), GIT_TYPE_CREATE_BRANCH_PANE, GitCreateBranchPaneClass))
+#define GIT_IS_CREATE_BRANCH_PANE(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIT_TYPE_CREATE_BRANCH_PANE))
+#define GIT_IS_CREATE_BRANCH_PANE_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GIT_TYPE_CREATE_BRANCH_PANE))
+#define GIT_CREATE_BRANCH_PANE_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GIT_TYPE_CREATE_BRANCH_PANE, GitCreateBranchPaneClass))
+
+typedef struct _GitCreateBranchPaneClass GitCreateBranchPaneClass;
+typedef struct _GitCreateBranchPane GitCreateBranchPane;
+typedef struct _GitCreateBranchPanePriv GitCreateBranchPanePriv;
+
+struct _GitCreateBranchPaneClass
+{
+	GitPaneClass parent_class;
+};
+
+struct _GitCreateBranchPane
+{
+	GitPane parent_instance;
+
+	GitCreateBranchPanePriv *priv;
+};
+
+GType git_create_branch_pane_get_type (void) G_GNUC_CONST;
+AnjutaDockPane * git_create_branch_pane_new (Git *plugin);
+void on_create_branch_button_clicked (GtkAction *action, Git *plugin);
+
+G_END_DECLS
+
+#endif /* _GIT_CREATE_BRANCH_PANE_H_ */
diff --git a/plugins/git/git-delete-branches-pane.c b/plugins/git/git-delete-branches-pane.c
new file mode 100644
index 0000000..a7e0c3a
--- /dev/null
+++ b/plugins/git/git-delete-branches-pane.c
@@ -0,0 +1,191 @@
+/* -*- 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-delete-branches-pane.h"
+
+struct _GitDeleteBranchesPanePriv
+{
+	GtkBuilder *builder;
+};
+
+G_DEFINE_TYPE (GitDeleteBranchesPane, git_delete_branches_pane, GIT_TYPE_PANE);
+
+static void
+on_ok_button_clicked (GtkButton *button, GitDeleteBranchesPane *self)
+{
+	Git *plugin;
+	GtkToggleButton *require_merged_check;
+	GList *selected_local_branches;
+	GList *selected_remote_branches;
+	GitBranchDeleteCommand *local_delete_command;
+	GitBranchDeleteCommand *remote_delete_command;
+	AnjutaCommandQueue *queue;
+
+	plugin = ANJUTA_PLUGIN_GIT (anjuta_dock_pane_get_plugin (ANJUTA_DOCK_PANE (self)));
+	require_merged_check = GTK_TOGGLE_BUTTON (gtk_builder_get_object (self->priv->builder,
+	                                                                  "require_merged_check"));
+	selected_local_branches = git_branches_pane_get_selected_local_branches (GIT_BRANCHES_PANE (plugin->branches_pane));
+	selected_remote_branches = git_branches_pane_get_selected_remote_branches (GIT_BRANCHES_PANE (plugin->branches_pane));
+
+	/* The user might not have selected anything */
+	if (git_branches_pane_count_selected_items (GIT_BRANCHES_PANE (plugin->branches_pane)) > 0)
+	{
+		queue = anjuta_command_queue_new (ANJUTA_COMMAND_QUEUE_EXECUTE_MANUAL);
+		
+		if (selected_local_branches)
+		{
+			local_delete_command = git_branch_delete_command_new (plugin->project_root_directory,
+			                                                      selected_local_branches,
+			                                                      FALSE,
+			                                                      gtk_toggle_button_get_active (require_merged_check));
+
+			g_signal_connect (G_OBJECT (local_delete_command), 
+			                  "command-finished",
+			                  G_CALLBACK (g_object_unref),
+			                  NULL);
+
+			anjuta_command_queue_push (queue, 
+			                           ANJUTA_COMMAND (local_delete_command));
+		}
+
+		if (selected_remote_branches)
+		{
+			remote_delete_command = git_branch_delete_command_new (plugin->project_root_directory,
+			                                                       selected_remote_branches,
+			                                                       TRUE,
+			                                                       gtk_toggle_button_get_active (require_merged_check));
+
+			g_signal_connect (G_OBJECT (remote_delete_command), "command-finished",
+			                  G_CALLBACK (g_object_unref),
+			                  NULL);
+			
+			anjuta_command_queue_push (queue, 
+			                           ANJUTA_COMMAND (remote_delete_command));
+		}
+
+		/* Run the commands */
+		g_signal_connect (G_OBJECT (queue), "finished",
+		                  G_CALLBACK (g_object_unref),
+		                  NULL);
+
+		anjuta_command_queue_start (queue);
+	}
+
+
+	anjuta_dock_remove_pane (ANJUTA_DOCK (plugin->dock), ANJUTA_DOCK_PANE (self));
+	                            
+}
+
+static void
+on_cancel_button_clicked (GtkButton *button, GitDeleteBranchesPane *self)
+{
+	Git *plugin;
+
+	plugin = ANJUTA_PLUGIN_GIT (anjuta_dock_pane_get_plugin (ANJUTA_DOCK_PANE (self)));
+
+	anjuta_dock_remove_pane (ANJUTA_DOCK (plugin->dock), ANJUTA_DOCK_PANE (self));
+}
+
+static void
+git_delete_branches_pane_init (GitDeleteBranchesPane *self)
+{
+	gchar *objects[] = {"delete_branches_pane",
+						NULL};
+	GError *error = NULL;
+	GtkButton *ok_button;
+	GtkButton *cancel_button;
+
+	self->priv = g_new0 (GitDeleteBranchesPanePriv, 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 (G_OBJECT (cancel_button), "clicked",
+	                  G_CALLBACK (on_cancel_button_clicked),
+	                  self);
+}
+
+static void
+git_delete_branches_pane_finalize (GObject *object)
+{
+	GitDeleteBranchesPane *self;
+
+	self = GIT_DELETE_BRANCHES_PANE (object);
+
+	g_object_unref (self->priv->builder);
+	g_free (self->priv);
+
+	G_OBJECT_CLASS (git_delete_branches_pane_parent_class)->finalize (object);
+}
+
+static GtkWidget *
+get_widget (AnjutaDockPane *pane)
+{
+	GitDeleteBranchesPane *self;
+
+	self = GIT_DELETE_BRANCHES_PANE (pane);
+
+	return GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
+	                                           "delete_branches_pane"));
+}
+
+static void
+git_delete_branches_pane_class_init (GitDeleteBranchesPaneClass *klass)
+{
+	GObjectClass* object_class = G_OBJECT_CLASS (klass);
+	AnjutaDockPaneClass* pane_class = ANJUTA_DOCK_PANE_CLASS (klass);
+
+	object_class->finalize = git_delete_branches_pane_finalize;
+	pane_class->get_widget = get_widget;
+	pane_class->refresh = NULL;
+}
+
+
+AnjutaDockPane *
+git_delete_branches_pane_new (Git *plugin)
+{
+	return g_object_new (GIT_TYPE_DELETE_BRANCHES_PANE, "plugin", plugin, NULL);
+}
+
+void
+on_delete_branches_button_clicked (GtkAction *action, Git *plugin)
+{
+	AnjutaDockPane *delete_branches_pane;
+
+	delete_branches_pane = git_delete_branches_pane_new (plugin);
+
+	anjuta_dock_add_pane (ANJUTA_DOCK (plugin->dock), "DeleteBranches",
+	                      "Delete Branches", NULL, delete_branches_pane,
+	                      GDL_DOCK_BOTTOM, NULL, 0, NULL);
+}
diff --git a/plugins/git/git-delete-branches-pane.h b/plugins/git/git-delete-branches-pane.h
new file mode 100644
index 0000000..d6c606a
--- /dev/null
+++ b/plugins/git/git-delete-branches-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_DELETE_BRANCHES_PANE_H_
+#define _GIT_DELETE_BRANCHES_PANE_H_
+
+#include <glib-object.h>
+#include <libanjuta/anjuta-command-queue.h>
+#include "git-pane.h"
+#include "git-branches-pane.h"
+#include "git-branch-delete-command.h"
+
+G_BEGIN_DECLS
+
+#define GIT_TYPE_DELETE_BRANCHES_PANE             (git_delete_branches_pane_get_type ())
+#define GIT_DELETE_BRANCHES_PANE(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIT_TYPE_DELETE_BRANCHES_PANE, GitDeleteBranchesPane))
+#define GIT_DELETE_BRANCHES_PANE_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), GIT_TYPE_DELETE_BRANCHES_PANE, GitDeleteBranchesPaneClass))
+#define GIT_IS_DELETE_BRANCHES_PANE(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIT_TYPE_DELETE_BRANCHES_PANE))
+#define GIT_IS_DELETE_BRANCHES_PANE_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GIT_TYPE_DELETE_BRANCHES_PANE))
+#define GIT_DELETE_BRANCHES_PANE_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GIT_TYPE_DELETE_BRANCHES_PANE, GitDeleteBranchesPaneClass))
+
+typedef struct _GitDeleteBranchesPaneClass GitDeleteBranchesPaneClass;
+typedef struct _GitDeleteBranchesPane GitDeleteBranchesPane;
+typedef struct _GitDeleteBranchesPanePriv GitDeleteBranchesPanePriv;
+
+struct _GitDeleteBranchesPaneClass
+{
+	GitPaneClass parent_class;
+};
+
+struct _GitDeleteBranchesPane
+{
+	GitPane parent_instance;
+
+	GitDeleteBranchesPanePriv *priv;
+};
+
+GType git_delete_branches_pane_get_type (void) G_GNUC_CONST;
+AnjutaDockPane * git_delete_branches_pane_new (Git *plugin);
+void on_delete_branches_button_clicked (GtkAction *action, 
+                                        Git *plugin);
+
+G_END_DECLS
+
+#endif /* _GIT_DELETE_BRANCHES_PANE_H_ */
diff --git a/plugins/git/git-switch-branch-pane.c b/plugins/git/git-switch-branch-pane.c
new file mode 100644
index 0000000..b6d3cea
--- /dev/null
+++ b/plugins/git/git-switch-branch-pane.c
@@ -0,0 +1,44 @@
+/* -*- 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-switch-branch-pane.h"
+
+void
+on_switch_branch_button_clicked (GtkAction *action, Git *plugin)
+{
+	gchar *selected_branch;
+	GitBranchCheckoutCommand *checkout_command;
+
+	selected_branch = git_branches_pane_get_selected_branch (GIT_BRANCHES_PANE (plugin->branches_pane));
+
+	if (selected_branch)
+	{
+		checkout_command = git_branch_checkout_command_new (plugin->project_root_directory,
+		                                                    selected_branch);
+
+		g_free (selected_branch);
+
+		g_signal_connect (G_OBJECT (checkout_command), "command-finished",
+		                  G_CALLBACK (g_object_unref),
+		                  NULL);
+		
+		anjuta_command_start (ANJUTA_COMMAND (checkout_command));
+	}
+}
+ 
\ No newline at end of file
diff --git a/plugins/git/git-switch-branch-pane.h b/plugins/git/git-switch-branch-pane.h
new file mode 100644
index 0000000..8429b93
--- /dev/null
+++ b/plugins/git/git-switch-branch-pane.h
@@ -0,0 +1,29 @@
+/* -*- 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_SWITCH_BRANCH_PANE_H_
+#define _GIT_SWITCH_BRANCH_PANE_H_
+
+#include "git-branch-checkout-command.h"
+#include "git-branches-pane.h"
+
+void on_switch_branch_button_clicked (GtkAction *action, 
+                                      Git *plugin);
+
+#endif
\ No newline at end of file
diff --git a/plugins/git/plugin.c b/plugins/git/plugin.c
index 3c56e5c..77f2f1f 100644
--- a/plugins/git/plugin.c
+++ b/plugins/git/plugin.c
@@ -22,6 +22,45 @@
 #include "plugin.h"
 #include "git-vcs-interface.h"
 #include "git-branches-pane.h"
+#include "git-create-branch-pane.h"
+#include "git-delete-branches-pane.h"
+#include "git-switch-branch-pane.h"
+
+AnjutaCommandBarEntry branch_entries[] =
+{
+	{
+		ANJUTA_COMMAND_BAR_ENTRY_FRAME,
+		"NULL",
+		N_("Branch tools"),
+		NULL,
+		NULL,
+		NULL
+	},
+	{
+		ANJUTA_COMMAND_BAR_ENTRY_BUTTON,
+		"CreateBranch",
+		N_("Create a branch"),
+		N_("Create a branch"),
+		GTK_STOCK_NEW,
+		G_CALLBACK (on_create_branch_button_clicked)
+	},
+	{
+		ANJUTA_COMMAND_BAR_ENTRY_BUTTON,
+		"DeleteBranches",
+		N_("Delete selected branches"),
+		N_("Delete selected branches"),
+		GTK_STOCK_DELETE,
+		G_CALLBACK (on_delete_branches_button_clicked)
+	},
+	{
+		ANJUTA_COMMAND_BAR_ENTRY_BUTTON,
+		"Switch",
+		N_("Switch to this branch"),
+		N_("Switch to the selected branch"),
+		GTK_STOCK_JUMP_TO,
+		G_CALLBACK (on_switch_branch_button_clicked)
+	}
+};
 
 static gpointer parent_class;
 
@@ -122,7 +161,6 @@ git_activate_plugin (AnjutaPlugin *plugin)
 	Git *git_plugin;
 	GtkWidget *command_bar_viewport;
 	GtkWidget *dock_viewport;
-	AnjutaDockPane *pane;
 	
 	DEBUG_PRINT ("%s", "Git: Activating Git plugin â?¦");
 	
@@ -176,10 +214,11 @@ git_activate_plugin (AnjutaPlugin *plugin)
 	                                                                      GIT_BRANCH_TYPE_REMOTE);
 
 	/* Add the panes to the dock */
-	pane = git_branches_pane_new (git_plugin);
+	git_plugin->branches_pane = git_branches_pane_new (git_plugin);
 	anjuta_dock_add_pane (ANJUTA_DOCK (git_plugin->dock), "Branches", 
-	                      _("Branches"), NULL, pane, GDL_DOCK_CENTER, NULL, 0, 
-	                      NULL);
+	                      _("Branches"), NULL, git_plugin->branches_pane,   
+	                      GDL_DOCK_CENTER, branch_entries, 
+	                      G_N_ELEMENTS (branch_entries), git_plugin);
 	
 	/* Add watches */
 	git_plugin->project_root_watch_id = anjuta_plugin_add_watch (plugin,
diff --git a/plugins/git/plugin.h b/plugins/git/plugin.h
index a8c2ee4..3742b43 100644
--- a/plugins/git/plugin.h
+++ b/plugins/git/plugin.h
@@ -61,6 +61,9 @@ struct _Git
 	GtkWidget *command_bar_window;
 	GtkWidget *dock_window;
 
+	/* Dock panes */
+	AnjutaDockPane *branches_pane;
+
 	/* Branch list commands */
 	GitBranchListCommand *local_branch_list_command;
 	GitBranchListCommand *remote_branch_list_command;



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