[gitg/wip/commit] Store environment in window



commit b759670df1943046dfeb73595c2ca956612a30b1
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Fri Jul 5 13:04:07 2013 +0200

    Store environment in window

 gitg/gitg-application.vala            |   22 +++++++++++++++++++-
 gitg/gitg-window.vala                 |   34 +++++++++++++++++++++++++++++++++
 libgitg-ext/gitg-ext-application.vala |    2 +
 3 files changed, 56 insertions(+), 2 deletions(-)
---
diff --git a/gitg/gitg-application.vala b/gitg/gitg-application.vala
index 8c56164..2395d2e 100644
--- a/gitg/gitg-application.vala
+++ b/gitg/gitg-application.vala
@@ -157,6 +157,12 @@ public class Application : Gtk.Application
                        return 0;
                }
 
+               if (!cmd.get_is_remote())
+               {
+                       Options.command_line = cmd;
+               }
+
+               var tmpcmd = Options.command_line;
                Options.command_line = cmd;
 
                if (argv.length > 1)
@@ -176,6 +182,8 @@ public class Application : Gtk.Application
                        activate();
                }
 
+               Options.command_line = tmpcmd;
+
                return 1;
        }
 
@@ -389,6 +397,7 @@ public class Application : Gtk.Application
                        if (window != null)
                        {
                                // Present the window with this repository open
+                               window.set_environment(Options.command_line.get_environ());
                                window.present();
                                continue;
                        }
@@ -409,7 +418,13 @@ public class Application : Gtk.Application
 
        private void new_window(Repository? repo = null, string? hint = null)
        {
-               Window.create_new(this, repo, hint);
+               var window = Window.create_new(this, repo, hint);
+
+               if (window != null)
+               {
+                       window.set_environment(Options.command_line.get_environ());
+               }
+
                present_window();
        }
 
@@ -427,7 +442,10 @@ public class Application : Gtk.Application
                        return;
                }
 
-               windows.first().data.present();
+               var w = (Gitg.Window)windows.first().data;
+
+               w.set_environment(Options.command_line.get_environ());
+               w.present();
        }
 }
 
diff --git a/gitg/gitg-window.vala b/gitg/gitg-window.vala
index 175cd7b..5393c1c 100644
--- a/gitg/gitg-window.vala
+++ b/gitg/gitg-window.vala
@@ -29,6 +29,7 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
        private Repository? d_repository;
        private GitgExt.MessageBus d_message_bus;
        private string? d_action;
+       private Gee.HashMap<string, string> d_environment;
 
        private UIElements<GitgExt.Activity> d_activities;
 
@@ -42,6 +43,8 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
        private MenuModel d_dash_model;
        private MenuModel d_activities_model;
 
+
+
        [GtkChild]
        private Gtk.Button d_dash_button;
        [GtkChild]
@@ -150,6 +153,13 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
                d_search_button.bind_property("active", d_search_bar, "search-mode-enabled", 
BindingFlags.BIDIRECTIONAL);
 
                d_activities_switcher.set_stack(d_stack_activities);
+
+               d_environment = new Gee.HashMap<string, string>();
+
+               foreach (var e in Environment.list_variables())
+               {
+                       d_environment[e] = Environment.get_variable(e);
+               }
        }
 
        private void on_close_activated()
@@ -593,6 +603,25 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
                return true;
        }
 
+       public void set_environment(string[] environment)
+       {
+               d_environment = new Gee.HashMap<string, string>();
+
+               foreach (var e in environment)
+               {
+                       string[] parts = e.split("=", 2);
+
+                       if (parts.length == 1)
+                       {
+                               d_environment[parts[0]] = "";
+                       }
+                       else
+                       {
+                               d_environment[parts[0]] = parts[1];
+                       }
+               }
+       }
+
        public static Window? create_new(Gtk.Application app,
                                         Repository? repository,
                                         string? action)
@@ -686,6 +715,11 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
                        infobar.hide();
                });
        }
+
+       public Gee.Map<string, string> environment
+       {
+               owned get { return d_environment; }
+       }
 }
 
 }
diff --git a/libgitg-ext/gitg-ext-application.vala b/libgitg-ext/gitg-ext-application.vala
index b3651c9..cffeb12 100644
--- a/libgitg-ext/gitg-ext-application.vala
+++ b/libgitg-ext/gitg-ext-application.vala
@@ -58,6 +58,8 @@ public interface Application : Object
        public abstract void show_infobar(string          primary_msg,
                                          string          secondary_msg,
                                          Gtk.MessageType type);
+
+       public abstract Gee.Map<string, string> environment { owned get; }
 }
 
 }


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