2009-06-16 16:20:12 +00:00
|
|
|
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
|
|
|
2010-02-09 17:42:07 +00:00
|
|
|
const St = imports.gi.St;
|
|
|
|
const Shell = imports.gi.Shell;
|
2009-07-09 01:06:06 +00:00
|
|
|
const Lang = imports.lang;
|
|
|
|
const Signals = imports.signals;
|
2009-11-29 22:45:30 +00:00
|
|
|
const Search = imports.ui.search;
|
2009-06-16 16:20:12 +00:00
|
|
|
|
|
|
|
const THUMBNAIL_ICON_MARGIN = 2;
|
|
|
|
|
|
|
|
function DocInfo(recentInfo) {
|
|
|
|
this._init(recentInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
DocInfo.prototype = {
|
|
|
|
_init : function(recentInfo) {
|
2009-10-21 20:56:06 +00:00
|
|
|
this.recentInfo = recentInfo;
|
2009-07-25 15:00:37 +00:00
|
|
|
// We actually used get_modified() instead of get_visited()
|
|
|
|
// here, as GtkRecentInfo doesn't updated get_visited()
|
|
|
|
// correctly. See http://bugzilla.gnome.org/show_bug.cgi?id=567094
|
2010-07-09 22:17:20 +00:00
|
|
|
this.timestamp = recentInfo.get_modified();
|
2009-06-16 16:20:12 +00:00
|
|
|
this.name = recentInfo.get_display_name();
|
2009-11-29 22:45:30 +00:00
|
|
|
this._lowerName = this.name.toLowerCase();
|
2009-06-16 16:20:12 +00:00
|
|
|
this.uri = recentInfo.get_uri();
|
|
|
|
this.mimeType = recentInfo.get_mime_type();
|
|
|
|
},
|
|
|
|
|
2009-06-29 19:08:48 +00:00
|
|
|
createIcon : function(size) {
|
2010-02-09 17:42:07 +00:00
|
|
|
return St.TextureCache.get_default().load_recent_thumbnail(size, this.recentInfo);
|
2009-06-16 16:20:12 +00:00
|
|
|
},
|
|
|
|
|
2011-01-30 21:09:58 +00:00
|
|
|
launch : function(workspaceIndex) {
|
|
|
|
Shell.DocSystem.get_default().open(this.recentInfo, workspaceIndex);
|
2009-06-16 16:20:12 +00:00
|
|
|
},
|
|
|
|
|
2009-11-29 22:45:30 +00:00
|
|
|
matchTerms: function(terms) {
|
|
|
|
let mtype = Search.MatchType.NONE;
|
|
|
|
for (let i = 0; i < terms.length; i++) {
|
|
|
|
let term = terms[i];
|
|
|
|
let idx = this._lowerName.indexOf(term);
|
|
|
|
if (idx == 0) {
|
|
|
|
mtype = Search.MatchType.PREFIX;
|
|
|
|
} else if (idx > 0) {
|
2010-06-06 23:09:15 +00:00
|
|
|
if (mtype == Search.MatchType.NONE)
|
|
|
|
mtype = Search.MatchType.SUBSTRING;
|
2009-11-29 22:45:30 +00:00
|
|
|
} else {
|
2010-06-06 23:09:15 +00:00
|
|
|
return Search.MatchType.NONE;
|
2009-11-29 22:45:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return mtype;
|
2009-06-16 16:20:12 +00:00
|
|
|
}
|
|
|
|
};
|
2009-07-09 01:06:06 +00:00
|
|
|
|
|
|
|
var docManagerInstance = null;
|
|
|
|
|
2009-08-17 02:23:44 +00:00
|
|
|
function getDocManager() {
|
2009-07-09 01:06:06 +00:00
|
|
|
if (docManagerInstance == null)
|
2009-08-17 02:23:44 +00:00
|
|
|
docManagerInstance = new DocManager();
|
2009-07-09 01:06:06 +00:00
|
|
|
return docManagerInstance;
|
|
|
|
}
|
|
|
|
|
2009-11-29 22:43:25 +00:00
|
|
|
/**
|
2011-01-14 21:15:53 +00:00
|
|
|
* DocManager wraps the DocSystem, primarily to expose DocInfo objects.
|
2009-11-29 22:43:25 +00:00
|
|
|
*/
|
2009-08-17 02:23:44 +00:00
|
|
|
function DocManager() {
|
|
|
|
this._init();
|
2009-07-09 01:06:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DocManager.prototype = {
|
2009-08-17 02:23:44 +00:00
|
|
|
_init: function() {
|
2009-11-29 22:43:25 +00:00
|
|
|
this._docSystem = Shell.DocSystem.get_default();
|
|
|
|
this._infosByTimestamp = [];
|
|
|
|
this._infosByUri = {};
|
|
|
|
this._docSystem.connect('changed', Lang.bind(this, this._reload));
|
2009-07-09 01:06:06 +00:00
|
|
|
this._reload();
|
|
|
|
},
|
|
|
|
|
|
|
|
_reload: function() {
|
2009-11-29 22:43:25 +00:00
|
|
|
let docs = this._docSystem.get_all();
|
|
|
|
this._infosByTimestamp = [];
|
|
|
|
this._infosByUri = {};
|
2009-07-09 01:06:06 +00:00
|
|
|
for (let i = 0; i < docs.length; i++) {
|
|
|
|
let recentInfo = docs[i];
|
2009-08-17 02:23:44 +00:00
|
|
|
|
2009-07-09 01:06:06 +00:00
|
|
|
let docInfo = new DocInfo(recentInfo);
|
2009-11-29 22:43:25 +00:00
|
|
|
this._infosByTimestamp.push(docInfo);
|
|
|
|
this._infosByUri[docInfo.uri] = docInfo;
|
2009-07-09 01:06:06 +00:00
|
|
|
}
|
2009-11-29 22:43:25 +00:00
|
|
|
this.emit('changed');
|
|
|
|
},
|
|
|
|
|
|
|
|
getTimestampOrderedInfos: function() {
|
|
|
|
return this._infosByTimestamp;
|
|
|
|
},
|
|
|
|
|
|
|
|
getInfosByUri: function() {
|
|
|
|
return this._infosByUri;
|
|
|
|
},
|
|
|
|
|
|
|
|
lookupByUri: function(uri) {
|
|
|
|
return this._infosByUri[uri];
|
2009-07-09 01:06:06 +00:00
|
|
|
},
|
|
|
|
|
2009-11-29 22:43:25 +00:00
|
|
|
queueExistenceCheck: function(count) {
|
|
|
|
return this._docSystem.queue_existence_check(count);
|
2009-11-29 22:45:30 +00:00
|
|
|
},
|
|
|
|
|
2010-06-06 23:09:15 +00:00
|
|
|
_searchDocs: function(items, terms) {
|
|
|
|
let multiplePrefixMatches = [];
|
2009-11-29 22:45:30 +00:00
|
|
|
let prefixMatches = [];
|
2010-06-06 23:09:15 +00:00
|
|
|
let multipleSubtringMatches = [];
|
2009-11-29 22:45:30 +00:00
|
|
|
let substringMatches = [];
|
2010-06-06 23:09:15 +00:00
|
|
|
for (let i = 0; i < items.length; i++) {
|
|
|
|
let item = items[i];
|
2009-11-29 22:45:30 +00:00
|
|
|
let mtype = item.matchTerms(terms);
|
2010-06-06 23:09:15 +00:00
|
|
|
if (mtype == Search.MatchType.MULTIPLE_PREFIX)
|
|
|
|
multiplePrefixMatches.push(item.uri);
|
2009-11-29 22:45:30 +00:00
|
|
|
else if (mtype == Search.MatchType.PREFIX)
|
|
|
|
prefixMatches.push(item.uri);
|
2010-06-06 23:09:15 +00:00
|
|
|
else if (mtype == Search.MatchType.MULTIPLE_SUBSTRING)
|
|
|
|
multipleSubtringMatches.push(item.uri);
|
2009-11-29 22:45:30 +00:00
|
|
|
else if (mtype == Search.MatchType.SUBSTRING)
|
|
|
|
substringMatches.push(item.uri);
|
|
|
|
}
|
2010-06-06 23:09:15 +00:00
|
|
|
return multiplePrefixMatches.concat(prefixMatches.concat(multipleSubtringMatches.concat(substringMatches)));
|
|
|
|
},
|
|
|
|
|
|
|
|
initialSearch: function(terms) {
|
|
|
|
return this._searchDocs(this._infosByTimestamp, terms);
|
2009-11-29 22:45:30 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
subsearch: function(previousResults, terms) {
|
2010-06-06 23:09:15 +00:00
|
|
|
return this._searchDocs(previousResults.map(Lang.bind(this,
|
|
|
|
function(url) {
|
|
|
|
return this._infosByUri[url];
|
|
|
|
})), terms);
|
2009-07-09 01:06:06 +00:00
|
|
|
}
|
2010-05-19 17:26:41 +00:00
|
|
|
};
|
2009-07-09 01:06:06 +00:00
|
|
|
|
|
|
|
Signals.addSignalMethods(DocManager.prototype);
|