forked from bananenfisch/RecentItems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.js
179 lines (147 loc) · 5.36 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
168
169
170
171
172
173
174
175
176
177
178
179
/*
RECENT ITEMS (Version 18), an extension for the gnome-shell.
(C) 2011-2020 Kurt Fleisch; <https://www.bananenfisch.net/gnome/> <https://github.com/bananenfisch/RecentItems>
Gnome Shell Extensions: <https://extensions.gnome.org/>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. <http://www.gnu.org/licenses/>
DEFINE YOUR SETTINGS HERE (restart the gnome-shell after changing...)
*/
const ITEMS = 10; // number of items to list
const MORE = 50; // number of items to list under "more..."
const BLACKLIST = ""; // to blacklist (hide) spezific MIME media types
/*
available media-types are: text, image, audio, video, application, multipart, message, model.
you can define one or more (seperate with ",") types.
for example to blacklist all images use:
const BLACKLIST = "image";
to blacklist all images, videos and audios, you can use:
const BLACKLIST = "image,audio,video";
END OF SETTINGS SECTION
*/
const Gtk = imports.gi.Gtk;
const Gio = imports.gi.Gio;
const GObject = imports.gi.GObject;
const St = imports.gi.St;
const Main = imports.ui.main;
const PopupMenu = imports.ui.popupMenu;
const PanelMenu = imports.ui.panelMenu;
function sortfunc(x,y) {
return y[0] - x[0];
}
var MyPopupMenuItem = GObject.registerClass({
GTypeName: "MyPopupMenuItem"
},
class MyPopupMenuItem extends PopupMenu.PopupBaseMenuItem {
_init(gicon, text, params) {
super._init(params);
this.box = new St.BoxLayout({ style_class: 'popup-combobox-item' });
if (gicon)
this.icon = new St.Icon({ gicon: gicon, style_class: 'popup-menu-icon' });
else
this.icon = new St.Icon({ icon_name: 'edit-clear-symbolic', icon_size: 22 });
this.box.add(this.icon);
this.label = new St.Label({ text: " " + text });
this.box.add(this.label);
this.actor.add(this.box);
}
});
var RecentItems = GObject.registerClass({
GTypeName: "RecentItems"
},
class RecentItems extends PanelMenu.Button {
_init() {
super._init(0.0);
this.connect('destroy', this._onDestroy.bind(this));
this._iconActor = new St.Icon({ icon_name: 'document-open-recent-symbolic', style_class: 'system-status-icon' });
this.actor.add_actor(this._iconActor);
this.actor.add_style_class_name('panel-status-button');
this.RecentManager = new Gtk.RecentManager();
this._display();
this.conhandler = this.RecentManager.connect('changed', this._redisplay.bind(this));
Main.panel.addToStatusArea('recent-items', this);
}
_onDestroy() {
this.RecentManager.disconnect(this.conhandler);
}
_display() {
let items = this.RecentManager.get_items();
let modlist = new Array();
let countItem = items.length;
for (let i = 0; i < countItem; i++) {
modlist[i] = new Array(2);
modlist[i][0] = items[i].get_modified();
modlist[i][1] = i;
}
modlist.sort(sortfunc);
let id = 0;
let idshow = 0;
let blacklistString = BLACKLIST.replace(/\s/g, "");
let blacklistList = blacklistString.split(",");
while (idshow < ITEMS && id < countItem) {
let itemtype = items[modlist[id][1]].get_mime_type();
if (blacklistList.indexOf((itemtype.split("/"))[0]) == -1) {
let gicon = Gio.content_type_get_icon(itemtype);
let menuItem = new MyPopupMenuItem(gicon, items[modlist[id][1]].get_display_name(), {});
let uri = items[modlist[id][1]].get_uri();
this.menu.addMenuItem(menuItem);
menuItem.connect('activate', (mItem, ev) => {
this._launchFile(uri, ev);
});
idshow++;
}
id++;
}
if (id < countItem && MORE > 0) {
this.moreItem = new PopupMenu.PopupSubMenuMenuItem(_("More..."));
this.menu.addMenuItem(this.moreItem);
while (idshow < ITEMS+MORE && id < countItem) {
let itemtype = items[modlist[id][1]].get_mime_type();
if (blacklistList.indexOf((itemtype.split("/"))[0]) == -1) {
let gicon = Gio.content_type_get_icon(itemtype);
let menuItem = new MyPopupMenuItem(gicon, items[modlist[id][1]].get_display_name(), {});
let uri = items[modlist[id][1]].get_uri();
this.moreItem.menu.addMenuItem(menuItem);
menuItem.connect('activate', (mItem, ev) => {
this._launchFile(uri, ev);
});
idshow++;
}
id++;
}
}
if (countItem > 0) {
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
let menuItem = new MyPopupMenuItem(false, ' Clear list', {});
this.menu.addMenuItem(menuItem);
menuItem.connect('activate', this._clearAll.bind(this));
}
}
_redisplay() {
this.menu.removeAll();
this._display();
}
_launchFile(uri, ev) {
if (ev.get_button() == 3) {
let dir = Gio.Vfs.get_default().get_file_for_uri(uri).get_parent().get_uri();
Gio.app_info_launch_default_for_uri(dir, global.create_app_launch_context(0, -1));
}
else {
Gio.app_info_launch_default_for_uri(uri, global.create_app_launch_context(0, -1));
}
}
_clearAll() {
let GtkRecent = new Gtk.RecentManager();
GtkRecent.purge_items();
}
});
function init() {
}
let Rec;
function enable() {
Rec = new RecentItems();
}
function disable() {
Rec.destroy();
}