Process iterator by a common utility

This commit is contained in:
Piro / YUKI Hiroshi 2013-10-30 02:11:31 +09:00
parent c10e126000
commit 037ed95977

View File

@ -171,13 +171,11 @@ var TreeStyleTabBookmarksServiceEditable = {
this.menulist.value = (selected || this.blankItem).getAttribute('value');
}).bind(this))
},
_createSiblingsFragment : function TSTBMEditable__createSiblingsFragment(aCurrentItem, aCallback)
_doProgressively : function TSTBMEditable__doProgressively(aParams)
{
var itemsIterator = this._getSiblingItemsIterator(aCurrentItem);
var items = [];
if (this._createSiblingsFragmentTimer)
window.clearTimeout(this._createSiblingsFragmentTimer);
var name = aParams.name;
if (this._doProgressivelyTimers[name])
window.clearTimeout(this._doProgressivelyTimers[name]);
var interval = 100;
var step = 10;
@ -185,24 +183,39 @@ var TreeStyleTabBookmarksServiceEditable = {
try {
for (let i = 0; i < step; i++)
{
items.push(itemsIterator.next());
aParams.onProgress();
}
this._createSiblingsFragmentTimer = window.setTimeout(progressiveIteration, interval);
this._doProgressivelyTimers[name] = window.setTimeout(progressiveIteration, interval);
}
catch(e if e instanceof StopIteration) {
aParams.onComplete();
}
catch(e) {
Components.utils.reportError(e);
}
finally {
this._doProgressivelyTimers[name] = null;
}
}).bind(this);
this._doProgressivelyTimers[name] = window.setTimeout(progressiveIteration, interval);
},
_doProgressivelyTimers : {},
_createSiblingsFragment : function TSTBMEditable__createSiblingsFragment(aCurrentItem, aCallback)
{
var itemsIterator = this._getSiblingItemsIterator(aCurrentItem);
var items = [];
this._doProgressively({
name : '_createSiblingsFragment',
onProgress : function() {
items.push(itemsIterator.next());
},
onComplete : (function() {
this._createSiblingsFragmentInternal(aCurrentItem, items, function(aSiblingsFragment) {
aCallback(aSiblingsFragment);
});
}
catch(e) {
}
finally {
this._createSiblingsFragmentTimer = null;
}
}).bind(this);
this._createSiblingsFragmentTimer = window.setTimeout(progressiveIteration, interval);
}).bind(this)
});
},
_createSiblingsFragmentTimer : null,
_createSiblingsFragmentInternal : function TSTBMEditable_createSiblingsFragmentInternal(aCurrentItem, aItems, aCallback)
{
var treeStructure = this.getTreeStructureFromItems(aItems);
@ -217,25 +230,17 @@ var TreeStyleTabBookmarksServiceEditable = {
var fragment = document.createDocumentFragment();
if (this._createSiblingsFragmentInternalTimer)
window.clearTimeout(this._createSiblingsFragmentInternalTimer);
var interval = 100;
var step = 10;
var current = 0;
var progressiveIteration = (function() {
let id;
for (let i = 0; i < step; i++)
{
id = aItems[current++];
if (!id)
break;
var itemsIterator = Iterator(aItems);
this._doProgressively({
name : '_createSiblingsFragment',
onProgress : (function() {
let [index, id] = itemsIterator.next();
let label = PlacesUtils.bookmarks.getItemTitle(id);
let menuitem = document.createElement('menuitem');
menuitem.setAttribute('value', id);
let parent = i;
let parent = index;
let nest = 0;
let disabled = false;
while ((parent = treeStructure[parent]) != -1)
@ -257,17 +262,12 @@ var TreeStyleTabBookmarksServiceEditable = {
menuitem.setAttribute('label', label);
fragment.appendChild(menuitem);
}).bind(this),
onComplete : function() {
aCallback(fragment);
}
if (id) {
this._createSiblingsFragmentInternalTimer = window.setTimeout(progressiveIteration, interval);
return;
}
this._createSiblingsFragmentInternalTimer = null;
aCallback(fragment);
}).bind(this);
this._createSiblingsFragmentInternalTimer = window.setTimeout(progressiveIteration, interval);
});
},
_createSiblingsFragmentInternalTimer : null,
_getItemsInFolderIterator : function TSTBMEditable_getItemsInFolderIterator(aId)
{
var count = 0;
@ -300,24 +300,15 @@ var TreeStyleTabBookmarksServiceEditable = {
var itemsIterator = this._getSiblingItemsIterator(aId);
var items = [];
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._doProgressively({
name : '_createSiblingsFragment',
onProgress : function() {
items.push(itemsIterator.next());
},
onComplete : (function() {
this._saveParentForInternal(aId, newParentId, items);
}
catch(e) {
}
}).bind(this);
window.setTimeout(progressiveIteration, interval);
}).bind(this)
});
},
_saveParentForInternal : function TSTBMEditable_saveParentForInternal(aId, aNewParentId, aItems)
{