debug-manager: use g_spawn_sync() instead of fork() and waitpid()
[anjuta.git] / plugins / git / git-pane.c
blobe45b917f69220f83cfe70aa5fbb95ca36859cef9
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * git-shell-test
4 * Copyright (C) James Liggett 2010 <jrliggett@cox.net>
5 *
6 * git-shell-test is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * git-shell-test is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "git-pane.h"
24 G_DEFINE_ABSTRACT_TYPE (GitPane, git_pane, ANJUTA_TYPE_DOCK_PANE);
26 static void
27 git_pane_init (GitPane *object)
29 /* TODO: Add initialization code here */
32 static void
33 git_pane_finalize (GObject *object)
35 /* TODO: Add deinitalization code here */
37 G_OBJECT_CLASS (git_pane_parent_class)->finalize (object);
40 static void
41 git_pane_class_init (GitPaneClass *klass)
43 GObjectClass* object_class = G_OBJECT_CLASS (klass);
44 #if 0
45 AnjutaDockPaneClass* parent_class = ANJUTA_DOCK_PANE_CLASS (klass);
46 #endif
48 object_class->finalize = git_pane_finalize;
51 void
52 git_pane_remove_from_dock (GitPane *self)
54 Git *plugin;
56 plugin = ANJUTA_PLUGIN_GIT (anjuta_dock_pane_get_plugin (ANJUTA_DOCK_PANE (self)));
58 anjuta_dock_remove_pane (ANJUTA_DOCK (plugin->dock),
59 ANJUTA_DOCK_PANE (self));
62 static void
63 on_message_view_destroyed (Git* plugin, gpointer destroyed_view)
65 plugin->message_view = NULL;
68 void
69 git_pane_create_message_view (Git *plugin)
71 IAnjutaMessageManager *message_manager;
74 message_manager = anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin)->shell,
75 IAnjutaMessageManager, NULL);
76 plugin->message_view = ianjuta_message_manager_get_view_by_name (message_manager,
77 _("Git"),
78 NULL);
79 if (!plugin->message_view)
81 plugin->message_view = ianjuta_message_manager_add_view (message_manager,
82 _("Git"),
83 ICON_FILE,
84 NULL);
85 g_object_weak_ref (G_OBJECT (plugin->message_view),
86 (GWeakNotify) on_message_view_destroyed, plugin);
89 ianjuta_message_view_clear (plugin->message_view, NULL);
90 ianjuta_message_manager_set_current_view (message_manager,
91 plugin->message_view,
92 NULL);
95 void
96 git_pane_on_command_info_arrived (AnjutaCommand *command, Git *plugin)
98 GQueue *info;
99 gchar *message;
101 info = git_command_get_info_queue (GIT_COMMAND (command));
103 while (g_queue_peek_head (info))
105 message = g_queue_pop_head (info);
106 ianjuta_message_view_append (plugin->message_view,
107 IANJUTA_MESSAGE_VIEW_TYPE_NORMAL,
108 message, "", NULL);
109 g_free (message);
113 void
114 git_pane_set_log_view_column_label (GtkTextBuffer *buffer,
115 GtkTextIter *location,
116 GtkTextMark *mark,
117 GtkLabel *column_label)
119 gint column;
120 gchar *text;
122 column = gtk_text_iter_get_line_offset (location) + 1;
123 text = g_strdup_printf (_("Column %i"), column);
125 gtk_label_set_text (column_label, text);
127 g_free (text);
130 gchar *
131 git_pane_get_log_from_text_view (GtkTextView *text_view)
133 GtkTextBuffer *log_buffer;
134 GtkTextIter start_iter;
135 GtkTextIter end_iter;
136 gchar *log;
138 log_buffer = gtk_text_view_get_buffer(text_view);
140 gtk_text_buffer_get_start_iter(log_buffer, &start_iter);
141 gtk_text_buffer_get_end_iter(log_buffer, &end_iter) ;
143 log = gtk_text_buffer_get_text(log_buffer, &start_iter, &end_iter, FALSE);
145 return log;
148 gboolean
149 git_pane_check_input (GtkWidget *parent, GtkWidget *widget, const gchar *input,
150 const gchar *error_message)
152 gboolean ret;
153 GtkWidget *dialog;
155 ret = FALSE;
157 if (input)
159 if (strlen (input) > 0)
160 ret = TRUE;
163 if (!ret)
165 dialog = gtk_message_dialog_new (GTK_WINDOW (parent),
166 GTK_DIALOG_DESTROY_WITH_PARENT,
167 GTK_MESSAGE_WARNING,
168 GTK_BUTTONS_OK,
169 "%s",
170 error_message);
172 gtk_dialog_run (GTK_DIALOG (dialog));
173 gtk_widget_destroy (dialog);
175 gtk_window_set_focus (GTK_WINDOW (parent), widget);
179 return ret;
182 static void
183 message_dialog (GtkMessageType message_type, const gchar *message, Git *plugin)
185 const gchar *dialog_title;
186 GtkWidget *image;
187 GtkWidget *dialog;
188 GtkWidget *close_button;
189 GtkWidget *content_area;
190 GtkWidget *hbox;
191 GtkWidget *scrolled_window;
192 GtkWidget *text_view;
193 GtkTextBuffer *text_buffer;
195 dialog_title = NULL;
196 image = gtk_image_new ();
198 switch (message_type)
200 case GTK_MESSAGE_ERROR:
201 gtk_image_set_from_icon_name (GTK_IMAGE (image),
202 GTK_STOCK_DIALOG_ERROR,
203 GTK_ICON_SIZE_DIALOG);
204 dialog_title = _("Git Error");
205 break;
206 case GTK_MESSAGE_WARNING:
207 gtk_image_set_from_icon_name (GTK_IMAGE (image),
208 GTK_STOCK_DIALOG_WARNING,
209 GTK_ICON_SIZE_DIALOG);
210 dialog_title = _("Git Warning");
211 break;
212 default:
213 break;
217 dialog = gtk_dialog_new_with_buttons (dialog_title,
218 GTK_WINDOW (ANJUTA_PLUGIN (plugin)->shell),
219 GTK_DIALOG_DESTROY_WITH_PARENT,
220 NULL);
222 close_button = gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CLOSE,
223 GTK_RESPONSE_CLOSE);
224 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
225 hbox = gtk_hbox_new (FALSE, 2);
226 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
227 text_view = gtk_text_view_new ();
228 text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
230 gtk_window_set_default_size (GTK_WINDOW (dialog), 550, 200);
232 gtk_container_add (GTK_CONTAINER (scrolled_window), text_view);
233 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
234 GTK_SHADOW_IN);
236 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
237 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
239 gtk_text_view_set_editable (GTK_TEXT_VIEW (text_view), FALSE);
240 gtk_text_buffer_set_text (text_buffer, message, strlen (message));
242 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
243 gtk_box_pack_start (GTK_BOX (hbox), scrolled_window, TRUE, TRUE, 0);
245 gtk_box_pack_start (GTK_BOX (content_area), hbox, TRUE, TRUE, 0);
247 gtk_widget_grab_default (close_button);
248 gtk_widget_grab_focus (close_button);
250 g_signal_connect (G_OBJECT (dialog), "response",
251 G_CALLBACK (gtk_widget_destroy),
252 NULL);
254 gtk_widget_show_all (dialog);
258 void
259 git_pane_report_errors (AnjutaCommand *command, guint return_code, Git *plugin)
261 gchar *message;
263 /* In some cases, git might report errors yet still indicate success.
264 * When this happens, use a warning dialog instead of an error, so the user
265 * knows that something actually happened. */
266 message = anjuta_command_get_error_message (command);
268 if (message)
270 if (return_code != 0)
271 message_dialog (GTK_MESSAGE_ERROR, message, plugin);
272 else
273 message_dialog (GTK_MESSAGE_WARNING, message, plugin);
275 g_free (message);
279 void
280 git_pane_send_raw_output_to_editor (AnjutaCommand *command,
281 IAnjutaEditor *editor)
283 GQueue *output;
284 gchar *line;
286 output = git_raw_output_command_get_output (GIT_RAW_OUTPUT_COMMAND (command));
288 while (g_queue_peek_head (output))
290 line = g_queue_pop_head (output);
291 ianjuta_editor_append (editor, line, strlen (line), NULL);
292 g_free (line);