home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2011 November
/
CHIP_2011_11.iso
/
Programy
/
Narzedzia
/
AIMP2
/
aimp_2.61.583.exe
/
$TEMP
/
YandexPackSetup.msi
/
filB1B037F8DE5ECE0089F2D0BF8443D365
< prev
next >
Wrap
Text File
|
2010-07-12
|
6KB
|
214 lines
const EXTENSION_PATH = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService)
.newFileURI(__LOCATION__.parent.parent)
.spec;
Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader)
.loadSubScript(EXTENSION_PATH + "modules/xb/config.js");
Cu.import(EXTENSION_PATH + "modules/xb/XPCOMUtilsEx.jsm");
Cu.import(EXTENSION_PATH + "modules/JSON.jsm");
// Hack: get last autocomplete result.
let LastResultHack = {
_result: null, // SimpleAutoCompleteResult
get result() {
return this._result;
},
set result(aValue) {
this._result = aValue;
},
clear: function LastResultHack_clear() {
this._result = null;
},
get lastResult() {
let result = this.result;
if (result)
return result._results[result._lastResultIndex];
return null;
},
getResultForString: function LastResultHack_getResultForString(aString) {
let result = this.lastResult;
if (result && result.value.toLowerCase() == aString.toLowerCase())
return result;
return null;
}
};
// Implements nsIAutoCompleteResult
function SimpleAutoCompleteResult(searchString, searchResult,
defaultIndex, errorDescription,
results, comments) {
this._searchString = searchString;
this._searchResult = searchResult;
this._defaultIndex = defaultIndex;
this._errorDescription = errorDescription;
this._results = results;
this._comments = comments;
this._lastResultIndex = -1;
}
SimpleAutoCompleteResult.prototype = {
_searchString: "",
_searchResult: 0,
_defaultIndex: 0,
_errorDescription: "",
_results: [],
_comments: [],
get wrappedJSObject() {
return this;
},
/**
* The original search string
*/
get searchString() {
return this._searchString;
},
/**
* The result code of this result object, either:
* RESULT_IGNORED (invalid searchString)
* RESULT_FAILURE (failure)
* RESULT_NOMATCH (no matches found)
* RESULT_SUCCESS (matches found)
*/
get searchResult() {
return this._searchResult;
},
/**
* Index of the default item that should be entered if none is selected
*/
get defaultIndex() {
return this._defaultIndex;
},
/**
* A string describing the cause of a search failure
*/
get errorDescription() {
return this._errorDescription;
},
/**
* The number of matches
*/
get matchCount() {
return this._results.length;
},
/**
* Get the value of the result at the given index
*/
getValueAt: function(aIndex) {
this._lastResultIndex = aIndex;
return this._results[aIndex].value;
},
/**
* Get the comment of the result at the given index
*/
getCommentAt: function(index) {
return this._comments[index];
},
/**
* Get the style hint for the result at the given index
*/
getStyleAt: function(index) {
if (!this._comments[index])
return null; // not a category label, so no special styling
if (index == 0)
return "suggestfirst"; // category label on first line of results
return "suggesthint"; // category label on any other line of results
},
/**
* Get the image for the result at the given index
* The return value is expected to be an URI to the image to display
*/
getImageAt: function (index) {
return "";
},
/**
* Remove the value at the given index from the autocomplete results.
* If removeFromDb is set to true, the value should be removed from
* persistent storage as well.
*/
removeValueAt: function(index, removeFromDb) {
this._results.splice(index, 1);
this._comments.splice(index, 1);
},
QueryInterface: XPCOMUtilsEx.generateQI([Ci.nsIAutoCompleteResult, Ci.nsISupports])
};
// Implements nsIAutoCompleteSearch
function SimpleAutoCompleteSearch() {
}
SimpleAutoCompleteSearch.prototype = {
classDescription: "Custom Yandex.Bar AutoComplete",
classID: Components.ID("7ec0573a-0738-11df-ab80-979cccaab3b0"),
contractID: "@mozilla.org/autocomplete/search;1?name=yacustombar-autocomplete",
QueryInterface: XPCOMUtilsEx.generateQI([Ci.nsIAutoCompleteSearch, Ci.nsISupports]),
get wrappedJSObject() {
return {
lastResult: LastResultHack
}
},
startSearch: function(aSearchString, aSearchParam, aResult, aListener) {
LastResultHack.result = null;
if (!aSearchParam.length)
return;
let results = [];
let comments = [];
let lowercaseSearchString = aSearchString.toLowerCase();
JSON.parse(aSearchParam).forEach(function(aSearchResult) {
if (aSearchResult.value.toLowerCase().indexOf(lowercaseSearchString) == 0) {
results.push({
value: aSearchResult.value,
realValue: aSearchResult.realValue,
});
comments.push(aSearchResult.comment || null);
}
});
let newResult = new SimpleAutoCompleteResult(aSearchString, Ci.nsIAutoCompleteResult.RESULT_SUCCESS,
0, "", results, comments);
LastResultHack.result = newResult;
aListener.onSearchResult(this, newResult);
},
stopSearch: function() {}
};
function NSGetModule(compMgr, fileSpec)
XPCOMUtilsEx.generateModule([SimpleAutoCompleteSearch]);