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>
33 #define CVS_INFO_REGEXP "(cvs update:.|cvs server:.)"
34 #define CVS_ERR_REGEXP "^C ."
37 static GtkWidget
* status_text
;
40 on_mesg_view_destroy(CVSPlugin
* plugin
, gpointer destroyed_view
)
42 plugin
->mesg_view
= NULL
;
46 on_cvs_mesg_format (IAnjutaMessageView
*view
, const gchar
*line
,
49 IAnjutaMessageViewType type
;
53 g_return_if_fail (line
!= NULL
);
55 /* Compile the regexps for message types. */
56 info
= g_regex_new (CVS_INFO_REGEXP
, 0, 0, &error
);
62 err
= g_regex_new (CVS_ERR_REGEXP
, 0, 0, &error
);
69 /* Match against type regexps to find the message type. */
70 if (g_regex_match (info
, line
, 0, NULL
))
71 type
= IANJUTA_MESSAGE_VIEW_TYPE_INFO
;
72 else if (g_regex_match (info
, line
, 0, NULL
))
73 type
= IANJUTA_MESSAGE_VIEW_TYPE_ERROR
;
75 type
= IANJUTA_MESSAGE_VIEW_TYPE_NORMAL
;
77 ianjuta_message_view_append (view
, type
, line
, "", NULL
);
84 on_cvs_mesg_parse (IAnjutaMessageView
*view
, const gchar
*line
,
87 /* FIXME: Parse the line and determine if there is filename to goto.
88 If there is, extract filename then open it.
96 if ((filename
= parse_filename (line
)))
99 IAnjutaFileLoader
*loader
;
101 /* Go to file and line number */
102 loader
= anjuta_shell_get_interface (plugin
->shell
, IAnjutaFileLoader
,
105 /* FIXME: Determine full file path */
106 file
= g_file_new_for_path (filename
);
107 ianjuta_file_loader_load (loader
, uri
, FALSE
, NULL
);
108 g_object_unref (file
);
115 on_cvs_terminated (AnjutaLauncher
*launcher
, gint child_pid
, gint status
,
116 gulong time_taken
, CVSPlugin
*plugin
)
118 g_return_if_fail (plugin
!= NULL
);
119 /* DEBUG_PRINT ("%s", "Shuting down cvs message view"); */
123 ianjuta_message_view_append (plugin
->mesg_view
,
124 IANJUTA_MESSAGE_VIEW_TYPE_INFO
,
125 _("CVS command failed. See above for details"), "", NULL
);
130 mesg
= g_strdup_printf (ngettext("CVS command successful! Time taken: %ld second",
131 "CVS command successful! Time taken: %ld seconds",
132 time_taken
), time_taken
);
133 ianjuta_message_view_append (plugin
->mesg_view
,
134 IANJUTA_MESSAGE_VIEW_TYPE_INFO
,
138 plugin
->executing_command
= FALSE
;
142 on_cvs_message (AnjutaLauncher
*launcher
,
143 AnjutaLauncherOutputType output_type
,
144 const gchar
* mesg
, gpointer user_data
)
146 CVSPlugin
* plugin
= ANJUTA_PLUGIN_CVS (user_data
);
147 if (plugin
->mesg_view
)
148 ianjuta_message_view_buffer_append (plugin
->mesg_view
, mesg
, NULL
);
152 on_cvs_status(AnjutaLauncher
*launcher
,
153 AnjutaLauncherOutputType output_type
,
154 const gchar
* mesg
, gpointer user_data
)
156 CVSPlugin
* plugin
= ANJUTA_PLUGIN_CVS (user_data
);
159 case ANJUTA_LAUNCHER_OUTPUT_STDERR
:
160 if (plugin
->mesg_view
)
161 ianjuta_message_view_buffer_append (plugin
->mesg_view
,
166 GtkTextBuffer
* textbuf
;
172 gtk_text_view_get_buffer(GTK_TEXT_VIEW(status_text
));
173 gtk_text_buffer_get_end_iter(textbuf
, &end
);
175 gtk_text_buffer_insert(textbuf
, &end
, mesg
, -1);
182 on_cvs_diff(AnjutaLauncher
*launcher
,
183 AnjutaLauncherOutputType output_type
,
184 const gchar
* mesg
, gpointer user_data
)
186 g_return_if_fail (user_data
!= NULL
);
187 CVSPlugin
* plugin
= ANJUTA_PLUGIN_CVS (user_data
);
191 case ANJUTA_LAUNCHER_OUTPUT_STDERR
:
192 if (plugin
->mesg_view
)
193 ianjuta_message_view_buffer_append (plugin
->mesg_view
,
197 ianjuta_editor_append (plugin
->diff_editor
, mesg
, -1, NULL
);
202 on_cvs_status_destroy(GtkWidget
* window
, GdkEvent
* event
, gpointer data
)
206 return FALSE
; /* Do not block the event */
210 cvs_execute_common (CVSPlugin
* plugin
, const gchar
* command
, const gchar
* dir
,
211 AnjutaLauncherOutputCallback output
)
213 IAnjutaMessageManager
*mesg_manager
;
215 g_return_if_fail (command
!= NULL
);
216 g_return_if_fail (dir
!= NULL
);
218 if (plugin
->executing_command
)
220 anjuta_util_dialog_error
221 (NULL
,_("CVS command is running — please wait until it finishes!"),
226 mesg_manager
= anjuta_shell_get_interface
227 (ANJUTA_PLUGIN (plugin
)->shell
, IAnjutaMessageManager
, NULL
);
229 ianjuta_message_manager_get_view_by_name(mesg_manager
, _("CVS"), NULL
);
230 if (!plugin
->mesg_view
)
233 ianjuta_message_manager_add_view (mesg_manager
, _("CVS"),
235 g_object_weak_ref (G_OBJECT (plugin
->mesg_view
),
236 (GWeakNotify
)on_mesg_view_destroy
, plugin
);
237 g_signal_connect (G_OBJECT (plugin
->mesg_view
), "buffer-flushed",
238 G_CALLBACK (on_cvs_mesg_format
), plugin
);
239 g_signal_connect (G_OBJECT (plugin
->mesg_view
), "message-clicked",
240 G_CALLBACK (on_cvs_mesg_parse
), plugin
);
242 ianjuta_message_view_clear(plugin
->mesg_view
, NULL
);
244 if (plugin
->launcher
== NULL
)
246 plugin
->launcher
= anjuta_launcher_new ();
248 g_signal_connect (G_OBJECT (plugin
->launcher
), "child-exited",
249 G_CALLBACK (on_cvs_terminated
), plugin
);
252 plugin
->executing_command
= TRUE
;
254 /* DEBUG_PRINT ("CVS Executing: %s", command); */
255 ianjuta_message_view_append (plugin
->mesg_view
,
256 IANJUTA_MESSAGE_VIEW_TYPE_NORMAL
,
258 anjuta_launcher_execute (plugin
->launcher
, command
, output
, plugin
);
262 cvs_execute(CVSPlugin
* plugin
, const gchar
* command
, const gchar
* dir
)
264 cvs_execute_common(plugin
, command
, dir
, on_cvs_message
);
268 cvs_execute_status(CVSPlugin
* plugin
, const gchar
* command
, const gchar
* dir
)
272 GError
* error
= NULL
;
273 bxml
= gtk_builder_new();
274 if (!gtk_builder_add_from_file(bxml
, GLADE_FILE
, &error
))
276 g_warning("Couldn't load builder file: %s", error
->message
);
280 window
= GTK_WIDGET(gtk_builder_get_object(bxml
, "cvs_status_output"));
281 status_text
= GTK_WIDGET(gtk_builder_get_object(bxml
, "cvs_status_text"));
283 g_signal_connect(G_OBJECT(window
), "delete-event",
284 G_CALLBACK(on_cvs_status_destroy
), status_text
);
286 gtk_widget_show(window
);
287 cvs_execute_common(plugin
, command
, dir
, on_cvs_status
);
291 cvs_execute_diff(CVSPlugin
* plugin
, const gchar
* command
, const gchar
* dir
)
293 IAnjutaDocumentManager
*docman
;
295 docman
= anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin
)->shell
,
296 IAnjutaDocumentManager
, NULL
);
297 plugin
->diff_editor
=
298 ianjuta_document_manager_add_buffer(docman
, "cvs.diff", "", NULL
);
299 cvs_execute_common(plugin
, command
, dir
, on_cvs_diff
);
303 cvs_execute_log(CVSPlugin
* plugin
, const gchar
* command
, const gchar
* dir
)
305 IAnjutaDocumentManager
*docman
;
307 docman
= anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin
)->shell
,
308 IAnjutaDocumentManager
, NULL
);
309 plugin
->diff_editor
=
310 ianjuta_document_manager_add_buffer(docman
, "cvs.log", "", NULL
);
311 cvs_execute_common(plugin
, command
, dir
, on_cvs_diff
);