1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
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
21 #include "cvs-execute.h"
24 #include <libanjuta/interfaces/ianjuta-message-manager.h>
25 #include <libanjuta/interfaces/ianjuta-document-manager.h>
26 #include <libanjuta/interfaces/ianjuta-editor.h>
27 #include <libanjuta/anjuta-launcher.h>
28 #include <libanjuta/anjuta-debug.h>
30 #include <glade/glade.h>
34 #define CVS_INFO_REGEXP "(cvs update:.|cvs server:.)"
35 #define CVS_ERR_REGEXP "^C ."
38 static GtkWidget
* status_text
;
41 on_mesg_view_destroy(CVSPlugin
* plugin
, gpointer destroyed_view
)
43 plugin
->mesg_view
= NULL
;
47 on_cvs_mesg_format (IAnjutaMessageView
*view
, const gchar
*line
,
50 IAnjutaMessageViewType type
;
53 int err_ptr
, output
[16];
55 g_return_if_fail (line
!= NULL
);
57 /* Compile the regexps for message types. */
58 if (!(info
= pcre_compile(CVS_INFO_REGEXP
, 0, &err_buf
, &err_ptr
, NULL
)))
60 g_free((gchar
*) err_buf
);
63 if (!(err
= pcre_compile(CVS_ERR_REGEXP
, 0, &err_buf
, &err_ptr
, NULL
)))
65 g_free((gchar
*) err_buf
);
69 /* Match against type regexps to find the message type. */
70 if (pcre_exec(info
, NULL
, line
, strlen(line
), 0, 0, output
, 16) >= 0)
72 type
= IANJUTA_MESSAGE_VIEW_TYPE_INFO
;
74 else if (pcre_exec(err
, NULL
, line
, strlen(line
), 0, 0, output
, 16) >= 0)
76 type
= IANJUTA_MESSAGE_VIEW_TYPE_ERROR
;
78 else type
= IANJUTA_MESSAGE_VIEW_TYPE_NORMAL
;
80 ianjuta_message_view_append (view
, type
, line
, "", NULL
);
87 on_cvs_mesg_parse (IAnjutaMessageView
*view
, const gchar
*line
,
90 /* FIXME: Parse the line and determine if there is filename to goto.
91 If there is, extract filename then open it.
99 if ((filename
= parse_filename (line
)))
102 IAnjutaFileLoader
*loader
;
104 /* Go to file and line number */
105 loader
= anjuta_shell_get_interface (plugin
->shell
, IAnjutaFileLoader
,
108 /* FIXME: Determine full file path */
109 uri
= gnome_vfs_get_uri_from_local_path(filename
);
110 ianjuta_file_loader_load (loader
, uri
, FALSE
, NULL
);
118 on_cvs_terminated (AnjutaLauncher
*launcher
, gint child_pid
, gint status
,
119 gulong time_taken
, CVSPlugin
*plugin
)
121 g_return_if_fail (plugin
!= NULL
);
122 /* DEBUG_PRINT ("Shuting down cvs message view"); */
126 ianjuta_message_view_append (plugin
->mesg_view
,
127 IANJUTA_MESSAGE_VIEW_TYPE_INFO
,
128 _("CVS command failed - See above for details"), "", NULL
);
133 mesg
= g_strdup_printf (ngettext("CVS command successful! - Time taken: %ld second",
134 "CVS command successful! - Time taken: %ld seconds",
135 time_taken
), time_taken
);
136 ianjuta_message_view_append (plugin
->mesg_view
,
137 IANJUTA_MESSAGE_VIEW_TYPE_INFO
,
141 plugin
->executing_command
= FALSE
;
145 on_cvs_message (AnjutaLauncher
*launcher
,
146 AnjutaLauncherOutputType output_type
,
147 const gchar
* mesg
, gpointer user_data
)
149 CVSPlugin
* plugin
= ANJUTA_PLUGIN_CVS (user_data
);
150 if (plugin
->mesg_view
)
151 ianjuta_message_view_buffer_append (plugin
->mesg_view
, mesg
, NULL
);
155 on_cvs_status(AnjutaLauncher
*launcher
,
156 AnjutaLauncherOutputType output_type
,
157 const gchar
* mesg
, gpointer user_data
)
159 CVSPlugin
* plugin
= ANJUTA_PLUGIN_CVS (user_data
);
162 case ANJUTA_LAUNCHER_OUTPUT_STDERR
:
163 if (plugin
->mesg_view
)
164 ianjuta_message_view_buffer_append (plugin
->mesg_view
,
169 GtkTextBuffer
* textbuf
;
175 gtk_text_view_get_buffer(GTK_TEXT_VIEW(status_text
));
176 gtk_text_buffer_get_end_iter(textbuf
, &end
);
178 gtk_text_buffer_insert(textbuf
, &end
, mesg
, -1);
185 on_cvs_diff(AnjutaLauncher
*launcher
,
186 AnjutaLauncherOutputType output_type
,
187 const gchar
* mesg
, gpointer user_data
)
189 g_return_if_fail (user_data
!= NULL
);
190 CVSPlugin
* plugin
= ANJUTA_PLUGIN_CVS (user_data
);
194 case ANJUTA_LAUNCHER_OUTPUT_STDERR
:
195 if (plugin
->mesg_view
)
196 ianjuta_message_view_buffer_append (plugin
->mesg_view
,
200 ianjuta_editor_append (plugin
->diff_editor
, mesg
, -1, NULL
);
205 on_cvs_status_destroy(GtkWidget
* window
, GdkEvent
* event
, gpointer data
)
209 return FALSE
; /* Do not block the event */
213 cvs_execute_common (CVSPlugin
* plugin
, const gchar
* command
, const gchar
* dir
,
214 AnjutaLauncherOutputCallback output
)
216 IAnjutaMessageManager
*mesg_manager
;
218 g_return_if_fail (command
!= NULL
);
219 g_return_if_fail (dir
!= NULL
);
221 if (plugin
->executing_command
)
223 anjuta_util_dialog_error
224 (NULL
,_("CVS command is running - please wait until it finishes!"),
229 mesg_manager
= anjuta_shell_get_interface
230 (ANJUTA_PLUGIN (plugin
)->shell
, IAnjutaMessageManager
, NULL
);
232 ianjuta_message_manager_get_view_by_name(mesg_manager
, _("CVS"), NULL
);
233 if (!plugin
->mesg_view
)
236 ianjuta_message_manager_add_view (mesg_manager
, _("CVS"),
238 g_object_weak_ref (G_OBJECT (plugin
->mesg_view
),
239 (GWeakNotify
)on_mesg_view_destroy
, plugin
);
240 g_signal_connect (G_OBJECT (plugin
->mesg_view
), "buffer-flushed",
241 G_CALLBACK (on_cvs_mesg_format
), plugin
);
242 g_signal_connect (G_OBJECT (plugin
->mesg_view
), "message-clicked",
243 G_CALLBACK (on_cvs_mesg_parse
), plugin
);
245 ianjuta_message_view_clear(plugin
->mesg_view
, NULL
);
247 if (plugin
->launcher
== NULL
)
249 plugin
->launcher
= anjuta_launcher_new ();
251 g_signal_connect (G_OBJECT (plugin
->launcher
), "child-exited",
252 G_CALLBACK (on_cvs_terminated
), plugin
);
255 plugin
->executing_command
= TRUE
;
257 /* DEBUG_PRINT ("CVS Executing: %s", command); */
258 ianjuta_message_view_append (plugin
->mesg_view
,
259 IANJUTA_MESSAGE_VIEW_TYPE_NORMAL
,
261 anjuta_launcher_execute (plugin
->launcher
, command
, output
, plugin
);
265 cvs_execute(CVSPlugin
* plugin
, const gchar
* command
, const gchar
* dir
)
267 cvs_execute_common(plugin
, command
, dir
, on_cvs_message
);
271 cvs_execute_status(CVSPlugin
* plugin
, const gchar
* command
, const gchar
* dir
)
276 gxml
= glade_xml_new(GLADE_FILE
, "cvs_status_output", NULL
);
277 window
= glade_xml_get_widget(gxml
, "cvs_status_output");
278 status_text
= glade_xml_get_widget(gxml
, "cvs_status_text");
280 g_signal_connect(G_OBJECT(window
), "delete-event",
281 G_CALLBACK(on_cvs_status_destroy
), status_text
);
283 gtk_widget_show(window
);
284 cvs_execute_common(plugin
, command
, dir
, on_cvs_status
);
288 cvs_execute_diff(CVSPlugin
* plugin
, const gchar
* command
, const gchar
* dir
)
290 IAnjutaDocumentManager
*docman
;
292 docman
= anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin
)->shell
,
293 IAnjutaDocumentManager
, NULL
);
294 plugin
->diff_editor
=
295 ianjuta_document_manager_add_buffer(docman
, "cvs.diff", "", NULL
);
296 cvs_execute_common(plugin
, command
, dir
, on_cvs_diff
);
300 cvs_execute_log(CVSPlugin
* plugin
, const gchar
* command
, const gchar
* dir
)
302 IAnjutaDocumentManager
*docman
;
304 docman
= anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin
)->shell
,
305 IAnjutaDocumentManager
, NULL
);
306 plugin
->diff_editor
=
307 ianjuta_document_manager_add_buffer(docman
, "cvs.log", "", NULL
);
308 cvs_execute_common(plugin
, command
, dir
, on_cvs_diff
);