[anjuta] git: Support selecting branches in the push dialog



commit e16cad0e2384b698a96416b7898f9fea0a324475
Author: James Liggett <jrliggett cox net>
Date:   Thu Jun 11 17:00:15 2009 -0700

    git: Support selecting branches in the push dialog

 plugins/git/anjuta-git.ui      |   65 +++++++++++++++++++++++++++++++++++++++-
 plugins/git/git-push-command.c |   11 +++++-
 plugins/git/git-push-command.h |    3 +-
 plugins/git/git-push-dialog.c  |   38 ++++++++++++++++++++++-
 plugins/git/git-ui-utils.c     |   60 ++++++++++++++++++++++++++++++++++++
 plugins/git/git-ui-utils.h     |    6 ++++
 6 files changed, 178 insertions(+), 5 deletions(-)
---
diff --git a/plugins/git/anjuta-git.ui b/plugins/git/anjuta-git.ui
index f91ef26..fb11374 100644
--- a/plugins/git/anjuta-git.ui
+++ b/plugins/git/anjuta-git.ui
@@ -4203,6 +4203,69 @@
               </packing>
             </child>
             <child>
+              <object class="GtkFrame" id="frame1">
+                <property name="visible">True</property>
+                <property name="label_xalign">0</property>
+                <property name="shadow_type">none</property>
+                <child>
+                  <object class="GtkAlignment" id="alignment1">
+                    <property name="visible">True</property>
+                    <property name="left_padding">12</property>
+                    <child>
+                      <object class="GtkScrolledWindow" id="push_branches_scrolled_window">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="hscrollbar_policy">automatic</property>
+                        <property name="vscrollbar_policy">automatic</property>
+                        <property name="shadow_type">in</property>
+                        <child>
+                          <object class="GtkTreeView" id="push_branches_view">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="model">branch_list_model</property>
+                            <property name="headers_visible">False</property>
+                            <property name="search_column">1</property>
+                            <child>
+                              <object class="GtkTreeViewColumn" id="treeviewcolumn1">
+                                <property name="title">column</property>
+                                <child>
+                                  <object class="GtkCellRendererToggle" id="push_branches_view_selected_renderer"/>
+                                  <attributes>
+                                    <attribute name="active">0</attribute>
+                                  </attributes>
+                                </child>
+                              </object>
+                            </child>
+                            <child>
+                              <object class="GtkTreeViewColumn" id="treeviewcolumn2">
+                                <property name="title">column</property>
+                                <child>
+                                  <object class="GtkCellRendererText" id="push_branches_view_name_renderer"/>
+                                  <attributes>
+                                    <attribute name="text">1</attribute>
+                                  </attributes>
+                                </child>
+                              </object>
+                            </child>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+                <child type="label">
+                  <object class="GtkLabel" id="label1">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">&lt;b&gt;Branches&lt;/b&gt;</property>
+                    <property name="use_markup">True</property>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="position">1</property>
+              </packing>
+            </child>
+            <child>
               <object class="GtkFrame" id="frame45">
                 <property name="visible">True</property>
                 <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
@@ -4256,7 +4319,7 @@
               </object>
               <packing>
                 <property name="expand">False</property>
-                <property name="position">1</property>
+                <property name="position">2</property>
               </packing>
             </child>
           </object>
diff --git a/plugins/git/git-push-command.c b/plugins/git/git-push-command.c
index 9871e99..ba51aaf 100644
--- a/plugins/git/git-push-command.c
+++ b/plugins/git/git-push-command.c
@@ -26,7 +26,8 @@
 
 struct _GitPushCommandPriv
 {
-	gchar *url; 
+	gchar *url;
+	GList *refs;
 	gboolean push_all;
 	gboolean push_tags;
 };
@@ -47,6 +48,7 @@ git_push_command_finalize (GObject *object)
 	self = GIT_PUSH_COMMAND (object);
 	
 	g_free (self->priv->url);
+	git_command_free_path_list (self->priv->refs);
 	g_free (self->priv);
 
 	G_OBJECT_CLASS (git_push_command_parent_class)->finalize (object);
@@ -68,6 +70,9 @@ git_push_command_run (AnjutaCommand *command)
 		git_command_add_arg (GIT_COMMAND (command), "--tags");
 	
 	git_command_add_arg (GIT_COMMAND (command), self->priv->url);
+
+	if (self->priv->refs)
+		git_command_add_list_to_args (GIT_COMMAND (command), self->priv->refs);
 	
 	return 0;
 }
