code-analyzer: Fixed bgo#667903 - Code Analyzer Crashes
[anjuta.git] / plugins / git / git-cherry-pick-pane.c
blob97327b4bdcaa574216d9c8bbb9c1c1b8952cbb48
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-cherry-pick-pane.h"
22 struct _GitCherryPickPanePriv
24 GtkBuilder *builder;
27 G_DEFINE_TYPE (GitCherryPickPane, git_cherry_pick_pane, GIT_TYPE_PANE);
29 static void
30 on_ok_button_clicked (GtkButton *button, GitCherryPickPane *self)
32 Git *plugin;
33 AnjutaEntry *revision_entry;
34 GtkToggleButton *no_commit_check;
35 GtkToggleButton *show_source_check;
36 GtkToggleButton *signoff_check;
37 gchar *revision;
38 GitCherryPickCommand *cherry_pick_command;
40 plugin = ANJUTA_PLUGIN_GIT (anjuta_dock_pane_get_plugin (ANJUTA_DOCK_PANE (self)));
41 revision_entry = ANJUTA_ENTRY (gtk_builder_get_object (self->priv->builder,
42 "revision_entry"));
43 no_commit_check = GTK_TOGGLE_BUTTON (gtk_builder_get_object (self->priv->builder,
44 "no_commit_check"));
45 show_source_check = GTK_TOGGLE_BUTTON (gtk_builder_get_object (self->priv->builder,
46 "show_source_check"));
47 signoff_check = GTK_TOGGLE_BUTTON (gtk_builder_get_object (self->priv->builder,
48 "signoff_check"));
49 revision = anjuta_entry_dup_text (revision_entry);
51 if (!git_pane_check_input (GTK_WIDGET (ANJUTA_PLUGIN (plugin)->shell),
52 GTK_WIDGET (revision_entry), revision,
53 _("Please enter a revision.")))
55 g_free (revision);
56 return;
59 cherry_pick_command = git_cherry_pick_command_new (plugin->project_root_directory,
60 revision,
61 gtk_toggle_button_get_active (no_commit_check),
62 gtk_toggle_button_get_active (show_source_check),
63 gtk_toggle_button_get_active (signoff_check));
65 git_pane_create_message_view (plugin);
67 g_signal_connect (G_OBJECT (cherry_pick_command), "data-arrived",
68 G_CALLBACK (git_pane_on_command_info_arrived),
69 plugin);
71 g_signal_connect (G_OBJECT (cherry_pick_command), "command-finished",
72 G_CALLBACK (git_pane_report_errors),
73 plugin);
76 g_signal_connect (G_OBJECT (cherry_pick_command), "command-finished",
77 G_CALLBACK (g_object_unref),
78 NULL);
80 anjuta_command_start (ANJUTA_COMMAND (cherry_pick_command));
82 g_free (revision);
84 git_pane_remove_from_dock (GIT_PANE (self));
88 static void
89 git_cherry_pick_pane_init (GitCherryPickPane *self)
91 gchar *objects[] = {"cherry_pick_pane",
92 NULL};
93 GError *error = NULL;
94 GtkWidget *ok_button;
95 GtkWidget *cancel_button;
98 self->priv = g_new0 (GitCherryPickPanePriv, 1);
99 self->priv->builder = gtk_builder_new ();
101 if (!gtk_builder_add_objects_from_file (self->priv->builder, BUILDER_FILE,
102 objects,
103 &error))
105 g_warning ("Couldn't load builder file: %s", error->message);
106 g_error_free (error);
109 ok_button = GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
110 "ok_button"));
111 cancel_button = GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
112 "cancel_button"));
114 g_signal_connect (G_OBJECT (ok_button), "clicked",
115 G_CALLBACK (on_ok_button_clicked),
116 self);
118 g_signal_connect_swapped (G_OBJECT (cancel_button), "clicked",
119 G_CALLBACK (git_pane_remove_from_dock),
120 self);
123 static void
124 git_cherry_pick_pane_finalize (GObject *object)
126 GitCherryPickPane *self;
128 self = GIT_CHERRY_PICK_PANE (object);
130 g_object_unref (self->priv->builder);
131 g_free (self->priv);
133 G_OBJECT_CLASS (git_cherry_pick_pane_parent_class)->finalize (object);
136 static GtkWidget *
137 git_cherry_pick_pane_get_widget (AnjutaDockPane *pane)
139 GitCherryPickPane *self;
141 self = GIT_CHERRY_PICK_PANE (pane);
143 return GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
144 "cherry_pick_pane"));
147 static void
148 git_cherry_pick_pane_class_init (GitCherryPickPaneClass *klass)
150 GObjectClass* object_class = G_OBJECT_CLASS (klass);
151 AnjutaDockPaneClass *pane_class = ANJUTA_DOCK_PANE_CLASS (klass);
153 object_class->finalize = git_cherry_pick_pane_finalize;
154 pane_class->get_widget = git_cherry_pick_pane_get_widget;
155 pane_class->refresh = NULL;
159 AnjutaDockPane *
160 git_cherry_pick_pane_new (Git *plugin)
162 return g_object_new (GIT_TYPE_CHERRY_PICK_PANE, "plugin", plugin, NULL);
165 void
166 on_cherry_pick_button_clicked (GtkAction *action, Git *plugin)
168 AnjutaDockPane *pane;
170 pane = git_cherry_pick_pane_new (plugin);
172 anjuta_dock_replace_command_pane (ANJUTA_DOCK (plugin->dock), "CherryPick",
173 _("Cherry Pick"), NULL, pane, GDL_DOCK_BOTTOM, NULL,
174 0, NULL);