Initialize list of sibling bookmark items progressively (#478)
This commit is contained in:
parent
dec4d773d5
commit
45f5df5b45
@ -141,39 +141,79 @@ var TreeStyleTabBookmarksServiceEditable = {
|
|||||||
{
|
{
|
||||||
var id = gEditItemOverlay.itemId;
|
var id = gEditItemOverlay.itemId;
|
||||||
|
|
||||||
|
this.menulist.disabled = true;
|
||||||
|
this.menulist.setAttribute('label', '...');
|
||||||
|
|
||||||
var popup = this.popup;
|
var popup = this.popup;
|
||||||
var range = document.createRange();
|
var range = document.createRange();
|
||||||
range.selectNodeContents(popup);
|
range.selectNodeContents(popup);
|
||||||
range.setEndBefore(this.separator);
|
range.setEndBefore(this.separator);
|
||||||
range.deleteContents();
|
range.deleteContents();
|
||||||
var fragment = this._createSiblingsFragment(id);
|
range.detach();
|
||||||
var siblings = Array.slice(fragment.childNodes)
|
|
||||||
|
this.canceled = false;
|
||||||
|
|
||||||
|
this._createSiblingsFragment(id, (function(aFragment) {
|
||||||
|
var siblings = Array.slice(aFragment.childNodes)
|
||||||
.map(function(aItem) {
|
.map(function(aItem) {
|
||||||
return parseInt(aItem.getAttribute('value'));
|
return parseInt(aItem.getAttribute('value'));
|
||||||
});
|
});
|
||||||
range.insertNode(fragment);
|
var range = document.createRange();
|
||||||
|
range.selectNodeContents(popup);
|
||||||
|
range.setEndBefore(this.separator);
|
||||||
|
range.insertNode(aFragment);
|
||||||
range.detach();
|
range.detach();
|
||||||
|
|
||||||
var selected = popup.getElementsByAttribute('selected', 'true')[0];
|
var selected = popup.getElementsByAttribute('selected', 'true')[0];
|
||||||
|
this.menulist.disabled = false;
|
||||||
this.menulist.value = (selected || this.blankItem).getAttribute('value');
|
this.menulist.value = (selected || this.blankItem).getAttribute('value');
|
||||||
|
}).bind(this))
|
||||||
this.canceled = false;
|
|
||||||
},
|
},
|
||||||
_createSiblingsFragment : function TSTBMEditable__createSiblingsFragment(aCurrentItem)
|
_createSiblingsFragment : function TSTBMEditable__createSiblingsFragment(aCurrentItem, aCallback)
|
||||||
{
|
{
|
||||||
var items = this._getSiblingItems(aCurrentItem);
|
var itemsIterator = this._getSiblingItemsIterator(aCurrentItem);
|
||||||
var treeStructure = this.getTreeStructureFromItems(items);
|
var items = [];
|
||||||
|
|
||||||
var currentIndex = items.indexOf(aCurrentItem);
|
if (this._createSiblingsFragmentTimer)
|
||||||
|
window.clearTimeout(this._createSiblingsFragmentTimer);
|
||||||
|
|
||||||
|
var interval = 100;
|
||||||
|
var step = 10;
|
||||||
|
var progressiveIteration = (function() {
|
||||||
|
try {
|
||||||
|
for (let i = 0; i < step; i++)
|
||||||
|
{
|
||||||
|
items.push(itemsIterator.next());
|
||||||
|
}
|
||||||
|
this._createSiblingsFragmentTimer = window.setTimeout(progressiveIteration, interval);
|
||||||
|
}
|
||||||
|
catch(e if e instanceof StopIteration) {
|
||||||
|
var fragment = this._createSiblingsFragmentInternal(aCurrentItem, items);
|
||||||
|
aCallback(fragment);
|
||||||
|
}
|
||||||
|
catch(e) {
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
this._createSiblingsFragmentTimer = null;
|
||||||
|
}
|
||||||
|
}).bind(this);
|
||||||
|
this._createSiblingsFragmentTimer = window.setTimeout(progressiveIteration, interval);
|
||||||
|
},
|
||||||
|
_createSiblingsFragmentTimer : null,
|
||||||
|
_createSiblingsFragmentInternal : function TSTBMEditable_createSiblingsFragmentInternal(aCurrentItem, aItems)
|
||||||
|
{
|
||||||
|
var treeStructure = this.getTreeStructureFromItems(aItems);
|
||||||
|
|
||||||
|
var currentIndex = aItems.indexOf(aCurrentItem);
|
||||||
var selected = treeStructure[currentIndex];
|
var selected = treeStructure[currentIndex];
|
||||||
if (selected > -1) {
|
if (selected > -1) {
|
||||||
let offset = treeStructure.lastIndexOf(-1, currentIndex);
|
let offset = treeStructure.lastIndexOf(-1, currentIndex);
|
||||||
let subStructure = treeStructure.slice(offset);
|
let subStructure = treeStructure.slice(offset);
|
||||||
selected = items[selected + offset];
|
selected = aItems[selected + offset];
|
||||||
}
|
}
|
||||||
|
|
||||||
var fragment = document.createDocumentFragment();
|
var fragment = document.createDocumentFragment();
|
||||||
for (let [i, id] in Iterator(items))
|
for (let [i, id] in Iterator(aItems))
|
||||||
{
|
{
|
||||||
let label = PlacesUtils.bookmarks.getItemTitle(id);
|
let label = PlacesUtils.bookmarks.getItemTitle(id);
|
||||||
let item = document.createElement('menuitem');
|
let item = document.createElement('menuitem');
|
||||||
@ -202,10 +242,9 @@ var TreeStyleTabBookmarksServiceEditable = {
|
|||||||
}
|
}
|
||||||
return fragment;
|
return fragment;
|
||||||
},
|
},
|
||||||
_getItemsInFolder : function TSTBMEditable__getItemsInFolder(aId)
|
_getItemsInFolderIterator : function TSTBMEditable_getItemsInFolderIterator(aId)
|
||||||
{
|
{
|
||||||
var count = 0;
|
var count = 0;
|
||||||
var items = [];
|
|
||||||
var item;
|
var item;
|
||||||
try {
|
try {
|
||||||
while((item = PlacesUtils.bookmarks.getIdForItemAt(aId, count++)) != -1)
|
while((item = PlacesUtils.bookmarks.getIdForItemAt(aId, count++)) != -1)
|
||||||
@ -213,7 +252,7 @@ var TreeStyleTabBookmarksServiceEditable = {
|
|||||||
try {
|
try {
|
||||||
let uri = PlacesUtils.bookmarks.getBookmarkURI(item);
|
let uri = PlacesUtils.bookmarks.getBookmarkURI(item);
|
||||||
if (uri.spec.indexOf('place:') != 0)
|
if (uri.spec.indexOf('place:') != 0)
|
||||||
items.push(item);
|
yield item;
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
// this is not a normal bookmark.
|
// this is not a normal bookmark.
|
||||||
@ -222,11 +261,10 @@ var TreeStyleTabBookmarksServiceEditable = {
|
|||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
}
|
}
|
||||||
return items;
|
|
||||||
},
|
},
|
||||||
_getSiblingItems : function TSTBMEditable__getSiblingItems(aId)
|
_getSiblingItemsIterator : function TSTBMEditable_getSiblingItemsIterator(aId)
|
||||||
{
|
{
|
||||||
return this._getItemsInFolder(PlacesUtils.bookmarks.getFolderIdForItem(aId));
|
return this._getItemsInFolderIterator(PlacesUtils.bookmarks.getFolderIdForItem(aId));
|
||||||
},
|
},
|
||||||
|
|
||||||
saveParentFor : function TSTBMEditable_saveParentFor(aId)
|
saveParentFor : function TSTBMEditable_saveParentFor(aId)
|
||||||
@ -234,10 +272,32 @@ var TreeStyleTabBookmarksServiceEditable = {
|
|||||||
var newParentId = parseInt(this.menulist.value || -1);
|
var newParentId = parseInt(this.menulist.value || -1);
|
||||||
if (this.canceled || newParentId == this.getParentItem(aId)) return;
|
if (this.canceled || newParentId == this.getParentItem(aId)) return;
|
||||||
|
|
||||||
var items = this._getSiblingItems(aId);
|
var itemsIterator = this._getSiblingItemsIterator(aId);
|
||||||
var treeStructure = this.getTreeStructureFromItems(items);
|
var items = [];
|
||||||
|
|
||||||
var parentIndex = items.indexOf(newParentId);
|
var interval = 100;
|
||||||
|
var step = 10;
|
||||||
|
var progressiveIteration = (function() {
|
||||||
|
try {
|
||||||
|
for (let i = 0; i < step; i++)
|
||||||
|
{
|
||||||
|
items.push(itemsIterator.next());
|
||||||
|
}
|
||||||
|
window.setTimeout(progressiveIteration, interval);
|
||||||
|
}
|
||||||
|
catch(e if e instanceof StopIteration) {
|
||||||
|
this._saveParentForInternal(aId, newParentId, items);
|
||||||
|
}
|
||||||
|
catch(e) {
|
||||||
|
}
|
||||||
|
}).bind(this);
|
||||||
|
window.setTimeout(progressiveIteration, interval);
|
||||||
|
},
|
||||||
|
_saveParentForInternal : function TSTBMEditable_saveParentForInternal(aId, aNewParentId, aItems)
|
||||||
|
{
|
||||||
|
var treeStructure = this.getTreeStructureFromItems(aItems);
|
||||||
|
|
||||||
|
var parentIndex = aItems.indexOf(aNewParentId);
|
||||||
var newIndex;
|
var newIndex;
|
||||||
if (TreeStyleTabUtils.getTreePref('insertNewChildAt') == this.kINSERT_FISRT) {
|
if (TreeStyleTabUtils.getTreePref('insertNewChildAt') == this.kINSERT_FISRT) {
|
||||||
newIndex = treeStructure.indexOf(parentIndex);
|
newIndex = treeStructure.indexOf(parentIndex);
|
||||||
@ -253,7 +313,7 @@ var TreeStyleTabBookmarksServiceEditable = {
|
|||||||
|
|
||||||
PlacesUtils.setAnnotationsForItem(aId, [{
|
PlacesUtils.setAnnotationsForItem(aId, [{
|
||||||
name : this.kPARENT,
|
name : this.kPARENT,
|
||||||
value : newParentId,
|
value : aNewParentId,
|
||||||
expires : PlacesUtils.annotations.EXPIRE_NEVER
|
expires : PlacesUtils.annotations.EXPIRE_NEVER
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user