1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) James Liggett 2010 <jrliggett@cox.net>
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/>.
24 G_DEFINE_ABSTRACT_TYPE (GitPane
, git_pane
, ANJUTA_TYPE_DOCK_PANE
);
27 git_pane_init (GitPane
*object
)
29 /* TODO: Add initialization code here */
33 git_pane_finalize (GObject
*object
)
35 /* TODO: Add deinitalization code here */
37 G_OBJECT_CLASS (git_pane_parent_class
)->finalize (object
);
41 git_pane_class_init (GitPaneClass
*klass
)
43 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
45 AnjutaDockPaneClass
* parent_class
= ANJUTA_DOCK_PANE_CLASS (klass
);
48 object_class
->finalize
= git_pane_finalize
;
52 git_pane_remove_from_dock (GitPane
*self
)
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
));
63 on_message_view_destroyed (Git
* plugin
, gpointer destroyed_view
)
65 plugin
->message_view
= NULL
;
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
,
79 if (!plugin
->message_view
)
81 plugin
->message_view
= ianjuta_message_manager_add_view (message_manager
,
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
,
96 git_pane_on_command_info_arrived (AnjutaCommand
*command
, Git
*plugin
)
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
,
114 git_pane_set_log_view_column_label (GtkTextBuffer
*buffer
,
115 GtkTextIter
*location
,
117 GtkLabel
*column_label
)
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
);
131 git_pane_get_log_from_text_view (GtkTextView
*text_view
)
133 GtkTextBuffer
*log_buffer
;
134 GtkTextIter start_iter
;
135 GtkTextIter end_iter
;
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
);
149 git_pane_check_input (GtkWidget
*parent
, GtkWidget
*widget
, const gchar
*input
,
150 const gchar
*error_message
)
159 if (strlen (input
) > 0)
165 dialog
= gtk_message_dialog_new (GTK_WINDOW (parent
),
166 GTK_DIALOG_DESTROY_WITH_PARENT
,
172 gtk_dialog_run (GTK_DIALOG (dialog
));
173 gtk_widget_destroy (dialog
);
175 gtk_window_set_focus (GTK_WINDOW (parent
), widget
);
183 message_dialog (GtkMessageType message_type
, const gchar
*message
, Git
*plugin
)
185 const gchar
*dialog_title
;
188 GtkWidget
*close_button
;
189 GtkWidget
*content_area
;
191 GtkWidget
*scrolled_window
;
192 GtkWidget
*text_view
;
193 GtkTextBuffer
*text_buffer
;
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");
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");
217 dialog
= gtk_dialog_new_with_buttons (dialog_title
,
218 GTK_WINDOW (ANJUTA_PLUGIN (plugin
)->shell
),
219 GTK_DIALOG_DESTROY_WITH_PARENT
,
222 close_button
= gtk_dialog_add_button (GTK_DIALOG (dialog
), GTK_STOCK_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
),
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
),
254 gtk_widget_show_all (dialog
);
259 git_pane_report_errors (AnjutaCommand
*command
, guint return_code
, Git
*plugin
)
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
);
270 if (return_code
!= 0)
271 message_dialog (GTK_MESSAGE_ERROR
, message
, plugin
);
273 message_dialog (GTK_MESSAGE_WARNING
, message
, plugin
);
280 git_pane_send_raw_output_to_editor (AnjutaCommand
*command
,
281 IAnjutaEditor
*editor
)
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
);