[gitg] Option to switch to the newly created branch



commit daaf84f8b0e75d38f0d9648b04d5de66e0639252
Author: Armandas JaruĊĦauskas <jarusauskas gmail com>
Date:   Sat Jun 27 08:29:36 2020 +0000

    Option to switch to the newly created branch

 data/org.gnome.gitg.gschema.xml.in             | 10 ++++++++++
 gitg/gitg-commit-action-create-branch.vala     |  6 ++++++
 gitg/gitg-create-branch-dialog.vala            | 20 ++++++++++++++++++++
 gitg/resources/ui/gitg-create-branch-dialog.ui | 15 +++++++++++++++
 4 files changed, 51 insertions(+)
---
diff --git a/data/org.gnome.gitg.gschema.xml.in b/data/org.gnome.gitg.gschema.xml.in
index 9f816ea8..d10ab842 100644
--- a/data/org.gnome.gitg.gschema.xml.in
+++ b/data/org.gnome.gitg.gschema.xml.in
@@ -18,6 +18,7 @@
   <schema gettext-domain="@GETTEXT_PACKAGE@" id="@APPLICATION_ID@.preferences" 
path="@SCHEMA_PATH@/preferences/">
     <child name="main" schema="@APPLICATION_ID  preferences main" />
     <child name="history" schema="@APPLICATION_ID@.preferences.history" />
+    <child name="branch" schema="@APPLICATION_ID@.preferences.branch" />
     <child name="commit" schema="@APPLICATION_ID@.preferences.commit" />
     <child name="diff" schema="@APPLICATION_ID  preferences diff" />
   </schema>
@@ -165,6 +166,15 @@
       </description>
     </key>
   </schema>
+  <schema gettext-domain="@GETTEXT_PACKAGE@" id="@APPLICATION_ID@.preferences.branch" 
path="@SCHEMA_PATH@/preferences/branch/">
+    <key name="checkout-created-branch" type="b">
+      <default>true</default>
+      <summary>Switch to the new branch on creation</summary>
+      <description>
+        Setting that controls whether the newly created branch is checked out automatically.
+      </description>
+    </key>
+  </schema>
   <schema gettext-domain="@GETTEXT_PACKAGE@" id="@APPLICATION_ID@.preferences.commit" 
path="@SCHEMA_PATH@/preferences/commit/">
     <child name="message" schema="@APPLICATION_ID@.preferences.commit.message" />
     <child name="diff" schema="@APPLICATION_ID  preferences commit diff" />
diff --git a/gitg/gitg-commit-action-create-branch.vala b/gitg/gitg-commit-action-create-branch.vala
index 76e86e89..ff30f522 100644
--- a/gitg/gitg-commit-action-create-branch.vala
+++ b/gitg/gitg-commit-action-create-branch.vala
@@ -81,6 +81,12 @@ class CommitActionCreateBranch : GitgExt.UIElement, GitgExt.Action, GitgExt.Comm
                                {
                                        action_interface.add_ref((Gitg.Ref)branch);
                                }
+
+                               if (dlg.checkout_created)
+                               {
+                                       var checkout = new RefActionCheckout(application, action_interface, 
(Gitg.Ref)branch);
+                                       checkout.checkout.begin();
+                               }
                        }
 
                        dlg.destroy();
diff --git a/gitg/gitg-create-branch-dialog.vala b/gitg/gitg-create-branch-dialog.vala
index 54a49dc5..9695fd33 100644
--- a/gitg/gitg-create-branch-dialog.vala
+++ b/gitg/gitg-create-branch-dialog.vala
@@ -29,8 +29,20 @@ class CreateBranchDialog : Gtk.Dialog
        [GtkChild]
        private Gtk.Entry d_entry_branch_name;
 
+       [GtkChild]
+       private Gtk.CheckButton d_checkout_created;
+
+       private Settings d_settings;
+
        construct
        {
+               d_settings = new Settings(Gitg.Config.APPLICATION_ID + ".preferences.branch");
+
+               d_settings.bind("checkout-created-branch",
+                               d_checkout_created,
+                               "active",
+                               SettingsBindFlags.GET | SettingsBindFlags.SET);
+
                d_entry_branch_name.changed.connect(() => {
                        d_button_create.sensitive = (new_branch_name.length != 0);
                });
@@ -56,6 +68,14 @@ class CreateBranchDialog : Gtk.Dialog
                        return d_entry_branch_name.text.strip();
                }
        }
+
+       public bool checkout_created
+       {
+               get
+               {
+                       return d_checkout_created.active;
+               }
+       }
 }
 
 }
diff --git a/gitg/resources/ui/gitg-create-branch-dialog.ui b/gitg/resources/ui/gitg-create-branch-dialog.ui
index 6fad9031..c5340d37 100644
--- a/gitg/resources/ui/gitg-create-branch-dialog.ui
+++ b/gitg/resources/ui/gitg-create-branch-dialog.ui
@@ -91,6 +91,21 @@
                 <property name="height">1</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkCheckButton" id="d_checkout_created">
+                <property name="label" translatable="yes">_Checkout the created branch</property>
+                <property name="use_underline">True</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="draw_indicator">True</property>
+                <property name="active">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">1</property>
+              </packing>
+            </child>
           </object>
           <packing>
             <property name="expand">False</property>


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