Put all of the UI utility functions into the "git" namespace.
[anjuta-git-plugin.git] / plugins / git / git-create-tag-dialog.c
blob793a544575801b65719cfbeb4feb6c4b7ffbb877
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-tag-dialog.h"
27 static void
28 on_create_command_finished (AnjutaCommand *command, guint return_code,
29 Git *plugin)
31 AnjutaStatus *status;
32 gchar *tag_name;
33 gchar *status_message;
35 if (return_code == 0)
37 status = anjuta_shell_get_status (ANJUTA_PLUGIN (plugin)->shell,
38 NULL);
40 tag_name = git_tag_create_command_get_tag_name (GIT_TAG_CREATE_COMMAND (command));
41 status_message = g_strdup_printf (_("Git: Created tag \"%s\"."),
42 tag_name);
43 anjuta_status (status, status_message, 5);
45 g_free (tag_name);
46 g_free (status_message);
51 git_report_errors (command, return_code);
53 g_object_unref (command);
57 static void
58 on_create_tag_dialog_response (GtkDialog *dialog, gint response_id,
59 GitUIData *data)
61 GtkWidget *tag_name_entry;
62 GtkWidget *tag_revision_radio;
63 GtkWidget *tag_revision_entry;
64 GtkWidget *tag_force_check;
65 GtkWidget *tag_annotate_check;
66 GtkWidget *tag_log_view;
67 gchar *log;
68 GtkWidget *log_prompt_dialog;
69 gint prompt_response;
70 gchar *tag_name;
71 gchar *revision;
72 GitTagCreateCommand *create_command;
74 if (response_id == GTK_RESPONSE_OK)
76 tag_name_entry = glade_xml_get_widget (data->gxml,
77 "tag_name_entry");
78 tag_revision_radio = glade_xml_get_widget (data->gxml,
79 "tag_revision_radio");
80 tag_revision_entry = glade_xml_get_widget (data->gxml,
81 "tag_revision_entry");
82 tag_force_check = glade_xml_get_widget (data->gxml,
83 "tag_force_check");
84 tag_annotate_check = glade_xml_get_widget (data->gxml,
85 "tag_annotate_check");
86 tag_log_view = glade_xml_get_widget (data->gxml,
87 "tag_log_view");
89 tag_name = gtk_editable_get_chars (GTK_EDITABLE (tag_name_entry),
90 0, -1);
91 revision = NULL;
92 log = NULL;
94 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (tag_revision_radio)))
96 revision = gtk_editable_get_chars (GTK_EDITABLE (tag_revision_entry),
97 0, -1);
98 if (!git_check_input (GTK_WIDGET (dialog), tag_revision_entry,
99 revision, _("Please enter a revision.")))
101 g_free (revision);
102 g_free (tag_name);
103 return;
107 if (!git_check_input (GTK_WIDGET (dialog), tag_revision_entry,
108 tag_name, _("Please enter a tag name.")))
111 g_free (revision);
112 g_free (tag_name);
113 return;
117 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (tag_annotate_check)))
119 log = git_get_log_from_textview (tag_log_view);
121 if (!g_utf8_strlen (log, -1))
123 log_prompt_dialog = gtk_message_dialog_new (GTK_WINDOW(dialog),
124 GTK_DIALOG_DESTROY_WITH_PARENT,
125 GTK_MESSAGE_INFO,
126 GTK_BUTTONS_YES_NO,
127 _("Are you sure that you want to pass an empty log message?"));
129 prompt_response = gtk_dialog_run(GTK_DIALOG (log_prompt_dialog));
130 gtk_widget_destroy (log_prompt_dialog);
132 if (prompt_response == GTK_RESPONSE_NO)
134 g_free (revision);
135 g_free (tag_name);
136 g_free (log);
137 return;
142 create_command = git_tag_create_command_new (data->plugin->project_root_directory,
143 tag_name,
144 revision,
145 log,
146 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (tag_force_check)));
148 g_free (tag_name);
149 g_free (revision);
150 g_free (log);
152 g_signal_connect (G_OBJECT (create_command), "command-finished",
153 G_CALLBACK (on_create_command_finished),
154 data->plugin);
156 anjuta_command_start (ANJUTA_COMMAND (create_command));
159 gtk_widget_destroy (GTK_WIDGET (dialog));
160 git_ui_data_free (data);
163 static void
164 on_tag_revision_radio_toggled (GtkToggleButton *toggle_button,
165 GitUIData *data)
167 GtkWidget *create_tag_dialog;
168 GtkWidget *tag_revision_entry;
169 gboolean active;
171 create_tag_dialog = glade_xml_get_widget (data->gxml,
172 "create_tag_dialog");
173 tag_revision_entry = glade_xml_get_widget (data->gxml,
174 "tag_revision_entry");
176 active = gtk_toggle_button_get_active (toggle_button);
177 gtk_widget_set_sensitive (tag_revision_entry, active);
179 if (active)
181 gtk_window_set_focus (GTK_WINDOW (create_tag_dialog),
182 tag_revision_entry);
187 static void
188 on_tag_annotate_check_toggled (GtkToggleButton *toggle_button,
189 GtkWidget *tag_log_view)
191 gtk_widget_set_sensitive (tag_log_view,
192 gtk_toggle_button_get_active (toggle_button));
195 static void
196 create_tag_dialog (Git *plugin, const gchar *revision)
198 GladeXML *gxml;
199 GtkWidget *dialog;
200 GtkWidget *tag_revision_radio;
201 GtkWidget *tag_revision_entry;
202 GtkWidget *tag_annotate_check;
203 GtkWidget *tag_log_view;
204 GitUIData *data;
206 gxml = glade_xml_new (GLADE_FILE, "create_tag_dialog", NULL);
207 dialog = glade_xml_get_widget (gxml, "create_tag_dialog");
208 tag_revision_radio = glade_xml_get_widget (gxml,
209 "tag_revision_radio");
210 tag_revision_entry = glade_xml_get_widget (gxml,
211 "tag_revision_entry");
212 tag_annotate_check = glade_xml_get_widget (gxml,
213 "tag_annotate_check");
214 tag_log_view = glade_xml_get_widget (gxml,
215 "tag_log_view");
216 data = git_ui_data_new (plugin, gxml);
218 g_signal_connect (G_OBJECT (dialog), "response",
219 G_CALLBACK (on_create_tag_dialog_response),
220 data);
222 g_signal_connect (G_OBJECT (tag_revision_radio), "toggled",
223 G_CALLBACK (on_tag_revision_radio_toggled),
224 data);
226 g_signal_connect (G_OBJECT (tag_annotate_check), "toggled",
227 G_CALLBACK (on_tag_annotate_check_toggled),
228 tag_log_view);
230 if (revision)
232 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (tag_revision_radio), TRUE);
233 gtk_entry_set_text (GTK_ENTRY (tag_revision_entry), revision);
236 gtk_widget_show_all (dialog);
239 void
240 on_menu_git_create_tag (GtkAction *action, Git *plugin)
242 create_tag_dialog (plugin, NULL);
245 void
246 on_log_menu_git_create_tag (GtkAction *action, Git *plugin)
248 GitRevision *revision;
249 gchar *sha;
251 revision = git_log_get_selected_revision (plugin);
253 if (revision)
255 sha = git_revision_get_sha (revision);
257 create_tag_dialog (plugin, sha);
258 g_free (sha);