Updated Swedish translation
[anjuta.git] / plugins / git / git-pane.c
blob71be370ba98452a1f089b912f1939ed6162b0661
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 void
63 git_pane_popup_menu (GitPane *self, const gchar *menu_name, guint button,
64 guint32 time)
66 gchar *path;
67 AnjutaPlugin *plugin;
68 AnjutaUI *ui;
69 GtkMenu *menu;
71 path = g_strconcat ("/", menu_name, NULL);
72 plugin = anjuta_dock_pane_get_plugin (ANJUTA_DOCK_PANE (self));
73 ui = anjuta_shell_get_ui (plugin->shell, NULL);
74 menu = GTK_MENU (gtk_ui_manager_get_widget (GTK_UI_MANAGER (ui),
75 path));
77 g_free (path);
78 gtk_menu_popup (menu, NULL, NULL, NULL, NULL, button, time);
81 static void
82 on_message_view_destroyed (Git* plugin, gpointer destroyed_view)
84 plugin->message_view = NULL;
87 void
88 git_pane_create_message_view (Git *plugin)
90 IAnjutaMessageManager *message_manager;
93 message_manager = anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin)->shell,
94 IAnjutaMessageManager, NULL);
95 plugin->message_view = ianjuta_message_manager_get_view_by_name (message_manager,
96 _("Git"),
97 NULL);
98 if (!plugin->message_view)
100 plugin->message_view = ianjuta_message_manager_add_view (message_manager,
101 _("Git"),
102 ICON_FILE,
103 NULL);
104 g_object_weak_ref (G_OBJECT (plugin->message_view),
105 (GWeakNotify) on_message_view_destroyed, plugin);
108 ianjuta_message_view_clear (plugin->message_view, NULL);
109 ianjuta_message_manager_set_current_view (message_manager,
110 plugin->message_view,
111 NULL);
114 void
115 git_pane_on_command_info_arrived (AnjutaCommand *command, Git *plugin)
117 GQueue *info;
118 gchar *message;
120 info = git_command_get_info_queue (GIT_COMMAND (command));
122 while (g_queue_peek_head (info))
124 message = g_queue_pop_head (info);
125 ianjuta_message_view_append (plugin->message_view,
126 IANJUTA_MESSAGE_VIEW_TYPE_NORMAL,
127 message, "", NULL);
128 g_free (message);
132 void
133 git_pane_set_log_view_column_label (GtkTextBuffer *buffer,
134 GtkTextIter *location,
135 GtkTextMark *mark,
136 GtkLabel *column_label)
138 gint column;
139 gchar *text;
141 column = gtk_text_iter_get_line_offset (location) + 1;
142 text = g_strdup_printf (_("Column %i"), column);
144 gtk_label_set_text (column_label, text);
146 g_free (text);
149 gchar *
150 git_pane_get_log_from_text_view (GtkTextView *text_view)
152 GtkTextBuffer *log_buffer;
153 GtkTextIter start_iter;
154 GtkTextIter end_iter;
155 gchar *log;
157 log_buffer = gtk_text_view_get_buffer(text_view);
159 gtk_text_buffer_get_start_iter(log_buffer, &start_iter);
160 gtk_text_buffer_get_end_iter(log_buffer, &end_iter) ;
162 log = gtk_text_buffer_get_text(log_buffer, &start_iter, &end_iter, FALSE);
164 return log;
167 gboolean
168 git_pane_check_input (GtkWidget *parent, GtkWidget *widget, const gchar *input,
169 const gchar *error_message)
171 gboolean ret;
172 GtkWidget *dialog;
174 ret = FALSE;
176 if (input)
178 if (strlen (input) > 0)
179 ret = TRUE;
182 if (!ret)
184 dialog = gtk_message_dialog_new (GTK_WINDOW (parent),
185 GTK_DIALOG_DESTROY_WITH_PARENT,
186 GTK_MESSAGE_WARNING,
187 GTK_BUTTONS_OK,
188 "%s",
189 error_message);
191 gtk_dialog_run (GTK_DIALOG (dialog));
192 gtk_widget_destroy (dialog);
194 gtk_window_set_focus (GTK_WINDOW (parent), widget);
198 return ret;
201 static void
202 message_dialog (GtkMessageType message_type, const gchar *message, Git *plugin)
204 const gchar *dialog_title;
205 GtkWidget *image;
206 GtkWidget *dialog;
207 GtkWidget *close_button;
208 GtkWidget *content_area;
209 GtkWidget *hbox;
210 GtkWidget *scrolled_window;
211 GtkWidget *text_view;
212 GtkTextBuffer *text_buffer;
214 dialog_title = NULL;
215 image = gtk_image_new ();
217 switch (message_type)
219 case GTK_MESSAGE_ERROR:
220 gtk_image_set_from_icon_name (GTK_IMAGE (image),
221 GTK_STOCK_DIALOG_ERROR,
222 GTK_ICON_SIZE_DIALOG);
223 dialog_title = _("Git Error");
224 break;
225 case GTK_MESSAGE_WARNING:
226 gtk_image_set_from_icon_name (GTK_IMAGE (image),
227 GTK_STOCK_DIALOG_WARNING,
228 GTK_ICON_SIZE_DIALOG);
229 dialog_title = _("Git Warning");
230 break;
231 default:
232 break;
236 dialog = gtk_dialog_new_with_buttons (dialog_title,
237 GTK_WINDOW (ANJUTA_PLUGIN (plugin)->shell),
238 GTK_DIALOG_DESTROY_WITH_PARENT,
239 NULL, NULL);
241 close_button = gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CLOSE,
242 GTK_RESPONSE_CLOSE);
243 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
244 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
245 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
246 text_view = gtk_text_view_new ();
247 text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
249 gtk_window_set_default_size (GTK_WINDOW (dialog), 550, 200);
251 gtk_container_add (GTK_CONTAINER (scrolled_window), text_view);
252 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
253 GTK_SHADOW_IN);
255 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
256 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
258 gtk_text_view_set_editable (GTK_TEXT_VIEW (text_view), FALSE);
259 gtk_text_buffer_set_text (text_buffer, message, strlen (message));
261 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
262 gtk_box_pack_start (GTK_BOX (hbox), scrolled_window, TRUE, TRUE, 0);
264 gtk_box_pack_start (GTK_BOX (content_area), hbox, TRUE, TRUE, 0);
266 gtk_widget_grab_default (close_button);
267 gtk_widget_grab_focus (close_button);
269 g_signal_connect (G_OBJECT (dialog), "response",
270 G_CALLBACK (gtk_widget_destroy),
271 NULL);
273 gtk_widget_show_all (dialog);
277 void
278 git_pane_report_errors (AnjutaCommand *command, guint return_code, Git *plugin)
280 gchar *message;
282 /* In some cases, git might report errors yet still indicate success.
283 * When this happens, use a warning dialog instead of an error, so the user
284 * knows that something actually happened. */
285 message = anjuta_command_get_error_message (command);
287 if (message)
289 if (return_code != 0)
290 message_dialog (GTK_MESSAGE_ERROR, message, plugin);
291 else
292 message_dialog (GTK_MESSAGE_WARNING, message, plugin);
294 g_free (message);
298 void
299 git_pane_send_raw_output_to_editor (AnjutaCommand *command,
300 IAnjutaEditor *editor)
302 GQueue *output;
303 gchar *line;
305 output = git_raw_output_command_get_output (GIT_RAW_OUTPUT_COMMAND (command));
307 while (g_queue_peek_head (output))
309 line = g_queue_pop_head (output);
310 ianjuta_editor_append (editor, line, strlen (line), NULL);
311 g_free (line);
315 void
316 git_pane_send_raw_output_to_string (AnjutaCommand *command, GString *string)
318 GQueue *output;
319 gchar *line;
321 output = git_raw_output_command_get_output (GIT_RAW_OUTPUT_COMMAND (command));
323 while (g_queue_peek_head (output))
325 line = g_queue_pop_head (output);
326 g_string_append (string, line);
327 g_free (line);