複数のツリーの同時生成を前提としたコードに修正

git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@5566 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
piro 2009-12-20 18:46:51 +00:00
parent 9b7494fad2
commit 259f5ae309
2 changed files with 25 additions and 4 deletions

View File

@ -90,9 +90,17 @@ var TreeStyleTabBookmarksService = {
getTreeStructureFromItems : function(aIDs)
{
/* this returns...
[A] => -1 (parent is not in this tree)
[B] => 0 (parent is 1st item in this tree)
[C] => 0 (parent is 1st item in this tree)
[D] => 2 (parent is 2nd in this tree)
[E] => -1 (parent is not in this tree, and this creates another tree)
[F] => 0 (parent is 1st item in this another tree)
*/
var treeStructure = aIDs.map(function(aId, aIndex) {
let id = this.getParentItem(aId);
let index = id < 0 ? -1 : aIDs.indexOf(id);
let index = aIDs.indexOf(id);
return index < aIndex ? index : -1 ;
}, this);
@ -116,8 +124,17 @@ var TreeStyleTabBookmarksService = {
});
treeStructure = treeStructure.reverse();
treeStructure = treeStructure.map(function(aPosition, aIndex) {
var offset = 0;
treeStructure = treeStructure
.map(function(aPosition, aIndex) {
return (aPosition == aIndex) ? -1 : aPosition ;
})
.map(function(aPosition, aIndex) {
if (aPosition == -1) {
offset = aIndex;
return aPosition;
}
return aPosition - offset;
});
return treeStructure;
},

View File

@ -1400,13 +1400,17 @@ TreeStyleTabBrowser.prototype = {
this.initTab(tab);
var hasStructure = this.treeStructure && this.treeStructure.length;
var positionInTree = hasStructure ? this.treeStructure.shift() : -1 ;
var pareintIndexInTree = hasStructure ? this.treeStructure.shift() : 0 ;
if (this.readiedToAttachNewTab) {
if (pareintIndexInTree < 0) { // there is no parent, so this is a new parent!
this.parentTab = tab.getAttribute(this.kID);
}
let parent = this.getTabById(this.parentTab);
if (parent) {
let tabs = [parent].concat(this.getDescendantTabs(parent));
parent = (positionInTree > -1 && positionInTree < tabs.length) ? tabs[positionInTree] : parent ;
parent = pareintIndexInTree < tabs.length ? tabs[pareintIndexInTree] : parent ;
}
if (parent) {
this.attachTabTo(tab, parent);