!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 *
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
8 *
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
13 *
14 * The Original Code is Selection List Properties Dialog.
15 *
16 * The Initial Developer of the Original Code is
17 * Neil Rashbrook.
18 * Portions created by the Initial Developer are Copyright (C) 2001
19 * the Initial Developer. All Rights Reserved.
20 *
21 * Contributor(s): Neil Rashbrook <neil@parkwaycc.co.uk>
22 *
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 2 or later (the "GPL"), or
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 * in which case the provisions of the GPL or the LGPL are applicable instead
27 * of those above. If you wish to allow use of your version of this file only
28 * under the terms of either the GPL or the LGPL, and not to allow others to
29 * use your version of this file under the terms of the MPL, indicate your
30 * decision by deleting the provisions above and replace them with the notice
31 * and other provisions required by the GPL or the LGPL. If you do not delete
32 * the provisions above, a recipient may use your version of this file under
33 * the terms of any one of the MPL, the GPL or the LGPL.
34 *
35 * ***** END LICENSE BLOCK ***** */
36
37 // Global variables
38
39 var atomService = Components.classes["@mozilla.org/atom-service;1"]
40 .getService(Components.interfaces.nsIAtomService);
41 var checkedAtoms = {
42 "false": atomService.getAtom("checked-false"),
43 "true": atomService.getAtom("checked-true")};
44
45 var hasValue;
46 var oldValue;
47 var insertNew;
48 var itemArray;
49 var treeBoxObject;
50 var treeSelection;
51 var selectElement;
52 var currentItem = null;
53 var selectedOption = null;
54 var selectedOptionCount = 0;
55
56 // Utility functions
57
getParentIndex
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
58 function getParentIndex(index)
59 {
60 switch (itemArray[index].level)
61 {
62 case 0: return -1;
63 case 1: return 0;
64 }
65 while (itemArray[--index].level > 1);
66 return index;
67 }
68
UpdateSelectMultiple
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
69 function UpdateSelectMultiple()
70 {
71 if (selectedOptionCount > 1)
72 {
73 gDialog.selectMultiple.checked = true;
74 gDialog.selectMultiple.disabled = true;
75 }
76 else
77 gDialog.selectMultiple.disabled = false;
78 }
79
80 /* wrapper objects:
81 * readonly attribute Node element; // DOM node (select/optgroup/option)
82 * readonly attribute int level; // tree depth
83 * readonly attribute boolean container; // can contain options
84 * string getCellText(string col); // tree view helper
85 * string cycleCell(int currentIndex); // tree view helper
86 * void onFocus(); // load data into deck
87 * void onBlur(); // save data from deck
88 * boolean canDestroy(boolean prompt); // NB prompt not used
89 * void destroy(); // post remove callback
90 * void moveUp();
91 * boolean canMoveDown();
92 * void moveDown();
93 * void appendOption(newElement, currentIndex);
94 */
95
96 // OPTION element wrapper object
97
98 // Create a wrapper for the given element at the given level
optionObject
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
99 function optionObject(option, level)
100 {
101 // select an added option (when loading from document)
102 if (option.hasAttribute("selected"))
103 selectedOptionCount++;
104 this.level = level;
105 this.element = option;
106 }
107
108 optionObject.prototype.container = false;
109
getCellText
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
110 optionObject.prototype.getCellText = function getCellText(column)
111 {
112 if (column.id == "SelectSelCol")
113 return "";
114 if (column.id == "SelectValCol" && this.element.hasAttribute("value"))
115 return this.element.getAttribute("value");
116 return this.element.text;
117 }
118
cycleCell
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
119 optionObject.prototype.cycleCell = function cycleCell(index)
120 {
121 if (this.element.hasAttribute("selected"))
122 {
123 this.element.removeAttribute("selected");
124 selectedOptionCount--;
125 selectedOption = null;
126 }
127 else
128 {
129 // Different handling for multiselect lists
130 if (gDialog.selectMultiple.checked || !selectedOption)
131 selectedOptionCount++;
132 else if (selectedOption)
133 {
134 selectedOption.removeAttribute("selected");
135 var column = treeBoxObject.columns["SelectSelCol"];
136 treeBoxObject.invalidateColumn(column);
137 selectedOption = null;
138 }
139 this.element.setAttribute("selected", "");
140 selectedOption = this.element;
141 var column = treeBoxObject.columns["SelectSelCol"];
142 treeBoxObject.invalidateCell(index, column);
143 }
144 if (currentItem == this)
145 // Also update the deck
146 gDialog.optionSelected.setAttribute("checked", this.element.hasAttribute("selected"));
147 UpdateSelectMultiple();
148 };
149
onFocus
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
150 optionObject.prototype.onFocus = function onFocus()
151 {
152 gDialog.optionText.value = this.element.text;
153 hasValue = this.element.hasAttribute("value");
154 oldValue = this.element.value;
155 gDialog.optionHasValue.checked = hasValue;
156 gDialog.optionValue.value = hasValue ? this.element.value : this.element.text;
157 gDialog.optionSelected.checked = this.element.hasAttribute("selected");
158 gDialog.optionDisabled.checked = this.element.hasAttribute("disabled");
159 gDialog.selectDeck.setAttribute("selectedIndex", "2");
160 };
161
onBlur
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
162 optionObject.prototype.onBlur = function onBlur()
163 {
164 this.element.text = gDialog.optionText.value;
165 if (gDialog.optionHasValue.checked)
166 this.element.value = gDialog.optionValue.value;
167 else
168 this.element.removeAttribute("value");
169 if (gDialog.optionSelected.checked)
170 this.element.setAttribute("selected", "");
171 else
172 this.element.removeAttribute("selected");
173 if (gDialog.optionDisabled.checked)
174 this.element.setAttribute("disabled", "");
175 else
176 this.element.removeAttribute("disabled");
177 };
178
canDestroy
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
179 optionObject.prototype.canDestroy = function canDestroy(prompt)
180 {
181 return true;
182 /*return !prompt ||
183 ConfirmWithTitle(GetString("DeleteOption"),
184 GetString("DeleteOptionMsg"),
185 GetString("DeleteOption"));*/
186 };
187
destroy
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
188 optionObject.prototype.destroy = function destroy()
189 {
190 // Deselect a removed option
191 if (this.element.hasAttribute("selected"))
192 {
193 selectedOptionCount--;
194 selectedOption = null;
195 UpdateSelectMultiple();
196 }
197 };
198
199 /* 4 cases:
200 * a) optgroup -> optgroup
201 * ... ...
202 * option option
203 * b) optgroup -> option
204 * option optgroup
205 * ... ...
206 * c) option
207 * option
208 * d) option
209 * option
210 */
211
moveUp
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
212 optionObject.prototype.moveUp = function moveUp()
213 {
214 var i;
215 var index = treeSelection.currentIndex;
216 if (itemArray[index].level < itemArray[index - 1].level + itemArray[index - 1].container)
217 {
218 // we need to repaint the tree's lines
219 treeBoxObject.invalidateRange(getParentIndex(index), index);
220 // a) option is just after an optgroup, so it becomes the last child
221 itemArray[index].level = 2;
222 treeBoxObject.view.selectionChanged();
223 }
224 else
225 {
226 // otherwise new option level is now the same as the previous item
227 itemArray[index].level = itemArray[index - 1].level;
228 // swap the option with the previous item
229 itemArray.splice(index, 0, itemArray.splice(--index, 1)[0]);
230 }
231 selectTreeIndex(index, true);
232 }
233
canMoveDown
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
234 optionObject.prototype.canMoveDown = function canMoveDown()
235 {
236 // move down is not allowed on the last option if its level is 1
237 return this.level > 1 || itemArray.length - treeSelection.currentIndex > 1;
238 }
239
moveDown
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
240 optionObject.prototype.moveDown = function moveDown()
241 {
242 var i;
243 var index = treeSelection.currentIndex;
244 if (index + 1 == itemArray.length || itemArray[index].level > itemArray[index + 1].level)
245 {
246 // we need to repaint the tree's lines
247 treeBoxObject.invalidateRange(getParentIndex(index), index);
248 // a) option is last child of an optgroup, so it moves just after
249 itemArray[index].level = 1;
250 treeBoxObject.view.selectionChanged();
251 }
252 else
253 {
254 // level increases if the option was preceding an optgroup
255 itemArray[index].level += itemArray[index + 1].container;
256 // swap the option with the next item
257 itemArray.splice(index, 0, itemArray.splice(++index, 1)[0]);
258 }
259 selectTreeIndex(index, true);
260 }
261
appendOption
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
262 optionObject.prototype.appendOption = function appendOption(child, parent)
263 {
264 // special case quick check
265 if (this.level == 1)
266 return gDialog.appendOption(child, 0);
267
268 // append the option to the parent element
269 parent = getParentIndex(parent);
270 return itemArray[parent].appendOption(child, parent);
271 };
272
273 // OPTGROUP element wrapper object
274
optgroupObject
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
275 function optgroupObject(optgroup)
276 {
277 this.element = optgroup;
278 }
279
280 optgroupObject.prototype.level = 1;
281
282 optgroupObject.prototype.container = true;
283
getCellText
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
284 optgroupObject.prototype.getCellText = function getCellText(column)
285 {
286 return column.id == "SelectTextCol" ? this.element.label : "";
287 }
288
cycleCell
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
289 optgroupObject.prototype.cycleCell = function cycleCell(index)
290 {
291 };
292
onFocus
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
293 optgroupObject.prototype.onFocus = function onFocus()
294 {
295 gDialog.optgroupLabel.value = this.element.label;
296 gDialog.optgroupDisabled.checked = this.element.disabled;
297 gDialog.selectDeck.setAttribute("selectedIndex", "1");
298 };
299
onBlur
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
300 optgroupObject.prototype.onBlur = function onBlur()
301 {
302 this.element.label = gDialog.optgroupLabel.value;
303 this.element.disabled = gDialog.optgroupDisabled.checked;
304 };
305
canDestroy
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
306 optgroupObject.prototype.canDestroy = function canDestroy(prompt)
307 {
308 // Only removing empty option groups for now
309 return gDialog.nextChild(treeSelection.currentIndex) - treeSelection.currentIndex == 1;
310 /*&& (!prompt ||
311 ConfirmWithTitle(GetString("DeleteOptGroup"),
312 GetString("DeleteOptGroupMsg"),
313 GetString("DeleteOptGroup")));
314 */
315 };
316
destroy
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
317 optgroupObject.prototype.destroy = function destroy()
318 {
319 };
320
moveUp
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
321 optgroupObject.prototype.moveUp = function moveUp()
322 {
323 // Find the index of the previous and next elements at the same level
324 var index = treeSelection.currentIndex;
325 var i = index;
326 while (itemArray[--index].level > 1);
327 var j = gDialog.nextChild(i);
328 // Cut out the element, cut the array in two, then join together
329 var movedItems = itemArray.splice(i, j - i);
330 var endItems = itemArray.splice(index);
331 itemArray = itemArray.concat(movedItems).concat(endItems);
332 // Repaint the lot
333 treeBoxObject.invalidateRange(index, j);
334 selectTreeIndex(index, true);
335 }
336
canMoveDown
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
337 optgroupObject.prototype.canMoveDown = function canMoveDown()
338 {
339 return gDialog.lastChild() > treeSelection.currentIndex;
340 }
341
moveDown
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
342 optgroupObject.prototype.moveDown = function moveDown()
343 {
344 // Find the index of the next two elements at the same level
345 var index = treeSelection.currentIndex;
346 var i = gDialog.nextChild(index);
347 var j = gDialog.nextChild(i);
348 // Cut out the element, cut the array in two, then join together
349 var movedItems = itemArray.splice(i, j - 1);
350 var endItems = itemArray.splice(index);
351 itemArray = itemArray.concat(movedItems).concat(endItems);
352 // Repaint the lot
353 treeBoxObject.invalidateRange(index, j);
354 index += j - i;
355 selectTreeIndex(index, true);
356 }
357
appendOption
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
358 optgroupObject.prototype.appendOption = function appendOption(child, parent)
359 {
360 var index = gDialog.nextChild(parent);
361 // XXX need to repaint the lines, tree won't do this
362 var primaryCol = treeBoxObject.getPrimaryColumn();
363 treeBoxObject.invalidateCell(index - 1, primaryCol);
364 // insert the wrapped object as the last child
365 itemArray.splice(index, 0, new optionObject(child, 2));
366 treeBoxObject.rowCountChanged(index, 1);
367 selectTreeIndex(index, false);
368 };
369
370 // dialog initialization code
371
Startup
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
372 function Startup()
373 {
374 var editor = GetCurrentEditor();
375 if (!editor)
376 {
377 dump("Failed to get active editor!\n");
378 window.close();
379 return;
380 }
381
382 // Get a single selected select element
383 const kTagName = "select";
384 try {
385 selectElement = editor.getSelectedElement(kTagName);
386 } catch (e) {}
387
388 if (selectElement)
389 // We found an element and don't need to insert one
390 insertNew = false;
391 else
392 {
393 insertNew = true;
394
395 // We don't have an element selected,
396 // so create one with default attributes
397 try {
398 selectElement = editor.createElementWithDefaults(kTagName);
399 } catch (e) {}
400
401 if(!selectElement)
402 {
403 dump("Failed to get selected element or create a new one!\n");
404 window.close();
405 return;
406 }
407 }
408
409 // SELECT element wrapper object
410 gDialog = {
411 // useful elements
412 accept: document.documentElement.getButton("accept"),
413 selectDeck: document.getElementById("SelectDeck"),
414 selectName: document.getElementById("SelectName"),
415 selectSize: document.getElementById("SelectSize"),
416 selectMultiple: document.getElementById("SelectMultiple"),
417 selectDisabled: document.getElementById("SelectDisabled"),
418 selectTabIndex: document.getElementById("SelectTabIndex"),
419 optgroupLabel: document.getElementById("OptGroupLabel"),
420 optgroupDisabled: document.getElementById("OptGroupDisabled"),
421 optionText: document.getElementById("OptionText"),
422 optionHasValue: document.getElementById("OptionHasValue"),
423 optionValue: document.getElementById("OptionValue"),
424 optionSelected: document.getElementById("OptionSelected"),
425 optionDisabled: document.getElementById("OptionDisabled"),
426 removeButton: document.getElementById("RemoveButton"),
427 previousButton: document.getElementById("PreviousButton"),
428 nextButton: document.getElementById("NextButton"),
429 tree: document.getElementById("SelectTree"),
430 // wrapper methods (except MoveUp and MoveDown)
431 element: selectElement.cloneNode(false),
432 level: 0,
433 container: true,
getCellText
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
434 getCellText: function getCellText(column)
435 {
436 return column.id == "SelectTextCol" ? this.element.getAttribute("name") : "";
437 },
cycleCell
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
438 cycleCell: function cycleCell(index) {},
onFocus
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
439 onFocus: function onFocus()
440 {
441 gDialog.selectName.value = this.element.getAttribute("name");
442 gDialog.selectSize.value = this.element.getAttribute("size");
443 gDialog.selectMultiple.checked = this.element.hasAttribute("multiple");
444 gDialog.selectDisabled.checked = this.element.hasAttribute("disabled");
445 gDialog.selectTabIndex.value = this.element.getAttribute("tabindex");
446 this.selectDeck.setAttribute("selectedIndex", "0");
447 onNameInput();
448 },
onBlur
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
449 onBlur: function onBlur()
450 {
451 this.element.setAttribute("name", gDialog.selectName.value);
452 if (gDialog.selectSize.value)
453 this.element.setAttribute("size", gDialog.selectSize.value);
454 else
455 this.element.removeAttribute("size");
456 if (gDialog.selectMultiple.checked)
457 this.element.setAttribute("multiple", "");
458 else
459 this.element.removeAttribute("multiple");
460 if (gDialog.selectDisabled.checked)
461 this.element.setAttribute("disabled", "");
462 else
463 this.element.removeAttribute("disabled");
464 if (gDialog.selectTabIndex.value)
465 this.element.setAttribute("tabindex", gDialog.selectTabIndex.value);
466 else
467 this.element.removeAttribute("tabindex");
468 },
appendOption
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
469 appendOption: function appendOption(child, parent)
470 {
471 var index = itemArray.length;
472 // XXX need to repaint the lines, tree won't do this
473 treeBoxObject.invalidateRange(this.lastChild(), index);
474 // append the wrapped object
475 itemArray.push(new optionObject(child, 1));
476 treeBoxObject.rowCountChanged(index, 1);
477 selectTreeIndex(index, false);
478 },
canDestroy
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
479 canDestroy: function canDestroy(prompt)
480 {
481 return false;
482 },
canMoveDown
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
483 canMoveDown: function canMoveDown()
484 {
485 return false;
486 },
487 // helper methods
488 // Find the index of the next immediate child of the select
nextChild
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
489 nextChild: function nextChild(index)
490 {
491 while (++index < itemArray.length && itemArray[index].level > 1);
492 return index;
493 },
494 // Find the index of the last immediate child of the select
lastChild
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
495 lastChild: function lastChild()
496 {
497 var index = itemArray.length;
498 while (itemArray[--index].level > 1);
499 return index;
500 }
501 }
502 // Start with the <select> wrapper
503 itemArray = [gDialog];
504
505 // We modify the actual option and optgroup elements so clone them first
506 for (var child = selectElement.firstChild; child; child = child.nextSibling)
507 {
508 if (child.tagName == "OPTION")
509 itemArray.push(new optionObject(child.cloneNode(true), 1));
510 else if (child.tagName == "OPTGROUP")
511 {
512 itemArray.push(new optgroupObject(child.cloneNode(false)));
513 for (var grandchild = child.firstChild; grandchild; grandchild = grandchild.nextSibling)
514 if (grandchild.tagName == "OPTION")
515 itemArray.push(new optionObject(grandchild.cloneNode(true), 2));
516 }
517 }
518
519 UpdateSelectMultiple();
520
521 // Define a custom view for the tree
522 treeBoxObject = gDialog.tree.treeBoxObject;
523 treeBoxObject.view = {
QueryInterface
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
524 QueryInterface : function QueryInterface(aIID)
525 {
526 if (aIID.equals(Components.interfaces.nsITreeView) ||
527 aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
528 aIID.equals(Components.interfaces.nsISupports))
529 return this;
530
531 Components.returnCode = Components.results.NS_ERROR_NO_INTERFACE;
532 return null;
533 },
534 // useful for debugging
get_wrappedJSObject
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
535 get wrappedJSObject() { return this; },
get_rowCount
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
536 get rowCount() { return itemArray.length; },
get_selection
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
537 get selection() { return treeSelection; },
set_selection
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
538 set selection(selection) { return treeSelection = selection; },
getRowProperties
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
539 getRowProperties: function getRowProperties(index, column, prop) { },
540 // could have used a wrapper for this
getCellProperties
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
541 getCellProperties: function getCellProperties(index, column, prop)
542 {
543 if (column.id == "SelectSelCol" && !itemArray[index].container)
544 prop.AppendElement(checkedAtoms[itemArray[index].element.hasAttribute("selected")]);
545 },
getColumnProperties
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
546 getColumnProperties: function getColumnProperties(column, prop) { },
547 // get info from wrapper
isContainer
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
548 isContainer: function isContainer(index) { return itemArray[index].container; },
isContainerOpen
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
549 isContainerOpen: function isContainerOpen(index) { return true; },
isContainerEmpty
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
550 isContainerEmpty: function isContainerEmpty(index) { return true; },
isSeparator
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
551 isSeparator: function isSeparator(index) { return false; },
isSorted
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
552 isSorted: function isSorted() { return false; },
553 // d&d not implemented yet!
canDrop
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
554 canDrop: function canDrop(index, orientation) { return false; },
drop
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
555 drop: function drop(index, orientation) { alert('drop:' + index + ',' + orientation); },
556 // same as the global helper
557 getParentIndex: getParentIndex,
558 // tree needs to know when to paint lines
hasNextSibling
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
559 hasNextSibling: function hasNextSibling(index, after)
560 {
561 if (!index)
562 return false;
563 var level = itemArray[index].level;
564 while (++after < itemArray.length)
565 switch (level - itemArray[after].level)
566 {
567 case 1: return false;
568 case 0: return true;
569 }
570 return false;
571 },
getLevel
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
572 getLevel: function getLevel(index) { return itemArray[index].level; },
getImageSrc
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
573 getImageSrc: function getImageSrc(index, column) { },
getProgressMode
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
574 getProgressMode : function getProgressMode(index,column) { },
getCellValue
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
575 getCellValue: function getCellValue(index, column) { },
getCellText
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
576 getCellText: function getCellText(index, column) { return itemArray[index].getCellText(column); },
setTree
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
577 setTree: function setTree(tree) { this.tree = tree; },
toggleOpenState
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
578 toggleOpenState: function toggleOpenState(index) { },
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
579 cycleHeader: function cycleHeader(col) { },
selectionChanged
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
580 selectionChanged: function selectionChanged()
581 {
582 // Save current values and update buttons and deck
583 if (currentItem)
584 currentItem.onBlur();
585 var currentIndex = treeSelection.currentIndex;
586 currentItem = itemArray[currentIndex];
587 gDialog.removeButton.disabled = !currentItem.canDestroy();
588 gDialog.previousButton.disabled = currentIndex < 2;
589 gDialog.nextButton.disabled = !currentItem.canMoveDown();
590 // For Advanced Edit
591 globalElement = currentItem.element;
592 currentItem.onFocus();
593 },
cycleCell
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
594 cycleCell: function cycleCell(index, column) { itemArray[index].cycleCell(index); },
isEditable
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
595 isEditable: function isEditable(index, column) { return false; },
isSelectable
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
596 isSelectable: function isSelectable(index, column) { return false; },
performAction
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
597 performAction: function performAction(action) { },
performActionOnCell
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
598 performActionOnCell: function performActionOnCell(action, index, column) { }
599 };
600 treeSelection.select(0);
601 currentItem = gDialog;
602 //onNameInput();
603
604 SetTextboxFocus(gDialog.selectName);
605
606 SetWindowLocation();
607 }
608
609 // Called from Advanced Edit
InitDialog
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
610 function InitDialog()
611 {
612 currentItem.onFocus();
613 }
614
615 // Called from Advanced Edit
ValidateData
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
616 function ValidateData()
617 {
618 currentItem.onBlur();
619 return true;
620 }
621
onAccept
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
622 function onAccept()
623 {
624 // All values are valid - copy to actual element in doc or
625 // element created to insert
626 ValidateData();
627
628 var editor = GetCurrentEditor();
629
630 // Coalesce into one undo transaction
631 editor.beginTransaction();
632
633 try
634 {
635 editor.cloneAttributes(selectElement, gDialog.element);
636
637 if (insertNew)
638 // 'true' means delete the selection before inserting
639 editor.insertElementAtSelection(selectElement, true);
640
641 editor.setShouldTxnSetSelection(false);
642
643 while (selectElement.lastChild)
644 editor.deleteNode(selectElement.lastChild);
645
646 var offset = 0;
647 for (var i = 1; i < itemArray.length; i++)
648 if (itemArray[i].level > 1)
649 selectElement.lastChild.appendChild(itemArray[i].element);
650 else
651 editor.insertNode(itemArray[i].element, selectElement, offset++, true);
652
653 editor.setShouldTxnSetSelection(true);
654 }
655 finally
656 {
657 editor.endTransaction();
658 }
659
660 SaveWindowLocation();
661
662 return true;
663 }
664
665 // Button actions
AddOption
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
666 function AddOption()
667 {
668 currentItem.appendOption(GetCurrentEditor().createElementWithDefaults("option"), treeSelection.currentIndex);
669 SetTextboxFocus(gDialog.optionText);
670 }
671
AddOptGroup
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
672 function AddOptGroup()
673 {
674 var optgroupElement = GetCurrentEditor().createElementWithDefaults("optgroup");
675 var index = itemArray.length;
676 // XXX need to repaint the lines, tree won't do this
677 treeBoxObject.invalidateRange(gDialog.lastChild(), index);
678 // append the wrapped object
679 itemArray.push(new optgroupObject(optgroupElement));
680 treeBoxObject.rowCountChanged(index, 1);
681 selectTreeIndex(index, false);
682 SetTextboxFocus(gDialog.optgroupLabel);
683 }
684
RemoveElement
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
685 function RemoveElement()
686 {
687 if (currentItem.canDestroy(true))
688 {
689 // Only removing empty option groups for now
690 var index = treeSelection.currentIndex;
691 var level = itemArray[index].level;
692 // Perform necessary cleanup and remove the wrapper
693 itemArray[index].destroy();
694 itemArray.splice(index, 1);
695 --index;
696 // XXX need to repaint the lines, tree won't do this
697 if (level == 1) {
698 var last = gDialog.lastChild();
699 if (index > last)
700 treeBoxObject.invalidateRange(last, index);
701 }
702 selectTreeIndex(index, true);
703 treeBoxObject.rowCountChanged(++index, -1);
704 }
705 }
706
707 // Event handler
onTreeKeyUp
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
708 function onTreeKeyUp(event)
709 {
710 if (event.keyCode == event.DOM_VK_SPACE)
711 currentItem.cycleCell();
712 }
713
onNameInput
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
714 function onNameInput()
715 {
716 var disabled = !gDialog.selectName.value;
717 if (gDialog.accept.disabled != disabled)
718 gDialog.accept.disabled = disabled;
719 gDialog.element.setAttribute("name", gDialog.selectName.value);
720 // repaint the tree
721 var primaryCol = treeBoxObject.getPrimaryColumn();
722 treeBoxObject.invalidateCell(treeSelection.currentIndex, primaryCol);
723 }
724
onLabelInput
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
725 function onLabelInput()
726 {
727 currentItem.element.setAttribute("label", gDialog.optgroupLabel.value);
728 // repaint the tree
729 var primaryCol = treeBoxObject.getPrimaryColumn();
730 treeBoxObject.invalidateCell(treeSelection.currentIndex, primaryCol);
731 }
732
onTextInput
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
733 function onTextInput()
734 {
735 currentItem.element.text = gDialog.optionText.value;
736 // repaint the tree
737 if (hasValue) {
738 var primaryCol = treeBoxObject.getPrimaryColumn();
739 treeBoxObject.invalidateCell(treeSelection.currentIndex, primaryCol);
740 }
741 else
742 {
743 gDialog.optionValue.value = gDialog.optionText.value;
744 treeBoxObject.invalidateRow(treeSelection.currentIndex);
745 }
746 }
747
onValueInput
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
748 function onValueInput()
749 {
750 gDialog.optionHasValue.checked = hasValue = true;
751 oldValue = gDialog.optionValue.value;
752 currentItem.element.setAttribute("value", oldValue);
753 // repaint the tree
754 var column = treeBoxObject.columns["SelectValCol"];
755 treeBoxObject.invalidateCell(treeSelection.currentIndex, column);
756 }
757
onHasValueClick
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
758 function onHasValueClick()
759 {
760 hasValue = gDialog.optionHasValue.checked;
761 if (hasValue)
762 {
763 gDialog.optionValue.value = oldValue;
764 currentItem.element.setAttribute("value", oldValue);
765 }
766 else
767 {
768 oldValue = gDialog.optionValue.value;
769 gDialog.optionValue.value = gDialog.optionText.value;
770 currentItem.element.removeAttribute("value");
771 }
772 // repaint the tree
773 var column = treeBoxObject.columns["SelectValCol"];
774 treeBoxObject.invalidateCell(treeSelection.currentIndex, column);
775 }
776
onSelectMultipleClick
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
777 function onSelectMultipleClick()
778 {
779 // Recalculate the unique selected option if we need it and have lost it
780 if (!gDialog.selectMultiple.checked && selectedOptionCount == 1 && !selectedOption)
781 for (var i = 1; !(selectedOption = itemArray[i].element).hasAttribute("selected"); i++);
782 }
783
selectTreeIndex
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
784 function selectTreeIndex(index, focus)
785 {
786 treeSelection.select(index);
787 treeBoxObject.ensureRowIsVisible(index);
788 if (focus)
789 gDialog.tree.focus();
790 }