[seed] [browser] Use nice property installation, fix toolbar bugs



commit 184e3f92d8892259879b0ee575a7afb6592ac40a
Author: Tim Horton <hortont424 gmail com>
Date:   Mon Aug 10 08:21:11 2009 -0800

    [browser] Use nice property installation, fix toolbar bugs

 examples/browser/BrowserTab.js     |   42 ++++++++++++------------------------
 examples/browser/BrowserToolbar.js |    9 ++++---
 examples/browser/TabbedBrowser.js  |    6 +---
 3 files changed, 21 insertions(+), 36 deletions(-)
---
diff --git a/examples/browser/BrowserTab.js b/examples/browser/BrowserTab.js
index 3eb07de..cf20581 100644
--- a/examples/browser/BrowserTab.js
+++ b/examples/browser/BrowserTab.js
@@ -1,4 +1,5 @@
 Gtk = imports.gi.Gtk;
+GObject = imports.gi.GObject;
 
 BrowserToolbar = imports.BrowserToolbar;
 BrowserView = imports.BrowserView;
@@ -7,23 +8,16 @@ BrowserStatusbar = imports.BrowserStatusbar;
 BrowserTab = new GType({
     parent: Gtk.VBox.type,
     name: "BrowserTab",
-    class_init: function(klass, prototype)
-    {
-        // TODO: Robb is promising a prettier interface to this.
-        // FIXME: Right now, constructor properties don't show up within init.
-
-        /*klass.c_install_property(GObject.param_spec_object("web_view",
-                                 "WebView",
-                                 "WebView to display",
-                                 GObject.TYPE_OBJECT,
-                                 GObject.ParamFlags.READABLE |
-                                     GObject.ParamFlags.WRITABLE));*/
-    },
-    init: function ()
+    properties: [{name: "web_view",
+		  type: GObject.TYPE_OBJECT,
+		  nick: "WebView",
+		  blurb: "The tab's represented BrowserView",
+		  object_type: BrowserView.BrowserView,
+		  flags: (GObject.ParamFlags.CONSTRUCT | GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE)}],
+    init: function (self)
     {
         // Private
         var toolbar = new BrowserToolbar.BrowserToolbar();
-        var web_view = new BrowserView.BrowserView();
         var scroll_view = new Gtk.ScrolledWindow();
         var statusbar = new BrowserStatusbar.BrowserStatusbar();
         var tab_label;
@@ -34,20 +28,9 @@ BrowserTab = new GType({
             return toolbar;
         };
 
-        this.set_web_view = function (new_web_view)
-        {
-            scroll_view.remove(web_view);
-
-            web_view = new_web_view;
-
-            scroll_view.add(web_view);
-            web_view.set_tab(this);
-            web_view.show();
-        };
-
         this.get_web_view = function ()
         {
-            return web_view;
+            return self.web_view;
         };
 
         this.set_tab_label = function (new_tab_label)
@@ -66,10 +49,13 @@ BrowserTab = new GType({
         };
 
         // Implementation
-        web_view.set_tab(this);
+        if(this.web_view == null)
+        	this.web_view = new BrowserView.BrowserView();
+        
+        this.web_view.set_tab(this);
 
         scroll_view.smooth_scroll = true;
-        scroll_view.add(web_view);
+        scroll_view.add(this.web_view);
         scroll_view.set_policy(Gtk.PolicyType.AUTOMATIC,
                                Gtk.PolicyType.AUTOMATIC);
 
diff --git a/examples/browser/BrowserToolbar.js b/examples/browser/BrowserToolbar.js
index 83febe8..aa87a5d 100644
--- a/examples/browser/BrowserToolbar.js
+++ b/examples/browser/BrowserToolbar.js
@@ -1,6 +1,7 @@
 Gtk = imports.gi.Gtk;
 
 BrowserSettings = imports.BrowserSettings;
+TabbedBrowser = imports.TabbedBrowser;
 
 BrowserToolbar = new GType({
     parent: Gtk.HBox.type,
@@ -16,22 +17,22 @@ BrowserToolbar = new GType({
 
         var back = function ()
         {
-            browser.current_tab().get_web_view().go_back();
+            TabbedBrowser.browser.current_tab().get_web_view().go_back();
         };
 
         var forward = function ()
         {
-            browser.current_tab().get_web_view().go_forward();
+            TabbedBrowser.browser.current_tab().get_web_view().go_forward();
         };
 
         var refresh = function ()
         {
-            browser.current_tab().get_web_view().reload();
+            TabbedBrowser.browser.current_tab().get_web_view().reload();
         };
 
         var browse = function (url)
         {
-            browser.current_tab().get_web_view().browse(url.text);
+            TabbedBrowser.browser.current_tab().get_web_view().browse(url.text);
         };
 
         // Public
diff --git a/examples/browser/TabbedBrowser.js b/examples/browser/TabbedBrowser.js
index 2a20d32..7ad2448 100644
--- a/examples/browser/TabbedBrowser.js
+++ b/examples/browser/TabbedBrowser.js
@@ -24,11 +24,9 @@ TabbedBrowser = new GType({
 
         this.new_tab = function (url, new_web_view)
         {
-            var new_tab = new BrowserTab.BrowserTab();
+            var new_tab = new BrowserTab.BrowserTab({web_view: new_web_view});
 
-            if(new_web_view)
-                new_tab.set_web_view(new_web_view);
-            else
+            if(!new_web_view)
                 new_tab.get_web_view().browse(url);
 
             var tab_label = new Gtk.Label({label:"Untitled"});



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