[anjuta] git: Fix bgo#641079 - check number of branches selected when switching



commit d70b94fb023aa49de1bba0b1964a220fdf8ef7bc
Author: Johannes Schmid <jhs gnome org>
Date:   Mon Nov 28 22:09:19 2011 +0100

    git: Fix bgo#641079 - check number of branches selected when switching

 plugins/git/git-branches-pane.c |   33 +++++++++++++++++++++++++++++++++
 plugins/git/git-branches-pane.h |    1 +
 plugins/git/plugin.c            |    1 +
 3 files changed, 35 insertions(+), 0 deletions(-)
---
diff --git a/plugins/git/git-branches-pane.c b/plugins/git/git-branches-pane.c
index 450f6ff..468e126 100644
--- a/plugins/git/git-branches-pane.c
+++ b/plugins/git/git-branches-pane.c
@@ -41,6 +41,10 @@ struct _GitBranchesPanePriv
 	GtkBuilder *builder;
 	GHashTable *selected_local_branches;
 	GHashTable *selected_remote_branches;
+
+	GtkAction *merge_action;
+	GtkAction *delete_action;
+	GtkAction *switch_action;
 };
 
 
@@ -227,6 +231,7 @@ on_branch_selected_renderer_toggled (GtkCellRendererToggle *renderer,
 
 	gtk_list_store_set (GTK_LIST_STORE (branches_list_model), &iter, 0, selected,
 	                    -1);
+	git_branches_pane_update_ui (self);
 }
 
 static void
@@ -470,3 +475,31 @@ git_branches_pane_get_selected_branch (GitBranchesPane *self)
 	return selected_branch;
 }
 
+void git_branches_pane_update_ui (GitBranchesPane *self)
+{
+	gint n_selection;
+	
+	/* Enable only actions that make sense with the selection */
+	if (!self->priv->merge_action || 
+	    !self->priv->delete_action ||
+	    !self->priv->switch_action)
+	{
+		Git* plugin = 
+			ANJUTA_PLUGIN_GIT (anjuta_dock_pane_get_plugin (ANJUTA_DOCK_PANE (self)));
+		AnjutaCommandBar* bar = anjuta_dock_get_command_bar (ANJUTA_DOCK(plugin->dock));
+		self->priv->merge_action = anjuta_command_bar_get_action (bar,
+		                                                          "Branches",
+		                                                          "Merge");
+		self->priv->delete_action = anjuta_command_bar_get_action (bar,
+		                                                          "Branches",
+		                                                          "DeleteBranches");
+		self->priv->switch_action = anjuta_command_bar_get_action (bar,
+		                                                          "Branches",
+		                                                          "Switch");
+	}
+	n_selection = g_hash_table_size (self->priv->selected_local_branches) + 
+		g_hash_table_size (self->priv->selected_remote_branches);
+	gtk_action_set_sensitive (self->priv->merge_action, n_selection > 0);
+	gtk_action_set_sensitive (self->priv->delete_action, n_selection > 0);
+	gtk_action_set_sensitive (self->priv->switch_action, n_selection == 1);	
+}
diff --git a/plugins/git/git-branches-pane.h b/plugins/git/git-branches-pane.h
index a9af306..dfc7a01 100644
--- a/plugins/git/git-branches-pane.h
+++ b/plugins/git/git-branches-pane.h
@@ -53,6 +53,7 @@ GList *git_branches_pane_get_selected_local_branches (GitBranchesPane *self);
 GList *git_branches_pane_get_selected_remote_branches (GitBranchesPane *self);
 gsize git_branches_pane_count_selected_items (GitBranchesPane *self);
 gchar *git_branches_pane_get_selected_branch (GitBranchesPane *self);
+void git_branches_pane_update_ui (GitBranchesPane* self);
 
 G_END_DECLS
 
diff --git a/plugins/git/plugin.c b/plugins/git/plugin.c
index fe9080d..7132657 100644
--- a/plugins/git/plugin.c
+++ b/plugins/git/plugin.c
@@ -770,6 +770,7 @@ git_activate_plugin (AnjutaPlugin *plugin)
 	                      _("Branches"), NULL, git_plugin->branches_pane,   
 	                      GDL_DOCK_CENTER, branch_entries, 
 	                      G_N_ELEMENTS (branch_entries), git_plugin);
+	git_branches_pane_update_ui (GIT_BRANCHES_PANE (git_plugin->branches_pane));
 
 	git_plugin->tags_pane = git_tags_pane_new (git_plugin);
 	anjuta_dock_add_pane (ANJUTA_DOCK (git_plugin->dock), "Tags", _("Tags"),



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]