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_button_clicked (GtkButton
*button
, 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 git_delete_branches_pane_init (GitDeleteBranchesPane
*self
)
114 gchar
*objects
[] = {"delete_branches_pane",
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
,
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
,
133 cancel_button
= GTK_BUTTON (gtk_builder_get_object (self
->priv
->builder
,
136 g_signal_connect (G_OBJECT (ok_button
), "clicked",
137 G_CALLBACK (on_ok_button_clicked
),
140 g_signal_connect_swapped (G_OBJECT (cancel_button
), "clicked",
141 G_CALLBACK (git_pane_remove_from_dock
),
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
);
155 G_OBJECT_CLASS (git_delete_branches_pane_parent_class
)->finalize (object
);
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"));
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
;
182 git_delete_branches_pane_new (Git
*plugin
)
184 return g_object_new (GIT_TYPE_DELETE_BRANCHES_PANE
, "plugin", plugin
, NULL
);
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
);