diff options
author | James Axl <bilimish@yandex.ru> | 2014-02-23 12:30:04 +0100 |
---|---|---|
committer | Christian Dywan <christian.dywan@canonical.com> | 2014-02-23 12:30:04 +0100 |
commit | e370bc2e2eafac4787aa7b7690337e310dc2dade (patch) | |
tree | 43bebca2056dbb2316fbffcd6b6d281ab14ab995 /extensions/domain-keys.vala | |
parent | 1444c19b4115a0dbe668dc8963258e2ca995feaf (diff) | |
download | midori-e370bc2e2eafac4787aa7b7690337e310dc2dade.tar.gz |
Add first version of Domain Hotkeys extension
Diffstat (limited to 'extensions/domain-keys.vala')
-rw-r--r-- | extensions/domain-keys.vala | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/extensions/domain-keys.vala b/extensions/domain-keys.vala new file mode 100644 index 00000000..8ce639da --- /dev/null +++ b/extensions/domain-keys.vala @@ -0,0 +1,64 @@ +/* + Copyright (C) 2014 James Axl <bilimish@yandex.ru> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + See the file COPYING for the full license text. +*/ + +namespace DomainHotkeys { + class Manager : Midori.Extension { + internal Manager () { + GLib.Object (name: _("Domain Hotkeys"), + description: _("Add www. and .com and proceed with Ctrl+Enter"), + version: "0.1" + Midori.VERSION_SUFFIX, + authors: "James Axl <bilimish@yandex.ru>"); + activate.connect (this.activated); + deactivate.connect (this.deactivated); + } + + bool key_press_event (Midori.LocationAction action, Gdk.EventKey event_key) { + if (event_key.keyval == Gdk.Key.Return) { + if ((bool)(event_key.state & Gdk.ModifierType.CONTROL_MASK)) { + var old_text = action.get_text (); + var new_text = "www." + old_text + ".com"; + action.submit_uri(new_text, false); + return true; + } + } + return false; + } + + void browser_added (Midori.Browser browser) { + var action_group = browser.get_action_group (); + var action = action_group.get_action ("Location") as Midori.LocationAction; + action.key_press_event.connect (key_press_event); + } + + void activated (Midori.App app) { + foreach (var browser in app.get_browsers ()) + browser_added (browser); + app.add_browser.connect (browser_added); + } + + void browser_removed (Midori.Browser browser) { + var action_group = browser.get_action_group (); + var action = action_group.get_action ("Location") as Midori.LocationAction; + action.key_press_event.disconnect (key_press_event); + } + + void deactivated () { + var app = get_app (); + app.add_browser.disconnect (browser_added); + foreach (var browser in app.get_browsers ()) + browser_removed (browser); + } + } +} + +public Midori.Extension extension_init () { + return new DomainHotkeys.Manager (); +} |