1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) James Liggett 2010 <jrliggett@cox.net>
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
27 G_DEFINE_TYPE (GitDeleteBranchesPane
, git_delete_branches_pane
, GIT_TYPE_PANE
);
30 on_ok_action_activated (GtkAction
*action
, GitDeleteBranchesPane
*self
)
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
,
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
),
62 G_CALLBACK (git_pane_report_errors
),
66 g_signal_connect (G_OBJECT (local_delete_command
),
68 G_CALLBACK (g_object_unref
),
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
,
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
),
86 G_CALLBACK (git_pane_report_errors
),
90 g_signal_connect (G_OBJECT (remote_delete_command
), "command-finished",
91 G_CALLBACK (g_object_unref
),
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
),
103 anjuta_command_queue_start (queue
);
107 git_pane_remove_from_dock (GIT_PANE (self
));
112 on_delete_branches_pane_map (GtkWidget
*widget
, GitBranchesPane
*branches_pane
)
114 git_branches_pane_set_select_column_visible (branches_pane
, TRUE
);
118 on_delete_branches_pane_unmap (GtkWidget
*widget
, GitBranchesPane
*branches_pane
)
120 git_branches_pane_set_select_column_visible (branches_pane
, FALSE
);
124 git_delete_branches_pane_init (GitDeleteBranchesPane
*self
)
126 gchar
*objects
[] = {"delete_branches_pane",
130 GError
*error
= NULL
;
131 GtkAction
*ok_action
;
132 GtkAction
*cancel_action
;
134 self
->priv
= g_new0 (GitDeleteBranchesPanePriv
, 1);
135 self
->priv
->builder
= gtk_builder_new ();
137 if (!gtk_builder_add_objects_from_file (self
->priv
->builder
, BUILDER_FILE
,
141 g_warning ("Couldn't load builder file: %s", error
->message
);
142 g_error_free (error
);
145 ok_action
= GTK_ACTION (gtk_builder_get_object (self
->priv
->builder
,
147 cancel_action
= GTK_ACTION (gtk_builder_get_object (self
->priv
->builder
,
150 g_signal_connect (G_OBJECT (ok_action
), "activate",
151 G_CALLBACK (on_ok_action_activated
),
154 g_signal_connect_swapped (G_OBJECT (cancel_action
), "activate",
155 G_CALLBACK (git_pane_remove_from_dock
),
160 git_delete_branches_pane_finalize (GObject
*object
)
162 GitDeleteBranchesPane
*self
;
164 self
= GIT_DELETE_BRANCHES_PANE (object
);
166 g_object_unref (self
->priv
->builder
);
169 G_OBJECT_CLASS (git_delete_branches_pane_parent_class
)->finalize (object
);
173 get_widget (AnjutaDockPane
*pane
)
175 GitDeleteBranchesPane
*self
;
177 self
= GIT_DELETE_BRANCHES_PANE (pane
);
179 return GTK_WIDGET (gtk_builder_get_object (self
->priv
->builder
,
180 "delete_branches_pane"));
184 git_delete_branches_pane_class_init (GitDeleteBranchesPaneClass
*klass
)
186 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
187 AnjutaDockPaneClass
* pane_class
= ANJUTA_DOCK_PANE_CLASS (klass
);
189 object_class
->finalize
= git_delete_branches_pane_finalize
;
190 pane_class
->get_widget
= get_widget
;
191 pane_class
->refresh
= NULL
;
196 git_delete_branches_pane_new (Git
*plugin
)
198 GitDeleteBranchesPane
*self
;
199 GtkWidget
*delete_branches_pane
;
201 self
= g_object_new (GIT_TYPE_DELETE_BRANCHES_PANE
, "plugin", plugin
, NULL
);
202 delete_branches_pane
= GTK_WIDGET (gtk_builder_get_object (self
->priv
->builder
,
203 "delete_branches_pane"));
205 g_signal_connect (G_OBJECT (delete_branches_pane
), "map",
206 G_CALLBACK (on_delete_branches_pane_map
),
207 plugin
->branches_pane
);
209 g_signal_connect (G_OBJECT (delete_branches_pane
), "unmap",
210 G_CALLBACK (on_delete_branches_pane_unmap
),
211 plugin
->branches_pane
);
213 return ANJUTA_DOCK_PANE (self
);
217 on_delete_branches_button_clicked (GtkAction
*action
, Git
*plugin
)
219 AnjutaDockPane
*delete_branches_pane
;
221 delete_branches_pane
= git_delete_branches_pane_new (plugin
);
223 anjuta_dock_replace_command_pane (ANJUTA_DOCK (plugin
->dock
), "DeleteBranches",
224 "Delete Branches", NULL
, delete_branches_pane
,
225 GDL_DOCK_BOTTOM
, NULL
, 0, NULL
);
229 on_git_branch_delete_activated (GtkAction
*action
, Git
*plugin
)
231 gchar
*selected_branch
;
233 GitBranchDeleteCommand
*delete_command
;
235 selected_branch
= git_branches_pane_get_selected_branch (GIT_BRANCHES_PANE (plugin
->branches_pane
));
237 if (anjuta_util_dialog_boolean_question (NULL
, FALSE
,
238 _("Are you sure you want to delete branch %s?"),
241 branches
= g_list_append (NULL
, selected_branch
);
242 delete_command
= git_branch_delete_command_new (plugin
->project_root_directory
,
244 git_branches_pane_is_selected_branch_remote (GIT_BRANCHES_PANE (plugin
->branches_pane
)),
247 g_list_free (branches
);
249 g_signal_connect (G_OBJECT (delete_command
), "command-finished",
250 G_CALLBACK (git_pane_report_errors
),
253 g_signal_connect (G_OBJECT (delete_command
), "command-finished",
254 G_CALLBACK (g_object_unref
),
257 anjuta_command_start (ANJUTA_COMMAND (delete_command
));
260 g_free (selected_branch
);