-
Notifications
You must be signed in to change notification settings - Fork 1
/
extension.js
167 lines (134 loc) · 4.61 KB
/
extension.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
* Copyright (C) 2013 Rodrigo Moya.
*
* 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.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Rodrigo Moya <[email protected]>
*
*/
const St = imports.gi.St;
const Lang = imports.lang;
const Shell = imports.gi.Shell;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const Gettext = imports.gettext.domain('gnome-shell-extensions');
const _ = Gettext.gettext;
const Main = imports.ui.main;
const Panel = imports.ui.panel;
const PanelMenu = imports.ui.panelMenu;
const PopupMenu = imports.ui.popupMenu;
var tomboyProxy = null;
function getTomboyProxy() {
if (tomboyProxy == null) {
try {
tomboyProxy = new Gio.DBusProxy.new_sync(
Gio.bus_get_sync (Gio.BusType.SESSION, null),
Gio.DBusProxyFlags.DO_NOT_CONNECT_SIGNALS,
null,
"org.gnome.Tomboy",
"/org/gnome/Tomboy/RemoteControl",
"org.gnome.Tomboy.RemoteControl",
null);
} catch (err) {
global.log (err.message);
}
}
return tomboyProxy;
}
function proxyCallSync (method, parameters) {
var proxy = getTomboyProxy();
if (proxy != null) {
try {
return proxy.call_sync (method, parameters, 0, -1, null);
} catch (err) {
global.log(err.message);
}
}
return null;
}
const TomboyNoteMenuItem = new Lang.Class({
Name: 'TomboyNoteMenuItem',
Extends: PopupMenu.PopupBaseMenuItem,
_init: function(note_url) {
this.parent();
this._note_url = note_url;
var title = proxyCallSync ("GetNoteTitle",
GLib.Variant.new ('(s)', [ this._note_url ]));
if (title)
this._title = title.deep_unpack ()[0];
else
this._title = this._note_url;
this.label = new St.Label({ text: this._title });
this.addActor (this.label);
},
activate: function (event) {
proxyCallSync("DisplayNote",
GLib.Variant.new ('(s)', [ this._note_url ]));
this.parent (event);
}
});
const TomboyPanelMenu = new Lang.Class({
Name: 'Tomboy.PanelMenu',
Extends: PanelMenu.SystemStatusButton,
_init: function() {
this.parent('folder-documents');
var menu_item;
menu_item = new PopupMenu.PopupMenuItem(_("New note"));
menu_item.connect('clicked', Lang.bind(this, this._new_note));
this.menu.addMenuItem(menu_item);
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
/* Section for notes menu items */
this._contentSection = new PopupMenu.PopupMenuSection();
this.menu.addMenuItem(this._contentSection);
/* Separator */
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
/* 'Search' menu item */
menu_item = new PopupMenu.PopupMenuItem(_("Search notes"));
menu_item.connect('clicked', Lang.bind(this, this._run_search));
this.menu.addMenuItem(menu_item);
var proxy = getTomboyProxy ();
if (proxy != null) {
/* Add notes now */
this._update();
this.actor.show();
} else {
global.log("Tomboy DBus RemoteControl interface not available");
this.hide();
}
},
_new_note: function() {
//proxyCallSync ("CreateNote", null);
},
_run_search: function() {
proxyCallSync ("DisplaySearch", null);
},
_update: function() {
this._contentSection.removeAll();
var notes = proxyCallSync ("ListAllNotes", null).get_child_value (0);
for (var i = 0; i < notes.n_children(); i++) {
var note_url = notes.get_child_value(i);
this._contentSection.addMenuItem (new TomboyNoteMenuItem (note_url.deep_unpack ()));
}
},
});
function init() {
}
let _indicator;
function enable() {
_indicator = new TomboyPanelMenu;
Main.panel.addToStatusArea('tomboy-menu', _indicator);
}
function disable() {
_indicator.destroy();
}