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 git_pane_popup_menu (GitPane
*self
, const gchar
*menu_name
, guint button
,
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
),
78 gtk_menu_popup (menu
, NULL
, NULL
, NULL
, NULL
, button
, time
);
82 on_message_view_destroyed (Git
* plugin
, gpointer destroyed_view
)
84 plugin
->message_view
= NULL
;
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
,
98 if (!plugin
->message_view
)
100 plugin
->message_view
= ianjuta_message_manager_add_view (message_manager
,
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
,
115 git_pane_on_command_info_arrived (AnjutaCommand
*command
, Git
*plugin
)
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
,
133 git_pane_set_log_view_column_label (GtkTextBuffer
*buffer
,
134 GtkTextIter
*location
,
136 GtkLabel
*column_label
)
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
);
150 git_pane_get_log_from_text_view (GtkTextView
*text_view
)
152 GtkTextBuffer
*log_buffer
;
153 GtkTextIter start_iter
;
154 GtkTextIter end_iter
;
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
);
168 git_pane_check_input (GtkWidget
*parent
, GtkWidget
*widget
, const gchar
*input
,
169 const gchar
*error_message
)
178 if (strlen (input
) > 0)
184 dialog
= gtk_message_dialog_new (GTK_WINDOW (parent
),
185 GTK_DIALOG_DESTROY_WITH_PARENT
,
191 gtk_dialog_run (GTK_DIALOG (dialog
));
192 gtk_widget_destroy (dialog
);
194 gtk_window_set_focus (GTK_WINDOW (parent
), widget
);
202 message_dialog (GtkMessageType message_type
, const gchar
*message
, Git
*plugin
)
204 const gchar
*dialog_title
;
207 GtkWidget
*close_button
;
208 GtkWidget
*content_area
;
210 GtkWidget
*scrolled_window
;
211 GtkWidget
*text_view
;
212 GtkTextBuffer
*text_buffer
;
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");
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");
236 dialog
= gtk_dialog_new_with_buttons (dialog_title
,
237 GTK_WINDOW (ANJUTA_PLUGIN (plugin
)->shell
),
238 GTK_DIALOG_DESTROY_WITH_PARENT
,
241 close_button
= gtk_dialog_add_button (GTK_DIALOG (dialog
), GTK_STOCK_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
),
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
),
273 gtk_widget_show_all (dialog
);
278 git_pane_report_errors (AnjutaCommand
*command
, guint return_code
, Git
*plugin
)
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
);
289 if (return_code
!= 0)
290 message_dialog (GTK_MESSAGE_ERROR
, message
, plugin
);
292 message_dialog (GTK_MESSAGE_WARNING
, message
, plugin
);
299 git_pane_send_raw_output_to_editor (AnjutaCommand
*command
,
300 IAnjutaEditor
*editor
)
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
);
316 git_pane_send_raw_output_to_string (AnjutaCommand
*command
, GString
*string
)
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
);