code-analyzer: Fixed bgo#667903 - Code Analyzer Crashes
[anjuta.git] / plugins / git / git-merge-pane.c
blob01b974e5f50bcc6e21167ff351f44a60cfc79b3f
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-merge-pane.h"
22 struct _GitMergePanePriv
24 GtkBuilder *builder;
27 G_DEFINE_TYPE (GitMergePane, git_merge_pane, GIT_TYPE_PANE);
29 static void
30 on_ok_button_clicked (GtkButton *button, GitMergePane *self)
32 Git *plugin;
33 GtkEditable *revision_entry;
34 GtkToggleButton *do_not_commit_check;
35 GtkToggleButton *squash_check;
36 GtkToggleButton *use_custom_log_check;
37 gchar *revision;
38 gchar *log;
39 AnjutaColumnTextView *log_view;
40 GitMergeCommand *merge_command;
42 plugin = ANJUTA_PLUGIN_GIT (anjuta_dock_pane_get_plugin (ANJUTA_DOCK_PANE (self)));
43 revision_entry = GTK_EDITABLE (gtk_builder_get_object (self->priv->builder,
44 "revision_entry"));
45 do_not_commit_check = GTK_TOGGLE_BUTTON (gtk_builder_get_object (self->priv->builder,
46 "do_not_commit_check"));
47 squash_check = GTK_TOGGLE_BUTTON (gtk_builder_get_object (self->priv->builder,
48 "squash_check"));
49 use_custom_log_check = GTK_TOGGLE_BUTTON (gtk_builder_get_object (self->priv->builder,
50 "use_custom_log_check"));
51 revision = gtk_editable_get_chars (revision_entry, 0, -1);
52 log = NULL;
54 if (!git_pane_check_input (GTK_WIDGET (ANJUTA_PLUGIN (plugin)->shell),
55 GTK_WIDGET (revision_entry), revision,
56 _("Please enter a revision.")))
58 g_free (revision);
59 return;
62 if (gtk_toggle_button_get_active (use_custom_log_check))
64 log_view = ANJUTA_COLUMN_TEXT_VIEW (gtk_builder_get_object (self->priv->builder,
65 "log_view"));
66 log = anjuta_column_text_view_get_text (log_view);
68 if (!git_pane_check_input (GTK_WIDGET (ANJUTA_PLUGIN (plugin)->shell),
69 GTK_WIDGET (log_view), log,
70 _("Please enter a log message.")))
72 g_free (revision);
73 g_free (log);
74 return;
78 merge_command = git_merge_command_new (plugin->project_root_directory,
79 revision, log,
80 gtk_toggle_button_get_active (do_not_commit_check),
81 gtk_toggle_button_get_active (squash_check));
83 g_free (revision);
84 g_free (log);
86 git_pane_create_message_view (plugin);
88 g_signal_connect (G_OBJECT (merge_command), "data-arrived",
89 G_CALLBACK (git_pane_on_command_info_arrived),
90 plugin);
92 g_signal_connect (G_OBJECT (merge_command), "command-finished",
93 G_CALLBACK (git_pane_report_errors),
94 plugin);
96 g_signal_connect (G_OBJECT (merge_command), "command-finished",
97 G_CALLBACK (g_object_unref),
98 NULL);
100 anjuta_command_start (ANJUTA_COMMAND (merge_command));
103 git_pane_remove_from_dock (GIT_PANE (self));
106 static void
107 on_use_custom_log_check_toggled (GtkToggleButton *button, GitMergePane *self)
109 GtkWidget *log_view;
110 gboolean active;
112 log_view = GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
113 "log_view"));
114 active = gtk_toggle_button_get_active (button);
116 gtk_widget_set_sensitive (log_view, active);
119 static void
120 git_merge_pane_init (GitMergePane *self)
122 gchar *objects[] = {"merge_pane",
123 NULL};
124 GError *error = NULL;
125 GtkWidget *ok_button;
126 GtkWidget *cancel_button;
127 GtkWidget *use_custom_log_check;
129 self->priv = g_new0 (GitMergePanePriv, 1);
130 self->priv->builder = gtk_builder_new ();
132 if (!gtk_builder_add_objects_from_file (self->priv->builder, BUILDER_FILE,
133 objects,
134 &error))
136 g_warning ("Couldn't load builder file: %s", error->message);
137 g_error_free (error);
140 ok_button = GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
141 "ok_button"));
142 cancel_button = GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
143 "cancel_button"));
144 use_custom_log_check = GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
145 "use_custom_log_check"));
147 g_signal_connect (G_OBJECT (ok_button), "clicked",
148 G_CALLBACK (on_ok_button_clicked),
149 self);
151 g_signal_connect_swapped (G_OBJECT (cancel_button), "clicked",
152 G_CALLBACK (git_pane_remove_from_dock),
153 self);
155 g_signal_connect (G_OBJECT (use_custom_log_check), "toggled",
156 G_CALLBACK (on_use_custom_log_check_toggled),
157 self);
160 static void
161 git_merge_pane_finalize (GObject *object)
163 GitMergePane *self;
165 self = GIT_MERGE_PANE (object);
167 g_object_unref (self->priv->builder);
168 g_free (self->priv);
170 G_OBJECT_CLASS (git_merge_pane_parent_class)->finalize (object);
173 static GtkWidget *
174 git_merge_pane_get_widget (AnjutaDockPane *pane)
176 GitMergePane *self;
178 self = GIT_MERGE_PANE (pane);
180 return GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
181 "merge_pane"));
184 static void
185 git_merge_pane_class_init (GitMergePaneClass *klass)
187 GObjectClass* object_class = G_OBJECT_CLASS (klass);
188 AnjutaDockPaneClass *pane_class = ANJUTA_DOCK_PANE_CLASS (klass);
190 object_class->finalize = git_merge_pane_finalize;
191 pane_class->get_widget = git_merge_pane_get_widget;
192 pane_class->refresh = NULL;
196 AnjutaDockPane *
197 git_merge_pane_new (Git *plugin)
199 return g_object_new (GIT_TYPE_MERGE_PANE, "plugin", plugin, NULL);
202 void
203 on_merge_button_clicked (GtkAction *action, Git *plugin)
205 AnjutaDockPane *pane;
207 pane = git_merge_pane_new (plugin);
209 anjuta_dock_replace_command_pane (ANJUTA_DOCK (plugin->dock), "Merge",
210 _("Merge"), NULL, pane, GDL_DOCK_BOTTOM, NULL, 0,
211 NULL);