git: Add a helper method to get log messages from text views
[anjuta.git] / plugins / git / git-pane.c
blob86f7f81426179bf623d769b018ffa4bf38562b10
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 static void
52 on_message_view_destroyed (Git* plugin, gpointer destroyed_view)
54 plugin->message_view = NULL;
57 void
58 git_pane_create_message_view (Git *plugin)
60 IAnjutaMessageManager *message_manager;
63 message_manager = anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin)->shell,
64 IAnjutaMessageManager, NULL);
65 plugin->message_view = ianjuta_message_manager_get_view_by_name (message_manager,
66 _("Git"),
67 NULL);
68 if (!plugin->message_view)
70 plugin->message_view = ianjuta_message_manager_add_view (message_manager,
71 _("Git"),
72 ICON_FILE,
73 NULL);
74 g_object_weak_ref (G_OBJECT (plugin->message_view),
75 (GWeakNotify) on_message_view_destroyed, plugin);
78 ianjuta_message_view_clear (plugin->message_view, NULL);
79 ianjuta_message_manager_set_current_view (message_manager,
80 plugin->message_view,
81 NULL);
84 void
85 git_pane_on_command_info_arrived (AnjutaCommand *command, Git *plugin)
87 GQueue *info;
88 gchar *message;
90 info = git_command_get_info_queue (GIT_COMMAND (command));
92 while (g_queue_peek_head (info))
94 message = g_queue_pop_head (info);
95 ianjuta_message_view_append (plugin->message_view,
96 IANJUTA_MESSAGE_VIEW_TYPE_NORMAL,
97 message, "", NULL);
98 g_free (message);
102 void
103 git_pane_set_log_view_column_label (GtkTextBuffer *buffer,
104 GtkTextIter *location,
105 GtkTextMark *mark,
106 GtkLabel *column_label)
108 gint column;
109 gchar *text;
111 column = gtk_text_iter_get_line_offset (location) + 1;
112 text = g_strdup_printf (_("Column %i"), column);
114 gtk_label_set_text (column_label, text);
116 g_free (text);
119 gchar *
120 git_pane_get_log_from_text_view (GtkTextView *text_view)
122 GtkTextBuffer *log_buffer;
123 GtkTextIter start_iter;
124 GtkTextIter end_iter;
125 gchar *log;
127 log_buffer = gtk_text_view_get_buffer(text_view);
129 gtk_text_buffer_get_start_iter(log_buffer, &start_iter);
130 gtk_text_buffer_get_end_iter(log_buffer, &end_iter) ;
132 log = gtk_text_buffer_get_text(log_buffer, &start_iter, &end_iter, FALSE);
134 return log;