[gitg] Added a menu to create a new branch



commit 7c73d4e5a90e206f9f2a15ac940eece08f706a3b
Author: Patrick Deschenes <patrick deschenes gmail com>
Date:   Thu Oct 7 20:59:10 2010 -0400

    Added a menu to create a new branch
    
    https://bugzilla.gnome.org/show_bug.cgi?id=624106

 gitg/Makefile.am           |    1 +
 gitg/gitg-branch-actions.c |   39 ++++++++++++++++
 gitg/gitg-branch-actions.h |    1 +
 gitg/gitg-menus.xml        |    7 +++
 gitg/gitg-new-branch.ui    |  105 ++++++++++++++++++++++++++++++++++++++++++++
 gitg/gitg-window.c         |   95 +++++++++++++++++++++++++++++++++++++++-
 6 files changed, 247 insertions(+), 1 deletions(-)
---
diff --git a/gitg/Makefile.am b/gitg/Makefile.am
index 0cee607..581f4d2 100644
--- a/gitg/Makefile.am
+++ b/gitg/Makefile.am
@@ -82,6 +82,7 @@ ui_DATA = \
 	gitg-ui.xml 			\
 	gitg-menus.xml			\
 	gitg-preferences.ui		\
+	gitg-new-branch.ui		\
 	gitg-tag.ui			\
 	gitg-repository.ui		\
 	gitg-revision-details-panel.ui	\
diff --git a/gitg/gitg-branch-actions.c b/gitg/gitg-branch-actions.c
index f725953..3370262 100644
--- a/gitg/gitg-branch-actions.c
+++ b/gitg/gitg-branch-actions.c
@@ -1579,6 +1579,45 @@ gitg_branch_actions_apply_stash (GitgWindow *window,
 }
 
 gboolean
