[gitg] User Information dialog is now Author Details



commit 6fcf6c7c10ad6621ccbd8f44a4d766dd5325f234
Author: Sindhu S <sindhus live in>
Date:   Fri Jul 12 14:11:25 2013 +0530

    User Information dialog is now Author Details
    
    Convert User Information dialog into a template
    Rename all 'User Information' functions to 'Author Details'

 gitg/Makefile.am                                   |    1 +
 gitg/gitg-author-details-dialog.vala               |  172 ++++++++++++++++++++
 gitg/gitg-window.vala                              |  139 +---------------
 gitg/resources/gitg-resources.xml                  |    2 +-
 ...ser-dialog.ui => gitg-author-details-dialog.ui} |   37 +++--
 gitg/resources/ui/gitg-menus.ui                    |   16 +-
 6 files changed, 209 insertions(+), 158 deletions(-)
---
diff --git a/gitg/Makefile.am b/gitg/Makefile.am
index 74a174c..cea2e78 100644
--- a/gitg/Makefile.am
+++ b/gitg/Makefile.am
@@ -40,6 +40,7 @@ VALASOURCES =                                                 \
        gitg-dirs.vala                                          \
        gitg-window.vala                                        \
        gitg-clone-dialog.vala                                  \
+       gitg-author-details-dialog.vala                                 \
        gitg-resource.vala                                      \
        gitg-application.vala                                   \
        gitg-plugins-engine.vala                                \