@@ -87,7 +92,8 @@ git_push_command_class_init (GitPushCommandClass *klass)
 
 GitPushCommand *
 git_push_command_new (const gchar *working_directory,
-					  const gchar *url, 
+					  const gchar *url,
+					  GList *refs,
 					  gboolean push_all, 
                       gboolean push_tags)
 {
@@ -99,6 +105,7 @@ git_push_command_new (const gchar *working_directory,
 						  NULL);
 	
 	self->priv->url = g_strdup (url);
+	self->priv->refs = git_command_copy_path_list (refs);
 	self->priv->push_all = push_all;
 	self->priv->push_tags = push_tags;
 	
diff --git a/plugins/git/git-push-command.h b/plugins/git/git-push-command.h
index f7d8550..ee4a80e 100644
--- a/plugins/git/git-push-command.h
+++ b/plugins/git/git-push-command.h
@@ -55,7 +55,8 @@ struct _GitPushCommand
 
 GType git_push_command_get_type (void) G_GNUC_CONST;
 GitPushCommand *git_push_command_new (const gchar *working_directory,
-									  const gchar *url, 
+									  const gchar *url,
+									  GList *refs,
 									  gboolean push_all, 
                                       gboolean push_tags);
 
diff --git a/plugins/git/git-push-dialog.c b/plugins/git/git-push-dialog.c
index e3eaa81..8ad0ced 100644
--- a/plugins/git/git-push-dialog.c
+++ b/plugins/git/git-push-dialog.c
@@ -49,7 +49,9 @@ on_push_dialog_response (GtkDialog *dialog, gint response_id,
 	GtkWidget *push_url_entry;
 	GtkWidget *push_all_check;
 	GtkWidget *push_tags_check;
+	GtkTreeModel *branch_list_model;
 	gchar *url;
+	GList *selected_refs;
 	GitPushCommand *push_command;
 	GitProgressData *progress_data;
 	
@@ -63,6 +65,8 @@ on_push_dialog_response (GtkDialog *dialog, gint response_id,
 		                                                     "push_all_check"));
 		push_tags_check = GTK_WIDGET (gtk_builder_get_object (data->bxml, 
 		                                                      "push_tags_check"));
+		branch_list_model = GTK_TREE_MODEL (gtk_builder_get_object (data->bxml,
+																	"branch_list_model"));
 
 		if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (push_origin_check)))
 			url = g_strdup ("origin");
@@ -77,14 +81,22 @@ on_push_dialog_response (GtkDialog *dialog, gint response_id,
 			g_free (url);
 			return;
 		}
+
+		selected_refs = NULL;
+
+		gtk_tree_model_foreach (branch_list_model, 
+								(GtkTreeModelForeachFunc) git_get_selected_refs,
+								&selected_refs);
 		
 		push_command = git_push_command_new (data->plugin->project_root_directory,
 		                                     url,
+											 selected_refs,
 		                                     gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (push_all_check)),
 		                                     gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (push_tags_check)));
 		progress_data = git_progress_data_new (data->plugin, _("Git: Pushing..."));
 
 		g_free (url);
+		git_command_free_path_list (selected_refs);
 
 		git_create_message_view (data->plugin);
 
@@ -112,11 +124,14 @@ static void
 push_dialog (Git *plugin)
 {
 	GtkBuilder *bxml;
-	gchar *objects[] = {"push_dialog", NULL};
+	gchar *objects[] = {"push_dialog", "branch_list_model", NULL};
 	GError *error;
 	GtkWidget *dialog;
 	GtkWidget *push_origin_check;
 	GtkWidget *push_url_entry;
+	GtkListStore *branch_list_model;
+	GtkCellRenderer *push_branches_view_selected_renderer;
+	GitBranchListCommand *branch_list_command;
 	GitUIData *data;
 	
 	bxml = gtk_builder_new ();
@@ -134,6 +149,23 @@ push_dialog (Git *plugin)
 	                                                        "push_origin_check"));
 	push_url_entry = GTK_WIDGET (gtk_builder_get_object (bxml, 
 	                                                     "push_url_entry"));
+	branch_list_model = GTK_LIST_STORE (gtk_builder_get_object (bxml,
+																"branch_list_model"));
+	push_branches_view_selected_renderer = GTK_CELL_RENDERER (gtk_builder_get_object (bxml,
+																					  "push_branches_view_selected_renderer"));
+
+	branch_list_command = git_branch_list_command_new (plugin->project_root_directory,
+													   GIT_BRANCH_TYPE_LOCAL);
+
+	g_signal_connect (G_OBJECT (branch_list_command), "data-arrived",
+					  G_CALLBACK (on_git_list_branch_command_data_arrived),
+					  branch_list_model);
+
+	g_signal_connect (G_OBJECT (branch_list_command), "command-finished",
+					  G_CALLBACK (g_object_unref),
+					  NULL);
+
+	anjuta_command_start (ANJUTA_COMMAND (branch_list_command));
 	
 	data = git_ui_data_new (plugin, bxml);
 