+gitg_branch_actions_create (GitgWindow *window, gchar const *sha1, gchar const *name)
+{
+	g_return_val_if_fail (GITG_IS_WINDOW (window), FALSE);
+	g_return_val_if_fail (sha1 != NULL, FALSE);
+	g_return_val_if_fail (name != NULL, FALSE);
+
+	GitgRepository *repository;
+	gboolean result = FALSE;
+
+	repository = gitg_window_get_repository (window);
+
+	result = gitg_repository_commandv (repository,
+	                                   NULL,
+	                                   "branch",
+	                                   name,
+	                                   sha1,
+	                                   NULL);
+
+	if (!result)
+	{
+		gchar const *message;
+
+		message = _ ("The branch could not be successfully created");
+
+		message_dialog (window,
+		                GTK_MESSAGE_ERROR,
+		                _ ("Failed to create a branch"),
+		                message,
+		                NULL);
+		return FALSE;
+	}
+	else
+	{
+		gitg_repository_reload (repository);
+		return TRUE;
+	}
+}
+
+gboolean
 gitg_branch_actions_tag (GitgWindow *window, gchar const *sha1, gchar const *name, gchar const *message, gboolean sign)
 {
 	g_return_val_if_fail (GITG_IS_WINDOW (window), FALSE);
diff --git a/gitg/gitg-branch-actions.h b/gitg/gitg-branch-actions.h
index dafccd4..58b7f18 100644
--- a/gitg/gitg-branch-actions.h
+++ b/gitg/gitg-branch-actions.h
@@ -28,6 +28,7 @@
 
 G_BEGIN_DECLS
 
+gboolean gitg_branch_actions_create (GitgWindow *window, gchar const *sha1, gchar const *name);
 GitgRunner *gitg_branch_actions_remove (GitgWindow *window, GitgRef *ref);
 GitgRunner *gitg_branch_actions_rename (GitgWindow *window, GitgRef *ref);
 gboolean gitg_branch_actions_checkout (GitgWindow *window, GitgRef *ref);
diff --git a/gitg/gitg-menus.xml b/gitg/gitg-menus.xml
index d479bf8..062fc92 100644
--- a/gitg/gitg-menus.xml
+++ b/gitg/gitg-menus.xml
@@ -95,6 +95,12 @@
     <child>
       <object class="GtkActionGroup" id="action_group_revision">
         <child>
+          <object class="GtkAction" id="NewBranchAction">
+            <property name="label" translatable="yes">Create branch</property>
+            <signal name="activate" handler="on_revision_new_branch_activate"/>
+          </object>
+        </child>
+        <child>
           <object class="GtkAction" id="TagAction">
             <property name="label" translatable="yes">Create tag</property>
             <signal name="activate" handler="on_revision_tag_activate"/>
@@ -149,6 +155,7 @@
         <menuitem action="MergeDndAction"/>
       </popup>
       <popup name="revision_popup">
+        <menuitem action="NewBranchAction"/>
         <menuitem action="TagAction"/>
         <menu name="CherryPick" action="CherryPickAction">
           <placeholder name="Placeholder"/>
diff --git a/gitg/gitg-new-branch.ui b/gitg/gitg-new-branch.ui
new file mode 100644
index 0000000..7da500f
--- /dev/null
+++ b/gitg/gitg-new-branch.ui
@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="2.16"/>
+  <!-- interface-naming-policy toplevel-contextual -->
+  <object class="GtkDialog" id="dialog_branch">
+    <property name="border_width">5</property>
+    <property name="title" translatable="yes">Create branch</property>
+    <property name="window_position">center-always</property>
+    <property name="destroy_with_parent">True</property>
+    <property name="type_hint">normal</property>
+    <child internal-child="vbox">
+      <object class="GtkVBox" id="dialog_vbox_main">
+        <property name="visible">True</property>
+        <property name="spacing">2</property>
+        <child>
+          <object class="GtkTable" id="table_main">
+            <property name="visible">True</property>
+            <property name="n_columns">2</property>
+            <property name="column_spacing">6</property>
+            <property name="row_spacing">6</property>
+            <child>
+              <object class="GtkLabel" id="label_name">
+                <property name="visible">True</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">Name:</property>
+              </object>
+              <packing>
+                <property name="x_options">GTK_SHRINK | GTK_FILL</property>
+                <property name="y_options">GTK_SHRINK</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkEntry" id="entry_name">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+		<property name="activates_default">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="right_attach">2</property>
+                <property name="y_options">GTK_FILL</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child internal-child="action_area">
+          <object class="GtkHButtonBox" id="dialog_action_area">
+            <property name="visible">True</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="button_cancel">
+                <property name="label">gtk-cancel</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="button_branch">
+                <property name="label" translatable="yes">Create branch</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="has_focus">True</property>
+                <property name="is_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="has_default">True</property>
+                <property name="receives_default">True</property>
+                <property name="image">image_tag</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="pack_type">end</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="-6">button_cancel</action-widget>
+      <action-widget response="-3">button_branch</action-widget>
+    </action-widgets>
+  </object>
+  <object class="GtkImage" id="image_tag">
+    <property name="visible">True</property>
+    <property name="stock">gtk-apply</property>
+  </object>
+</interface>
diff --git a/gitg/gitg-window.c b/gitg/gitg-window.c
index a500528..f0f6315 100644
--- a/gitg/gitg-window.c
+++ b/gitg/gitg-window.c
@@ -147,6 +147,7 @@ void on_rename_branch_action_activate (GtkAction *action, GitgWindow *window);
 void on_rebase_branch_action_activate (GtkAction *action, GitgWindow *window);
 void on_merge_branch_action_activate (GtkAction *action, GitgWindow *window);
 void on_revision_format_patch_activate (GtkAction *action, GitgWindow *window);
+void on_revision_new_branch_activate (GtkAction *action, GitgWindow *window);
 void on_revision_tag_activate (GtkAction *action, GitgWindow *window);
 void on_revision_squash_activate (GtkAction *action, GitgWindow *window);
 
@@ -3207,6 +3208,54 @@ free_tag_info (TagInfo *info)
 }
 
 static void
