34 _binding_enabled:
null,
39 _disabledHotkeyList:
null,
43 var jsLoader = Components.classes[
"@mozilla.org/moz/jssubscript-loader;1"].getService(Components.interfaces.mozIJSSubScriptLoader);
44 jsLoader.loadSubScript(
"chrome://songbird/content/scripts/messageBox.js",
this );
48 this._hotkeyService =
Cc[
"@songbirdnest.com/Songbird/HotkeyService;1"]
49 .getService(
Ci.sbIHotkeyService);
51 this._binding_enabled =
SBDataBindElementAttribute(this._hotkeyService.hotkeysEnabledDRKey,
"hotkeys.enabled",
"checked",
true);
53 this._list = document.getElementById(
"hotkey.list");
54 this._add = document.getElementById(
"hotkey.add");
55 this._set = document.getElementById(
"hotkey.set");
56 this._remove = document.getElementById(
"hotkey.remove");
57 this._actionlist = document.getElementById(
"hotkey.actions");
58 this._hotkey = document.getElementById(
"hotkey.hotkey");
59 this._tool = document.getElementById(
"hotkey-hotkeytool");
60 this._hotkeylabel = document.getElementById(
"hotkey.hotkeylabel");
61 this._actionlabel = document.getElementById(
"hotkey.actionlabel");
62 this._enabled = document.getElementById(
"hotkeys.enabled");
63 this._disabledHotkeyList = [];
67 this.enableDisableElements();
73 this._binding_enabled.unbind();
74 this._binding_enabled =
null;
77 loadActions:
function()
79 var menupopup = this._actionlist.firstChild;
80 while (menupopup.childNodes.length>0) menupopup.removeChild(menupopup.childNodes[0]);
82 var hotkeyActionsComponent = Components.classes[
"@songbirdnest.com/Songbird/HotkeyActions;1"];
83 if (hotkeyActionsComponent) this._actions = hotkeyActionsComponent.getService(Components.interfaces.sbIHotkeyActions);
86 for (var
i=0;
i<this._actions.bundleCount;
i++)
88 var
bundle = this._actions.enumBundle(
i);
89 for (var j=0;j<bundle.actionCount;j++)
91 var actionid = bundle.enumActionID(j);
92 var actiondesc = bundle.enumActionLocaleDescription(j);
93 var item = document.createElement(
"menuitem");
94 item.actionid = actionid;
95 item.setAttribute(
"label", actiondesc);
96 menupopup.appendChild(item);
99 this._actionlist.selectedItem = menupopup.childNodes[0];
103 loadHotkeys:
function()
105 var hotkeyConfigList = this._hotkeyService.getHotkeys();
106 for (var
i = 0;
i < hotkeyConfigList.length;
i++) {
109 hotkeyConfigList.queryElementAt(
i,
Ci.sbIHotkeyConfiguration);
110 if (!this._hotkeyDisabled(hotkeyConfig)) {
111 var keycombo = hotkeyConfig.key;
112 var keydisplay = hotkeyConfig.keyReadable;
113 var actionid = hotkeyConfig.action;
114 var action = this._getLocalizedAction(actionid);
116 this._addItem(keycombo, keydisplay, actionid, action, -1);
119 this._disabledHotkeyList.push(hotkeyConfig);
122 this.updateButtons();
125 _hotkeyDisabled:
function(hotkeyConfig) {
128 var nodes = this._actionlist.firstChild.childNodes;
129 for (var
i=0;
i<nodes.length;
i++) {
130 if (hotkeyConfig.action == nodes[
i].actionid)
137 _getLocalizedAction:
function(actionid)
139 var nodes = this._actionlist.firstChild.childNodes;
140 for (var
i=0;
i<nodes.length;
i++) {
141 if (actionid == nodes[
i].actionid)
return nodes[
i].getAttribute(
"label");
146 _addItem:
function(keycombo, keydisplay, actionid, action, replace)
148 this._tool.setHotkey(keycombo, keydisplay);
149 keydisplay = this._tool.getHotkey(1);
152 var before = (replace == -1) ?
null : this._list.getItemAtIndex(replace);
154 var listitem = document.createElement(
"listitem");
155 listitem.keycombo = keycombo;
156 listitem.actionid = actionid;
157 var listcell_action = document.createElement(
"listcell");
158 listcell_action.setAttribute(
"label", action);
159 var listcell_keydisplay = document.createElement(
"listcell");
160 listcell_keydisplay.setAttribute(
"label", keydisplay.toUpperCase());
161 listitem.appendChild(listcell_action);
162 listitem.appendChild(listcell_keydisplay);
165 this._list.insertBefore(listitem, before);
167 this._list.removeChild(before);
170 this._list.appendChild(listitem);
174 saveHotkeys:
function()
177 var hotkeyConfigList =
Cc[
"@songbirdnest.com/moz/xpcom/threadsafe-array;1"]
178 .createInstance(
Ci.nsIMutableArray);
179 var n = this._list.getRowCount();
180 for (var
i=0;
i<n;
i++)
182 var hotkeyConfig =
Cc[
"@songbirdnest.com/Songbird/HotkeyConfiguration;1"]
183 .createInstance(
Ci.sbIHotkeyConfiguration);
184 var item = this._list.getItemAtIndex(
i);
185 var keycombo = item.keycombo;
186 var actionid = item.actionid;
187 var actioncell = item.firstChild;
188 var keydisplaycell = actioncell.nextSibling;
189 var keydisplay = keydisplaycell.getAttribute(
"label");
190 hotkeyConfig.key = keycombo;
191 hotkeyConfig.keyReadable = keydisplay;
192 hotkeyConfig.action = actionid;
193 if (!this._configListContainsKey(hotkeyConfigList, hotkeyConfig.key))
194 hotkeyConfigList.appendElement(hotkeyConfig,
false);
201 if (this._disabledHotkeyList) {
202 for (var
i = 0;
i < this._disabledHotkeyList.length;
i++) {
203 if (!this._configListContainsKey(hotkeyConfigList, hotkeyConfig.key))
204 hotkeyConfigList.appendElement(this._disabledHotkeyList[
i],
false);
208 this._hotkeyService.setHotkeys(hotkeyConfigList);
211 _configListContainsKey:
function(aHotkeyConfigList, aKey) {
212 for (var
i = 0;
i < aHotkeyConfigList.length;
i++) {
214 aHotkeyConfigList.queryElementAt(
i,
Ci.sbIHotkeyConfiguration);
215 if (hotkeyConfig.key == aKey)
222 onSelectHotkey:
function()
224 this.updateButtons();
225 var selected = this._list.selectedIndex;
227 var item = this._list.getItemAtIndex(selected);
228 var actioncell = item.firstChild;
229 var keydisplaycell = actioncell.nextSibling;
231 var nodes = this._actionlist.firstChild.childNodes;
232 var actionstr = actioncell.getAttribute(
"label");
233 for (var
i=0;
i<nodes.length;
i++) {
235 this._actionlist.selectedItem = nodes[
i]
240 this._hotkey.setHotkey(item.keycombo, keydisplaycell.getAttribute(
"label"));
244 updateButtons:
function()
247 var disabled = (this._list.selectedIndex== -1);
248 var alldisabled = !this._hotkeyService.hotkeysEnabled;
249 this._remove.setAttribute(
"disabled", (disabled||alldisabled));
250 this._set.setAttribute(
"disabled", (disabled||alldisabled));
251 this._add.setAttribute(
"disabled", alldisabled);
254 addHotkey:
function()
257 var keycombo = this._hotkey.getHotkey(
false);
258 if (this._checkComboExists(keycombo, -1))
return;
259 var keydisplay = this._hotkey.getHotkey(
true);
260 var action = this._actionlist.selectedItem.getAttribute(
"label");
261 var actionid = this._actionlist.selectedItem.actionid;
262 if (action ==
"" || keycombo ==
"" || keydisplay ==
"" || actionid ==
"")
return;
263 this._addItem(keycombo, keydisplay, actionid, action, -1);
265 this._list.selectedIndex = this._list.getRowCount()-1;
269 setHotkey:
function()
272 var selected = this._list.selectedIndex;
273 var keycombo = this._hotkey.getHotkey(
false);
274 if (this._checkComboExists(keycombo, selected))
return;
275 var keydisplay = this._hotkey.getHotkey(
true);
276 var action = this._actionlist.selectedItem.getAttribute(
"label");
277 var actionid = this._actionlist.selectedItem.actionid;
278 if (action ==
"" || keycombo ==
"" || keydisplay ==
"")
return;
279 this._addItem(keycombo, keydisplay, actionid, action, selected);
281 this._list.selectedIndex = selected;
285 _checkComboExists:
function(keycombo, ignoreentry)
288 for (var
i=0;
i<this._list.getRowCount();
i++)
290 if (
i == ignoreentry)
continue;
291 var item = this._list.getItemAtIndex(
i);
292 if (item.keycombo == keycombo) {
293 this.
sbMessageBox_strings(
"hotkeys.hotkeyexists.title",
"hotkeys.hotkeyexists.msg",
"Hotkey",
"This hotkey is already taken",
false);
300 removeHotkey:
function()
303 var index = this._list.selectedIndex;
304 var item = this._list.getItemAtIndex(index);
305 this._list.removeChild(item);
307 if (index >= this._list.getRowCount()) index = this._list.getRowCount()-1;
308 this._list.selectedIndex = index;
312 onEnableDisable:
function()
314 this._hotkeyService.hotkeysEnabled =
315 (this._enabled.getAttribute(
"checked") ==
"true");
316 this.enableDisableElements();
319 enableDisableElements:
function() {
320 var enabled = this._hotkeyService.hotkeysEnabled;
322 this._actionlist.removeAttribute(
"disabled");
323 this._list.removeAttribute(
"disabled");
324 this._hotkey.removeAttribute(
"disabled");
325 this._hotkeylabel.removeAttribute(
"disabled");
326 this._actionlabel.removeAttribute(
"disabled");
327 this._list.setAttribute(
"style",
"opacity: 1 !important;");
328 this._hotkey.setAttribute(
"style",
"opacity: 1 !important;");
330 this._actionlist.setAttribute(
"disabled",
"true");
331 this._list.setAttribute(
"disabled",
"true");
332 this._list.setAttribute(
"disabled",
"true");
333 this._hotkey.setAttribute(
"disabled",
"true");
334 this._hotkeylabel.setAttribute(
"disabled",
"true");
335 this._actionlabel.setAttribute(
"disabled",
"true");
336 this._list.setAttribute(
"style",
"opacity: 0.5 !important;");
337 this._hotkey.setAttribute(
"style",
"opacity: 0.5 !important;");
339 this.updateButtons();
function onHotkeysUnload()
function SBDataBindElementAttribute(aKey, aElement, aAttribute, aIsBool, aIsNot, aEvalString)
Create a DataRemote and bind an Element's attribute to the data. This method creates a DataRemote ass...
function sbMessageBox_strings(titlestring, msgstring, deftitle, defmsg, wantcancel, notmodal)
return aWindow document documentElement getAttribute(aAttribute)||dimension
function onUnload()
onUnload - called when the cover preview window unloads.
_getSelectedPageStyle s i