Build menulist items for sibling bookmarks in the folder progressively.

I think this can become a workaround for #398.
This commit is contained in:
Piro / YUKI Hiroshi 2013-10-30 01:55:46 +09:00
parent 63114ca99f
commit c10e126000

View File

@ -159,15 +159,11 @@ var TreeStyleTabBookmarksServiceEditable = {
if (PlacesUtils.bookmarks.getFolderIdForItem(id) == PlacesUtils.unfiledBookmarksFolderId) if (PlacesUtils.bookmarks.getFolderIdForItem(id) == PlacesUtils.unfiledBookmarksFolderId)
return; return;
this._createSiblingsFragment(id, (function(aFragment) { this._createSiblingsFragment(id, (function(aSiblingsFragment) {
var siblings = Array.slice(aFragment.childNodes)
.map(function(aItem) {
return parseInt(aItem.getAttribute('value'));
});
var range = document.createRange(); var range = document.createRange();
range.selectNodeContents(popup); range.selectNodeContents(popup);
range.setEndBefore(this.separator); range.setEndBefore(this.separator);
range.insertNode(aFragment); range.insertNode(aSiblingsFragment);
range.detach(); range.detach();
var selected = popup.getElementsByAttribute('selected', 'true')[0]; var selected = popup.getElementsByAttribute('selected', 'true')[0];
@ -194,8 +190,9 @@ var TreeStyleTabBookmarksServiceEditable = {
this._createSiblingsFragmentTimer = window.setTimeout(progressiveIteration, interval); this._createSiblingsFragmentTimer = window.setTimeout(progressiveIteration, interval);
} }
catch(e if e instanceof StopIteration) { catch(e if e instanceof StopIteration) {
var fragment = this._createSiblingsFragmentInternal(aCurrentItem, items); this._createSiblingsFragmentInternal(aCurrentItem, items, function(aSiblingsFragment) {
aCallback(fragment); aCallback(aSiblingsFragment);
});
} }
catch(e) { catch(e) {
} }
@ -206,7 +203,7 @@ var TreeStyleTabBookmarksServiceEditable = {
this._createSiblingsFragmentTimer = window.setTimeout(progressiveIteration, interval); this._createSiblingsFragmentTimer = window.setTimeout(progressiveIteration, interval);
}, },
_createSiblingsFragmentTimer : null, _createSiblingsFragmentTimer : null,
_createSiblingsFragmentInternal : function TSTBMEditable_createSiblingsFragmentInternal(aCurrentItem, aItems) _createSiblingsFragmentInternal : function TSTBMEditable_createSiblingsFragmentInternal(aCurrentItem, aItems, aCallback)
{ {
var treeStructure = this.getTreeStructureFromItems(aItems); var treeStructure = this.getTreeStructureFromItems(aItems);
@ -219,35 +216,58 @@ var TreeStyleTabBookmarksServiceEditable = {
} }
var fragment = document.createDocumentFragment(); var fragment = document.createDocumentFragment();
for (let [i, id] in Iterator(aItems))
{
let label = PlacesUtils.bookmarks.getItemTitle(id);
let item = document.createElement('menuitem');
item.setAttribute('value', id);
let parent = i; if (this._createSiblingsFragmentInternalTimer)
let nest = 0; window.clearTimeout(this._createSiblingsFragmentInternalTimer);
let disabled = false;
while ((parent = treeStructure[parent]) != -1) var interval = 100;
var step = 10;
var current = 0;
var progressiveIteration = (function() {
let id;
for (let i = 0; i < step; i++)
{ {
nest++; id = aItems[current++];
if (parent == currentIndex) disabled = true; if (!id)
break;
let label = PlacesUtils.bookmarks.getItemTitle(id);
let menuitem = document.createElement('menuitem');
menuitem.setAttribute('value', id);
let parent = i;
let nest = 0;
let disabled = false;
while ((parent = treeStructure[parent]) != -1)
{
nest++;
if (parent == currentIndex) disabled = true;
}
if (nest)
menuitem.setAttribute('style', 'padding-left:'+nest+'em');
if (disabled || id == aCurrentItem) {
menuitem.setAttribute('disabled', true);
if (id == aCurrentItem)
label = TreeStyleTabUtils.treeBundle.getFormattedString('bookmarkProperty.parent.current.label', [label]);
}
if (id == selected)
menuitem.setAttribute('selected', true);
menuitem.setAttribute('label', label);
fragment.appendChild(menuitem);
} }
if (nest) item.setAttribute('style', 'padding-left:'+nest+'em'); if (id) {
this._createSiblingsFragmentInternalTimer = window.setTimeout(progressiveIteration, interval);
if (disabled || id == aCurrentItem) { return;
item.setAttribute('disabled', true);
if (id == aCurrentItem)
label = TreeStyleTabUtils.treeBundle.getFormattedString('bookmarkProperty.parent.current.label', [label]);
} }
if (id == selected) item.setAttribute('selected', true); this._createSiblingsFragmentInternalTimer = null;
aCallback(fragment);
item.setAttribute('label', label); }).bind(this);
this._createSiblingsFragmentInternalTimer = window.setTimeout(progressiveIteration, interval);
fragment.appendChild(item);
}
return fragment;
}, },
_createSiblingsFragmentInternalTimer : null,
_getItemsInFolderIterator : function TSTBMEditable_getItemsInFolderIterator(aId) _getItemsInFolderIterator : function TSTBMEditable_getItemsInFolderIterator(aId)
{ {
var count = 0; var count = 0;