Updated Spanish translation
[anjuta.git] / plugins / subversion / subversion-merge-dialog.c
blob4e4b06953808bce4837c139583cdf7e409e490cb
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * anjuta
4 * Copyright (C) James Liggett 2007 <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 "subversion-merge-dialog.h"
27 #define BROWSE_BUTTON_MERGE_DIALOG "browse_button_merge_dialog"
29 static void
30 on_merge_command_finished (AnjutaCommand *command, guint return_code,
31 Subversion *plugin)
33 AnjutaStatus *status;
35 status = anjuta_shell_get_status (ANJUTA_PLUGIN (plugin)->shell,
36 NULL);
38 anjuta_status (status, _("Subversion: Merge complete."), 5);
40 report_errors (command, return_code);
42 svn_merge_command_destroy (SVN_MERGE_COMMAND (command));
45 static void
46 on_subversion_merge_response (GtkDialog *dialog, gint response,
47 SubversionData *data)
49 GtkWidget *merge_first_path_entry;
50 GtkWidget *merge_second_path_entry;
51 GtkWidget *merge_working_copy_path_entry;
52 GtkWidget *merge_start_revision_radio;
53 GtkWidget *merge_start_revision_entry;
54 GtkWidget *merge_end_revision_radio;
55 GtkWidget *merge_end_revision_entry;
56 GtkWidget *merge_no_recursive_check;
57 GtkWidget *merge_ignore_ancestry_check;
58 GtkWidget *merge_force_check;
59 GtkWidget *merge_dry_run_check;
60 const gchar *first_path;
61 const gchar *second_path;
62 const gchar *working_copy_path;
63 const gchar *start_revision_text;
64 glong start_revision;
65 const gchar *end_revision_text;
66 glong end_revision;
67 SvnMergeCommand *merge_command;
69 if (response == GTK_RESPONSE_OK)
71 merge_first_path_entry = GTK_WIDGET (gtk_builder_get_object (data->bxml,
72 "merge_first_path_entry"));
73 merge_second_path_entry = GTK_WIDGET (gtk_builder_get_object (data->bxml,
74 "merge_second_path_entry"));
75 merge_working_copy_path_entry = GTK_WIDGET (gtk_builder_get_object (data->bxml,
76 "merge_working_copy_path_entry"));
77 merge_start_revision_radio = GTK_WIDGET (gtk_builder_get_object (data->bxml,
78 "merge_start_revision_radio"));
79 merge_start_revision_entry = GTK_WIDGET (gtk_builder_get_object (data->bxml,
80 "merge_start_revision_entry"));
81 merge_end_revision_radio = GTK_WIDGET (gtk_builder_get_object (data->bxml,
82 "merge_end_revision_radio"));
83 merge_end_revision_entry = GTK_WIDGET (gtk_builder_get_object (data->bxml,
84 "merge_end_revision_entry"));
85 merge_no_recursive_check = GTK_WIDGET (gtk_builder_get_object (data->bxml,
86 "merge_no_recursive_check"));
87 merge_ignore_ancestry_check = GTK_WIDGET (gtk_builder_get_object (data->bxml,
88 "merge_ignore_ancestry_check"));
89 merge_force_check = GTK_WIDGET (gtk_builder_get_object (data->bxml,
90 "merge_force_check"));
91 merge_dry_run_check = GTK_WIDGET (gtk_builder_get_object (data->bxml,
92 "merge_dry_run_check"));
94 if (!check_input (GTK_WIDGET (dialog), merge_first_path_entry,
95 _("Please enter the first path.")))
97 return;
100 if (!check_input (GTK_WIDGET (dialog), merge_second_path_entry,
101 _("Please enter the second path.")))
103 return;
106 if (!check_input (GTK_WIDGET (dialog), merge_working_copy_path_entry,
107 _("Please enter a working copy path.")))
109 return;
112 first_path = gtk_entry_get_text (GTK_ENTRY (merge_first_path_entry));
113 second_path = gtk_entry_get_text (GTK_ENTRY (merge_second_path_entry));
114 working_copy_path = gtk_entry_get_text (GTK_ENTRY (merge_working_copy_path_entry));
116 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (merge_start_revision_radio)))
118 start_revision_text = gtk_entry_get_text (GTK_ENTRY (merge_start_revision_entry));
120 if (!check_input (GTK_WIDGET (dialog), merge_start_revision_entry,
121 _("Please enter the start revision.")))
123 return;
126 start_revision = atol (start_revision_text);
128 else
129 start_revision = SVN_MERGE_REVISION_HEAD;
131 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (merge_end_revision_radio)))
133 end_revision_text = gtk_entry_get_text (GTK_ENTRY (merge_end_revision_entry));
135 if (!check_input (GTK_WIDGET (dialog), merge_end_revision_entry,
136 _("Please enter the end revision.")))
138 return;
141 end_revision = atol (end_revision_text);
143 else
144 end_revision = SVN_MERGE_REVISION_HEAD;
146 create_message_view (data->plugin);
148 merge_command = svn_merge_command_new ((gchar *) first_path,
149 (gchar *) second_path,
150 start_revision,
151 end_revision,
152 (gchar *) working_copy_path,
153 !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (merge_no_recursive_check)),
154 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (merge_ignore_ancestry_check)),
155 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (merge_force_check)),
156 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (merge_dry_run_check)));
158 g_signal_connect (G_OBJECT (merge_command), "command-finished",
159 G_CALLBACK (on_merge_command_finished),
160 data->plugin);
162 g_signal_connect (G_OBJECT (merge_command), "data-arrived",
163 G_CALLBACK (on_command_info_arrived),
164 data->plugin);
166 anjuta_command_start (ANJUTA_COMMAND (merge_command));
169 subversion_data_free (data);
170 gtk_widget_destroy (GTK_WIDGET (dialog));
173 static void
174 on_merge_first_path_browse_button_clicked (GtkButton *button,
175 SubversionData *data)
177 GtkWidget *subversion_merge;
178 GtkWidget *merge_first_path_entry;
179 GtkWidget *file_chooser_dialog;
180 gchar *selected_path;
182 subversion_merge = GTK_WIDGET (gtk_builder_get_object (data->bxml, "subversion_merge"));
183 merge_first_path_entry = GTK_WIDGET (gtk_builder_get_object (data->bxml,
184 "merge_first_path_entry"));
185 file_chooser_dialog = gtk_file_chooser_dialog_new ("Select file or folder",
186 GTK_WINDOW (subversion_merge),
187 GTK_FILE_CHOOSER_ACTION_OPEN,
188 GTK_STOCK_CANCEL,
189 GTK_RESPONSE_CANCEL,
190 GTK_STOCK_OPEN,
191 GTK_RESPONSE_ACCEPT,
192 NULL);
194 if (gtk_dialog_run (GTK_DIALOG (file_chooser_dialog)) == GTK_RESPONSE_ACCEPT)
196 selected_path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (file_chooser_dialog));
197 gtk_entry_set_text (GTK_ENTRY (merge_first_path_entry), selected_path);
198 g_free (selected_path);
201 gtk_widget_destroy (GTK_WIDGET (file_chooser_dialog));
204 static void
205 on_merge_second_path_browse_button_clicked (GtkButton *button,
206 SubversionData *data)
208 GtkWidget *subversion_merge;
209 GtkWidget *merge_second_path_entry;
210 GtkWidget *file_chooser_dialog;
211 gchar *selected_path;
213 subversion_merge = GTK_WIDGET (gtk_builder_get_object (data->bxml, "subversion_merge"));
214 merge_second_path_entry = GTK_WIDGET (gtk_builder_get_object (data->bxml,
215 "merge_second_path_entry"));
216 file_chooser_dialog = gtk_file_chooser_dialog_new ("Select file or folder",
217 GTK_WINDOW (subversion_merge),
218 GTK_FILE_CHOOSER_ACTION_OPEN,
219 GTK_STOCK_CANCEL,
220 GTK_RESPONSE_CANCEL,
221 GTK_STOCK_OPEN,
222 GTK_RESPONSE_ACCEPT,
223 NULL);
225 if (gtk_dialog_run (GTK_DIALOG (file_chooser_dialog)) == GTK_RESPONSE_ACCEPT)
227 selected_path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (file_chooser_dialog));
228 gtk_entry_set_text (GTK_ENTRY (merge_second_path_entry), selected_path);
229 g_free (selected_path);
232 gtk_widget_destroy (GTK_WIDGET (file_chooser_dialog));
235 static void
236 on_merge_use_first_path_check_toggled (GtkToggleButton *toggle_button,
237 SubversionData *data)
239 GtkWidget *merge_first_path_entry;
240 GtkWidget *merge_second_path_entry;
241 gboolean active;
242 const gchar *first_path;
244 merge_second_path_entry = GTK_WIDGET (gtk_builder_get_object (data->bxml,
245 "merge_second_path_entry"));
247 active = gtk_toggle_button_get_active (toggle_button);
249 if (active)
251 merge_first_path_entry = GTK_WIDGET (gtk_builder_get_object (data->bxml,
252 "merge_first_path_entry"));
253 first_path = gtk_entry_get_text (GTK_ENTRY (merge_first_path_entry));
255 gtk_entry_set_text (GTK_ENTRY (merge_second_path_entry), first_path);
258 gtk_widget_set_sensitive (merge_second_path_entry, !active);
262 static void
263 on_merge_start_revision_radio_toggled (GtkToggleButton *toggle_button,
264 SubversionData *data)
266 GtkWidget *merge_start_revision_entry;
267 GtkWidget *subversion_merge;
268 gboolean active;
270 merge_start_revision_entry = GTK_WIDGET (gtk_builder_get_object (data->bxml,
271 "merge_start_revision_entry"));
272 subversion_merge = GTK_WIDGET (gtk_builder_get_object (data->bxml, "subversion_merge"));
274 active = gtk_toggle_button_get_active (toggle_button);
276 gtk_widget_set_sensitive (merge_start_revision_entry, active);
278 if (active)
280 gtk_window_set_focus (GTK_WINDOW (subversion_merge),
281 merge_start_revision_entry);
285 static void
286 on_merge_end_revision_radio_toggled (GtkToggleButton *toggle_button,
287 SubversionData *data)
289 GtkWidget *merge_end_revision_entry;
290 GtkWidget *subversion_merge;
291 gboolean active;
293 merge_end_revision_entry = GTK_WIDGET (gtk_builder_get_object (data->bxml,
294 "merge_end_revision_entry"));
295 subversion_merge = GTK_WIDGET (gtk_builder_get_object (data->bxml, "subversion_merge"));
297 active = gtk_toggle_button_get_active (toggle_button);
299 gtk_widget_set_sensitive (merge_end_revision_entry, active);
301 if (active)
303 gtk_window_set_focus (GTK_WINDOW (subversion_merge),
304 merge_end_revision_entry);
308 static void
309 subversion_merge_dialog (GtkAction *action, Subversion *plugin)
311 GtkBuilder *bxml = gtk_builder_new ();
312 GtkWidget *subversion_merge;
313 GtkWidget *merge_first_path_browse_button;
314 GtkWidget *merge_second_path_browse_button;
315 GtkWidget *merge_use_first_path_check;
316 GtkWidget *merge_working_copy_path_entry;
317 GtkWidget *merge_start_revision_radio;
318 GtkWidget *merge_end_revision_radio;
319 GtkWidget *button;
320 SubversionData *data;
321 GError* error = NULL;
323 if (!gtk_builder_add_from_file (bxml, GLADE_FILE, &error))
325 g_warning ("Couldn't load builder file: %s", error->message);
326 g_error_free (error);
328 subversion_merge = GTK_WIDGET (gtk_builder_get_object (bxml,
329 "subversion_merge"));
330 merge_first_path_browse_button = GTK_WIDGET (gtk_builder_get_object (bxml,
331 "merge_first_path_browse_button"));
332 merge_second_path_browse_button = GTK_WIDGET (gtk_builder_get_object (bxml,
333 "merge_second_path_browse_button"));
334 merge_use_first_path_check = GTK_WIDGET (gtk_builder_get_object (bxml,
335 "merge_use_first_path_check"));
336 merge_working_copy_path_entry = GTK_WIDGET (gtk_builder_get_object (bxml,
337 "merge_working_copy_path_entry"));
338 merge_start_revision_radio = GTK_WIDGET (gtk_builder_get_object (bxml,
339 "merge_start_revision_radio"));
340 merge_end_revision_radio = GTK_WIDGET (gtk_builder_get_object (bxml,
341 "merge_end_revision_radio"));
343 data = subversion_data_new (plugin, bxml);
345 gtk_entry_set_text (GTK_ENTRY (merge_working_copy_path_entry),
346 plugin->project_root_dir);
348 g_signal_connect (G_OBJECT (subversion_merge), "response",
349 G_CALLBACK (on_subversion_merge_response),
350 data);
352 button = GTK_WIDGET (gtk_builder_get_object (bxml, BROWSE_BUTTON_MERGE_DIALOG));
353 g_signal_connect(G_OBJECT(button), "clicked",
354 G_CALLBACK(on_subversion_browse_button_clicked), merge_working_copy_path_entry);
356 g_signal_connect (G_OBJECT (merge_first_path_browse_button), "clicked",
357 G_CALLBACK (on_merge_first_path_browse_button_clicked),
358 data);
360 g_signal_connect (G_OBJECT (merge_second_path_browse_button), "clicked",
361 G_CALLBACK (on_merge_second_path_browse_button_clicked),
362 data);
364 g_signal_connect (G_OBJECT (merge_use_first_path_check), "toggled",
365 G_CALLBACK (on_merge_use_first_path_check_toggled),
366 data);
368 g_signal_connect (G_OBJECT (merge_start_revision_radio), "toggled",
369 G_CALLBACK (on_merge_start_revision_radio_toggled),
370 data);
372 g_signal_connect (G_OBJECT (merge_end_revision_radio), "toggled",
373 G_CALLBACK (on_merge_end_revision_radio_toggled),
374 data);
376 gtk_dialog_run (GTK_DIALOG (subversion_merge));
379 void
380 on_menu_subversion_merge (GtkAction *action, Subversion *plugin)
382 subversion_merge_dialog (action, plugin);