From 3b7aa45af6255f415abf98aa2385d2f4ebce0953 Mon Sep 17 00:00:00 2001 From: James Liggett Date: Sat, 26 Apr 2008 17:05:03 -0700 Subject: [PATCH] Implement simple branch creation. --- plugins/git/Makefile.am | 6 +- plugins/git/anjuta-git.glade | 118 ++++++++++++++++++++++++++++++- plugins/git/anjuta-git.ui | 3 +- plugins/git/git-branch-create-command.c | 108 ++++++++++++++++++++++++++++ plugins/git/git-branch-create-command.h | 64 +++++++++++++++++ plugins/git/git-create-branch-dialog.c | 121 ++++++++++++++++++++++++++++++++ plugins/git/git-create-branch-dialog.h | 33 +++++++++ plugins/git/plugin.c | 11 ++- 8 files changed, 460 insertions(+), 4 deletions(-) create mode 100644 plugins/git/git-branch-create-command.c create mode 100644 plugins/git/git-branch-create-command.h create mode 100644 plugins/git/git-create-branch-dialog.c create mode 100644 plugins/git/git-create-branch-dialog.h diff --git a/plugins/git/Makefile.am b/plugins/git/Makefile.am index 0f0b878a..04a0392b 100644 --- a/plugins/git/Makefile.am +++ b/plugins/git/Makefile.am @@ -83,7 +83,11 @@ libanjuta_git_la_SOURCES = \ git-branch-checkout-command.h \ git-branch-checkout-command.c \ git-switch-dialog.c \ - git-switch-dialog.h + git-switch-dialog.h \ + git-branch-create-command.h \ + git-branch-create-command.c \ + git-create-branch-dialog.c \ + git-create-branch-dialog.h libanjuta_git_la_LDFLAGS = $(ANJUTA_PLUGIN_LDFLAGS) diff --git a/plugins/git/anjuta-git.glade b/plugins/git/anjuta-git.glade index 0b36feea..a98657b2 100644 --- a/plugins/git/anjuta-git.glade +++ b/plugins/git/anjuta-git.glade @@ -1,6 +1,6 @@ - + @@ -993,4 +993,120 @@ + + 5 + Create Branch + GTK_WIN_POS_CENTER_ON_PARENT + GDK_WINDOW_TYPE_HINT_DIALOG + False + + + True + 2 + + + 250 + True + 0 + GTK_SHADOW_NONE + + + True + 12 + + + True + True + + + + + + + True + <b>Branch name:</b> + True + + + label_item + + + + + False + 1 + + + + + True + 0 + GTK_SHADOW_NONE + + + True + 12 + + + True + True + Check out the branch after it is created + 0 + True + + + + + + + True + <b>Options:</b> + True + + + label_item + + + + + False + 2 + + + + + True + GTK_BUTTONBOX_END + + + True + True + True + gtk-cancel + True + -6 + + + + + True + True + True + gtk-ok + True + -5 + + + 1 + + + + + False + GTK_PACK_END + + + + + diff --git a/plugins/git/anjuta-git.ui b/plugins/git/anjuta-git.ui index f54c3958..20c831a4 100644 --- a/plugins/git/anjuta-git.ui +++ b/plugins/git/anjuta-git.ui @@ -5,11 +5,12 @@ - + + diff --git a/plugins/git/git-branch-create-command.c b/plugins/git/git-branch-create-command.c new file mode 100644 index 00000000..6cc4c329 --- /dev/null +++ b/plugins/git/git-branch-create-command.c @@ -0,0 +1,108 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ +/* + * anjuta + * Copyright (C) James Liggett 2008 + * + * 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-branch-create-command.h" + +struct _GitBranchCreateCommandPriv +{ + gchar *name; + gboolean checkout; +}; + +G_DEFINE_TYPE (GitBranchCreateCommand, git_branch_create_command, GIT_TYPE_COMMAND); + +static void +git_branch_create_command_init (GitBranchCreateCommand *self) +{ + self->priv = g_new0 (GitBranchCreateCommandPriv, 1); +} + +static void +git_branch_create_command_finalize (GObject *object) +{ + GitBranchCreateCommand *self; + + self = GIT_BRANCH_CREATE_COMMAND (object); + + g_free (self->priv->name); + g_free (self->priv); + + G_OBJECT_CLASS (git_branch_create_command_parent_class)->finalize (object); +} + +static guint +git_branch_create_command_run (AnjutaCommand *command) +{ + GitBranchCreateCommand *self; + + self = GIT_BRANCH_CREATE_COMMAND (command); + + if (self->priv->checkout) + { + git_command_add_arg (GIT_COMMAND (command), "checkout"); + git_command_add_arg (GIT_COMMAND (command), "-b"); + } + else + git_command_add_arg (GIT_COMMAND (command), "branch"); + + git_command_add_arg (GIT_COMMAND (command), self->priv->name); + + return 0; +} + +static void +git_branch_create_command_class_init (GitBranchCreateCommandClass *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_branch_create_command_finalize; + parent_class->output_handler = git_command_send_output_to_info; + command_class->run = git_branch_create_command_run; +} + + +GitBranchCreateCommand * +git_branch_create_command_new (const gchar *working_directory, + const gchar *name, gboolean checkout) +{ + GitBranchCreateCommand *self; + + self = g_object_new (GIT_TYPE_BRANCH_CREATE_COMMAND, + "working-directory", working_directory, + "single-line-output", TRUE, + NULL); + + self->priv->name = g_strdup (name); + self->priv->checkout = checkout; + + return self; +} + +gchar * +git_branch_create_command_get_branch_name (GitBranchCreateCommand *self) +{ + return g_strdup (self->priv->name); +} diff --git a/plugins/git/git-branch-create-command.h b/plugins/git/git-branch-create-command.h new file mode 100644 index 00000000..e985267b --- /dev/null +++ b/plugins/git/git-branch-create-command.h @@ -0,0 +1,64 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ +/* + * anjuta + * Copyright (C) James Liggett 2008 + * + * 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_BRANCH_CREATE_COMMAND_H_ +#define _GIT_BRANCH_CREATE_COMMAND_H_ + +#include +#include "git-command.h" + +G_BEGIN_DECLS + +#define GIT_TYPE_BRANCH_CREATE_COMMAND (git_branch_create_command_get_type ()) +#define GIT_BRANCH_CREATE_COMMAND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIT_TYPE_BRANCH_CREATE_COMMAND, GitBranchCreateCommand)) +#define GIT_BRANCH_CREATE_COMMAND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIT_TYPE_BRANCH_CREATE_COMMAND, GitBranchCreateCommandClass)) +#define GIT_IS_BRANCH_CREATE_COMMAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIT_TYPE_BRANCH_CREATE_COMMAND)) +#define GIT_IS_BRANCH_CREATE_COMMAND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIT_TYPE_BRANCH_CREATE_COMMAND)) +#define GIT_BRANCH_CREATE_COMMAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIT_TYPE_BRANCH_CREATE_COMMAND, GitBranchCreateCommandClass)) + +typedef struct _GitBranchCreateCommandClass GitBranchCreateCommandClass; +typedef struct _GitBranchCreateCommand GitBranchCreateCommand; +typedef struct _GitBranchCreateCommandPriv GitBranchCreateCommandPriv; + +struct _GitBranchCreateCommandClass +{ + GitCommandClass parent_class; +}; + +struct _GitBranchCreateCommand +{ + GitCommand parent_instance; + + GitBranchCreateCommandPriv *priv; +}; + +GType git_branch_create_command_get_type (void) G_GNUC_CONST; +GitBranchCreateCommand *git_branch_create_command_new (const gchar *working_directory, + const gchar *name, + gboolean checkout); +gchar *git_branch_create_command_get_branch_name (GitBranchCreateCommand *self); + +G_END_DECLS + +#endif /* _GIT_BRANCH_CREATE_COMMAND_H_ */ diff --git a/plugins/git/git-create-branch-dialog.c b/plugins/git/git-create-branch-dialog.c new file mode 100644 index 00000000..b939bee6 --- /dev/null +++ b/plugins/git/git-create-branch-dialog.c @@ -0,0 +1,121 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ +/* + * anjuta + * Copyright (C) James Liggett 2008 + * + * 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-create-branch-dialog.h" + +static void +on_checkout_command_finished (AnjutaCommand *command, guint return_code, + Git *plugin) +{ + AnjutaStatus *status; + gchar *branch_name; + gchar *status_message; + + if (return_code == 0) + { + status = anjuta_shell_get_status (ANJUTA_PLUGIN (plugin)->shell, + NULL); + + branch_name = git_branch_create_command_get_branch_name (GIT_BRANCH_CREATE_COMMAND (command)); + status_message = g_strdup_printf (_("Git: Created branch \"%s\"."), + branch_name); + anjuta_status (status, status_message, 5); + + g_free (branch_name); + g_free (status_message); + } + + + + report_errors (command, return_code); + + g_object_unref (command); +} + + +static void +on_create_branch_dialog_response (GtkDialog *dialog, gint response_id, + GitUIData *data) +{ + GtkWidget *branch_name_entry; + GtkWidget *checkout_check; + gchar *branch_name; + gboolean checkout; + GitBranchCreateCommand *create_command; + + if (response_id == GTK_RESPONSE_OK) + { + branch_name_entry = glade_xml_get_widget (data->gxml, + "branch_name_entry"); + checkout_check = glade_xml_get_widget (data->gxml, "checkout_check"); + branch_name = gtk_editable_get_chars (GTK_EDITABLE (branch_name_entry), + 0, -1); + checkout = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkout_check)); + + create_command = git_branch_create_command_new (data->plugin->project_root_directory, + branch_name, + checkout); + + g_free (branch_name); + + create_message_view (data->plugin); + + g_signal_connect (G_OBJECT (create_command), "command-finished", + G_CALLBACK (on_checkout_command_finished), + data->plugin); + + g_signal_connect (G_OBJECT (create_command), "data-arrived", + G_CALLBACK (on_command_info_arrived), + data->plugin); + + anjuta_command_start (ANJUTA_COMMAND (create_command)); + } + + gtk_widget_destroy (GTK_WIDGET (dialog)); + git_ui_data_free (data); +} + +static void +create_branch_dialog (Git *plugin) +{ + GladeXML *gxml; + GtkWidget *dialog; + GitUIData *data; + + gxml = glade_xml_new (GLADE_FILE, "create_branch_dialog", NULL); + dialog = glade_xml_get_widget (gxml, "create_branch_dialog"); + data = git_ui_data_new (plugin, gxml); + + g_signal_connect (G_OBJECT (dialog), "response", + G_CALLBACK (on_create_branch_dialog_response), + data); + + gtk_widget_show_all (dialog); +} + +void +on_menu_git_create_branch (GtkAction *action, Git *plugin) +{ + create_branch_dialog (plugin); +} diff --git a/plugins/git/git-create-branch-dialog.h b/plugins/git/git-create-branch-dialog.h new file mode 100644 index 00000000..79dccb9f --- /dev/null +++ b/plugins/git/git-create-branch-dialog.h @@ -0,0 +1,33 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ +/* + * anjuta + * Copyright (C) James Liggett 2008 + * + * 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_CREATE_BRANCH_DIALOG_H +#define _GIT_CREATE_BRANCH_DIALOG_H + +#include "git-branch-create-command.h" +#include "git-ui-utils.h" + +void on_menu_git_create_branch (GtkAction *action, Git *plugin); + +#endif diff --git a/plugins/git/plugin.c b/plugins/git/plugin.c index 7f75b607..a0aa7827 100644 --- a/plugins/git/plugin.c +++ b/plugins/git/plugin.c @@ -27,6 +27,7 @@ #include "git-resolve-dialog.h" #include "git-merge-dialog.h" #include "git-switch-dialog.h" +#include "git-create-branch-dialog.h" #define UI_FILE PACKAGE_DATA_DIR"/ui/anjuta-git.ui" @@ -52,7 +53,7 @@ static GtkActionEntry actions_git[] = { { "ActionGitResolve", /* Action name */ GTK_STOCK_PREFERENCES, /* Stock icon, if any */ - N_("_Resolve Conflicts..."), /* Display label */ + N_("_Resolve conflicts..."), /* Display label */ NULL, /* short-cut */ NULL, /* Tooltip */ G_CALLBACK (on_menu_git_resolve) /* action callback */ @@ -74,6 +75,14 @@ static GtkActionEntry actions_git[] = { G_CALLBACK (on_menu_git_remove) /* action callback */ }, { + "ActionGitCreateBranch", /* Action name */ + GTK_STOCK_NEW, /* Stock icon, if any */ + N_("_Create branch..."), /* Display label */ + NULL, /* short-cut */ + NULL, /* Tooltip */ + G_CALLBACK (on_menu_git_create_branch) /* action callback */ + }, + { "ActionGitSwitch", /* Action name */ GTK_STOCK_JUMP_TO, /* Stock icon, if any */ N_("_Switch to another branch..."), /* Display label */ -- 2.11.4.GIT