1 // -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 deleteAll: function (aTree, aView, aItems, aDeletedItems)
10 for (var i = 0; i < aItems.length; ++i)
11 aDeletedItems.push(aItems[i]);
12 aItems.splice(0, aItems.length);
13 var oldCount = aView.rowCount;
15 aTree.treeBoxObject.rowCountChanged(0, -oldCount);
18 deleteSelectedItems: function (aTree, aView, aItems, aDeletedItems)
20 var selection = aTree.view.selection;
21 selection.selectEventsSuppressed = true;
23 var rc = selection.getRangeCount();
24 for (var i = 0; i < rc; ++i) {
25 var min = { }; var max = { };
26 selection.getRangeAt(i, min, max);
27 for (var j = min.value; j <= max.value; ++j) {
28 aDeletedItems.push(aItems[j]);
33 var nextSelection = 0;
34 for (i = 0; i < aItems.length; ++i) {
37 while (j < aItems.length && !aItems[j])
39 aItems.splice(i, j - i);
40 nextSelection = j < aView.rowCount ? j - 1 : j - 2;
41 aView._rowCount -= j - i;
42 aTree.treeBoxObject.rowCountChanged(i, i - j);
47 selection.select(nextSelection);
48 aTree.treeBoxObject.ensureRowIsVisible(nextSelection);
51 selection.selectEventsSuppressed = false;
54 sort: function (aTree, aView, aDataSet, aColumn, aComparator,
55 aLastSortColumn, aLastSortAscending)
57 var ascending = (aColumn == aLastSortColumn) ? !aLastSortAscending : true;
58 if (aDataSet.length == 0)
61 var numericSort = !isNaN(aDataSet[0][aColumn]);
62 var sortFunction = null;
64 sortFunction = function (a, b) { return aComparator(a[aColumn], b[aColumn]); };
66 aDataSet.sort(sortFunction);
70 aTree.view.selection.clearSelection();
71 aTree.view.selection.select(0);
72 aTree.treeBoxObject.invalidate();
73 aTree.treeBoxObject.ensureRowIsVisible(0);