diff --git a/gitg/gitg-author-details-dialog.vala b/gitg/gitg-author-details-dialog.vala
new file mode 100644
index 0000000..c689f61
--- /dev/null
+++ b/gitg/gitg-author-details-dialog.vala
@@ -0,0 +1,172 @@
+/*
+ * This file is part of gitg
+ *
+ * Copyright (C) 2013 - Sindhu S
+ *
+ * gitg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * gitg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with gitg. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace Gitg
+{
+       [GtkTemplate (ui = "/org/gnome/gitg/ui/gitg-author-details-dialog.ui")]
+       public class AuthorDetailsDialog : Gtk.Dialog
+       {
+               //Do this to pull in config.h before glib.h (for gettext)
+               private const string version = Gitg.Config.VERSION;
+
+               [GtkChild (name = "input_name")]
+               private Gtk.Entry d_input_name;
+
+               [GtkChild (name = "input_email")]
+               private Gtk.Entry d_input_email;
+
+               [GtkChild (name = "label_view")]
+               private Gtk.Label d_label_view;
+
+               [GtkChild (name = "label_dash")]
+               private Gtk.Label d_label_dash;
+
+               private string? d_repository_name;
+
+               private Ggit.Config d_config;
+
+               public AuthorDetailsDialog (Gtk.Window? parent, Ggit.Config config, string? repository_name)
+               {
+                       if (parent != null)
+                       {
+                               set_transient_for (parent);
+                       }
+
+                       d_repository_name = repository_name;
+                       d_config = config;
+               }
+
+               public override void show()
+               {
+                       base.show();
+                       if (d_repository_name == null)
+                       {
+                               d_label_view.hide();
+                               d_label_dash.show();
+
+                               if (Ggit.Config.find_global().get_path() == null)
+                               {
+                                       show_config_error(_("Unable to open the .gitconfig file."), "");
+                                       return;
+                               }
+                       }
+                       else
+                       {
+                               d_label_view.label = d_label_view.label.printf(d_repository_name);
+
+                               d_label_view.show();
+                               d_label_dash.hide();
+                       }
+
+                       string author_name = "";
+                       string author_email = "";
+
+                       try
+                       {
+                               d_config.refresh();
+                               author_name = d_config.get_string("user.name");
+                       }
+                       catch {}
+
+                       try
+                       {
+                               author_email = d_config.get_string("user.email");
+                       }
+                       catch {}
+
+                       if (author_name != "")
+                       {
+                               d_input_name.set_text(author_name);
+                       }
+
+                       if (author_email != "")
+                       {
+                               d_input_email.set_text(author_email);
+                       }
+
+                       set_response_sensitive(Gtk.ResponseType.OK, false);
+
+                       d_input_name.activate.connect((e) => {
+                               response(Gtk.ResponseType.OK);
+                       });
+                       
+                       d_input_email.activate.connect((e) => {
+                               response(Gtk.ResponseType.OK);
+                       });
+
+                       d_input_name.changed.connect((e) => {
+                               set_response_sensitive(Gtk.ResponseType.OK, true);
+                       });
+
+                       d_input_email.changed.connect((e) => {
+                               set_response_sensitive(Gtk.ResponseType.OK, true);
+                       });
+               }
+
+               public override void response(int id) {
+                       if (id == Gtk.ResponseType.OK)
+                       {
+                               try
+                               {
+                                       if (d_input_name.get_text() == "")
+                                       {
+                                               d_config.delete_entry("user.name");
+                                       }
+                                       else
+                                       {
+                                               d_config.set_string("user.name", d_input_name.get_text());
+                                       }
+
+                                       if (d_input_email.get_text() == "")
+                                       {
+                                               d_config.delete_entry("user.email");
+                                       }
+                                       else
+                                       {
+                                               d_config.set_string("user.email", d_input_email.get_text());
+                                       }
+                               }
+                               catch (Error e)
+                               {
+                                       show_config_error(_("Failed to set Git user config."), e.message);
+                                       destroy();
+                                       return;
+                               }
+                       }
+
+                       destroy();
+               }
+
+               private void show_config_error(string primary_message, string secondary_message)
+               {
+                       var error_dialog = new Gtk.MessageDialog(this,
+                                                                Gtk.DialogFlags.DESTROY_WITH_PARENT,
+                                                                Gtk.MessageType.ERROR,
+                                                                Gtk.ButtonsType.OK,
+                                                                primary_message);
+
+                       error_dialog.secondary_text = secondary_message;
+                       error_dialog.response.connect((d, id) => {
+                               error_dialog.destroy();
+                       });
+
+                       error_dialog.show();
+               }
+       }
+}
\ No newline at end of file
diff --git a/gitg/gitg-window.vala b/gitg/gitg-window.vala
index 3b1a66d..14d6c13 100644
--- a/gitg/gitg-window.vala
+++ b/gitg/gitg-window.vala
@@ -85,8 +85,8 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
                {"clone-repository", on_clone_repository},
                {"close", on_close_activated},
                {"reload", on_reload_activated},
-               {"user-information-global", on_global_user_info_activated},
-               {"user-information-repo", on_repo_user_info_activated},
+               {"author-details-global", on_global_author_details_activated},
+               {"author-details-repo", on_repo_author_details_activated},
        };
 
        [GtkCallback]
@@ -338,116 +338,7 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
                dlg.show();
        }
 
-       private void show_user_information_dialog(Ggit.Config config, string? repository_name)
-       {
-               var ret = GitgExt.UI.from_builder("ui/gitg-user-dialog.ui",
-                                                 "dialog",
-                                                 "input-name",
-                                                 "input-email",
-                                                 "label-view",
-                                                 "label-dash");
-
-               var user_information_dialog = ret["dialog"] as Gtk.Dialog;
-               var input_name = ret["input-name"] as Gtk.Entry;
-               var input_email = ret["input-email"] as Gtk.Entry;
-               var label_view = ret["label-view"] as Gtk.Label;
-               var label_dash = ret["label-dash"] as Gtk.Label;
-
-               if (repository_name == null)
-               {
-                       label_view.hide();
-                       label_dash.show();
-
-                       if (Ggit.Config.find_global().get_path() == null)
-                       {
-                               show_config_error(user_information_dialog, _("Unable to open the .gitconfig 
file."), "");
-                               return;
-                       }
-               }
-               else
-               {
-                       label_view.label = label_view.label.printf(repository_name);
-
-                       label_view.show();
-                       label_dash.hide();
-               }
-
-               string user_name = "";
-               string user_email = "";
-
-               try
-               {
-                       config.refresh();
-                       user_name = config.get_string("user.name");
-               }
-               catch {}
-
-               try
-               {
-                       user_email = config.get_string("user.email");
-               }
-               catch {}
-
-               if (user_name != "")
-               {
-                       input_name.set_text(user_name);
-               }
-
-               if (user_email != "")
-               {
-                       input_email.set_text(user_email);
-               }
-
-               user_information_dialog.set_transient_for(this);
-
-               user_information_dialog.set_response_sensitive(Gtk.ResponseType.OK, false);
-
-               input_name.changed.connect((e) => {
-                       user_information_dialog.set_response_sensitive(Gtk.ResponseType.OK, true);
-               });
-
-               input_email.changed.connect((e) => {
-                       user_information_dialog.set_response_sensitive(Gtk.ResponseType.OK, true);
-               });
-
-               user_information_dialog.response.connect((d, id) => {
-                       if (id == Gtk.ResponseType.OK)
-                       {
-                               try
-                               {
-                                       if (input_name.get_text() == "")
-                                       {
-                                               config.delete_entry("user.name");
-                                       }
-                                       else
-                                       {
-                                               config.set_string("user.name", input_name.get_text());
-                                       }
-
-                                       if (input_email.get_text() == "")
-                                       {
-                                               config.delete_entry("user.email");
-                                       }
-                                       else
-                                       {
-                                               config.set_string("user.email", input_email.get_text());
-                                       }
-                               }
-                               catch (Error e)
-                               {
-                                       show_config_error(user_information_dialog, _("Failed to set Git user 
config."), e.message);
-                                       d.destroy();
-                                       return;
-                               }
-                       }
-
-                       d.destroy();
-               });
-
-               user_information_dialog.show();
-       }
-
-       private void on_global_user_info_activated()
+       private void on_global_author_details_activated()
        {
                Ggit.Config global_config = null;
 
@@ -460,10 +351,11 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
                        return;
                }
 
-               show_user_information_dialog(global_config, null);
+               var author_details = new AuthorDetailsDialog(this, global_config, null);
+               author_details.show();
        }
 
-       private void on_repo_user_info_activated()
+       private void on_repo_author_details_activated()
        {
                Ggit.Config repo_config = null;
 
@@ -476,23 +368,8 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
                        return;
                }
 
-               show_user_information_dialog(repo_config, d_repository.name);
-       }
-
-       private void show_config_error(Gtk.Window parent, string primary_message, string secondary_message)
-       {
-               var error_dialog = new Gtk.MessageDialog(parent,
-                                                        Gtk.DialogFlags.DESTROY_WITH_PARENT,
-                                                        Gtk.MessageType.ERROR,
-                                                        Gtk.ButtonsType.OK,
-                                                        primary_message);
-
-               error_dialog.secondary_text = secondary_message;
-               error_dialog.show();
-
-               error_dialog.response.connect((d, id) => {
-                       error_dialog.destroy();
-               });
+               var author_details = new AuthorDetailsDialog(this, repo_config, d_repository.name);
+               author_details.show();
        }
 
        private void on_current_activity_changed(Object obj, ParamSpec pspec)
diff --git a/gitg/resources/gitg-resources.xml b/gitg/resources/gitg-resources.xml
index 2dee59c..0d08cca 100644
--- a/gitg/resources/gitg-resources.xml
+++ b/gitg/resources/gitg-resources.xml
@@ -9,7 +9,7 @@
     <file compressed="true" preprocess="xml-stripblanks">ui/gitg-preferences-interface.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/gitg-preferences.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/gitg-clone-dialog.ui</file>
-    <file compressed="true" preprocess="xml-stripblanks">ui/gitg-user-dialog.ui</file>
+    <file compressed="true" preprocess="xml-stripblanks">ui/gitg-author-details-dialog.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/gitg-history-paned.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/gitg-commit-paned.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/gitg-commit-dialog.ui</file>
diff --git a/gitg/resources/ui/gitg-user-dialog.ui b/gitg/resources/ui/gitg-author-details-dialog.ui
similarity index 87%
rename from gitg/resources/ui/gitg-user-dialog.ui
rename to gitg/resources/ui/gitg-author-details-dialog.ui
index 1ca1d0d..60372aa 100644
--- a/gitg/resources/ui/gitg-user-dialog.ui
+++ b/gitg/resources/ui/gitg-author-details-dialog.ui
@@ -3,25 +3,25 @@
   <!-- interface-requires gtk+ 3.3 -->
   <!-- interface-requires gitg 0.0 -->
   <!-- interface-requires gd 1.0 -->
-  <object class="GtkDialog" id="dialog">
+  <template class="GitgAuthorDetailsDialog" parent="GtkDialog">
     <property name="width_request">390</property>
     <property name="height_request">185</property>
     <property name="can_focus">False</property>
     <property name="border_width">6</property>
-    <property name="title" translatable="yes">User Information</property>
+    <property name="title" translatable="yes">Author Details</property>
     <property name="type_hint">dialog</property>
     <property name="modal">True</property>
     <property name="gravity">north</property>
     <property name="has_resize_grip">False</property>
     <child internal-child="vbox">
-      <object class="GtkBox" id="user-details-box">
+      <object class="GtkBox" id="box_user_details">
         <property name="can_focus">False</property>
         <property name="hexpand">True</property>
         <property name="vexpand">True</property>
         <property name="orientation">vertical</property>
         <property name="spacing">2</property>
         <child>
-          <object class="GtkLabel" id="label-file-not-found">
+          <object class="GtkLabel" id="label_file_not_found">
             <property name="can_focus">False</property>
             <property name="xalign">0</property>
             <property name="label" translatable="yes">Note: The git config file '%s' does not 
exist.</property>
@@ -34,7 +34,7 @@
           </packing>
         </child>
         <child>
-          <object class="GtkLabel" id="label-dash">
+          <object class="GtkLabel" id="label_dash">
             <property name="can_focus">False</property>
             <property name="xalign">0</property>
             <property name="label" translatable="yes">Enter details to set as default for all 
repositories:</property>
@@ -47,7 +47,7 @@
           </packing>
         </child>
         <child>
-          <object class="GtkLabel" id="label-view">
+          <object class="GtkLabel" id="label_view">
             <property name="can_focus">False</property>
             <property name="xalign">0</property>
             <property name="label" translatable="yes">Enter details for repository '%s':</property>
@@ -60,7 +60,7 @@
           </packing>
         </child>
         <child>
-          <object class="GtkGrid" id="user-details-grid">
+          <object class="GtkGrid" id="grid_user_details">
             <property name="width_request">0</property>
             <property name="height_request">0</property>
             <property name="visible">True</property>
@@ -69,7 +69,7 @@
             <property name="row_spacing">6</property>
             <property name="column_spacing">6</property>
             <child>
-              <object class="GtkEntry" id="input-name">
+              <object class="GtkEntry" id="input_name">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="hexpand">True</property>
@@ -83,7 +83,7 @@
               </packing>
             </child>
             <child>
-              <object class="GtkEntry" id="input-email">
+              <object class="GtkEntry" id="input_email">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="hexpand">True</property>
@@ -97,7 +97,7 @@
               </packing>
             </child>
             <child>
-              <object class="GtkLabel" id="label-email">
+              <object class="GtkLabel" id="label_email">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
                 <property name="label" translatable="yes">E-mail: </property>
@@ -110,7 +110,7 @@
               </packing>
             </child>
             <child>
-              <object class="GtkLabel" id="label-name">
+              <object class="GtkLabel" id="label_name">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
                 <property name="label" translatable="yes">Name: </property>
@@ -130,11 +130,11 @@
           </packing>
         </child>
         <child internal-child="action_area">
-          <object class="GtkButtonBox" id="user-action-area">
+          <object class="GtkButtonBox" id="author_action_area">
             <property name="can_focus">False</property>
             <property name="layout_style">end</property>
             <child>
-              <object class="GtkButton" id="cancel-button">
+              <object class="GtkButton" id="button_cancel">
                 <property name="label" translatable="yes">Cancel</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
@@ -147,12 +147,13 @@
               </packing>
             </child>
             <child>
-              <object class="GtkButton" id="save-button">
+              <object class="GtkButton" id="button_save">
                 <property name="label" translatable="yes">Save</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
-                <property name="can_default">True</property>
                 <property name="has_default">True</property>
+                <property name="receives_default">True</property>
+                <property name="can_default">True</property>
                 <property name="use_stock">True</property>
               </object>
               <packing>
@@ -172,8 +173,8 @@
       </object>
     </child>
     <action-widgets>
-      <action-widget response="-6">cancel-button</action-widget>
-      <action-widget response="-5">save-button</action-widget>
+      <action-widget response="-5">button_save</action-widget>
+      <action-widget response="-6">button_cancel</action-widget>
     </action-widgets>
-  </object>
+  </template>
 </interface>
diff --git a/gitg/resources/ui/gitg-menus.ui b/gitg/resources/ui/gitg-menus.ui
index 93fc49d..be62f75 100644
--- a/gitg/resources/ui/gitg-menus.ui
+++ b/gitg/resources/ui/gitg-menus.ui
@@ -48,8 +48,8 @@
     </section>
     <section>
       <item>
-        <attribute name="label" translatable="yes">_User Information</attribute>
-        <attribute name="action">win.user-information-global</attribute>
+        <attribute name="label" translatable="yes">_Author Details</attribute>
+        <attribute name="action">win.author-details-global</attribute>
       </item>
     </section>
   </menu>
@@ -63,8 +63,8 @@
     </section>
     <section>
       <item>
-        <attribute name="label" translatable="yes">_User Information</attribute>
-        <attribute name="action">win.user-information-repo</attribute>
+        <attribute name="label" translatable="yes">_Author Details</attribute>
+        <attribute name="action">win.author-details-repo</attribute>
       </item>
     </section>
   </menu>
@@ -89,8 +89,8 @@
     </section>
     <section>
       <item>
-        <attribute name="label" translatable="yes">_User Information</attribute>
-        <attribute name="action">win.user-information-global</attribute>
+        <attribute name="label" translatable="yes">_Author Details</attribute>
+        <attribute name="action">win.author-details-global</attribute>
       </item>
     </section>
     <section>
@@ -135,8 +135,8 @@
     </section>
     <section>
       <item>
-        <attribute name="label" translatable="yes">_User Information</attribute>
-        <attribute name="action">win.user-information-repo</attribute>
+        <attribute name="label" translatable="yes">_Author Details</attribute>
+        <attribute name="action">win.author-details-repo</attribute>
       </item>
     </section>
     <section>


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