1
/* See license.txt for terms of usage */
3
// ************************************************************************************************
6
const prefs = XPCOMUtils.CCSV("@mozilla.org/preferences-service;1", "nsIPrefBranch");
7
const names = ["label", "executable", "cmdline", "image"];
9
// ************************************************************************************************
21
var args = window.arguments[0];
23
this._prefName = args.prefName;
25
(this._removeButton = document.getElementById("removeEditor")).disabled = true;
26
(this._changeButton = document.getElementById("changeEditor")).disabled = true;
28
this._tree = document.getElementById("editorsList");
35
get rowCount() { return this.data.length; },
36
getCellText: function(row, column)
41
return " "+this.data[row].label;
42
case "editorExecutable":
43
return this.data[row].executable;
45
return this.data[row].cmdline;
49
setTree: function(treebox){ this.treebox = treebox; },
50
isContainer: function(row) { return false; },
51
isContainerOpen: function(row) { return false; },
52
isContainerEmpty: function(row) { return false; },
53
isSeparator: function(row) { return false; },
54
isSorted: function() { return false; },
55
getLevel: function(row) { return 0; },
56
getImageSrc: function(row,column) { return column.id=="editorName" ? this.data[row].image : null; },
57
getRowProperties: function(row,props) {},
58
getCellProperties: function(row,column,props) {},
59
getColumnProperties: function(colid,column,props) {}
63
this._tree.view = this._treeView;
70
onSelectionChanged: function()
72
var selection = this._tree.view.selection;
73
this._removeButton.disabled = (selection.count != 1);
74
this._changeButton.disabled = (selection.count != 1);
77
addEditorHandler: function()
79
var item = { label: "", executable: null, cmdline: "" };
81
openDialog("chrome://firebug/content/changeeditor.xul", "_blank", "modal,centerscreen", item, result);
82
if (result.saveChanges)
84
item.id = item.label.replace(/\W/g, "_");
88
this._data.push(item);
89
this._tree.view = this._treeView;
93
editors = prefs.getCharPref(this._prefName).split(",");
94
for( var i = 0; i < editors.length; ++i )
96
if ( editors[i].replace(/^\s+|\s+$/,"") == "" )
102
this._FBL.ERROR(exc);
104
editors.push(item.id);
105
prefs.setCharPref(this._prefName, editors.join(","));
109
removeEditorHandler: function()
111
var selection = this._tree.view.selection;
112
if (selection.count < 1)
114
var item = this._data[selection.currentIndex];
115
this._data.splice(selection.currentIndex, 1);
116
this._tree.view = this._treeView;
119
var editors = prefs.getCharPref(this._prefName).split(",");
120
this._FBL.remove(editors, item.id);
121
prefs.setCharPref(this._prefName, editors.join(","));
122
prefs.deleteBranch(this._prefName+"."+item.id);
126
this._FBL.ERROR(exc);
130
changeEditorHandler: function()
132
var selection = this._tree.view.selection;
133
if (selection.count != 1)
135
var item = this._data[selection.currentIndex];
137
openDialog("chrome://firebug/content/changeeditor.xul", "_blank", "modal,centerscreen", item, result);
138
if (result.saveChanges)
140
this._saveItem(item);
142
this._loadItem(item);
143
this._tree.view = this._treeView;
146
_loadItem: function(item)
148
const prefName = this._prefName;
149
for( var i = 0; i < names.length; ++i )
152
item[names[i]] = prefs.getCharPref(prefName+"."+item.id+"."+names[i]);
158
item.image = this._FBL.getIconURLForFile(item.executable);
161
_saveItem: function(item)
163
if ( item.image && item.image == this._FBL.getIconURLForFile(item.executable) )
166
const prefName = this._prefName;
167
for( var i = 0; i < names.length; ++i )
170
var value = item[names[i]];
172
prefs.setCharPref(prefName+"."+item.id+"."+names[i], value);
174
prefs.clearUserPref(prefName+"."+item.id+"."+names[i]);
184
var list = prefs.getCharPref(this._prefName).split(",");
185
for (var i = 0; i < list.length; ++i)
187
var editorId = list[i].replace(/\s/g, "_");
190
var item = { id: editorId };
191
this._data.push(item);
192
this._loadItem(item);
197
this._FBL.ERROR(exc);
203
// ************************************************************************************************