43 const Ci = Components.interfaces;
44 const Cc = Components.classes;
53 init:
function engineManager_init() {
56 var prefService =
Cc[
"@mozilla.org/preferences-service;1"].
59 document.getElementById(
"enableSuggest").checked = suggestEnabled;
61 var tree = document.getElementById(
"engineList");
64 var
os =
Cc[
"@mozilla.org/observer-service;1"].
66 os.addObserver(
this,
"browser-search-engine-modified",
false);
69 observe:
function engineManager_observe(aEngine, aTopic, aVerb) {
70 if (aTopic ==
"browser-search-engine-modified") {
71 aEngine.QueryInterface(
Ci.nsISearchEngine)
77 case "engine-changed":
80 case "engine-removed":
81 case "engine-current":
89 onOK:
function engineManager_onOK() {
91 var
os =
Cc[
"@mozilla.org/observer-service;1"].
93 os.removeObserver(
this,
"browser-search-engine-modified");
96 var newSuggestEnabled = document.getElementById(
"enableSuggest").checked;
97 var prefService =
Cc[
"@mozilla.org/preferences-service;1"].
105 onCancel:
function engineManager_onCancel() {
107 var
os =
Cc[
"@mozilla.org/observer-service;1"].
109 os.removeObserver(
this,
"browser-search-engine-modified");
112 onRestoreDefaults:
function engineManager_onRestoreDefaults() {
118 showRestoreDefaults:
function engineManager_showRestoreDefaults(
val) {
119 document.documentElement.getButton(
"extra2").disabled = !
val;
122 loadAddEngines:
function engineManager_loadAddEngines() {
124 window.opener.BrowserSearch.loadAddEngines();
128 remove:
function engineManager_remove() {
135 document.getElementById(
"engineList").focus();
143 bump:
function engineManager_move(aDir) {
147 gEngineView._engineStore.moveEngine(selectedEngine, newIndex);
152 this.showRestoreDefaults(
true);
153 document.getElementById(
"engineList").focus();
156 editKeyword:
function engineManager_editKeyword() {
161 var
prompt =
Cc[
"@mozilla.org/embedcomp/prompt-service;1"].
164 var
strings = document.getElementById(
"engineManagerBundle");
165 var title = strings.getString(
"editTitle");
166 var
msg = strings.getFormattedString(
"editMsg", [selectedEngine.name]);
168 while (prompt.prompt(
window, title, msg, alias,
null, { })) {
169 var bduplicate =
false;
170 var eduplicate =
false;
172 if (
alias.value !=
"") {
174 let bmserv =
Cc[
"@mozilla.org/browser/nav-bookmarks-service;1"].
176 if (bmserv.getURIForKeyword(
alias.value))
182 for each (let engine
in engines) {
183 if (engine.alias ==
alias.value &&
184 engine.name != selectedEngine.name) {
192 if (eduplicate || bduplicate) {
193 var dtitle =
strings.getString(
"duplicateTitle");
194 var bmsg =
strings.getString(
"duplicateBookmarkMsg");
195 var emsg =
strings.getFormattedString(
"duplicateEngineMsg",
198 prompt.alert(
window, dtitle, (eduplicate) ? emsg : bmsg);
200 gEngineView._engineStore.changeEngine(selectedEngine,
"alias",
208 onSelect:
function engineManager_onSelect() {
210 var disableButtons = (
gEngineView.selectedIndex == -1) ||
213 var firstSelected = (
gEngineView.selectedIndex == 0);
214 var noSelection = (
gEngineView.selectedIndex == -1);
217 var isSongbirdEngine = (
gEngineView.selectedEngine.alias ==
"songbird-internal-search");
219 document.getElementById(
"cmd_remove").setAttribute(
"disabled",
220 disableButtons || isSongbirdEngine);
222 document.getElementById(
"cmd_moveup").setAttribute(
"disabled",
223 disableButtons || firstSelected);
225 document.getElementById(
"cmd_movedown").setAttribute(
"disabled",
226 disableButtons || lastSelected);
227 document.getElementById(
"cmd_editkeyword").setAttribute(
"disabled",
234 if (selectedIndex > 0) {
235 event.dataTransfer.setData(
ENGINE_FLAVOR, selectedIndex.toString());
236 event.dataTransfer.effectAllowed =
"move";
243 throw new Error(
"bad args to new EngineMoveOp!");
244 this._engine = aEngineClone.originalEngine;
245 this._newIndex = aNewIndex;
250 commit:
function EMO_commit() {
251 var searchService =
Cc[
"@mozilla.org/browser/search-service;1"].
253 searchService.moveEngine(this._engine, this._newIndex);
257 function EngineRemoveOp(aEngineClone) {
259 throw new Error(
"bad args to new EngineRemoveOp!");
260 this._engine = aEngineClone.originalEngine;
262 EngineRemoveOp.prototype = {
264 commit:
function ERO_commit() {
265 var searchService =
Cc[
"@mozilla.org/browser/search-service;1"].
267 searchService.removeEngine(this._engine);
271 function EngineUnhideOp(aEngineClone, aNewIndex) {
273 throw new Error(
"bad args to new EngineUnhideOp!");
274 this._engine = aEngineClone.originalEngine;
275 this._newIndex = aNewIndex;
277 EngineUnhideOp.prototype = {
280 commit:
function EUO_commit() {
281 this._engine.hidden =
false;
282 var searchService =
Cc[
"@mozilla.org/browser/search-service;1"].
284 searchService.moveEngine(this._engine, this._newIndex);
288 function EngineChangeOp(aEngineClone, aProp,
aValue) {
290 throw new Error(
"bad args to new EngineChangeOp!");
292 this._engine = aEngineClone.originalEngine;
296 EngineChangeOp.prototype = {
300 commit:
function ECO_commit() {
301 this._engine[this._prop] = this._newValue;
305 function EngineStore() {
306 var searchService =
Cc[
"@mozilla.org/browser/search-service;1"].
308 this._engines = searchService.getVisibleEngines({}).map(this._cloneEngine);
309 this._defaultEngines = searchService.getDefaultEngines({}).map(this._cloneEngine);
314 var someHidden = this._defaultEngines.some(
function (e) {
return e.hidden;});
317 EngineStore.prototype = {
319 _defaultEngines:
null,
323 return this._engines;
330 _getIndexForEngine:
function ES_getIndexForEngine(aEngine) {
331 return this._engines.indexOf(aEngine);
334 _getEngineByName:
function ES_getEngineByName(
aName) {
335 for each (var engine
in this._engines)
336 if (engine.name ==
aName)
342 _cloneEngine:
function ES_cloneObj(aEngine) {
344 for (var
i in aEngine)
345 newO[
i] = aEngine[
i];
346 newO.originalEngine = aEngine;
351 _isSameEngine:
function ES_isSameEngine(aEngineClone) {
352 return aEngineClone.originalEngine == this.originalEngine;
355 commit:
function ES_commit() {
356 var searchService =
Cc[
"@mozilla.org/browser/search-service;1"].
358 var currentEngine = this._cloneEngine(searchService.currentEngine);
359 for (var
i = 0;
i < this._ops.length;
i++)
360 this._ops[
i].commit();
364 if (this._defaultEngines.some(
this._isSameEngine, currentEngine) &&
365 !currentEngine.originalEngine.hidden)
366 searchService.currentEngine = currentEngine.originalEngine;
369 addEngine:
function ES_addEngine(aEngine) {
370 this._engines.push(this._cloneEngine(aEngine));
373 moveEngine:
function ES_moveEngine(aEngine, aNewIndex) {
374 if (aNewIndex < 0 || aNewIndex > this._engines.length - 1)
375 throw new Error(
"ES_moveEngine: invalid aNewIndex!");
376 var index = this._getIndexForEngine(aEngine);
378 throw new Error(
"ES_moveEngine: invalid engine?");
380 if (index == aNewIndex)
384 var removedEngine = this._engines.splice(index, 1)[0];
385 this._engines.splice(aNewIndex, 0, removedEngine);
390 removeEngine:
function ES_removeEngine(aEngine) {
391 var index = this._getIndexForEngine(aEngine);
393 throw new Error(
"invalid engine?");
395 this._engines.splice(index, 1);
396 this._ops.push(
new EngineRemoveOp(aEngine));
397 if (this._defaultEngines.some(
this._isSameEngine, aEngine))
401 restoreDefaultEngines:
function ES_restoreDefaultEngines() {
404 for (var
i = 0;
i < this._defaultEngines.length; ++
i) {
405 var e = this._defaultEngines[
i];
408 if (this._engines.some(
this._isSameEngine, e)) {
409 this.moveEngine(this._getEngineByName(e.name),
i);
412 this._engines.splice(
i, 0, e);
413 this._ops.push(
new EngineUnhideOp(e,
i));
421 changeEngine:
function ES_changeEngine(aEngine, aProp, aNewValue) {
422 var index = this._getIndexForEngine(aEngine);
424 throw new Error(
"invalid engine?");
426 this._engines[index][aProp] = aNewValue;
427 this._ops.push(
new EngineChangeOp(aEngine, aProp, aNewValue));
430 reloadIcons:
function ES_reloadIcons() {
431 this._engines.forEach(
function (e) {
432 e.uri = e.originalEngine.uri;
437 function EngineView(aEngineStore) {
438 this._engineStore = aEngineStore;
440 EngineView.prototype = {
445 return this.rowCount - 1;
447 get selectedIndex() {
448 var seln = this.selection;
449 if (seln.getRangeCount() > 0) {
451 seln.getRangeAt(0, min, { });
456 get selectedEngine() {
457 return this._engineStore.engines[this.selectedIndex];
461 rowCountChanged:
function (index,
count) {
462 this.tree.rowCountChanged(index,
count);
465 invalidate:
function () {
466 this.tree.invalidate();
469 ensureRowIsVisible:
function (index) {
470 this.tree.ensureRowIsVisible(index);
473 getSourceIndexFromDrag:
function () {
474 var dragService =
Cc[
"@mozilla.org/widget/dragservice;1"].
476 var dragSession = dragService.getCurrentSession();
477 var transfer =
Cc[
"@mozilla.org/widget/transferable;1"].
481 dragSession.getData(transfer, 0);
485 var sourceIndex = -1;
487 transfer.getAnyTransferData({}, dataObj, len);
491 sourceIndex = dataObj.value.QueryInterface(
Ci.nsISupportsString).data;
492 sourceIndex = parseInt(sourceIndex.substring(0, len.value));
500 return this._engineStore.engines.length;
503 getImageSrc:
function(index, column) {
504 if (column.id ==
"engineName" &&
this._engineStore.engines[index].iconURI)
505 return this._engineStore.engines[index].iconURI.spec;
509 getCellText:
function(index, column) {
510 if (column.id ==
"engineName")
511 return this._engineStore.engines[index].name;
512 else if (column.id ==
"engineKeyword")
513 return this._engineStore.engines[index].alias;
517 setTree:
function(tree) {
521 canDrop:
function(targetIndex, orientation) {
522 var sourceIndex = this.getSourceIndexFromDrag();
523 return (sourceIndex != -1 &&
524 sourceIndex != targetIndex &&
525 sourceIndex != (targetIndex + orientation));
528 drop:
function(dropIndex, orientation) {
529 var sourceIndex = this.getSourceIndexFromDrag();
530 var sourceEngine = this._engineStore.engines[sourceIndex];
532 if (dropIndex > sourceIndex) {
533 if (orientation ==
Ci.nsITreeView.DROP_BEFORE)
536 if (orientation ==
Ci.nsITreeView.DROP_AFTER)
540 this._engineStore.moveEngine(sourceEngine, dropIndex);
545 this.selection.clearSelection();
546 this.selection.select(dropIndex);
550 getRowProperties:
function(index, properties) { },
552 getColumnProperties:
function(column, properties) { },
553 isContainer:
function(index) {
return false; },
554 isContainerOpen:
function(index) {
return false; },
555 isContainerEmpty:
function(index) {
return false; },
556 isSeparator:
function(index) {
return false; },
557 isSorted:
function(index) {
return false; },
558 getParentIndex:
function(index) {
return -1; },
559 hasNextSibling:
function(parentIndex, index) {
return false; },
560 getLevel:
function(index) {
return 0; },
561 getProgressMode:
function(index, column) { },
562 getCellValue:
function(index, column) { },
563 toggleOpenState:
function(index) { },
564 cycleHeader:
function(column) { },
565 selectionChanged:
function() { },
566 cycleCell:
function(row, column) { },
567 isEditable:
function(index, column) {
return false; },
568 isSelectable:
function(index, column) {
return false; },
569 setCellValue:
function(index, column,
value) { },
570 setCellText:
function(index, column,
value) { },
571 performAction:
function(action) { },
572 performActionOnRow:
function(action, index) { },
573 performActionOnCell:
function(action, index, column) { }
function EngineMoveOp(aEngineClone, aNewIndex)
getService(Ci.sbIFaceplateManager)
function onDragEngineStart(event)
gImageView getCellProperties
this _dialogInput val(dateText)
const BROWSER_SUGGEST_PREF
_dialogDatepicker onSelect
_getSelectedPageStyle s i
sbDeviceFirmwareAutoCheckForUpdate prototype observe