2
Copyright (C) 2013 Paweł Forysiuk <tuxator@o2.pl>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Lesser General Public
6
License as published by the Free Software Foundation; either
7
version 2.1 of the License, or (at your option) any later version.
9
See the file COPYING for the full license text.
19
private class Sidebar : Gtk.VBox, Midori.Viewable {
20
Gtk.Toolbar? toolbar = null;
22
Gtk.TreeView notes_tree_view;
23
Gtk.TextView note_text_view = new Gtk.TextView ();
24
Gtk.ListStore notes_list_store = new Gtk.ListStore (2, typeof (string), typeof (string));
26
public unowned string get_stock_id () {
27
return Gtk.STOCK_EDIT;
30
public unowned string get_label () {
34
public Gtk.Widget get_toolbar () {
35
if (toolbar == null) {
36
toolbar = new Gtk.Toolbar ();
37
var new_note_button = new Gtk.ToolButton.from_stock (Gtk.STOCK_EDIT);
38
new_note_button.label = _("New Note");
39
new_note_button.tooltip_text = _("Creates a new empty note, urelated to opened pages");
40
new_note_button.use_underline = true;
41
new_note_button.is_important = true;
42
new_note_button.show ();
43
new_note_button.clicked.connect (() => {
44
stdout.printf ("IMPLEMENT ME: would add new empty note INSERT INTO NOTES ....\n");
46
toolbar.insert (new_note_button, -1);
47
} // if (toolbar != null)
52
Gtk.TreeViewColumn column;
55
notes_tree_view = new Gtk.TreeView.with_model (notes_list_store);
56
notes_tree_view.headers_visible = true;
58
column = new Gtk.TreeViewColumn ();
59
Gtk.CellRendererText renderer_title = new Gtk.CellRendererText ();
60
column.set_title (_("Notes"));
61
column.pack_start (renderer_title, true);
62
column.set_cell_data_func (renderer_title, on_renderer_note_title);
63
notes_tree_view.append_column (column);
66
notes_list_store.append (out iter);
67
notes_list_store.set (iter, 0, "test note nr1");
68
notes_list_store.append (out iter);
69
notes_list_store.set (iter, 0, "test note nr2");
72
notes_tree_view.show ();
73
pack_start (notes_tree_view, false, false, 0);
75
note_label = new Gtk.Label (null);
76
note_label.set_text (_("Note clipped from: some_uri"));
78
pack_start (note_label, false, false, 0);
80
note_text_view.show ();
81
pack_start (note_text_view, true, true, 0);
84
private void on_renderer_note_title (Gtk.CellLayout column, Gtk.CellRenderer renderer,
85
Gtk.TreeModel model, Gtk.TreeIter iter) {
88
model.get (iter, 0, out note_title);
89
renderer.set ("text", note_title,
90
"ellipsize", Pango.EllipsizeMode.END);
91
} // on_renderer_note_title
94
private class Manager : Midori.Extension {
95
internal GLib.List<Gtk.Widget> widgets;
97
void tab_added (Midori.Browser browser, Midori.Tab tab) {
99
tab.context_menu.connect (add_menu_items);
103
void note_add_new (string title, string uri, string note_content)
105
// GLib.DateTime time = new DateTime.now_local ();
106
stdout.printf ("add note title %s uri %s note: %s \n", title, uri, note_content);
109
void add_menu_items (Midori.Tab tab, WebKit.HitTestResult hit_test_result, Midori.ContextAction menu) {
110
if ((hit_test_result.context & WebKit.HitTestResultContext.SELECTION) == 0)
113
var view = tab as Midori.View;
114
var action = new Gtk.Action ("Notes", _("Copy text to note"), null, null);
115
action.activate.connect ((action)=> {
116
if (view.has_selection () == true)
118
string selected_text = view.get_selected_text ();
119
string uri = view.get_display_uri ();
120
string title = view.get_display_title ();
121
note_add_new (title, uri, selected_text);
128
void browser_added (Midori.Browser browser) {
129
var viewable = new Sidebar ();
131
browser.panel.append_page (viewable);
132
widgets.append (viewable);
134
foreach (var tab in browser.get_tabs ())
135
tab_added (browser, tab);
137
browser.add_tab.connect (tab_added);
140
void activated (Midori.App app) {
141
widgets = new GLib.List<Gtk.Widget> ();
142
foreach (var browser in app.get_browsers ())
143
browser_added (browser);
146
void deactivated () {
147
var app = get_app ();
148
app.add_browser.disconnect (browser_added);
149
foreach (var widget in widgets)
153
internal Manager () {
154
GLib.Object (name: _("Notes"),
155
description: _("Save text clips from websites as notes"),
156
version: "0.1" + Midori.VERSION_SUFFIX,
157
authors: "Paweł Forysiuk");
159
this.activate.connect (activated);
160
this.deactivate.connect (deactivated);
162
} // Manager : Midori.Extension
163
} // namespace Clipnotes
165
public Midori.Extension extension_init () {
166
return new ClipNotes.Manager ();