Merge lp:~ivaldi/midori/advanced-page-actions into lp:midori

Proposed by André Stösel
Status: Work in progress
Proposed branch: lp:~ivaldi/midori/advanced-page-actions
Merge into: lp:midori
Diff against target: 141 lines (+137/-0)
1 file modified
extensions/advanced-actions.vala (+137/-0)
To merge this branch: bzr merge lp:~ivaldi/midori/advanced-page-actions
Reviewer Review Type Date Requested Status
Midori Devs Pending
Review via email: mp+181108@code.launchpad.net
To post a comment you must log in.

Unmerged revisions

6357. By André Stösel

New extension "Advanced Actions"

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'extensions/advanced-actions.vala'
2--- extensions/advanced-actions.vala 1970-01-01 00:00:00 +0000
3+++ extensions/advanced-actions.vala 2013-08-20 17:25:34 +0000
4@@ -0,0 +1,137 @@
5+/*
6+ Copyright (C) 2013 André Stösel <andre@stoesel.de>
7+
8+ This library is free software; you can redistribute it and/or
9+ modify it under the terms of the GNU Lesser General Public
10+ License as published by the Free Software Foundation; either
11+ version 2.1 of the License, or (at your option) any later version.
12+
13+ See the file COPYING for the full license text.
14+*/
15+
16+namespace AdvancedActions {
17+ private class LinkBucket : Gtk.Window {
18+ public GLib.HashTable<string, string?> link_bucket {get; construct; }
19+
20+ private void create_content () {
21+ this.title = _("LinkBucket");
22+ this.set_default_size (500, 500);
23+
24+ Gtk.VBox vbox = new Gtk.VBox (false, 1);
25+ this.add (vbox);
26+
27+ Gtk.TextIter iter;
28+ Gtk.TextBuffer buffer = new Gtk.TextBuffer (null);
29+ buffer.get_end_iter (out iter);
30+ foreach (string uri in this.link_bucket.get_keys ()) {
31+ buffer.insert (ref iter, "%s\n".printf (uri), -1);
32+ }
33+
34+ Gtk.TextView text_view = new Gtk.TextView.with_buffer (buffer);
35+ text_view.editable = false;
36+
37+ Gtk.ScrolledWindow scroll = new Gtk.ScrolledWindow (null, null);
38+ scroll.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
39+ scroll.add (text_view);
40+
41+ vbox.pack_end (scroll, true, true, 0);
42+
43+ this.show_all ();
44+ }
45+
46+ internal LinkBucket (GLib.HashTable<string, string?> link_bucket) {
47+ GLib.Object (type: Gtk.WindowType.TOPLEVEL,
48+ window_position: Gtk.WindowPosition.CENTER,
49+ link_bucket: link_bucket);
50+
51+ this.create_content ();
52+ }
53+ }
54+
55+ private class Manager : Midori.Extension {
56+ private GLib.HashTable<string, string?> link_bucket;
57+
58+ private void open_link_bucket () {
59+ LinkBucket lb = new LinkBucket (this.link_bucket);
60+ lb.show ();
61+ }
62+
63+ private void create_menu_item (Midori.Browser browser, Gtk.MenuShell menu) {
64+ Gtk.MenuItem menu_item = new Gtk.MenuItem.with_mnemonic (_("Open link bucket"));
65+ menu_item.activate.connect (this.open_link_bucket);
66+ if (this.link_bucket.size () <= 0)
67+ menu_item.sensitive = false;
68+ menu_item.show ();
69+ menu.append (menu_item);
70+ }
71+
72+ private void collect_links (string? title, string? uri) {
73+ if (uri != null) {
74+ Gdk.ModifierType state;
75+ Gdk.Event event = Gtk.get_current_event ();
76+ if (event.get_state (out state)) {
77+ if ((state & Gdk.ModifierType.SHIFT_MASK) == Gdk.ModifierType.SHIFT_MASK &&
78+ (state & Gdk.ModifierType.CONTROL_MASK) == Gdk.ModifierType.CONTROL_MASK) {
79+ this.link_bucket.insert (uri, title);
80+ }
81+ }
82+ }
83+ }
84+
85+ private void tab_added (Midori.Browser browser, Midori.View view) {
86+ view.web_view.hovering_over_link.connect (this.collect_links);
87+ }
88+
89+ private void tab_removed (Midori.Browser browser, Midori.View view) {
90+ view.web_view.hovering_over_link.disconnect (this.collect_links);
91+ }
92+
93+ private void browser_added (Midori.Browser browser) {
94+ foreach (Midori.View tab in browser.get_tabs ())
95+ this.tab_added (browser, tab);
96+ browser.add_tab.connect (this.tab_added);
97+ browser.remove_tab.connect (this.tab_removed);
98+ browser.populate_tool_menu.connect (this.create_menu_item);
99+ }
100+
101+ private void browser_removed (Midori.Browser browser) {
102+ foreach (Midori.View tab in browser.get_tabs ())
103+ this.tab_removed (browser, tab);
104+ browser.add_tab.disconnect (this.tab_added);
105+ browser.remove_tab.disconnect (this.tab_removed);
106+ browser.populate_tool_menu.disconnect (this.create_menu_item);
107+ }
108+
109+ private void activated (Midori.App app) {
110+ foreach (Midori.Browser browser in app.get_browsers ())
111+ this.browser_added (browser);
112+ app.add_browser.connect (this.browser_added);
113+ app.remove_browser.connect (this.browser_removed);
114+ }
115+
116+ private void deactivated () {
117+ Midori.App app = this.get_app ();
118+ foreach (Midori.Browser browser in app.get_browsers ())
119+ this.browser_removed (browser);
120+ app.add_browser.disconnect (this.browser_added);
121+ app.remove_browser.disconnect (this.browser_removed);
122+ }
123+
124+ internal Manager () {
125+ GLib.Object (name: _("Advanced Actions"),
126+ description: _("Adds additional actions to midori"),
127+ version: "0.1" + Midori.VERSION_SUFFIX,
128+ authors: "André Stösel <andre@stoesel.de>");
129+
130+ this.link_bucket = new GLib.HashTable<string, string?> (GLib.str_hash, GLib.str_equal);
131+
132+ this.activate.connect (this.activated);
133+ this.deactivate.connect (this.deactivated);
134+ }
135+ }
136+}
137+
138+public Midori.Extension extension_init () {
139+ return new AdvancedActions.Manager ();
140+}
141+

Subscribers

People subscribed via source and target branches

to all changes: