Added a menu to create a new branch

https://bugzilla.gnome.org/show_bug.cgi?id=624106
This commit is contained in:
Patrick Deschenes 2010-10-07 20:59:10 -04:00 committed by Jesse van den Kieboom
parent c05377a59c
commit 7c73d4e5a9
6 changed files with 247 additions and 1 deletions

View file

@ -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 \

View file

@ -1578,6 +1578,45 @@ gitg_branch_actions_apply_stash (GitgWindow *window,
return ret;
}
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)
{

View file

@ -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);

View file

@ -94,6 +94,12 @@
</child>
<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>
@ -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"/>

105
gitg/gitg-new-branch.ui Normal file
View file

@ -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>

View file

@ -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);
@ -3206,6 +3207,54 @@ free_tag_info (TagInfo *info)
g_slice_free (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,
@ -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);
}
@ -3396,6 +3445,50 @@ on_revision_format_patch_activate (GtkAction *action,
g_list_free (rows);
}
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)