1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) James Liggett 2007 <jrliggett@cox.net>
6 * Portions based on the original Subversion plugin
7 * Copyright (C) Johannes Schmid 2005
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)
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 */
38 subversion_data_new (Subversion
* plugin
, GladeXML
* gxml
)
40 SubversionData
* data
= g_new0(SubversionData
, 1);
41 data
->plugin
= plugin
;
47 void subversion_data_free(SubversionData
* data
)
53 on_mesg_view_destroy(Subversion
* plugin
, gpointer destroyed_view
)
55 plugin
->mesg_view
= NULL
;
59 create_message_view(Subversion
* plugin
)
61 IAnjutaMessageManager
* mesg_manager
= anjuta_shell_get_interface
62 (ANJUTA_PLUGIN (plugin
)->shell
, IAnjutaMessageManager
, NULL
);
64 ianjuta_message_manager_get_view_by_name(mesg_manager
, _("Subversion"),
66 if (!plugin
->mesg_view
)
69 ianjuta_message_manager_add_view (mesg_manager
, _("Subversion"),
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
,
80 check_input (GtkWidget
*parent
, GtkWidget
*entry
, const gchar
*error_message
)
86 input
= gtk_editable_get_chars (GTK_EDITABLE (entry
), 0, -1);
88 if (strlen (input
) > 0)
92 dialog
= gtk_message_dialog_new (GTK_WINDOW (parent
),
93 GTK_DIALOG_DESTROY_WITH_PARENT
,
98 gtk_dialog_run (GTK_DIALOG (dialog
));
99 gtk_widget_destroy (dialog
);
101 gtk_window_set_focus (GTK_WINDOW (parent
), entry
);
112 get_log_from_textview (GtkWidget
* textview
)
115 GtkTextBuffer
* textbuf
;
116 GtkTextIter iterbegin
, iterend
;
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 */
125 escaped_log
= anjuta_util_escape_quotes (log
);
130 status_pulse_timer (PulseProgressData
*data
)
132 anjuta_status_progress_pulse (data
->status
, data
->text
);
137 pulse_timer (GtkProgressBar
*progress_bar
)
139 gtk_progress_bar_pulse (progress_bar
);
144 on_pulse_timer_destroyed (PulseProgressData
*data
)
146 anjuta_status_progress_reset (data
->status
);
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
,
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
);
168 clear_status_bar_progress_pulse (guint timer_id
)
170 g_source_remove (timer_id
);
174 report_errors (AnjutaCommand
*command
, guint return_code
)
178 if (return_code
!= 0)
180 message
= anjuta_command_get_error_message (command
);
182 anjuta_util_dialog_error (NULL
, message
);
188 stop_pulse_timer (gpointer timer_id
, GtkProgressBar
*progress_bar
)
190 g_source_remove (GPOINTER_TO_UINT (timer_id
));
194 pulse_progress_bar (GtkProgressBar
*progress_bar
)
198 timer_id
= g_timeout_add (100, (GSourceFunc
) pulse_timer
,
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
));
209 get_filename_from_full_path (gchar
*path
)
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);
219 return g_strdup ("");
223 on_status_command_finished (AnjutaCommand
*command
, guint return_code
,
226 report_errors (command
, return_code
);
228 svn_status_command_destroy (SVN_STATUS_COMMAND (command
));
232 on_status_command_data_arrived (AnjutaCommand
*command
,
233 AnjutaVcsStatusTreeView
*tree_view
)
235 GQueue
*status_queue
;
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
),
250 svn_status_destroy (status
);
256 on_command_info_arrived (AnjutaCommand
*command
, Subversion
*plugin
)
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
,
274 select_all_status_items (GtkButton
*select_all_button
,
275 AnjutaVcsStatusTreeView
*tree_view
)
277 anjuta_vcs_status_tree_view_select_all (tree_view
);
281 clear_all_status_selections (GtkButton
*clear_button
,
282 AnjutaVcsStatusTreeView
*tree_view
)
284 anjuta_vcs_status_tree_view_unselect_all (tree_view
);
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
);
297 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (project
), active
);
301 on_whole_project_toggled (GtkToggleButton
* project
, Subversion
*plugin
)
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
);
313 gtk_widget_set_sensitive(GTK_WIDGET(fileentry
), TRUE
);
317 send_diff_command_output_to_editor (AnjutaCommand
*command
,
318 IAnjutaEditor
*editor
)
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
);
334 on_diff_command_finished (AnjutaCommand
*command
, guint return_code
,
337 AnjutaStatus
*status
;
339 status
= anjuta_shell_get_status (ANJUTA_PLUGIN (plugin
)->shell
,
342 anjuta_status (status
, _("Subversion: Diff complete."), 5);
344 report_errors (command
, return_code
);
346 svn_diff_command_destroy (SVN_DIFF_COMMAND (command
));
350 stop_status_bar_progress_pulse (AnjutaCommand
*command
, guint return_code
,
353 clear_status_bar_progress_pulse (GPOINTER_TO_UINT (timer_id
));
357 hide_pulse_progress_bar (AnjutaCommand
*command
, guint return_code
,
358 GtkProgressBar
*progress_bar
)
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
),
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. */
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
,
402 cancel_data_arrived_signal_disconnect (AnjutaCommand
*command
,
404 GObject
*signal_target
)
406 g_object_weak_unref (signal_target
,
407 (GWeakNotify
) disconnect_data_arrived_signals
,