[gitg] Show local/global author details on toggling override



commit eccb1fd5d855042c083832a7230d93bd38a9fbaf
Author: Jesse van den Kieboom <jessevdk gnome org>
Date:   Sat Aug 8 18:27:01 2015 +0200

    Show local/global author details on toggling override

 gitg/gitg-author-details-dialog.vala |   51 ++++++++++++++++++++++------------
 1 files changed, 33 insertions(+), 18 deletions(-)
---
diff --git a/gitg/gitg-author-details-dialog.vala b/gitg/gitg-author-details-dialog.vala
index 1f73c17..2a992f1 100644
--- a/gitg/gitg-author-details-dialog.vala
+++ b/gitg/gitg-author-details-dialog.vala
@@ -118,6 +118,25 @@ namespace Gitg
                {
                        d_entry_name.sensitive = d_checkbutton_override_global.active;
                        d_entry_email.sensitive = d_checkbutton_override_global.active;
+
+                       Ggit.Config? config = null;
+
+                       try
+                       {
+                               if (!d_checkbutton_override_global.active)
+                               {
+                                       config = d_config.open_level(Ggit.ConfigLevel.GLOBAL);
+                               }
+                               else
+                               {
+                                       config = d_config;
+                               }
+                       } catch {}
+
+                       if (config != null)
+                       {
+                               update_entries(config);
+                       }
                }
 
                public override void show()
@@ -133,29 +152,25 @@ namespace Gitg
                                build_repository();
                        }
 
-                       string author_name = "";
-                       string author_email = "";
+                       update_entries(d_config);
+               }
+
+               private string read_config_string(Ggit.Config config, string name, string defval = "")
+               {
+                       string? ret = null;
 
                        try
                        {
-                               var config = d_config.snapshot();
-
-                               try
-                               {
-                                       author_name = config.get_string("user.name");
-                               } catch {}
+                               ret = config.snapshot().get_string(name);
+                       } catch {}
 
-                               try
-                               {
-                                       author_email = config.get_string("user.email");
-                               } catch {}
-                       }
-                       catch
-                       {
-                       }
+                       return ret != null ? ret : defval;
+               }
 
-                       d_entry_name.set_text(author_name.chomp());
-                       d_entry_email.set_text(author_email.chomp());
+               private void update_entries(Ggit.Config config)
+               {
+                       d_entry_name.set_text(read_config_string(config, "user.name").chomp());
+                       d_entry_email.set_text(read_config_string(config, "user.email").chomp());
                }
 
                private void delete_local_entries()


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