Integrate removing files with the file manager
[anjuta-git-plugin.git] / plugins / subversion / subversion-ui-utils.c
blobde6a78321bb2750ed9eea1c5bbefae882f7bdafb
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>
6 * Portions based on the original Subversion plugin
7 * Copyright (C) Johannes Schmid 2005
8 *
9 * anjuta is free software.
11 * You may redistribute it and/or modify it under the terms of the
12 * GNU General Public License, as published by the Free Software
13 * Foundation; either version 2 of the License, or (at your option)
14 * any later version.
16 * anjuta is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 * See the GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with anjuta. If not, write to:
23 * The Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor
25 * Boston, MA 02110-1301, USA.
28 #include "subversion-ui-utils.h"
30 /* Private structure for pulse progress */
31 typedef struct
33 AnjutaStatus *status;
34 gchar *text;
35 } PulseProgressData;
37 SubversionData*
38 subversion_data_new (Subversion* plugin, GladeXML* gxml)
40 SubversionData* data = g_new0(SubversionData, 1);
41 data->plugin = plugin;
42 data->gxml = gxml;
44 return data;
47 void subversion_data_free(SubversionData* data)
49 g_free(data);
52 static void
53 on_mesg_view_destroy(Subversion* plugin, gpointer destroyed_view)
55 plugin->mesg_view = NULL;
58 void
59 create_message_view(Subversion* plugin)
61 IAnjutaMessageManager* mesg_manager = anjuta_shell_get_interface
62 (ANJUTA_PLUGIN (plugin)->shell, IAnjutaMessageManager, NULL);
63 plugin->mesg_view =
64 ianjuta_message_manager_get_view_by_name(mesg_manager, _("Subversion"),
65 NULL);
66 if (!plugin->mesg_view)
68 plugin->mesg_view =
69 ianjuta_message_manager_add_view (mesg_manager, _("Subversion"),
70 ICON_FILE, NULL);
71 g_object_weak_ref (G_OBJECT (plugin->mesg_view),
72 (GWeakNotify)on_mesg_view_destroy, plugin);
74 ianjuta_message_view_clear(plugin->mesg_view, NULL);
75 ianjuta_message_manager_set_current_view(mesg_manager, plugin->mesg_view,
76 NULL);
79 gboolean
80 check_input (GtkWidget *parent, GtkWidget *entry, const gchar *error_message)
82 gchar *input;
83 gboolean ret;
84 GtkWidget *dialog;
86 input = gtk_editable_get_chars (GTK_EDITABLE (entry), 0, -1);
88 if (strlen (input) > 0)
89 ret = TRUE;
90 else
92 dialog = gtk_message_dialog_new (GTK_WINDOW (parent),
93 GTK_DIALOG_DESTROY_WITH_PARENT,
94 GTK_MESSAGE_WARNING,
95 GTK_BUTTONS_OK,
96 error_message);
98 gtk_dialog_run (GTK_DIALOG (dialog));
99 gtk_widget_destroy (dialog);
101 gtk_window_set_focus (GTK_WINDOW (parent), entry);
103 ret = FALSE;
106 g_free (input);
108 return ret;
111 gchar *
112 get_log_from_textview (GtkWidget* textview)
114 gchar* log;
115 GtkTextBuffer* textbuf;
116 GtkTextIter iterbegin, iterend;
117 gchar* escaped_log;
119 textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
120 gtk_text_buffer_get_start_iter(textbuf, &iterbegin);
121 gtk_text_buffer_get_end_iter(textbuf, &iterend) ;
122 log = gtk_text_buffer_get_text(textbuf, &iterbegin, &iterend, FALSE);
123 /* #warning FIXME: Check for escape chars in log */
124 /* Fixed. -naba*/
125 escaped_log = anjuta_util_escape_quotes (log);
126 return escaped_log;
129 static gboolean
130 status_pulse_timer (PulseProgressData *data)
132 anjuta_status_progress_pulse (data->status, data->text);
133 return TRUE;
136 static gboolean
137 pulse_timer (GtkProgressBar *progress_bar)
139 gtk_progress_bar_pulse (progress_bar);
140 return TRUE;
143 static void
144 on_pulse_timer_destroyed (PulseProgressData *data)
146 anjuta_status_progress_reset (data->status);
148 g_free (data->text);
149 g_free (data);
152 guint
153 status_bar_progress_pulse (Subversion *plugin, gchar *text)
155 PulseProgressData *data;
157 data = g_new0 (PulseProgressData, 1);
158 data->status = anjuta_shell_get_status (ANJUTA_PLUGIN (plugin)->shell,
159 NULL);
160 data->text = g_strdup (text);
162 return g_timeout_add_full (G_PRIORITY_DEFAULT, 100,
163 (GSourceFunc) status_pulse_timer, data,
164 (GDestroyNotify) on_pulse_timer_destroyed);
167 void
168 clear_status_bar_progress_pulse (guint timer_id)
170 g_source_remove (timer_id);
173 void
174 report_errors (AnjutaCommand *command, guint return_code)
176 gchar *message;
178 if (return_code != 0)
180 message = anjuta_command_get_error_message (command);
182 anjuta_util_dialog_error (NULL, message);
183 g_free (message);
187 static void
188 stop_pulse_timer (gpointer timer_id, GtkProgressBar *progress_bar)
190 g_source_remove (GPOINTER_TO_UINT (timer_id));
193 void
194 pulse_progress_bar (GtkProgressBar *progress_bar)
196 guint timer_id;
198 timer_id = g_timeout_add (100, (GSourceFunc) pulse_timer,
199 progress_bar);
200 g_object_set_data (G_OBJECT (progress_bar), "pulse-timer-id",
201 GUINT_TO_POINTER (timer_id));
203 g_object_weak_ref (G_OBJECT (progress_bar),
204 (GWeakNotify) stop_pulse_timer,
205 GUINT_TO_POINTER (timer_id));
208 gchar *
209 get_filename_from_full_path (gchar *path)
211 gchar *last_slash;
213 last_slash = strrchr (path, '/');
215 /* There might be a trailing slash in the string */
216 if ((last_slash - path) < strlen (path))
217 return g_strdup (last_slash + 1);
218 else
219 return g_strdup ("");
222 void
223 on_status_command_finished (AnjutaCommand *command, guint return_code,
224 gpointer user_data)
226 report_errors (command, return_code);
228 svn_status_command_destroy (SVN_STATUS_COMMAND (command));
231 void
232 on_status_command_data_arrived (AnjutaCommand *command,
233 AnjutaVcsStatusTreeView *tree_view)
235 GQueue *status_queue;
236 SvnStatus *status;
237 gchar *path;
239 status_queue = svn_status_command_get_status_queue (SVN_STATUS_COMMAND (command));
241 while (g_queue_peek_head (status_queue))
243 status = g_queue_pop_head (status_queue);
244 path = svn_status_get_path (status);
246 anjuta_vcs_status_tree_view_add (tree_view, path,
247 svn_status_get_vcs_status (status),
248 FALSE);
250 svn_status_destroy (status);
251 g_free (path);
255 void
256 on_command_info_arrived (AnjutaCommand *command, Subversion *plugin)
258 GQueue *info;
259 gchar *message;
261 info = svn_command_get_info_queue (SVN_COMMAND (command));
263 while (g_queue_peek_head (info))
265 message = g_queue_pop_head (info);
266 ianjuta_message_view_append (plugin->mesg_view,
267 IANJUTA_MESSAGE_VIEW_TYPE_INFO,
268 message, "", NULL);
269 g_free (message);
273 void
274 select_all_status_items (GtkButton *select_all_button,
275 AnjutaVcsStatusTreeView *tree_view)
277 anjuta_vcs_status_tree_view_select_all (tree_view);
280 void
281 clear_all_status_selections (GtkButton *clear_button,
282 AnjutaVcsStatusTreeView *tree_view)
284 anjuta_vcs_status_tree_view_unselect_all (tree_view);
287 void
288 init_whole_project (Subversion *plugin, GtkWidget* project, gboolean active)
290 gboolean project_loaded;
292 project_loaded = (plugin->project_root_dir != NULL);
294 gtk_widget_set_sensitive(project, project_loaded);
296 if (project_loaded)
297 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (project), active);
300 void
301 on_whole_project_toggled (GtkToggleButton* project, Subversion *plugin)
303 GtkEntry* fileentry;
305 fileentry = g_object_get_data (G_OBJECT (project), "fileentry");
307 if (gtk_toggle_button_get_active(project) && plugin->project_root_dir)
309 gtk_entry_set_text (fileentry, plugin->project_root_dir);
310 gtk_widget_set_sensitive(GTK_WIDGET(fileentry), FALSE);
312 else
313 gtk_widget_set_sensitive(GTK_WIDGET(fileentry), TRUE);
316 void
317 send_diff_command_output_to_editor (AnjutaCommand *command,
318 IAnjutaEditor *editor)
320 GQueue *output;
321 gchar *line;
323 output = svn_diff_command_get_output (SVN_DIFF_COMMAND (command));
325 while (g_queue_peek_head (output))
327 line = g_queue_pop_head (output);
328 ianjuta_editor_append (editor, line, strlen (line), NULL);
329 g_free (line);
333 void
334 on_diff_command_finished (AnjutaCommand *command, guint return_code,
335 Subversion *plugin)
337 AnjutaStatus *status;
339 status = anjuta_shell_get_status (ANJUTA_PLUGIN (plugin)->shell,
340 NULL);
342 anjuta_status (status, _("Subversion: Diff complete."), 5);
344 report_errors (command, return_code);
346 svn_diff_command_destroy (SVN_DIFF_COMMAND (command));
349 void
350 stop_status_bar_progress_pulse (AnjutaCommand *command, guint return_code,
351 gpointer timer_id)
353 clear_status_bar_progress_pulse (GPOINTER_TO_UINT (timer_id));
356 void
357 hide_pulse_progress_bar (AnjutaCommand *command, guint return_code,
358 GtkProgressBar *progress_bar)
360 guint timer_id;
362 /* If the progress bar has already been destroyed, the timer should be
363 * stopped by stop_pulse_timer */
364 if (GTK_IS_PROGRESS_BAR (progress_bar))
366 timer_id = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (progress_bar),
367 "pulse-timer-id"));
369 g_source_remove (GPOINTER_TO_UINT (timer_id));
370 gtk_widget_hide (GTK_WIDGET (progress_bar));
374 /* This function is normally intended to disconnect stock data-arrived signal
375 * handlers in this file. It is assumed that object is the user data for the
376 * callback. If you use any of the stock callbacks defined here, make sure
377 * to weak ref its target with this callback. Make sure to cancel this ref
378 * by connecting cancel_data_arrived_signal_disconnect to the command-finished
379 * signal so we don't try to disconnect signals on a destroyed command. */
380 void
381 disconnect_data_arrived_signals (AnjutaCommand *command, GObject *object)
383 guint data_arrived_signal;
385 if (ANJUTA_IS_COMMAND (command))
387 data_arrived_signal = g_signal_lookup ("data-arrived",
388 ANJUTA_TYPE_COMMAND);
390 g_signal_handlers_disconnect_matched (command,
391 G_SIGNAL_MATCH_DATA,
392 data_arrived_signal,
394 NULL,
395 NULL,
396 object);
401 void
402 cancel_data_arrived_signal_disconnect (AnjutaCommand *command,
403 guint return_code,
404 GObject *signal_target)
406 g_object_weak_unref (signal_target,
407 (GWeakNotify) disconnect_data_arrived_signals,
408 command);