forked from sciancio/connectionmanager2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.js
115 lines (95 loc) · 3.57 KB
/
search.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
// ConnectionManager 3 - Simple GUI app for Gnome 3 that provides a menu
// for initiating SSH/Telnet/Custom Apps connections.
// Copyright (C) 2011 Stefano Ciancio
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 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
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
const St = imports.gi.St;
const Gio = imports.gi.Gio;
const Shell = imports.gi.Shell;
const Util = imports.misc.util;
const Lang = imports.lang;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const Config = imports.misc.config;
// SSH / Apps Search Provider
var SshSearchProvider = new Lang.Class({
Name: 'SshSearchProvider',
_init: function(title) {
this.id = title;
this.sshNames = [];
},
// Update list of SSH/Apps on configuration changes
_update: function (sshNames) {
this.sshNames = sshNames;
},
filterResults: function(providerResults, maxResults) {
return providerResults;
},
createResultObject: function(result, terms) {
return null;
},
getInitialResultSet: function(terms, callback) {
let searching = [];
for (var i=0; i<this.sshNames.length; i++) {
for (var j=0; j<terms.length; j++) {
let pattern = new RegExp(terms[j],"gi");
if (this.sshNames[i].name.match(pattern)) {
// +1 because id 0 breaks search results
searching.push(i+1);
}
}
}
if (typeof callback === "function") {
callback(searching);
}
},
getSubsearchResultSet: function(previousResults, terms, callback) {
this.getInitialResultSet(terms, callback);
},
getResultMetas: function(resultIds, callback) {
let metas = [];
let app = null;
for (let i=0; i<resultIds.length; i++) {
let result = this.sshNames[resultIds[i]-1]
let appSys = Shell.AppSystem.get_default();
let app = null;
switch (result.type) {
case '__app__':
app = null;
break;
case '__item__':
app = appSys.lookup_app(result.terminal + '.desktop');
break;
}
metas.push({
'id': resultIds[i],
'name': result.name,
'createIcon': function(size) {
let icon = null;
let appt = app;
if (app)
icon = app.create_icon_texture(size);
else
icon = new St.Icon({ gicon: Gio.icon_new_for_string(Me.path + '/emblem-cm-symbolic.svg'),
icon_size: size });
return icon;
}
})
}
callback(metas);
},
activateResult: function(id) {
Util.spawnCommandLine(this.sshNames[id-1].command);
},
});