Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
midori:tutorial [2014/03/02 10:38] – [Add a context menu item] axlrose | midori:tutorial [2014/03/04 18:34] – [Add an app menu item] axlrose | ||
---|---|---|---|
Line 194: | Line 194: | ||
var listsubmenu = new List< | var listsubmenu = new List< | ||
for (int i = 0; i < 10; i++) | for (int i = 0; i < 10; i++) | ||
- | listsubmenu.append(new Gtk.Action(" | + | |
- | listsubmenu.foreach ((entry) => { | + | |
- | | + | entry.activate.connect(() => { |
- | | + | stdout.printf ("I am a submenu\n" |
- | | + | }); |
- | | + | submenu.add(entry); |
- | | + | }); |
- | | + | 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 ====== | ||
+ | <vala code> | ||
+ | namespace Sandcat { | ||
+ | private class Manager : Midori.Extension { | ||
+ | internal Manager () { | ||
+ | GLib.Object (name: _(" | ||
+ | | ||
+ | | ||
+ | | ||
+ | activate.connect (this.activated); | ||
+ | deactivate.connect (this.deactivated); | ||
+ | } | ||
+ | void tool_menu_populated (Gtk.Menu menu) { | ||
+ | var item = new Gtk.MenuItem.with_label(" | ||
+ | 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 (); | ||
+ | } | ||
+ | </ | ||
+ | Here you are enjoy, it is easy, isn't it ? :-) | ||
====== Modify resources or webpages loaded ====== | ====== Modify resources or webpages loaded ====== | ||
Line 250: | Line 286: | ||
<code vala> | <code vala> | ||
- | // in browser_added | + | namespace Sandcat { |
- | | + | |
- | | + | |
- | | + | internal Manager () { |
- | </ | + | GLib.Object (name: _("Furry example extension"), |
+ | description: | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | void browser_added (Midori.Browser browser) { | ||
+ | var button = new Gtk.Button.with_label (" | ||
+ | var click_counter = 0; | ||
+ | browser.statusbar.pack_start (button, false, false, 3); | ||
+ | button.clicked.connect (() => { | ||
+ | button.label = "You Clicked me (%d) time(s)" | ||
+ | }); | ||
+ | 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 (); | ||
+ | } | ||
+ | </ | ||
+ | Enjoy How much time you click :-), you can add any Gtk widget in this StatusBar. | ||
====== Add a panel ====== | ====== Add a panel ====== | ||
Line 316: | Line 386: | ||
| | ||
} | } | ||
+ | </ | ||
+ | |||
+ | With a simple example it will be like this: | ||
+ | <code vala> | ||
+ | void test_furry_purr () { | ||
+ | assert (1 == 1); | ||
+ | } | ||
+ | |||
+ | public void extension_test () { | ||
+ | | ||
+ | } | ||
+ | |||
+ | void main (string[] args) { | ||
+ | Test.init (ref args); | ||
+ | extension_test(); | ||
+ | Test.run (); | ||
+ | }</ | ||
+ | The output could look like this. | ||
+ | <code bash> | ||
+ | / | ||
</ | </ |