code-analyzer: Fixed bgo#667903 - Code Analyzer Crashes
[anjuta.git] / plugins / git / git-delete-branches-pane.c
blob8116def43b99a79653922b8a977c8d201dbf50ce
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-delete-branches-pane.h"
22 struct _GitDeleteBranchesPanePriv
24 GtkBuilder *builder;
27 G_DEFINE_TYPE (GitDeleteBranchesPane, git_delete_branches_pane, GIT_TYPE_PANE);
29 static void
30 on_ok_button_clicked (GtkButton *button, GitDeleteBranchesPane *self)
32 Git *plugin;
33 GtkToggleButton *require_merged_check;
34 GList *selected_local_branches;
35 GList *selected_remote_branches;
36 GitBranchDeleteCommand *local_delete_command;
37 GitBranchDeleteCommand *remote_delete_command;
38 AnjutaCommandQueue *queue;
40 plugin = ANJUTA_PLUGIN_GIT (anjuta_dock_pane_get_plugin (ANJUTA_DOCK_PANE (self)));
41 require_merged_check = GTK_TOGGLE_BUTTON (gtk_builder_get_object (self->priv->builder,
42 "require_merged_check"));
43 selected_local_branches = git_branches_pane_get_selected_local_branches (GIT_BRANCHES_PANE (plugin->branches_pane));
44 selected_remote_branches = git_branches_pane_get_selected_remote_branches (GIT_BRANCHES_PANE (plugin->branches_pane));
46 /* The user might not have selected anything */
47 if (git_branches_pane_count_selected_items (GIT_BRANCHES_PANE (plugin->branches_pane)) > 0)
49 queue = anjuta_command_queue_new (ANJUTA_COMMAND_QUEUE_EXECUTE_MANUAL);
51 if (selected_local_branches)
53 local_delete_command = git_branch_delete_command_new (plugin->project_root_directory,
54 selected_local_branches,
55 FALSE,
56 gtk_toggle_button_get_active (require_merged_check));
58 anjuta_util_glist_strings_free (selected_local_branches);
60 g_signal_connect (G_OBJECT (local_delete_command),
61 "command-finished",
62 G_CALLBACK (git_pane_report_errors),
63 plugin);
66 g_signal_connect (G_OBJECT (local_delete_command),
67 "command-finished",
68 G_CALLBACK (g_object_unref),
69 NULL);
71 anjuta_command_queue_push (queue,
72 ANJUTA_COMMAND (local_delete_command));
75 if (selected_remote_branches)
77 remote_delete_command = git_branch_delete_command_new (plugin->project_root_directory,
78 selected_remote_branches,
79 TRUE,
80 gtk_toggle_button_get_active (require_merged_check));
82 anjuta_util_glist_strings_free (selected_remote_branches);
84 g_signal_connect (G_OBJECT (remote_delete_command),
85 "command-finished",
86 G_CALLBACK (git_pane_report_errors),
87 plugin);
90 g_signal_connect (G_OBJECT (remote_delete_command), "command-finished",
91 G_CALLBACK (g_object_unref),
92 NULL);
94 anjuta_command_queue_push (queue,
95 ANJUTA_COMMAND (remote_delete_command));
98 /* Run the commands */
99 g_signal_connect (G_OBJECT (queue), "finished",
100 G_CALLBACK (g_object_unref),
101 NULL);
103 anjuta_command_queue_start (queue);
107 git_pane_remove_from_dock (GIT_PANE (self));
111 static void
112 git_delete_branches_pane_init (GitDeleteBranchesPane *self)
114 gchar *objects[] = {"delete_branches_pane",
115 NULL};
116 GError *error = NULL;
117 GtkButton *ok_button;
118 GtkButton *cancel_button;
120 self->priv = g_new0 (GitDeleteBranchesPanePriv, 1);
121 self->priv->builder = gtk_builder_new ();
123 if (!gtk_builder_add_objects_from_file (self->priv->builder, BUILDER_FILE,
124 objects,
125 &error))
127 g_warning ("Couldn't load builder file: %s", error->message);
128 g_error_free (error);
131 ok_button = GTK_BUTTON (gtk_builder_get_object (self->priv->builder,
132 "ok_button"));
133 cancel_button = GTK_BUTTON (gtk_builder_get_object (self->priv->builder,
134 "cancel_button"));
136 g_signal_connect (G_OBJECT (ok_button), "clicked",
137 G_CALLBACK (on_ok_button_clicked),
138 self);
140 g_signal_connect_swapped (G_OBJECT (cancel_button), "clicked",
141 G_CALLBACK (git_pane_remove_from_dock),
142 self);
145 static void
146 git_delete_branches_pane_finalize (GObject *object)
148 GitDeleteBranchesPane *self;
150 self = GIT_DELETE_BRANCHES_PANE (object);
152 g_object_unref (self->priv->builder);
153 g_free (self->priv);
155 G_OBJECT_CLASS (git_delete_branches_pane_parent_class)->finalize (object);
158 static GtkWidget *
159 get_widget (AnjutaDockPane *pane)
161 GitDeleteBranchesPane *self;
163 self = GIT_DELETE_BRANCHES_PANE (pane);
165 return GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
166 "delete_branches_pane"));
169 static void
170 git_delete_branches_pane_class_init (GitDeleteBranchesPaneClass *klass)
172 GObjectClass* object_class = G_OBJECT_CLASS (klass);
173 AnjutaDockPaneClass* pane_class = ANJUTA_DOCK_PANE_CLASS (klass);
175 object_class->finalize = git_delete_branches_pane_finalize;
176 pane_class->get_widget = get_widget;
177 pane_class->refresh = NULL;
181 AnjutaDockPane *
182 git_delete_branches_pane_new (Git *plugin)
184 return g_object_new (GIT_TYPE_DELETE_BRANCHES_PANE, "plugin", plugin, NULL);
187 void
188 on_delete_branches_button_clicked (GtkAction *action, Git *plugin)
190 AnjutaDockPane *delete_branches_pane;
192 delete_branches_pane = git_delete_branches_pane_new (plugin);
194 anjuta_dock_replace_command_pane (ANJUTA_DOCK (plugin->dock), "DeleteBranches",
195 "Delete Branches", NULL, delete_branches_pane,
196 GDL_DOCK_BOTTOM, NULL, 0, NULL);