From 401b83b92fd4492fa384082db768c278c86cbddb Mon Sep 17 00:00:00 2001 From: Piro / SHIMODA Hiroshi Date: Sun, 30 Oct 2011 01:10:17 +0900 Subject: [PATCH] split long method --- content/treestyletab/bookmarksOverlay.js | 134 +++++++++++++---------- 1 file changed, 76 insertions(+), 58 deletions(-) diff --git a/content/treestyletab/bookmarksOverlay.js b/content/treestyletab/bookmarksOverlay.js index 901f5a89..a04e1bad 100644 --- a/content/treestyletab/bookmarksOverlay.js +++ b/content/treestyletab/bookmarksOverlay.js @@ -229,64 +229,11 @@ var TreeStyleTabBookmarksService = { ).replace( /(browserWindow\.(?:getBrowser\(\)|gBrowser)\.loadTabs\([^;]+\);)/, 1 && - ( - TSTOpenGroupBookmarkBehavior & sv.kGROUP_BOOKMARK_USE_DUMMY_FORCE || - // when there is any orphan, then all of parents and orphans should be grouped under a dummy tab. - childCount < parentCount - ) - ) { - ids.unshift(-1); - treeStructure = sv.getTreeStructureFromItems(ids, 0); - urls.unshift(sv.getGroupTabURI(aFolderTitle)); - } - } - - if (sv.getTreePref('compatibility.TMP') && - 'TMP_Places' in browserWindow && - 'openGroup' in browserWindow.TMP_Places) { - TSTTreeStructure = treeStructure; - TSTPreviousTabs = browserWindow.TreeStyleTabBookmarksService.getTabsInfo(browserWindow.gBrowser); - } - else { - sv.readyToOpenNewTabGroup(null, treeStructure, TSTOpenGroupBookmarkBehavior & sv.kGROUP_BOOKMARK_EXPAND_ALL_TREE); - } - // replaceCurrentTab works only on Firefox 7 or earlier - // See: https://bugzilla.mozilla.org/show_bug.cgi?id=440093 - if (typeof replaceCurrentTab !== 'undefined') - replaceCurrentTab = false; - } - else { - if (typeof replaceCurrentTab !== 'undefined') - replaceCurrentTab = !!(TSTOpenGroupBookmarkBehavior & sv.kGROUP_BOOKMARK_REPLACE); - } - } + var TSTResult = browserWindow.TreeStyleTabBookmarksService.handleTabsOpenProcess(where, aEvent, browserWindow, ids, urls, replaceCurrentTab, aFolderTitle); + TSTTreeStructure = TSTResult.treeStructure; + TSTPreviousTabs = TSTResult.previousTabs; + TSTOpenGroupBookmarkBehavior = TSTResult.behavior; + replaceCurrentTab = TSTResult.replaceCurrentTab; $1 ]]> ).replace( @@ -385,6 +332,77 @@ var TreeStyleTabBookmarksService = { ); } }, + handleTabsOpenProcess : function TSTBMService_handleTabsOpenProcess(aWhere, aEvent, aBrowserWindow, aIDs, aURLs, aReplaceCurrentTab, aFolderTitle) + { + var result = { + behavior : undefined, + treeStructure : undefined, + previousTabs : undefined, + replaceCurrentTab : undefined + }; + if ( + aWhere.indexOf('tab') != 0 && + aEvent.target.id != 'placesContext_openContainer:tabs' && + aEvent.target.id != 'placesContext_openLinks:tabs' && + aEvent.target != aEvent.target.parentNode._endOptOpenAllInTabs && + aEvent.target.getAttribute('openInTabs') != 'true' + ) + return result; + + var sv = aBrowserWindow.TreeStyleTabBookmarksService; + result.behavior = sv.openGroupBookmarkBehavior(); + if (result.behavior & sv.kGROUP_BOOKMARK_SUBTREE) { + let treeStructure = result.behavior & sv.kGROUP_BOOKMARK_DONT_RESTORE_TREE_STRUCTURE ? + null : + sv.getTreeStructureFromItems(aIDs) ; + if ( + treeStructure && + result.behavior & sv.kGROUP_BOOKMARK_USE_DUMMY + ) { + let parentCount = 0; + let childCount = 0; + for (let i in treeStructure) { + if (treeStructure[i] == -1) + parentCount++; + else + childCount++; + } + if ( + parentCount > 1 && + ( + result.behavior & sv.kGROUP_BOOKMARK_USE_DUMMY_FORCE || + // when there is any orphan, then all of parents and orphans should be grouped under a dummy tab. + childCount < parentCount + ) + ) { + aIDs.unshift(-1); + treeStructure = sv.getTreeStructureFromItems(aIDs, 0); + aURLs.unshift(sv.getGroupTabURI(aFolderTitle)); + } + } + + if (sv.getTreePref('compatibility.TMP') && + 'TMP_Places' in aBrowserWindow && + 'openGroup' in aBrowserWindow.TMP_Places) { + result.treeStructure = treeStructure; + result.previousTabs = aBrowserWindow.TreeStyleTabBookmarksService.getTabsInfo(aBrowserWindow.gBrowser); + } + else { + sv.readyToOpenNewTabGroup(null, treeStructure, result.behavior & sv.kGROUP_BOOKMARK_EXPAND_ALL_TREE); + } + // replaceCurrentTab works only on Firefox 7 or earlier + // See: https://bugzilla.mozilla.org/show_bug.cgi?id=440093 + if (typeof aReplaceCurrentTab !== 'undefined') + result.replaceCurrentTab = false; + } + else { + if (typeof aReplaceCurrentTab !== 'undefined') + result.replaceCurrentTab = !!(result.behavior & sv.kGROUP_BOOKMARK_REPLACE); + } + return result; + }, + + destroy : function TSTBMService_destroy() {