Updated Swedish translation
[anjuta.git] / plugins / git / git-commit-pane.c
blob58f7f6da4348a7fd918761bf5f454334a2991791
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * anjuta
4 * Copyright (C) James Liggett 2010 <jrliggett@cox.net>
5 *
6 * anjuta 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 * anjuta 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-commit-pane.h"
22 struct _GitCommitPanePriv
24 GtkBuilder *builder;
27 G_DEFINE_TYPE (GitCommitPane, git_commit_pane, GIT_TYPE_PANE);
29 static void
30 on_amend_check_toggled (GtkToggleButton *button, GitCommitPane *self)
32 Git *plugin;
33 AnjutaColumnTextView *commit_log_view;
34 GtkTextBuffer *log_text_buffer;
35 gchar *commit_message_path;
36 GIOChannel *io_channel;
37 gchar *line;
38 GtkTextIter end_iter;
40 plugin = ANJUTA_PLUGIN_GIT (anjuta_dock_pane_get_plugin (ANJUTA_DOCK_PANE (self)));
41 commit_log_view = ANJUTA_COLUMN_TEXT_VIEW (gtk_builder_get_object (self->priv->builder,
42 "commit_log_view"));
43 log_text_buffer = anjuta_column_text_view_get_buffer (commit_log_view);
45 /* Make sure to clear any pre-existing text */
46 gtk_text_buffer_set_text (log_text_buffer, "", 0);
48 if (gtk_toggle_button_get_active (button))
50 commit_message_path = g_strjoin (G_DIR_SEPARATOR_S,
51 plugin->project_root_directory,
52 ".git",
53 "COMMIT_EDITMSG",
54 NULL);
55 io_channel = g_io_channel_new_file (commit_message_path, "r", NULL);
57 while (g_io_channel_read_line (io_channel, &line, NULL, NULL,
58 NULL) == G_IO_STATUS_NORMAL)
60 /* Filter out comment lines */
61 if (line[0] != '#')
63 gtk_text_buffer_get_end_iter (log_text_buffer, &end_iter);
64 gtk_text_buffer_insert (log_text_buffer, &end_iter, line, -1);
66 g_free (line);
68 else
70 g_free (line);
71 break;
75 g_free (commit_message_path);
76 g_io_channel_unref (io_channel);
80 static void
81 on_use_custom_author_info_check_toggled (GtkToggleButton *button,
82 GitCommitPane *self)
84 GtkWidget *author_info_alignment;
86 author_info_alignment = GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
87 "author_info_alignment"));
89 gtk_widget_set_sensitive (author_info_alignment,
90 gtk_toggle_button_get_active (button));
93 static void
94 on_ok_action_activated (GtkAction *action, GitCommitPane *self)
96 Git *plugin;
97 AnjutaColumnTextView *commit_log_view;
98 GtkToggleButton *amend_check;
99 GtkToggleButton *failed_merge_check;
100 GtkToggleButton *use_custom_author_info_check;
101 gchar *log;
102 gchar *author_name;
103 gchar *author_email;
104 GtkEditable *author_name_entry;
105 GtkEditable *author_email_entry;
106 GList *selected_paths;
107 GitCommitCommand *commit_command;
109 plugin = ANJUTA_PLUGIN_GIT (anjuta_dock_pane_get_plugin (ANJUTA_DOCK_PANE(self)));
110 commit_log_view = ANJUTA_COLUMN_TEXT_VIEW (gtk_builder_get_object (self->priv->builder,
111 "commit_log_view"));
112 amend_check = GTK_TOGGLE_BUTTON (gtk_builder_get_object (self->priv->builder,
113 "amend_check"));
114 failed_merge_check = GTK_TOGGLE_BUTTON (gtk_builder_get_object (self->priv->builder,
115 "failed_merge_check"));
116 use_custom_author_info_check = GTK_TOGGLE_BUTTON (gtk_builder_get_object (self->priv->builder,
117 "use_custom_author_info_check"));
118 log = anjuta_column_text_view_get_text (commit_log_view);
119 author_name = NULL;
120 author_email = NULL;
122 if (!git_pane_check_input (GTK_WIDGET (ANJUTA_PLUGIN (plugin)->shell),
123 GTK_WIDGET (commit_log_view), log,
124 _("Please enter a log message.")))
126 g_free (log);
128 return;
131 if (gtk_toggle_button_get_active (use_custom_author_info_check))
133 author_name_entry = GTK_EDITABLE (gtk_builder_get_object (self->priv->builder,
134 "author_name_entry"));
135 author_email_entry = GTK_EDITABLE (gtk_builder_get_object (self->priv->builder,
136 "author_email_entry"));
138 author_name = gtk_editable_get_chars (author_name_entry, 0, -1);
139 author_email = gtk_editable_get_chars (author_email_entry, 0, -1);
141 /* Check both the name and e-mail fields with one statement instead of
142 * two */
143 if (!git_pane_check_input (GTK_WIDGET (ANJUTA_PLUGIN (plugin)->shell),
144 GTK_WIDGET (author_name_entry), author_name,
145 _("Please enter the commit author's name")) ||
146 !git_pane_check_input (GTK_WIDGET (ANJUTA_PLUGIN (plugin)->shell),
147 GTK_WIDGET (author_email_entry),
148 author_email,
149 _("Please enter the commit author's e-mail address.")))
151 g_free (log);
152 g_free (author_name);
153 g_free (author_email);
155 return;
159 selected_paths = git_status_pane_get_all_checked_items (GIT_STATUS_PANE (plugin->status_pane),
160 ANJUTA_VCS_STATUS_ALL);
162 commit_command = git_commit_command_new (plugin->project_root_directory,
163 gtk_toggle_button_get_active (amend_check),
164 gtk_toggle_button_get_active (failed_merge_check),
165 log,
166 author_name,
167 author_email,
168 selected_paths);
170 g_free (log);
171 g_free (author_name);
172 g_free (author_email);
173 anjuta_util_glist_strings_free (selected_paths);
175 git_pane_create_message_view (plugin);
177 g_signal_connect (G_OBJECT (commit_command), "data-arrived",
178 G_CALLBACK (git_pane_on_command_info_arrived),
179 plugin);
181 g_signal_connect (G_OBJECT (commit_command), "command-finished",
182 G_CALLBACK (git_pane_report_errors),
183 plugin);
185 g_signal_connect (G_OBJECT (commit_command), "command-finished",
186 G_CALLBACK (git_plugin_status_changed_emit),
187 plugin);
189 g_signal_connect (G_OBJECT (commit_command), "command-finished",
190 G_CALLBACK (g_object_unref),
191 NULL);
193 anjuta_command_start (ANJUTA_COMMAND (commit_command));
195 git_pane_remove_from_dock (GIT_PANE (self));
198 static void
199 git_commit_pane_init (GitCommitPane *self)
201 gchar *objects[] = {"commit_pane",
202 "ok_action",
203 "cancel_action",
204 NULL};
205 GError *error = NULL;
206 GtkWidget *amend_check;
207 GtkWidget *use_custom_author_info_check;
208 GtkAction *ok_action;
209 GtkAction *cancel_action;
211 self->priv = g_new0 (GitCommitPanePriv, 1);
212 self->priv->builder = gtk_builder_new ();
214 if (!gtk_builder_add_objects_from_file (self->priv->builder, BUILDER_FILE,
215 objects,
216 &error))
218 g_warning ("Couldn't load builder file: %s", error->message);
219 g_error_free (error);
222 amend_check = GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
223 "amend_check"));
224 use_custom_author_info_check = GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
225 "use_custom_author_info_check"));
226 ok_action = GTK_ACTION (gtk_builder_get_object (self->priv->builder,
227 "ok_action"));
228 cancel_action = GTK_ACTION (gtk_builder_get_object (self->priv->builder,
229 "cancel_action"));
231 g_signal_connect (G_OBJECT (amend_check), "toggled",
232 G_CALLBACK (on_amend_check_toggled),
233 self);
235 g_signal_connect (G_OBJECT (use_custom_author_info_check), "toggled",
236 G_CALLBACK (on_use_custom_author_info_check_toggled),
237 self);
239 g_signal_connect (G_OBJECT (ok_action), "activate",
240 G_CALLBACK (on_ok_action_activated),
241 self);
243 g_signal_connect_swapped (G_OBJECT (cancel_action), "activate",
244 G_CALLBACK (git_pane_remove_from_dock),
245 self);
249 static void
250 git_commit_pane_finalize (GObject *object)
252 GitCommitPane *self;
254 self = GIT_COMMIT_PANE (object);
256 g_object_unref (self->priv->builder);
257 g_free (self->priv);
259 G_OBJECT_CLASS (git_commit_pane_parent_class)->finalize (object);
262 static GtkWidget *
263 git_commit_pane_get_widget (AnjutaDockPane *pane)
265 GitCommitPane *self;
267 self = GIT_COMMIT_PANE (pane);
269 return GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
270 "commit_pane"));
273 static void
274 git_commit_pane_class_init (GitCommitPaneClass *klass)
276 GObjectClass* object_class = G_OBJECT_CLASS (klass);
277 AnjutaDockPaneClass* pane_class = ANJUTA_DOCK_PANE_CLASS (klass);
279 object_class->finalize = git_commit_pane_finalize;
280 pane_class->get_widget = git_commit_pane_get_widget;
281 pane_class->refresh = NULL;
285 AnjutaDockPane *
286 git_commit_pane_new (Git *plugin)
288 return g_object_new (GIT_TYPE_COMMIT_PANE, "plugin", plugin, NULL);
291 void
292 on_commit_button_clicked (GtkAction *action, Git *plugin)
294 AnjutaDockPane *pane;
296 pane = git_commit_pane_new (plugin);
298 anjuta_dock_replace_command_pane (ANJUTA_DOCK (plugin->dock),
299 "Commit", _("Commit"),
300 NULL, pane, GDL_DOCK_BOTTOM, NULL, 0, NULL);