[gitg/wip/repositoryprop: 5/5] Set repository through property



commit 74aa97b0fdbfe78963c154587d777b7a7f34847a
Author: Jesse van den Kieboom <jesse vandenkieboom epfl ch>
Date:   Tue Oct 30 11:03:55 2012 +0100

    Set repository through property

 gitg/gitg-window.vala                 |   35 +++++++++++++++++++++++---------
 libgitg-ext/gitg-ext-application.vala |    2 +-
 2 files changed, 26 insertions(+), 11 deletions(-)
---
diff --git a/gitg/gitg-window.vala b/gitg/gitg-window.vala
index 202ea57..8ada317 100644
--- a/gitg/gitg-window.vala
+++ b/gitg/gitg-window.vala
@@ -62,16 +62,29 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable, Gtk.
                owned get { return d_message_bus; }
        }
 
+       [Notify]
        public Repository? repository
        {
                owned get { return d_repository; }
+               set
+               {
+                       close();
+                       d_repository = value;
+
+                       repository_changed();
+               }
+       }
+
+       private void repository_changed()
+       {
+               d_views.update();
+               activate_default_view();
        }
 
        private void parser_finished(Gtk.Builder builder)
        {
                // Extract widgets from the builder
                d_notebook = builder.get_object("notebook") as Gtk.Notebook;
-               d_dash_view = builder.get_object("dash_view") as GitgGtk.DashView;
 
                d_toolbar_views = builder.get_object("toolbar_views") as Gtk.Toolbar;
                d_paned_views = builder.get_object("paned_views") as Gtk.Paned;
@@ -85,6 +98,11 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable, Gtk.
                d_navigation = builder.get_object("tree_view_navigation") as GitgExt.NavigationTreeView;
                d_config = builder.get_object("button_config") as Gtk.MenuButton;
 
+               d_dash_view = builder.get_object("dash_view") as GitgGtk.DashView;
+               d_dash_view.repository_activated.connect((repository) => {
+                       this.repository = repository;
+               });
+
                var model = Resource.load_object<MenuModel>("ui/gitg-menus.ui", "win-menu");
                d_config.menu_model = model;
 
@@ -110,6 +128,7 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable, Gtk.
 
                // Update panels
                d_panels.update();
+               notify_property("current_view");
        }
 
        private void on_panel_activated(UIElements elements,
@@ -187,8 +206,8 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable, Gtk.
 
                if (ret != null)
                {
-                       ret.d_repository = repository;
                        ret.d_action = action;
+                       ret.d_repository = repository;
                }
 
                try
@@ -196,6 +215,7 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable, Gtk.
                        ((Initable)ret).init(null);
                } catch {}
 
+               ret.repository_changed();
                return ret;
        }
 
@@ -222,6 +242,7 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable, Gtk.
        public void open(File path)
        {
                File repo;
+               Gitg.Repository? repository = null;
 
                if (d_repository != null &&
                    d_repository.get_location().equal(path))
@@ -239,19 +260,13 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable, Gtk.
                        return;
                }
 
-               if (d_repository != null)
-               {
-                       close();
-               }
-
                try
                {
-                       d_repository = new Gitg.Repository(repo, null);
-                       notify_property("repository");
+                       repository = new Gitg.Repository(repo, null);
                }
                catch {}
 
-               d_views.update();
+               this.repository = repository;
        }
 
        public void create(File path)
diff --git a/libgitg-ext/gitg-ext-application.vala b/libgitg-ext/gitg-ext-application.vala
index dd6c91a..0d86ed3 100644
--- a/libgitg-ext/gitg-ext-application.vala
+++ b/libgitg-ext/gitg-ext-application.vala
@@ -33,7 +33,7 @@ public interface Application : Object
        /**
         * The currently open repository.
         */
-       public abstract Gitg.Repository? repository { owned get; }
+       public abstract Gitg.Repository? repository { owned get; set; }
 
        /**
         * An application wide message bus over which plugins can communicate.


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