@@ -144,6 +176,10 @@ push_dialog (Git *plugin)
 	g_signal_connect (G_OBJECT (push_origin_check), "toggled",
 	                  G_CALLBACK (on_git_origin_check_toggled),
 	                  push_url_entry);
+
+	g_signal_connect (G_OBJECT (push_branches_view_selected_renderer), "toggled",
+					  G_CALLBACK (on_git_selected_column_toggled),
+					  branch_list_model);
 	
 	gtk_widget_show_all (dialog);
 }
diff --git a/plugins/git/git-ui-utils.c b/plugins/git/git-ui-utils.c
index 837f890..3ca0a68 100644
--- a/plugins/git/git-ui-utils.c
+++ b/plugins/git/git-ui-utils.c
@@ -371,6 +371,31 @@ on_git_list_branch_combo_command_data_arrived (AnjutaCommand *command,
 	}
 }
 
+/* This function is used for selection lists. */
+void
+on_git_list_branch_command_data_arrived (AnjutaCommand *command,
+										 GtkListStore *branch_list_model)
+{
+	GQueue *output_queue;
+	GitBranch *branch;
+	GtkTreeIter iter;
+	gchar *name;
+	
+	output_queue = git_branch_list_command_get_output (GIT_BRANCH_LIST_COMMAND (command));
+
+	while (g_queue_peek_head (output_queue))
+	{
+		branch = g_queue_pop_head (output_queue);
+		name = git_branch_get_name (branch);
+
+		gtk_list_store_append (branch_list_model, &iter);
+		gtk_list_store_set (branch_list_model, &iter, 1, name, -1);
+		
+		g_object_unref (branch);
+		g_free (name);
+	}
+}
+
 void
 on_git_list_branch_combo_command_finished (AnjutaCommand *command, 
                                            guint return_code,
@@ -521,3 +546,38 @@ git_cancel_data_arrived_signal_disconnect (AnjutaCommand *command,
 						 (GWeakNotify) git_disconnect_data_arrived_signals,
 						 command);
 }
+
+
+gboolean
+git_get_selected_refs (GtkTreeModel *model, GtkTreePath *path, 
+					   GtkTreeIter *iter, GList **selected_list)
+{
+	gboolean selected;
+	gchar *name;
+
+	gtk_tree_model_get (model, iter, 
+						0, &selected,
+						1, &name,
+						-1);
+
+	if (selected)
+		*selected_list = g_list_append (*selected_list, name);
+
+	return FALSE;
+}
+
+void
+on_git_selected_column_toggled (GtkCellRendererToggle *renderer, gchar *path,
+								GtkListStore *list_store)
+{
+	GtkTreeIter iter;
+	gboolean selected;
+
+	gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (list_store), &iter, 
+										 path);
+
+	gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter, 0, &selected, -1);
+	
+	gtk_list_store_set (list_store, &iter, 0, !selected, -1);
+	
+}
\ No newline at end of file
diff --git a/plugins/git/git-ui-utils.h b/plugins/git/git-ui-utils.h
index 11a8357..1a61f42 100644
--- a/plugins/git/git-ui-utils.h
+++ b/plugins/git/git-ui-utils.h
@@ -73,6 +73,8 @@ void on_git_command_progress (AnjutaCommand *command, gfloat progress,
 							  GitProgressData *data);
 void on_git_list_branch_combo_command_data_arrived (AnjutaCommand *command,
                                                     GtkListStore *branch_combo_model);
+void on_git_list_branch_command_data_arrived (AnjutaCommand *command,
+											  GtkListStore *branch_list_model);
 void on_git_list_branch_combo_command_finished (AnjutaCommand *command,
                                                 guint return_code,
                                                 GtkComboBox *combo_box);
@@ -98,4 +100,8 @@ void git_disconnect_data_arrived_signals (AnjutaCommand *command, GObject *objec
 void git_cancel_data_arrived_signal_disconnect (AnjutaCommand *command, 
 												guint return_code,
 												GObject *signal_target);
+gboolean git_get_selected_refs (GtkTreeModel *model, GtkTreePath *path, 
+							    GtkTreeIter *iter, GList **selected_list);
+void on_git_selected_column_toggled (GtkCellRendererToggle *renderer,
+									 gchar *path, GtkListStore *list_store);
 #endif



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