sourceview: Completely get rid of GtkSourceSearchFlags
[anjuta.git] / plugins / cvs-plugin / cvs-actions.c
blobf90180def36242f56ea31f3a985055dbd7d5e93b
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 cvs-actions.c
4 Copyright (C) 2004 Johannes Schmid
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "cvs-actions.h"
23 #include "cvs-execute.h"
24 #include "cvs-callbacks.h"
26 #include "libgen.h"
28 #include <libanjuta/anjuta-preferences.h>
29 #include <libanjuta/anjuta-utils.h>
30 #include <libanjuta/anjuta-debug.h>
32 #define BROWSE_BUTTON_ADD_DIALOG "browse_button_add_dialog"
33 #define BROWSE_BUTTON_REMOVE_DIALOG "browse_button_remove_dialog"
34 #define BROWSE_BUTTON_COMMIT_DIALOG "browse_button_commit_dialog"
35 #define BROWSE_BUTTON_UPDATE_DIALOG "browse_button_update_dialog"
36 #define BROWSE_BUTTON_DIFF_DIALOG "browse_button_diff_dialog"
37 #define BROWSE_BUTTON_STATUS_DIALOG "browse_button_status_dialog"
38 #define BROWSE_BUTTON_LOG_DIALOG "browse_button_log_dialog"
40 void cvs_add_dialog(GtkAction* action, CVSPlugin* plugin, gchar *filename);
41 void cvs_remove_dialog(GtkAction* action, CVSPlugin* plugin, gchar *filename);
42 void cvs_commit_dialog(GtkAction* action, CVSPlugin* plugin, gchar *filename);
43 void cvs_update_dialog(GtkAction* action, CVSPlugin* plugin, gchar *filename);
44 void cvs_diff_dialog(GtkAction* action, CVSPlugin* plugin, gchar *filename);
45 void cvs_status_dialog(GtkAction* action, CVSPlugin* plugin, gchar *filename);
46 void cvs_log_dialog(GtkAction* action, CVSPlugin* plugin, gchar *filename);
48 static void on_server_type_changed(GtkComboBox* combo, GtkBuilder* bxml)
50 GtkWidget* username;
51 GtkWidget* password;
53 username = GTK_WIDGET(gtk_builder_get_object(bxml, "cvs_username"));
54 password = GTK_WIDGET(gtk_builder_get_object(bxml, "cvs_password"));
56 switch (gtk_combo_box_get_active(combo))
58 case SERVER_LOCAL:
59 gtk_widget_set_sensitive(username, FALSE);
60 gtk_widget_set_sensitive(password, FALSE);
61 break;
62 case SERVER_EXTERN:
63 gtk_widget_set_sensitive(username, TRUE);
64 gtk_widget_set_sensitive(password, FALSE);
65 break;
66 case SERVER_PASSWORD:
67 gtk_widget_set_sensitive(username, TRUE);
68 gtk_widget_set_sensitive(password, TRUE);
69 break;
70 default:
71 DEBUG_PRINT("%s", "Unknown CVS server type");
75 static void on_diff_type_changed(GtkComboBox* combo, GtkWidget* unified_check)
77 if (gtk_combo_box_get_active(combo) == DIFF_STANDARD)
79 gtk_widget_set_sensitive(unified_check, FALSE);
81 else if (gtk_combo_box_get_active(combo) == DIFF_PATCH)
83 gtk_widget_set_sensitive(unified_check, TRUE);
85 else
86 gtk_combo_box_set_active(combo, DIFF_STANDARD);
89 static void init_whole_project(CVSPlugin *plugin, GtkWidget* project)
91 gboolean project_loaded = (plugin->project_root_dir != NULL);
92 gtk_widget_set_sensitive(project, project_loaded);
95 static void on_whole_project_toggled(GtkToggleButton* project, CVSPlugin *plugin)
97 GtkEntry* fileentry = g_object_get_data (G_OBJECT (project), "fileentry");
98 if (gtk_toggle_button_get_active(project) && plugin->project_root_dir)
100 gtk_entry_set_text (fileentry, plugin->project_root_dir);
101 gtk_widget_set_sensitive(GTK_WIDGET(fileentry), FALSE);
103 else
104 gtk_widget_set_sensitive(GTK_WIDGET(fileentry), TRUE);
107 static void
108 on_browse_button_clicked(GtkButton *button, GtkEntry *entry)
110 GtkWidget *dialog;
111 dialog = gtk_file_chooser_dialog_new("Open File",
112 NULL,
113 GTK_FILE_CHOOSER_ACTION_OPEN,
114 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
115 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
116 NULL);
117 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
119 char *filename;
120 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER (dialog));
122 gtk_entry_set_text(entry, filename);
124 g_free(filename);
126 gtk_widget_destroy(dialog);
129 void cvs_add_dialog(GtkAction* action, CVSPlugin* plugin, gchar *filename)
131 GtkBuilder* bxml;
132 GtkWidget* dialog;
133 GtkWidget* fileentry;
134 GtkWidget* button;
135 CVSData* data;
136 GError* error = NULL;
137 bxml = gtk_builder_new();
138 if (!gtk_builder_add_from_file(bxml, GLADE_FILE, &error))
140 g_warning("Couldn't load builder file: %s", error->message);
141 g_error_free(error);
144 dialog = GTK_WIDGET(gtk_builder_get_object(bxml, "cvs_add"));
145 fileentry = GTK_WIDGET(gtk_builder_get_object(bxml, "cvs_add_filename"));
146 if (filename)
147 gtk_entry_set_text(GTK_ENTRY(fileentry), filename);
149 button = GTK_WIDGET(gtk_builder_get_object(bxml, BROWSE_BUTTON_ADD_DIALOG));
150 g_signal_connect(G_OBJECT(button), "clicked",
151 G_CALLBACK(on_browse_button_clicked), fileentry);
153 data = cvs_data_new(plugin, bxml);
154 g_signal_connect(G_OBJECT(dialog), "response",
155 G_CALLBACK(on_cvs_add_response), data);
157 gtk_widget_show(dialog);
160 void cvs_remove_dialog(GtkAction* action, CVSPlugin* plugin, gchar *filename)
162 GtkBuilder* bxml;
163 GtkWidget* dialog;
164 GtkWidget* fileentry;
165 GtkWidget* button;
166 CVSData* data;
167 GError* error = NULL;
168 bxml = gtk_builder_new();
169 if (!gtk_builder_add_from_file(bxml, GLADE_FILE, &error))
171 g_warning("Couldn't load builder file: %s", error->message);
172 g_error_free(error);
175 dialog = GTK_WIDGET(gtk_builder_get_object(bxml, "cvs_remove"));
176 fileentry = GTK_WIDGET(gtk_builder_get_object(bxml, "cvs_remove_filename"));
177 if (filename)
178 gtk_entry_set_text(GTK_ENTRY(fileentry), filename);
180 button = GTK_WIDGET(gtk_builder_get_object(bxml, BROWSE_BUTTON_REMOVE_DIALOG));
181 g_signal_connect(G_OBJECT(button), "clicked",
182 G_CALLBACK(on_browse_button_clicked), fileentry);
184 data = cvs_data_new(plugin, bxml);
185 g_signal_connect(G_OBJECT(dialog), "response",
186 G_CALLBACK(on_cvs_remove_response), data);
188 gtk_widget_show(dialog);
192 void cvs_commit_dialog (GtkAction* action, CVSPlugin* plugin, gchar *filename)
194 GtkBuilder* bxml;
195 GtkWidget* dialog;
196 GtkWidget* fileentry;
197 GtkWidget* project;
198 GtkWidget* button;
199 CVSData* data;
200 GError* error = NULL;
201 bxml = gtk_builder_new();
202 if (!gtk_builder_add_from_file(bxml, GLADE_FILE, &error))
204 g_warning("Couldn't load builder file: %s", error->message);
205 g_error_free(error);
208 dialog = GTK_WIDGET(gtk_builder_get_object(bxml, "cvs_commit"));
209 fileentry = GTK_WIDGET(gtk_builder_get_object(bxml, "cvs_commit_filename"));
210 if (filename)
211 gtk_entry_set_text(GTK_ENTRY(fileentry), filename);
213 project = GTK_WIDGET(gtk_builder_get_object(bxml, "cvs_commit_project"));
214 g_object_set_data (G_OBJECT (project), "fileentry", fileentry);
215 g_signal_connect(G_OBJECT(project), "toggled",
216 G_CALLBACK(on_whole_project_toggled), plugin);
217 init_whole_project(plugin, project);
219 button = GTK_WIDGET(gtk_builder_get_object(bxml, BROWSE_BUTTON_COMMIT_DIALOG));
220 g_signal_connect(G_OBJECT(button), "clicked",
221 G_CALLBACK(on_browse_button_clicked), fileentry);
223 data = cvs_data_new(plugin, bxml);
224 g_signal_connect(G_OBJECT(dialog), "response",
225 G_CALLBACK(on_cvs_commit_response), data);
227 gtk_widget_show(dialog);
231 void cvs_update_dialog (GtkAction* action, CVSPlugin* plugin, gchar *filename)
233 GtkBuilder* bxml;
234 GtkWidget* dialog;
235 GtkWidget* fileentry;
236 GtkWidget* project;
237 GtkWidget* button;
238 CVSData* data;
239 GError* error = NULL;
240 bxml = gtk_builder_new();
241 if (!gtk_builder_add_from_file(bxml, GLADE_FILE, &error))
243 g_warning("Couldn't load builder file: %s", error->message);
244 g_error_free(error);
247 dialog = GTK_WIDGET(gtk_builder_get_object(bxml, "cvs_update"));
248 fileentry = GTK_WIDGET(gtk_builder_get_object(bxml, "cvs_update_filename"));
249 if (filename)
250 gtk_entry_set_text(GTK_ENTRY(fileentry), filename);
252 project = GTK_WIDGET(gtk_builder_get_object(bxml, "cvs_update_project"));
253 g_object_set_data (G_OBJECT (project), "fileentry", fileentry);
254 g_signal_connect(G_OBJECT(project), "toggled",
255 G_CALLBACK(on_whole_project_toggled), plugin);
256 init_whole_project(plugin, project);
258 button = GTK_WIDGET(gtk_builder_get_object(bxml, BROWSE_BUTTON_UPDATE_DIALOG));
259 g_signal_connect(G_OBJECT(button), "clicked",
260 G_CALLBACK(on_browse_button_clicked), fileentry);
262 data = cvs_data_new(plugin, bxml);
263 g_signal_connect(G_OBJECT(dialog), "response",
264 G_CALLBACK(on_cvs_update_response), data);
266 gtk_widget_show(dialog);
269 void cvs_diff_dialog (GtkAction* action, CVSPlugin* plugin, gchar *filename)
271 GtkBuilder* bxml;
272 GtkWidget* dialog;
273 GtkWidget* fileentry;
274 GtkWidget* diff_type;
275 GtkWidget* unified_diff;
276 GtkWidget* project;
277 GtkWidget* button;
278 CVSData* data;
279 GError* error = NULL;
280 bxml = gtk_builder_new();
281 if (!gtk_builder_add_from_file(bxml, GLADE_FILE, &error))
283 g_warning("Couldn't load builder file: %s", error->message);
284 g_error_free(error);
287 dialog = GTK_WIDGET(gtk_builder_get_object(bxml, "cvs_diff"));
288 fileentry = GTK_WIDGET(gtk_builder_get_object(bxml, "cvs_diff_filename"));
289 if (filename)
290 gtk_entry_set_text(GTK_ENTRY(fileentry), filename);
292 project = GTK_WIDGET(gtk_builder_get_object(bxml, "cvs_diff_project"));
293 g_object_set_data (G_OBJECT (project), "fileentry", fileentry);
294 g_signal_connect(G_OBJECT(project), "toggled",
295 G_CALLBACK(on_whole_project_toggled), plugin);
296 init_whole_project(plugin, project);
298 diff_type = GTK_WIDGET(gtk_builder_get_object(bxml, "cvs_diff_type"));
299 unified_diff = GTK_WIDGET(gtk_builder_get_object(bxml, "cvs_unified"));
300 gtk_combo_box_set_active(GTK_COMBO_BOX(diff_type), DIFF_PATCH);
301 g_signal_connect(G_OBJECT(diff_type), "changed",
302 G_CALLBACK(on_diff_type_changed), unified_diff);
304 button = GTK_WIDGET(gtk_builder_get_object(bxml, BROWSE_BUTTON_DIFF_DIALOG));
305 g_signal_connect(G_OBJECT(button), "clicked",
306 G_CALLBACK(on_browse_button_clicked), fileentry);
308 data = cvs_data_new(plugin, bxml);
309 g_signal_connect(G_OBJECT(dialog), "response",
310 G_CALLBACK(on_cvs_diff_response), data);
312 gtk_widget_show(dialog);
315 void cvs_status_dialog (GtkAction* action, CVSPlugin* plugin, gchar *filename)
317 GtkBuilder* bxml;
318 GtkWidget* dialog;
319 GtkWidget* fileentry;
320 GtkWidget* project;
321 GtkWidget* button;
322 CVSData* data;
323 GError* error = NULL;
324 bxml = gtk_builder_new();
325 if (!gtk_builder_add_from_file(bxml, GLADE_FILE, &error))
327 g_warning("Couldn't load builder file: %s", error->message);
328 g_error_free(error);
331 dialog = GTK_WIDGET(gtk_builder_get_object(bxml, "cvs_status"));
332 fileentry = GTK_WIDGET(gtk_builder_get_object(bxml, "cvs_status_filename"));
333 if (filename)
334 gtk_entry_set_text(GTK_ENTRY(fileentry), filename);
336 project = GTK_WIDGET(gtk_builder_get_object(bxml, "cvs_status_project"));
337 g_object_set_data (G_OBJECT (project), "fileentry", fileentry);
338 g_signal_connect(G_OBJECT(project), "toggled",
339 G_CALLBACK(on_whole_project_toggled), plugin);
340 init_whole_project(plugin, project);
342 button = GTK_WIDGET(gtk_builder_get_object(bxml, BROWSE_BUTTON_STATUS_DIALOG));
343 g_signal_connect(G_OBJECT(button), "clicked",
344 G_CALLBACK(on_browse_button_clicked), fileentry);
346 data = cvs_data_new(plugin, bxml);
347 g_signal_connect(G_OBJECT(dialog), "response",
348 G_CALLBACK(on_cvs_status_response), data);
350 gtk_widget_show(dialog);
353 void cvs_log_dialog (GtkAction* action, CVSPlugin* plugin, gchar *filename)
355 GtkBuilder* bxml;
356 GtkWidget* dialog;
357 GtkWidget* fileentry;
358 GtkWidget* project;
359 GtkWidget* button;
360 CVSData* data;
361 GError* error = NULL;
362 bxml = gtk_builder_new();
363 if (!gtk_builder_add_from_file(bxml, GLADE_FILE, &error))
365 g_warning("Couldn't load builder file: %s", error->message);
366 g_error_free(error);
369 dialog = GTK_WIDGET(gtk_builder_get_object(bxml, "cvs_logdialog"));
370 fileentry = GTK_WIDGET(gtk_builder_get_object(bxml, "cvs_logdialog_filename"));
371 if (filename)
372 gtk_entry_set_text(GTK_ENTRY(fileentry), filename);
374 project = GTK_WIDGET(gtk_builder_get_object(bxml, "cvs_logdialog_project"));
375 g_object_set_data (G_OBJECT (project), "fileentry", fileentry);
376 g_signal_connect(G_OBJECT(project), "toggled",
377 G_CALLBACK(on_whole_project_toggled), plugin);
378 init_whole_project(plugin, project);
380 button = GTK_WIDGET(gtk_builder_get_object(bxml, BROWSE_BUTTON_LOG_DIALOG));
381 g_signal_connect(G_OBJECT(button), "clicked",
382 G_CALLBACK(on_browse_button_clicked), fileentry);
384 data = cvs_data_new(plugin, bxml);
385 g_signal_connect(G_OBJECT(dialog), "response",
386 G_CALLBACK(on_cvs_log_response), data);
388 gtk_widget_show(dialog);
391 void on_menu_cvs_add (GtkAction* action, CVSPlugin* plugin)
393 cvs_add_dialog(action, plugin, plugin->current_editor_filename);
396 void on_menu_cvs_remove (GtkAction* action, CVSPlugin* plugin)
398 cvs_remove_dialog(action, plugin, plugin->current_editor_filename);
401 void on_menu_cvs_commit (GtkAction* action, CVSPlugin* plugin)
403 cvs_commit_dialog(action, plugin, plugin->current_editor_filename);
406 void on_menu_cvs_update (GtkAction* action, CVSPlugin* plugin)
408 cvs_update_dialog(action, plugin, plugin->current_editor_filename);
411 void on_menu_cvs_diff (GtkAction* action, CVSPlugin* plugin)
413 cvs_diff_dialog(action, plugin, plugin->current_editor_filename);
416 void on_menu_cvs_status (GtkAction* action, CVSPlugin* plugin)
418 cvs_status_dialog(action, plugin, plugin->current_editor_filename);
421 void on_menu_cvs_import (GtkAction* action, CVSPlugin* plugin)
423 GtkBuilder* bxml;
424 GtkWidget* dialog;
425 GtkFileChooser* dir;
426 GtkWidget* typecombo;
427 CVSData* data;
429 GError* error = NULL;
430 bxml = gtk_builder_new();
431 if (!gtk_builder_add_from_file(bxml, GLADE_FILE, &error))
433 g_warning("Couldn't load builder file: %s", error->message);
434 g_error_free(error);
437 dialog = GTK_WIDGET(gtk_builder_get_object(bxml, "cvs_import"));
438 dir = GTK_FILE_CHOOSER (gtk_builder_get_object(bxml, "cvs_rootdir"));
439 typecombo = GTK_WIDGET(gtk_builder_get_object(bxml, "cvs_server_type"));
441 g_signal_connect (G_OBJECT(typecombo), "changed",
442 G_CALLBACK(on_server_type_changed), bxml);
443 gtk_combo_box_set_active(GTK_COMBO_BOX(typecombo), SERVER_LOCAL);
445 if (plugin->project_root_dir)
446 gtk_file_chooser_set_filename(dir, plugin->project_root_dir);
448 data = cvs_data_new(plugin, bxml);
449 g_signal_connect(G_OBJECT(dialog), "response",
450 G_CALLBACK(on_cvs_import_response), data);
452 gtk_widget_show(dialog);
456 void on_menu_cvs_log (GtkAction* action, CVSPlugin* plugin)
458 cvs_log_dialog(action, plugin, plugin->current_editor_filename);
461 void on_fm_cvs_commit (GtkAction* action, CVSPlugin* plugin)
463 cvs_commit_dialog(action, plugin, plugin->fm_current_filename);
466 void on_fm_cvs_update (GtkAction* action, CVSPlugin* plugin)
468 cvs_update_dialog(action, plugin, plugin->fm_current_filename);
471 void on_fm_cvs_diff (GtkAction* action, CVSPlugin* plugin)
473 cvs_diff_dialog(action, plugin, plugin->fm_current_filename);
476 void on_fm_cvs_status (GtkAction* action, CVSPlugin* plugin)
478 cvs_status_dialog(action, plugin, plugin->fm_current_filename);
481 void on_fm_cvs_log (GtkAction* action, CVSPlugin* plugin)
483 cvs_log_dialog(action, plugin, plugin->fm_current_filename);