[gitg] Allow amending without having staged changes



commit 85fe3ff20fcdfd8c71510a4b8a2eaa88db82389a
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Sun Jul 7 13:07:44 2013 +0200

    Allow amending without having staged changes

 gitg/commit/gitg-commit-dialog.vala     |   33 ++++++
 gitg/commit/gitg-commit.vala            |   18 ++--
 gitg/resources/ui/gitg-commit-dialog.ui |  175 +++++++++++++++++++++---------
 gitg/resources/ui/gitg-commit-paned.ui  |    1 -
 4 files changed, 164 insertions(+), 63 deletions(-)
---
diff --git a/gitg/commit/gitg-commit-dialog.vala b/gitg/commit/gitg-commit-dialog.vala
index 48a417f..843e1a3 100644
--- a/gitg/commit/gitg-commit-dialog.vala
+++ b/gitg/commit/gitg-commit-dialog.vala
@@ -44,6 +44,21 @@ class Dialog : Gtk.Dialog
        [GtkChild (name = "label_date")]
        private Gtk.Label d_label_date;
 
+       [GtkChild (name = "infobar")]
+       private Gtk.InfoBar d_infobar;
+
+       [GtkChild (name = "infobar_revealer")]
+       private Gtk.Revealer d_infobar_revealer;
+
+       [GtkChild (name = "infobar_primary_label")]
+       private Gtk.Label d_infobar_primary_label;
+
+       [GtkChild (name = "infobar_secondary_label")]
+       private Gtk.Label d_infobar_secondary_label;
+
+       [GtkChild (name = "infobar_close_button")]
+       private Gtk.Button d_infobar_close_button;
+
        private bool d_show_markup;
        private bool d_show_right_margin;
        private bool d_show_subject_margin;
@@ -452,6 +467,24 @@ class Dialog : Gtk.Dialog
 
                d_source_view_message.override_font(desc);
        }
+
+       public void show_infobar(string          primary_msg,
+                                string          secondary_msg,
+                                Gtk.MessageType type)
+       {
+               d_infobar.message_type = type;
+
+               var primary = "<b>%s</b>".printf(Markup.escape_text(primary_msg));
+               var secondary = "<small>%s</small>".printf(Markup.escape_text(secondary_msg));
+
+               d_infobar_primary_label.set_label(primary);
+               d_infobar_secondary_label.set_label(secondary);
+               d_infobar_revealer.set_reveal_child(true);
+
+               d_infobar_close_button.clicked.connect(() => {
+                       d_infobar_revealer.set_reveal_child(false);
+               });
+       }
 }
 
 }
diff --git a/gitg/commit/gitg-commit.vala b/gitg/commit/gitg-commit.vala
index 5612d8c..c6e0d42 100644
--- a/gitg/commit/gitg-commit.vala
+++ b/gitg/commit/gitg-commit.vala
@@ -25,6 +25,7 @@ namespace GitgCommit
                private const string version = Gitg.Config.VERSION;
                private Paned? d_main;
                private bool d_reloading;
+               private bool d_has_staged;
 
                public GitgExt.Application? application { owned get; construct set; }
 
@@ -402,15 +403,7 @@ namespace GitgCommit
                                model.end_header();
 
                                d_main.sidebar.expand_all();
-
-                               if (staged.length == 0)
-                               {
-                                       d_main.button_commit.sensitive = false;
-                               }
-                               else
-                               {
-                                       d_main.button_commit.sensitive = true;
-                               }
+                               d_has_staged = staged.length != 0;
 
                                d_reloading = false;
                        });
@@ -434,6 +427,13 @@ namespace GitgCommit
                        {
                                opts |= Gitg.StageCommitOptions.AMEND;
                        }
