Implement simple branch creation.
[anjuta-git-plugin.git] / plugins / git / git-create-branch-dialog.c
blobb939bee674ea8d16b3bf9cdd3241088f3638ede3
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * anjuta
4 * Copyright (C) James Liggett 2008 <jrliggett@cox.net>
5 *
6 * anjuta is free software.
7 *
8 * You may redistribute it and/or modify it under the terms of the
9 * GNU General Public License, as published by the Free Software
10 * Foundation; either version 2 of the License, or (at your option)
11 * any later version.
13 * anjuta is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 * See the GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with anjuta. If not, write to:
20 * The Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor
22 * Boston, MA 02110-1301, USA.
25 #include "git-create-branch-dialog.h"
27 static void
28 on_checkout_command_finished (AnjutaCommand *command, guint return_code,
29 Git *plugin)
31 AnjutaStatus *status;
32 gchar *branch_name;
33 gchar *status_message;
35 if (return_code == 0)
37 status = anjuta_shell_get_status (ANJUTA_PLUGIN (plugin)->shell,
38 NULL);
40 branch_name = git_branch_create_command_get_branch_name (GIT_BRANCH_CREATE_COMMAND (command));
41 status_message = g_strdup_printf (_("Git: Created branch \"%s\"."),
42 branch_name);
43 anjuta_status (status, status_message, 5);
45 g_free (branch_name);
46 g_free (status_message);
51 report_errors (command, return_code);
53 g_object_unref (command);
57 static void
58 on_create_branch_dialog_response (GtkDialog *dialog, gint response_id,
59 GitUIData *data)
61 GtkWidget *branch_name_entry;
62 GtkWidget *checkout_check;
63 gchar *branch_name;
64 gboolean checkout;
65 GitBranchCreateCommand *create_command;
67 if (response_id == GTK_RESPONSE_OK)
69 branch_name_entry = glade_xml_get_widget (data->gxml,
70 "branch_name_entry");
71 checkout_check = glade_xml_get_widget (data->gxml, "checkout_check");
72 branch_name = gtk_editable_get_chars (GTK_EDITABLE (branch_name_entry),
73 0, -1);
74 checkout = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkout_check));
76 create_command = git_branch_create_command_new (data->plugin->project_root_directory,
77 branch_name,
78 checkout);
80 g_free (branch_name);
82 create_message_view (data->plugin);
84 g_signal_connect (G_OBJECT (create_command), "command-finished",
85 G_CALLBACK (on_checkout_command_finished),
86 data->plugin);
88 g_signal_connect (G_OBJECT (create_command), "data-arrived",
89 G_CALLBACK (on_command_info_arrived),
90 data->plugin);
92 anjuta_command_start (ANJUTA_COMMAND (create_command));
95 gtk_widget_destroy (GTK_WIDGET (dialog));
96 git_ui_data_free (data);
99 static void
100 create_branch_dialog (Git *plugin)
102 GladeXML *gxml;
103 GtkWidget *dialog;
104 GitUIData *data;
106 gxml = glade_xml_new (GLADE_FILE, "create_branch_dialog", NULL);
107 dialog = glade_xml_get_widget (gxml, "create_branch_dialog");
108 data = git_ui_data_new (plugin, gxml);
110 g_signal_connect (G_OBJECT (dialog), "response",
111 G_CALLBACK (on_create_branch_dialog_response),
112 data);
114 gtk_widget_show_all (dialog);
117 void
118 on_menu_git_create_branch (GtkAction *action, Git *plugin)
120 create_branch_dialog (plugin);