+on_new_branch_dialog_response (GtkWidget *dialog,
+                        gint       response,
+                        TagInfo   *info)
+{
+	gboolean destroy = TRUE;
+
+	if (response == GTK_RESPONSE_ACCEPT)
+	{
+		gchar const *name = gtk_entry_get_text (GTK_ENTRY (gtk_builder_get_object (info->builder, "entry_name")));
+
+		if (*name)
+		{
+			gchar *sha1 = gitg_revision_get_sha1 (info->revision);
+
+			if (!gitg_branch_actions_create (info->window, sha1, name))
+			{
+				destroy = FALSE;
+			}
+
+			g_free (sha1);
+		}
+		else
+		{
+			GtkWidget *dlg = gtk_message_dialog_new (GTK_WINDOW (dialog),
+			                                         GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+			                                         GTK_MESSAGE_ERROR,
+			                                         GTK_BUTTONS_OK,
+			                                         _ ("Not all fields are correctly filled in"));
+
+			gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dlg),
+			                                          "%s",
+			                                          _("Please make sure to fill in the branch name"));
+
+			g_signal_connect (dlg, "response", G_CALLBACK (gtk_widget_destroy), NULL);
+			gtk_widget_show (dlg);
+
+			destroy = FALSE;
+		}
+	}
+
+	if (destroy)
+	{
+		free_tag_info (info);
+		gtk_widget_destroy (dialog);
+	}
+}
+
+static void
 on_tag_dialog_response (GtkWidget *dialog,
                         gint       response,
                         TagInfo   *info)
@@ -3266,7 +3315,7 @@ on_tag_dialog_response (GtkWidget *dialog,
 
 			g_free (sha1);
 
-			GitgPreferences *preferences = gitg_preferences_get_default ();
+				GitgPreferences *preferences = gitg_preferences_get_default ();
 			g_object_set (preferences, "hidden-sign-tag", sign, NULL);
 		}
 
@@ -3397,6 +3446,50 @@ on_revision_format_patch_activate (GtkAction  *action,
 }
 
 void
+on_revision_new_branch_activate (GtkAction  *action,
+                          GitgWindow *window)
+{
+	GtkTreeSelection *selection;
+	GtkTreeModel *model;
+
+	selection = gtk_tree_view_get_selection (window->priv->tree_view);
+	GList *rows = gtk_tree_selection_get_selected_rows (selection, &model);
+
+	if (rows && !rows->next)
+	{
+		GtkBuilder *builder = gitg_utils_new_builder ("gitg-new-branch.ui");
+		GtkWidget *widget = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_branch"));
+
+		gtk_window_set_transient_for (GTK_WINDOW (widget), GTK_WINDOW (window));
+
+		GtkTreeIter iter;
+		GitgRevision *rev;
+
+		gtk_tree_model_get_iter (model, &iter, (GtkTreePath *)rows->data);
+		gtk_tree_model_get (model, &iter, 0, &rev, -1);
+
+		TagInfo *info = g_slice_new (TagInfo);
+
+		info->revision = gitg_revision_ref (rev);
+		info->window = window;
+		info->builder = builder;
+
+		g_signal_connect (widget,
+		                  "response",
+		                  G_CALLBACK (on_new_branch_dialog_response),
+		                  info);
+
+		gtk_widget_show (widget);
+
+		gtk_widget_grab_focus (GTK_WIDGET (gtk_builder_get_object (builder, "entry_name")));
+		gitg_revision_unref (rev);
+	}
+
+	g_list_foreach (rows, (GFunc)gtk_tree_path_free, NULL);
+	g_list_free (rows);
+}
+
+void
 on_revision_tag_activate (GtkAction  *action,
                           GitgWindow *window)
 {



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