seed r568 - trunk/doc/tutorial-standalone



Author: hortont
Date: Sun Dec 28 04:12:54 2008
New Revision: 568
URL: http://svn.gnome.org/viewvc/seed?rev=568&view=rev

Log:
Update tutorial.


Modified:
   trunk/doc/tutorial-standalone/2.js
   trunk/doc/tutorial-standalone/3.js

Modified: trunk/doc/tutorial-standalone/2.js
==============================================================================
--- trunk/doc/tutorial-standalone/2.js	(original)
+++ trunk/doc/tutorial-standalone/2.js	Sun Dec 28 04:12:54 2008
@@ -6,64 +6,15 @@
 Seed.import_namespace("WebKit");
 Gtk.init(null, null);
 
-TabbedBrowser = new GType({
-    parent: Gtk.Notebook.type,
-    name: "TabbedBrowser",
-    instance_init: function (klass)
-    {
-        // Public
-        this.close_tab = function (tab)
-        {
-            browser.remove_page(browser.page_num(tab));
-            tab.destroy();
-            
-            if(!browser.get_n_pages())
-            {
-                browser.new_tab(home_page);
-            }
-        };
-        
-        this.new_tab = function (url)
-        {
-            var new_tab = new BrowserTab();
-            new_tab.get_web_view().browse(url);
-            
-            var tab_label = new Gtk.Label({label:"Untitled"});
-            var tab_button = new Gtk.Button({relief: Gtk.ReliefStyle.None});
-            tab_button.set_image(new Gtk.Image({stock: "gtk-close", 
-                                                icon_size: Gtk.IconSize.Menu}));
-            tab_button.signal.clicked.connect(this.close_tab, this);
-            
-            var tab_title = new Gtk.HBox();
-            tab_title.pack_start(tab_label);
-            tab_title.pack_start(tab_button);
-            tab_title.show_all();
-            
-            new_tab.set_tab_label(tab_label);
-            
-            this.append_page(new_tab, tab_title);
-        };
-
-        this.current_tab = function ()
-        {
-            return this.get_nth_page(this.page);
-        };
-
-        // Implementation
-        this.new_tab(home_page);
-    }
-});
-
-BrowserTab = new GType({
+Browser = new GType({
     parent: Gtk.VBox.type,
-    name: "BrowserTab",
+    name: "Browser",
     instance_init: function (klass)
     {
         // Private
         var toolbar = new BrowserToolbar();
         var web_view = new BrowserView();
         var scroll_view = new Gtk.ScrolledWindow();
-        var tab_label;
         
         // Public
         this.get_toolbar = function ()
@@ -76,19 +27,7 @@
             return web_view;
         };
         
-        this.set_tab_label = function (new_tab_label)
-        {
-            tab_label = new_tab_label;
-        };
-        
-        this.get_tab_label = function ()
-        {
-            return tab_label;
-        };
-        
         // Implementation
-        web_view.set_tab(this);
-        
         scroll_view.smooth_scroll = true;
         scroll_view.add(web_view);
         scroll_view.set_policy(Gtk.PolicyType.Automatic,
@@ -106,19 +45,9 @@
     instance_init: function (klass)
     {
         // Private
-        var tab;
-        
-        var update_title = function (web_view, web_frame, title)
-        {
-            if(title.length > 25)
-                title = title.slice(0,25) + "...";
-            
-            tab.get_tab_label().label = title;
-        };
-        
         var update_url = function (web_view, web_frame)
         {
-            var toolbar = tab.get_toolbar();
+            var toolbar = browser.get_toolbar();
             
             toolbar.set_url(web_frame.get_uri());
             toolbar.set_can_go_back(web_view.can_go_back());
@@ -134,19 +63,8 @@
             this.open(url);
         };
         
-        this.set_tab = function (new_tab)
-        {
-            tab = new_tab;
-        }
-        
-        this.get_tab = function ()
-        {
-            return tab;
-        };
-        
         // Implementation
         this.set_scroll_adjustments(null, null);
-        this.signal.title_changed.connect(update_title);
         this.signal.load_committed.connect(update_url);
     }
 });
@@ -165,22 +83,22 @@
 
         var back = function ()
         {
-            browser.current_tab().get_web_view().go_back();
+            browser.get_web_view().go_back();
         };
 
         var forward = function ()
         {
-            browser.current_tab().get_web_view().go_forward();
+            browser.get_web_view().go_forward();
         };
 
         var refresh = function ()
         {
-            browser.current_tab().get_web_view().reload();
+            browser.get_web_view().reload();
         };
 
         var browse = function (url)
         {
-            browser.current_tab().get_web_view().browse(url.text);
+            browser.get_web_view().browse(url.text);
         };
 
         // Public
@@ -215,7 +133,8 @@
 window = new Gtk.Window({title: "Browser"});
 window.signal.hide.connect(function () { Gtk.main_quit(); });
 
-browser = new TabbedBrowser();
+browser = new Browser();
+browser.get_web_view().browse(home_page);
 window.add(browser);
 window.show_all();
 

Modified: trunk/doc/tutorial-standalone/3.js
==============================================================================
--- trunk/doc/tutorial-standalone/3.js	(original)
+++ trunk/doc/tutorial-standalone/3.js	Sun Dec 28 04:12:54 2008
@@ -1,81 +1,222 @@
 #!/usr/bin/env seed
 
+var home_page = "http://www.google.com";;
+
 Seed.import_namespace("Gtk");
 Seed.import_namespace("WebKit");
 Gtk.init(null, null);
 
-var window = new Gtk.Window({title: "Browser"});
-window.resize(600,600);
+TabbedBrowser = new GType({
+    parent: Gtk.Notebook.type,
+    name: "TabbedBrowser",
+    instance_init: function (klass)
+    {
+        // Public
+        this.close_tab = function (tab)
+        {
+            browser.remove_page(browser.page_num(tab));
+            tab.destroy();
+            
+            if(!browser.get_n_pages())
+            {
+                browser.new_tab(home_page);
+            }
+        };
+        
+        this.new_tab = function (url)
+        {
+            var new_tab = new BrowserTab();
+            new_tab.get_web_view().browse(url);
+            
+            var tab_label = new Gtk.Label({label:"Untitled"});
+            var tab_button = new Gtk.Button({relief: Gtk.ReliefStyle.None});
+            tab_button.set_image(new Gtk.Image({stock: "gtk-close", 
+                                                icon_size: Gtk.IconSize.Menu}));
+            tab_button.signal.clicked.connect(this.close_tab, this);
+            
+            var tab_title = new Gtk.HBox();
+            tab_title.pack_start(tab_label);
+            tab_title.pack_start(tab_button);
+            tab_title.show_all();
+            
+            new_tab.set_tab_label(tab_label);
+            
+            this.append_page(new_tab, tab_title);
+        };
+
+        this.current_tab = function ()
+        {
+            return this.get_nth_page(this.page);
+        };
+
+        // Implementation
+        this.new_tab(home_page);
+    }
+});
+
+BrowserTab = new GType({
+    parent: Gtk.VBox.type,
+    name: "BrowserTab",
+    instance_init: function (klass)
+    {
+        // Private
+        var toolbar = new BrowserToolbar();
+        var web_view = new BrowserView();
+        var scroll_view = new Gtk.ScrolledWindow();
+        var tab_label;
+        
+        // Public
+        this.get_toolbar = function ()
+        {
+            return toolbar;
+        };
+
+        this.get_web_view = function ()
+        {
+            return web_view;
+        };
+        
+        this.set_tab_label = function (new_tab_label)
+        {
+            tab_label = new_tab_label;
+        };
+        
+        this.get_tab_label = function ()
+        {
+            return tab_label;
+        };
+        
+        // Implementation
+        web_view.set_tab(this);
+        
+        scroll_view.smooth_scroll = true;
+        scroll_view.add(web_view);
+        scroll_view.set_policy(Gtk.PolicyType.Automatic,
+                               Gtk.PolicyType.Automatic);
+
+        this.pack_start(toolbar);
+        this.pack_start(scroll_view, true, true);
+        this.show_all();
+    }
+});
+
+BrowserView = new GType({
+    parent: WebKit.WebView.type,
+    name: "BrowserView",
+    instance_init: function (klass)
+    {
+        // Private
+        var tab;
+        
+        var update_title = function (web_view, web_frame, title)
+        {
+            if(title.length > 25)
+                title = title.slice(0,25) + "...";
+            
+            tab.get_tab_label().label = title;
+        };
+        
+        var update_url = function (web_view, web_frame)
+        {
+            var toolbar = tab.get_toolbar();
+            
+            toolbar.set_url(web_frame.get_uri());
+            toolbar.set_can_go_back(web_view.can_go_back());
+            toolbar.set_can_go_forward(web_view.can_go_forward());
+        };
+        
+        // Public
+        this.browse = function (url)
+        {
+            if(url.search("://") < 0)
+                url = "http://"; + url;
+
+            this.open(url);
+        };
+        
+        this.set_tab = function (new_tab)
+        {
+            tab = new_tab;
+        }
+        
+        this.get_tab = function ()
+        {
+            return tab;
+        };
+        
+        // Implementation
+        this.set_scroll_adjustments(null, null);
+        this.signal.title_changed.connect(update_title);
+        this.signal.load_committed.connect(update_url);
+    }
+});
+
+BrowserToolbar = new GType({
+    parent: Gtk.HBox.type,
+    name: "BrowserToolbar",
+    instance_init: function (klass)
+    {
+        // Private
+        var url_bar = new Gtk.Entry();
+
+        var back_button = new Gtk.ToolButton({stock_id:"gtk-go-back"});
+        var forward_button = new Gtk.ToolButton({stock_id:"gtk-go-forward"});
+        var refresh_button = new Gtk.ToolButton({stock_id:"gtk-refresh"});
+
+        var back = function ()
+        {
+            browser.current_tab().get_web_view().go_back();
+        };
+
+        var forward = function ()
+        {
+            browser.current_tab().get_web_view().go_forward();
+        };
+
+        var refresh = function ()
+        {
+            browser.current_tab().get_web_view().reload();
+        };
+
+        var browse = function (url)
+        {
+            browser.current_tab().get_web_view().browse(url.text);
+        };
+
+        // Public
+        this.set_url = function (url)
+        {
+            url_bar.text = url;
+        };
+        
+        this.set_can_go_back = function (can_go_back)
+        {
+            back_button.sensitive = can_go_back;
+        };
+        
+        this.set_can_go_forward = function (can_go_forward)
+        {
+            forward_button.sensitive = can_go_forward;
+        };
+        
+        // Implementation
+        back_button.signal.clicked.connect(back);
+        forward_button.signal.clicked.connect(forward);
+        refresh_button.signal.clicked.connect(refresh);
+        url_bar.signal.activate.connect(browse);
+
+        this.pack_start(back_button);
+        this.pack_start(forward_button);
+        this.pack_start(refresh_button);
+        this.pack_start(url_bar, true, true);
+    }
+});
 
-function quit()
-{
-    Gtk.main_quit();
-}
-
-window.signal.hide.connect(quit);
-
-function create_ui()
-{
-    var main_ui = new Gtk.VBox();
-    var toolbar = new Gtk.HBox();
-    
-    var browser = new WebKit.WebView();
-    browser.open("http://www.gnome.org";);
-
-    var back_button = new Gtk.ToolButton({stock_id: "gtk-go-back"});
-    var forward_button = new Gtk.ToolButton({stock_id: "gtk-go-forward"});
-    var refresh_button = new Gtk.ToolButton({stock_id: "gtk-refresh"});
-
-    var url_entry = new Gtk.Entry();
-
-    back_button.signal.clicked.connect(back, browser);
-    forward_button.signal.clicked.connect(forward, browser);
-    refresh_button.signal.clicked.connect(refresh, browser);
-
-    url_entry.signal.activate.connect(browse, browser);
-    browser.signal.load_committed.connect(url_changed, url_entry);
-
-    toolbar.pack_start(back_button);
-    toolbar.pack_start(forward_button);
-    toolbar.pack_start(refresh_button);
-    toolbar.pack_start(url_entry, true, true);
-
-    main_ui.pack_start(toolbar);
-    main_ui.pack_start(browser, true, true);
-    return main_ui;
-}
-
-function forward(button)
-{
-	this.go_forward();
-}
-
-function back(button)
-{
-	this.go_back();
-}
-
-function refresh(button)
-{
-	this.reload();
-}
-
-function browse(url)
-{
-	if (url.text.search("://") < 0)
-	{
-		url.text = "http://"; + url.text;
-	}
-	
-	this.open(url.text);
-}
-
-function url_changed(browser, frame)
-{
-    this.text = frame.get_uri();
-}
+window = new Gtk.Window({title: "Browser"});
+window.signal.hide.connect(function () { Gtk.main_quit(); });
 
-window.add(create_ui());
+browser = new TabbedBrowser();
+window.add(browser);
 window.show_all();
 
 Gtk.main();



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