Xfce Wiki

Sub domains
 

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
midori:tutorial [2014/03/02 10:38] – [Add a context menu item] axlrosemidori:tutorial [2014/06/06 20:08] (current) – [Add a new extension] axlrose
Line 45: Line 45:
 After any modifiction in "sandcat.vala" you just run: After any modifiction in "sandcat.vala" you just run:
 <code bash>user@host:~/midori/build$ make </code> <code bash>user@host:~/midori/build$ make </code>
-If you add a new extentioon you run :+If you add a new extention you will run :
 <code bash>user@host:~/midori/build$ make clean <code bash>user@host:~/midori/build$ make clean
 user@host:~/midori/build$ cd .. ; rm -rf build</code> user@host:~/midori/build$ cd .. ; rm -rf build</code>
Line 194: Line 194:
             var listsubmenu = new List<Gtk.Action>();             var listsubmenu = new List<Gtk.Action>();
             for (int i = 0; i < 10; i++)             for (int i = 0; i < 10; i++)
-                 listsubmenu.append(new Gtk.Action("Submenu%d".printf (i), "Submenu #%i".printf (i), null, null));+                listsubmenu.append(new Gtk.Action("Submenu%d".printf (i), "Submenu #%i".printf (i), null, null));
  
  
-             listsubmenu.foreach ((entry) => { +            listsubmenu.foreach ((entry) => { 
-                 entry.activate.connect(() => { +                entry.activate.connect(() => { 
-                 stdout.printf ("I am a submenu\n"); +                    stdout.printf ("I am a submenu\n"); 
-                 }); +                }); 
-                 submenu.add(entry); +                submenu.add(entry); 
-             }); +            }); 
-             menu.add (submenu);+            menu.add (submenu);
         }         }
  
Line 240: Line 240:
 In the Web page try to select a word or a sentence right click and you are going to see three menu item which were added, click on one of them and you will see the magic in the terminal :) .  In the Web page try to select a word or a sentence right click and you are going to see three menu item which were added, click on one of them and you will see the magic in the terminal :) . 
 ====== Add an app menu item ====== ====== Add an app menu item ======
 +<code vala>
 +namespace Sandcat {
 +    private class Manager : Midori.Extension {
 +        internal Manager () {
 +            GLib.Object (name: _("Furry example extension"),
 +                         description: _("Take care of petting cats"),
 +                         version: "0.1" + Midori.VERSION_SUFFIX,
 +                         authors: "Jane Doe <email@domain.tld>");
 +            activate.connect (this.activated);
 +            deactivate.connect (this.deactivated);
 +        }
 +        void tool_menu_populated (Gtk.Menu menu) {
 +            var item = new Gtk.MenuItem.with_label("i am here");
 +            menu.add(item);
 +            item.show();
 +        }
  
-whatever+        void browser_added (Midori.Browser browser) { 
 +            browser.populate_tool_menu.connect(tool_menu_populated); 
 +        } 
 + 
 +        void activated (Midori.App app) { 
 +            foreach (var browser in app.get_browsers ()) 
 +                browser_added (browser); 
 +            app.add_browser.connect (browser_added); 
 +        } 
 + 
 +        void deactivated () { 
 +            var app = get_app (); 
 +            app.add_browser.disconnect (browser_added); 
 +        } 
 +    } 
 +
 + 
 +public Midori.Extension extension_init () { 
 +    return new Sandcat.Manager (); 
 +
 +</code>
  
 +Here you are enjoy, it is easy, isn't it ? :-)
 ====== Modify resources or webpages loaded ====== ====== Modify resources or webpages loaded ======
  
Line 250: Line 287:
  
 <code vala> <code vala>
-    // in browser_added +namespace Sandcat { 
-    var button = new Gtk.Button.with_label ("Click Here!"); +    private class Manager : Midori.Extension { 
-    browser.statusbar.pack_start (button, falsefalse, 3); +  
-    button.show (); +        internal Manager () { 
-</code>+            GLib.Object (name: _("Furry example extension"), 
 +                         description: _("Take care of petting cats"), 
 +                         version: "0.1" + Midori.VERSION_SUFFIX, 
 +                         authors: "Jane Doe <email@domain.tld>"); 
 +            activate.connect (this.activated); 
 +            deactivate.connect (this.deactivated); 
 +        }
  
 +        void browser_added (Midori.Browser browser) {
 +            var button = new Gtk.Button.with_label ("Click Here!");
 +            var click_counter = 0;
 +            browser.statusbar.pack_start (button, false, false, 3);
 +            button.clicked.connect (() => {
 +                button.label = "You Clicked me (%d) time(s)".printf (++click_counter);
 +            });
 +            button.show ();
 +        }
 +
 +        void activated (Midori.App app) {
 +            foreach (var browser in app.get_browsers ())
 +                browser_added (browser);
 +            app.add_browser.connect (browser_added);
 +        }
 +
 +        void deactivated () {
 +            var app = get_app ();
 +            app.add_browser.disconnect (browser_added);
 +        }
 +    }
 +}
 +
 +public Midori.Extension extension_init () {
 +    return new Sandcat.Manager ();
 +}
 +</code>
 +Enjoy How much time you click :-), you can add any Gtk widget in this StatusBar.
 ====== Add a panel ====== ====== Add a panel ======
  
Line 316: Line 387:
      Test.add_func ("/extensions/furry/purr", test_furry_purr);      Test.add_func ("/extensions/furry/purr", test_furry_purr);
 } }
 +</code>
 +
 +With a simple example it will be like this:
 +<code vala>
 +void test_furry_purr () {
 +    assert (1 == 1);
 +}
 + 
 +public void extension_test () {
 +     Test.add_func ("/extensions/furry/purr", test_furry_purr);
 +}
 +
 +void main (string[] args) {
 +    Test.init (ref args);
 +    extension_test();
 +    Test.run ();
 +}</code>
 +The output could look like this.
 +<code bash>
 +/extensions/furry/purr: OK
 </code> </code>