+                       else if (!d_has_staged)
+                       {
+                               dlg.show_infobar(_("There are no changes to be committed"),
+                                                _("Use amend to change the commit message of the previous 
commit"),
+                                                Gtk.MessageType.INFO);
+                               return;
+                       }
 
                        if (dlg.sign_off)
                        {
diff --git a/gitg/resources/ui/gitg-commit-dialog.ui b/gitg/resources/ui/gitg-commit-dialog.ui
index 56844d1..a09e921 100644
--- a/gitg/resources/ui/gitg-commit-dialog.ui
+++ b/gitg/resources/ui/gitg-commit-dialog.ui
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
-  <!-- interface-requires gtk+ 3.0 -->
+  <!-- interface-requires gtk+ 3.10 -->
   <!-- interface-requires gtksourceview 3.0 -->
   <template class="GitgCommitDialog" parent="GtkDialog">
     <property name="can_focus">False</property>
@@ -64,46 +64,46 @@
             <property name="row_spacing">6</property>
             <property name="column_spacing">6</property>
             <child>
-              <object class="GtkScrolledWindow" id="scrolled_window_message">
+              <object class="GtkImage" id="image_avatar">
                 <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="hexpand">True</property>
-                <property name="vexpand">True</property>
-                <property name="shadow_type">in</property>
-                <child>
-                  <object class="GtkSourceView" id="source_view_message">
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="left_margin">2</property>
-                    <property name="right_margin">2</property>
-                    <property name="auto_indent">True</property>
-                    <property name="show_right_margin">True</property>
-                    <property name="right_margin_position">72</property>
-                    <property name="smart_home_end">after</property>
-                  </object>
-                </child>
+                <property name="can_focus">False</property>
+                <property name="pixel_size">50</property>
+                <property name="icon_size">6</property>
               </object>
               <packing>
                 <property name="left_attach">0</property>
-                <property name="top_attach">2</property>
-                <property name="width">2</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label_user">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">start</property>
+                <property name="valign">end</property>
+                <property name="hexpand">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
                 <property name="height">1</property>
               </packing>
             </child>
             <child>
-              <object class="GtkCheckButton" id="check_button_amend">
-                <property name="label" translatable="yes">_Amend previous commit</property>
+              <object class="GtkLabel" id="label_date">
                 <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">False</property>
-                <property name="use_underline">True</property>
-                <property name="xalign">0</property>
-                <property name="draw_indicator">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">start</property>
+                <property name="valign">start</property>
+                <property name="hexpand">True</property>
               </object>
               <packing>
-                <property name="left_attach">0</property>
-                <property name="top_attach">3</property>
-                <property name="width">2</property>
+                <property name="left_attach">1</property>
+                <property name="top_attach">1</property>
+                <property name="width">1</property>
                 <property name="height">1</property>
               </packing>
             </child>
@@ -119,52 +119,121 @@
               </object>
               <packing>
                 <property name="left_attach">0</property>
-                <property name="top_attach">4</property>
+                <property name="top_attach">5</property>
                 <property name="width">2</property>
                 <property name="height">1</property>
               </packing>
             </child>
             <child>
-              <object class="GtkImage" id="image_avatar">
+              <object class="GtkCheckButton" id="check_button_amend">
+                <property name="label" translatable="yes">_Amend previous commit</property>
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="pixel_size">50</property>
-                <property name="icon_size">6</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_underline">True</property>
+                <property name="xalign">0</property>
+                <property name="draw_indicator">True</property>
               </object>
               <packing>
                 <property name="left_attach">0</property>
-                <property name="top_attach">0</property>
-                <property name="width">1</property>
-                <property name="height">2</property>
+                <property name="top_attach">4</property>
+                <property name="width">2</property>
+                <property name="height">1</property>
               </packing>
             </child>
             <child>
-              <object class="GtkLabel" id="label_user">
+              <object class="GtkScrolledWindow" id="scrolled_window_message">
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="halign">start</property>
+                <property name="can_focus">True</property>
                 <property name="hexpand">True</property>
-                <property name="valign">end</property>
+                <property name="vexpand">True</property>
+                <property name="shadow_type">in</property>
+                <child>
+                  <object class="GtkSourceView" id="source_view_message">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="left_margin">2</property>
+                    <property name="right_margin">2</property>
+                    <property name="auto_indent">True</property>
+                    <property name="show_right_margin">True</property>
+                    <property name="right_margin_position">72</property>
+                    <property name="smart_home_end">after</property>
+                  </object>
+                </child>
               </object>
               <packing>
-                <property name="left_attach">1</property>
-                <property name="top_attach">0</property>
-                <property name="width">1</property>
+                <property name="left_attach">0</property>
+                <property name="top_attach">3</property>
+                <property name="width">2</property>
                 <property name="height">1</property>
               </packing>
             </child>
             <child>
-              <object class="GtkLabel" id="label_date">
+              <object class="GtkRevealer" id="infobar_revealer">
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="halign">start</property>
-                <property name="hexpand">True</property>
-                <property name="valign">start</property>
+                <child>
+                  <object class="GtkInfoBar" id="infobar">
+                    <property name="visible">True</property>
+                    <child internal-child="content_area">
+                      <object class="GtkBox" id="infobar_content_area">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="border_width">8</property>
+                        <property name="orientation">vertical</property>
+                        <property name="spacing">16</property>
+                        <child>
+                          <object class="GtkLabel" id="infobar_primary_label">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="selectable">True</property>
+                            <property name="use-markup">True</property>
+                            <property name="halign">GTK_ALIGN_START</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">True</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="infobar_secondary_label">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="selectable">True</property>
+                            <property name="use-markup">True</property>
+                            <property name="halign">GTK_ALIGN_START</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">True</property>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                        <child internal-child="action_area">
+                          <object class="GtkButtonBox" id="infobar_action_area">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="border_width">5</property>
+                            <property name="orientation">vertical</property>
+                            <property name="spacing">6</property>
+                            <property name="layout_style">end</property>
+                            <child>
+                              <object class="GtkButton" id="infobar_close_button">
+                                <property name="visible">True</property>
+                                <property name="label" translatable="yes">Close</property>
+                              </object>
+                            </child>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
               </object>
               <packing>
-                <property name="left_attach">1</property>
-                <property name="top_attach">1</property>
-                <property name="width">1</property>
+                <property name="left_attach">0</property>
+                <property name="top_attach">2</property>
+                <property name="width">2</property>
                 <property name="height">1</property>
               </packing>
             </child>
diff --git a/gitg/resources/ui/gitg-commit-paned.ui b/gitg/resources/ui/gitg-commit-paned.ui
index 88dfc63..f6f281d 100644
--- a/gitg/resources/ui/gitg-commit-paned.ui
+++ b/gitg/resources/ui/gitg-commit-paned.ui
@@ -75,7 +75,6 @@
                 <child>
                   <object class="GtkButton" id="button_commit">
                     <property name="visible">True</property>
-                    <property name="sensitive">False</property>
                     <property name="use_underline">True</property>
                     <property name="label" translatable="yes">C_ommit</property>
                   </object>


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