move some codes to utility
git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@5627 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
parent
189803de7e
commit
de514657a3
@ -1,41 +1,4 @@
|
|||||||
var TreeStyleTabService = {
|
var TreeStyleTabService = {
|
||||||
kFOCUS_ALL : 0,
|
|
||||||
kFOCUS_VISIBLE : 1,
|
|
||||||
|
|
||||||
kDROP_BEFORE : -1,
|
|
||||||
kDROP_ON : 0,
|
|
||||||
kDROP_AFTER : 1,
|
|
||||||
|
|
||||||
kACTION_MOVE : 1 << 0,
|
|
||||||
kACTION_STAY : 1 << 1,
|
|
||||||
kACTION_DUPLICATE : 1 << 2,
|
|
||||||
kACTION_IMPORT : 1 << 3,
|
|
||||||
kACTION_NEWTAB : 1 << 4,
|
|
||||||
kACTION_ATTACH : 1 << 10,
|
|
||||||
kACTION_PART : 1 << 11,
|
|
||||||
kACTIONS_FOR_SOURCE : (1 << 0) | (1 << 1),
|
|
||||||
kACTIONS_FOR_DESTINATION : (1 << 2) | (1 << 3),
|
|
||||||
|
|
||||||
kTABBAR_TOP : 1 << 0,
|
|
||||||
kTABBAR_BOTTOM : 1 << 1,
|
|
||||||
kTABBAR_LEFT : 1 << 2,
|
|
||||||
kTABBAR_RIGHT : 1 << 3,
|
|
||||||
|
|
||||||
kTABBAR_HORIZONTAL : (1 << 0) | (1 << 1),
|
|
||||||
kTABBAR_VERTICAL : (1 << 2) | (1 << 3),
|
|
||||||
|
|
||||||
kINSERT_FISRT : 0,
|
|
||||||
kINSERT_LAST : 1,
|
|
||||||
|
|
||||||
baseIndent : 12,
|
|
||||||
shouldDetectClickOnIndentSpaces : true,
|
|
||||||
|
|
||||||
smoothScrollEnabled : true,
|
|
||||||
smoothScrollDuration : 150,
|
|
||||||
|
|
||||||
animationEnabled : true,
|
|
||||||
indentDuration : 200,
|
|
||||||
collapseDuration : 150,
|
|
||||||
|
|
||||||
get treeBundle() {
|
get treeBundle() {
|
||||||
return window['piro.sakura.ne.jp']
|
return window['piro.sakura.ne.jp']
|
||||||
@ -50,50 +13,6 @@ var TreeStyleTabService = {
|
|||||||
|
|
||||||
/* API */
|
/* API */
|
||||||
|
|
||||||
setTabbarWidth : function TSTService_setTabbarWidth(aWidth, aForceExpanded) /* PUBLIC API */
|
|
||||||
{
|
|
||||||
gBrowser.treeStyleTab.autoHide.setWidth(aWidth, aForceExpanded);
|
|
||||||
},
|
|
||||||
|
|
||||||
setContentWidth : function TSTService_setContentWidth(aWidth, aKeepWindowSize) /* PUBLIC API */
|
|
||||||
{
|
|
||||||
var treeStyleTab = gBrowser.treeStyleTab;
|
|
||||||
var tabbarWidth = treeStyleTab.splitterWidth + (treeStyleTab.isVertical ? gBrowser.mStrip.boxObject.width : 0 );
|
|
||||||
var contentWidth = gBrowser.boxObject.width - tabbarWidth;
|
|
||||||
if (aKeepWindowSize ||
|
|
||||||
window.fullScreen ||
|
|
||||||
window.windowState != Components.interfaces.nsIDOMChromeWindow.STATE_NORMAL) {
|
|
||||||
this.setTabbarWidth(Math.max(10, gBrowser.boxObject.width - aWidth));
|
|
||||||
}
|
|
||||||
else if (tabbarWidth + aWidth <= screen.availWidth) {
|
|
||||||
window.resizeBy(aWidth - contentWidth, 0);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
window.resizeBy(screen.availWidth - window.outerWidth, 0);
|
|
||||||
this.setTabbarWidth(gBrowser.boxObject.width - aWidth);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
toggleAutoHide : function TSTService_toggleAutoHide()
|
|
||||||
{
|
|
||||||
TreeStyleTabBrowserAutoHide.toggleMode();
|
|
||||||
},
|
|
||||||
|
|
||||||
toggleFixed : function TSTService_toggleFixed()
|
|
||||||
{
|
|
||||||
var pos = this.currentTabbarPosition;
|
|
||||||
var isVertical = (pos == 'left' || pos == 'right');
|
|
||||||
|
|
||||||
var orient = isVertical ? 'vertical' : 'horizontal' ;
|
|
||||||
var pref = 'tabbar.fixed.'+orient;
|
|
||||||
this.setTreePref(pref, !this.getTreePref(pref));
|
|
||||||
|
|
||||||
if (!this.getTreePref('tabbar.syncRelatedPrefsForDynamicPosition')) return;
|
|
||||||
|
|
||||||
if (!isVertical)
|
|
||||||
this.setTreePref('enableSubtreeIndent.horizontal', !this.getTreePref(pref));
|
|
||||||
},
|
|
||||||
|
|
||||||
changeTabbarPosition : function TSTService_changeTabbarPosition(aNewPosition) /* PUBLIC API (obsolete, for backward compatibility) */
|
changeTabbarPosition : function TSTService_changeTabbarPosition(aNewPosition) /* PUBLIC API (obsolete, for backward compatibility) */
|
||||||
{
|
{
|
||||||
this.currentTabbarPosition = aNewPosition;
|
this.currentTabbarPosition = aNewPosition;
|
||||||
@ -122,6 +41,15 @@ var TreeStyleTabService = {
|
|||||||
return this.utils.treeViewEnabled = aValue;
|
return this.utils.treeViewEnabled = aValue;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
get useTMPSessionAPI() /* PUBLIC API */
|
||||||
|
{
|
||||||
|
return this.utils.useTMPSessionAPI;
|
||||||
|
},
|
||||||
|
set useTMPSessionAPI(aValue)
|
||||||
|
{
|
||||||
|
return this.utils.useTMPSessionAPI = aValue;
|
||||||
|
},
|
||||||
|
|
||||||
/* backward compatibility */
|
/* backward compatibility */
|
||||||
getTempTreeStyleTab : function TSTService_getTempTreeStyleTab(aTabBrowser)
|
getTempTreeStyleTab : function TSTService_getTempTreeStyleTab(aTabBrowser)
|
||||||
{
|
{
|
||||||
@ -172,6 +100,7 @@ var TreeStyleTabService = {
|
|||||||
XPathResult.BOOLEAN_TYPE
|
XPathResult.BOOLEAN_TYPE
|
||||||
).booleanValue;
|
).booleanValue;
|
||||||
},
|
},
|
||||||
|
|
||||||
canExpandTwistyArea : function TSTService_canExpandTwistyArea(aTabBrowser)
|
canExpandTwistyArea : function TSTService_canExpandTwistyArea(aTabBrowser)
|
||||||
{
|
{
|
||||||
return (
|
return (
|
||||||
@ -181,7 +110,6 @@ var TreeStyleTabService = {
|
|||||||
}, this)
|
}, this)
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
expandTwistyArea : true,
|
|
||||||
|
|
||||||
getBoxObjectFor : function TSTService_getBoxObjectFor(aNode)
|
getBoxObjectFor : function TSTService_getBoxObjectFor(aNode)
|
||||||
{
|
{
|
||||||
@ -196,71 +124,6 @@ var TreeStyleTabService = {
|
|||||||
return Number(style.getPropertyValue(aProp).replace(/px$/, ''));
|
return Number(style.getPropertyValue(aProp).replace(/px$/, ''));
|
||||||
},
|
},
|
||||||
|
|
||||||
/* Session Store API */
|
|
||||||
|
|
||||||
getTabValue : function TSTService_getTabValue(aTab, aKey)
|
|
||||||
{
|
|
||||||
var value = '';
|
|
||||||
try {
|
|
||||||
value = this.SessionStore.getTabValue(aTab, aKey);
|
|
||||||
}
|
|
||||||
catch(e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.useTMPSessionAPI) {
|
|
||||||
let TMPValue = aTab.getAttribute(this.kTMP_SESSION_DATA_PREFIX+aKey);
|
|
||||||
if (TMPValue) value = TMPValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
},
|
|
||||||
|
|
||||||
setTabValue : function TSTService_setTabValue(aTab, aKey, aValue)
|
|
||||||
{
|
|
||||||
if (!aValue) return this.deleteTabValue(aTab, aKey);
|
|
||||||
|
|
||||||
aTab.setAttribute(aKey, aValue);
|
|
||||||
try {
|
|
||||||
this.checkCachedSessionDataExpiration(aTab);
|
|
||||||
this.SessionStore.setTabValue(aTab, aKey, aValue);
|
|
||||||
}
|
|
||||||
catch(e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.useTMPSessionAPI)
|
|
||||||
aTab.setAttribute(this.kTMP_SESSION_DATA_PREFIX+aKey, aValue);
|
|
||||||
|
|
||||||
return aValue;
|
|
||||||
},
|
|
||||||
|
|
||||||
deleteTabValue : function TSTService_deleteTabValue(aTab, aKey)
|
|
||||||
{
|
|
||||||
aTab.removeAttribute(aKey);
|
|
||||||
try {
|
|
||||||
this.checkCachedSessionDataExpiration(aTab);
|
|
||||||
this.SessionStore.setTabValue(aTab, aKey, '');
|
|
||||||
this.SessionStore.deleteTabValue(aTab, aKey);
|
|
||||||
}
|
|
||||||
catch(e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.useTMPSessionAPI)
|
|
||||||
aTab.removeAttribute(this.kTMP_SESSION_DATA_PREFIX+aKey);
|
|
||||||
},
|
|
||||||
|
|
||||||
// workaround for http://piro.sakura.ne.jp/latest/blosxom/mozilla/extension/treestyletab/2009-09-29_debug.htm
|
|
||||||
checkCachedSessionDataExpiration : function TSTService_checkCachedSessionDataExpiration(aTab)
|
|
||||||
{
|
|
||||||
if (aTab.linkedBrowser.parentNode.__SS_data &&
|
|
||||||
aTab.linkedBrowser.parentNode.__SS_data._tabStillLoading &&
|
|
||||||
aTab.getAttribute('busy') != 'true')
|
|
||||||
aTab.linkedBrowser.parentNode.__SS_data._tabStillLoading = false;
|
|
||||||
},
|
|
||||||
|
|
||||||
useTMPSessionAPI : false,
|
|
||||||
|
|
||||||
kTMP_SESSION_DATA_PREFIX : 'tmp-session-data-',
|
|
||||||
|
|
||||||
dropLinksOnTabBehavior : function TSTService_dropLinksOnTabBehavior()
|
dropLinksOnTabBehavior : function TSTService_dropLinksOnTabBehavior()
|
||||||
{
|
{
|
||||||
var behavior = this.getTreePref('dropLinksOnTab.behavior');
|
var behavior = this.getTreePref('dropLinksOnTab.behavior');
|
||||||
@ -506,7 +369,6 @@ var TreeStyleTabService = {
|
|||||||
appcontent.addEventListener('SubBrowserRemoveRequest', this, false);
|
appcontent.addEventListener('SubBrowserRemoveRequest', this, false);
|
||||||
|
|
||||||
this.addPrefListener(this);
|
this.addPrefListener(this);
|
||||||
this.ObserverService.addObserver(this, 'private-browsing-change-granted', false);
|
|
||||||
|
|
||||||
this.initUninstallationListener();
|
this.initUninstallationListener();
|
||||||
|
|
||||||
@ -517,22 +379,12 @@ var TreeStyleTabService = {
|
|||||||
|
|
||||||
this.processRestoredTabs();
|
this.processRestoredTabs();
|
||||||
|
|
||||||
this.onPrefChange('extensions.treestyletab.indent');
|
|
||||||
this.onPrefChange('extensions.treestyletab.tabbar.autoHide.mode');
|
this.onPrefChange('extensions.treestyletab.tabbar.autoHide.mode');
|
||||||
this.onPrefChange('extensions.treestyletab.clickOnIndentSpaces.enabled');
|
|
||||||
this.onPrefChange('browser.link.open_newwindow.restriction.override');
|
|
||||||
this.onPrefChange('browser.tabs.loadFolderAndReplace.override');
|
|
||||||
this.onPrefChange('browser.tabs.insertRelatedAfterCurrent.override');
|
|
||||||
this.onPrefChange('extensions.treestyletab.tabbar.style');
|
this.onPrefChange('extensions.treestyletab.tabbar.style');
|
||||||
this.onPrefChange('extensions.treestyletab.tabbar.scroll.smooth');
|
|
||||||
this.onPrefChange('extensions.treestyletab.tabbar.scroll.duration');
|
|
||||||
this.onPrefChange('extensions.treestyletab.animation.enabled');
|
|
||||||
this.onPrefChange('extensions.treestyletab.animation.indent.duration');
|
|
||||||
this.onPrefChange('extensions.treestyletab.animation.collapse.duration');
|
|
||||||
this.onPrefChange('extensions.treestyletab.twisty.expandSensitiveArea');
|
|
||||||
this.onPrefChange('extensions.treestyletab.autoCollapseExpandSubtreeOnSelect.whileFocusMovingByShortcut');
|
this.onPrefChange('extensions.treestyletab.autoCollapseExpandSubtreeOnSelect.whileFocusMovingByShortcut');
|
||||||
},
|
},
|
||||||
initialized : false,
|
initialized : false,
|
||||||
|
|
||||||
initUninstallationListener : function TSTService_initUninstallationListener()
|
initUninstallationListener : function TSTService_initUninstallationListener()
|
||||||
{
|
{
|
||||||
var prefs = window['piro.sakura.ne.jp'].prefs;
|
var prefs = window['piro.sakura.ne.jp'].prefs;
|
||||||
@ -1419,20 +1271,6 @@ catch(e) {
|
|||||||
},
|
},
|
||||||
showHideSubTreeMenuItem : function() { return this.showHideSubtreeMenuItem.apply(this, arguments); }, // obsolete, for backward compatibility
|
showHideSubTreeMenuItem : function() { return this.showHideSubtreeMenuItem.apply(this, arguments); }, // obsolete, for backward compatibility
|
||||||
|
|
||||||
updateTabWidthPrefs : function TSTService_updateTabWidthPrefs(aPrefName)
|
|
||||||
{
|
|
||||||
var expanded = this.getTreePref('tabbar.width');
|
|
||||||
var shrunken = this.getTreePref('tabbar.shrunkenWidth');
|
|
||||||
if (expanded <= shrunken) {
|
|
||||||
this.tabbarWidthResetting = true;
|
|
||||||
if (aPrefName == 'extensions.treestyletab.tabbar.width')
|
|
||||||
this.setTreePref('tabbar.shrunkenWidth', parseInt(expanded / 1.5));
|
|
||||||
else
|
|
||||||
this.setTreePref('tabbar.width', parseInt(shrunken * 1.5));
|
|
||||||
this.tabbarWidthResetting = false;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
handleTooltip : function TSTService_handleTooltip(aEvent, aTab)
|
handleTooltip : function TSTService_handleTooltip(aEvent, aTab)
|
||||||
{
|
{
|
||||||
var label;
|
var label;
|
||||||
@ -1505,6 +1343,50 @@ catch(e) {
|
|||||||
|
|
||||||
/* Commands */
|
/* Commands */
|
||||||
|
|
||||||
|
setTabbarWidth : function TSTService_setTabbarWidth(aWidth, aForceExpanded) /* PUBLIC API */
|
||||||
|
{
|
||||||
|
gBrowser.treeStyleTab.autoHide.setWidth(aWidth, aForceExpanded);
|
||||||
|
},
|
||||||
|
|
||||||
|
setContentWidth : function TSTService_setContentWidth(aWidth, aKeepWindowSize) /* PUBLIC API */
|
||||||
|
{
|
||||||
|
var treeStyleTab = gBrowser.treeStyleTab;
|
||||||
|
var tabbarWidth = treeStyleTab.splitterWidth + (treeStyleTab.isVertical ? gBrowser.mStrip.boxObject.width : 0 );
|
||||||
|
var contentWidth = gBrowser.boxObject.width - tabbarWidth;
|
||||||
|
if (aKeepWindowSize ||
|
||||||
|
window.fullScreen ||
|
||||||
|
window.windowState != Components.interfaces.nsIDOMChromeWindow.STATE_NORMAL) {
|
||||||
|
this.setTabbarWidth(Math.max(10, gBrowser.boxObject.width - aWidth));
|
||||||
|
}
|
||||||
|
else if (tabbarWidth + aWidth <= screen.availWidth) {
|
||||||
|
window.resizeBy(aWidth - contentWidth, 0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
window.resizeBy(screen.availWidth - window.outerWidth, 0);
|
||||||
|
this.setTabbarWidth(gBrowser.boxObject.width - aWidth);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
toggleAutoHide : function TSTService_toggleAutoHide()
|
||||||
|
{
|
||||||
|
TreeStyleTabBrowserAutoHide.toggleMode();
|
||||||
|
},
|
||||||
|
|
||||||
|
toggleFixed : function TSTService_toggleFixed()
|
||||||
|
{
|
||||||
|
var pos = this.currentTabbarPosition;
|
||||||
|
var isVertical = (pos == 'left' || pos == 'right');
|
||||||
|
|
||||||
|
var orient = isVertical ? 'vertical' : 'horizontal' ;
|
||||||
|
var pref = 'tabbar.fixed.'+orient;
|
||||||
|
this.setTreePref(pref, !this.getTreePref(pref));
|
||||||
|
|
||||||
|
if (!this.getTreePref('tabbar.syncRelatedPrefsForDynamicPosition')) return;
|
||||||
|
|
||||||
|
if (!isVertical)
|
||||||
|
this.setTreePref('enableSubtreeIndent.horizontal', !this.getTreePref(pref));
|
||||||
|
},
|
||||||
|
|
||||||
removeTabSubtree : function TSTService_removeTabSubtree(aTabOrTabs, aOnlyChildren)
|
removeTabSubtree : function TSTService_removeTabSubtree(aTabOrTabs, aOnlyChildren)
|
||||||
{
|
{
|
||||||
var tabs = this.normalizeToTabs(aTabOrTabs, aOnlyChildren);
|
var tabs = this.normalizeToTabs(aTabOrTabs, aOnlyChildren);
|
||||||
@ -1744,11 +1626,6 @@ catch(e) {
|
|||||||
this.onPrefChange(aData);
|
this.onPrefChange(aData);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case 'private-browsing-change-granted':
|
|
||||||
if (aData == 'enter')
|
|
||||||
this.ObserverService.notifyObservers(window, 'TreeStyleTab:collapseExpandAllSubtree', 'expand-now');
|
|
||||||
return;
|
|
||||||
|
|
||||||
case 'sessionstore-windows-restored':
|
case 'sessionstore-windows-restored':
|
||||||
if (!this.useTMPSessionAPI)
|
if (!this.useTMPSessionAPI)
|
||||||
this.restoringWindow = this.getRestoringTabsCount() > 1;
|
this.restoringWindow = this.getRestoringTabsCount() > 1;
|
||||||
@ -1770,12 +1647,6 @@ catch(e) {
|
|||||||
|
|
||||||
domains : [
|
domains : [
|
||||||
'extensions.treestyletab',
|
'extensions.treestyletab',
|
||||||
'browser.link.open_newwindow.restriction',
|
|
||||||
'browser.link.open_newwindow.restriction.override',
|
|
||||||
'browser.tabs.loadFolderAndReplace',
|
|
||||||
'browser.tabs.loadFolderAndReplace.override',
|
|
||||||
'browser.tabs.insertRelatedAfterCurrent',
|
|
||||||
'browser.tabs.insertRelatedAfterCurrent.override',
|
|
||||||
'browser.ctrlTab.previews'
|
'browser.ctrlTab.previews'
|
||||||
],
|
],
|
||||||
|
|
||||||
@ -1784,11 +1655,6 @@ catch(e) {
|
|||||||
var value = this.getPref(aPrefName);
|
var value = this.getPref(aPrefName);
|
||||||
switch (aPrefName)
|
switch (aPrefName)
|
||||||
{
|
{
|
||||||
case 'extensions.treestyletab.indent':
|
|
||||||
this.baseIndent = value;
|
|
||||||
this.ObserverService.notifyObservers(null, 'TreeStyleTab:indentModified', value);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'extensions.treestyletab.tabbar.autoHide.mode':
|
case 'extensions.treestyletab.tabbar.autoHide.mode':
|
||||||
// don't set on this time, because appearance of all tabbrowsers are not updated yet.
|
// don't set on this time, because appearance of all tabbrowsers are not updated yet.
|
||||||
// this.autoHide.mode = this.getTreePref('tabbar.autoHide.mode');
|
// this.autoHide.mode = this.getTreePref('tabbar.autoHide.mode');
|
||||||
@ -1798,50 +1664,6 @@ catch(e) {
|
|||||||
TreeStyleTabBrowserAutoHide.updateKeyListeners();
|
TreeStyleTabBrowserAutoHide.updateKeyListeners();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'extensions.treestyletab.tabbar.width':
|
|
||||||
case 'extensions.treestyletab.tabbar.shrunkenWidth':
|
|
||||||
this.updateTabWidthPrefs(aPrefName);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'browser.link.open_newwindow.restriction':
|
|
||||||
case 'browser.tabs.loadFolderAndReplace':
|
|
||||||
case 'browser.tabs.insertRelatedAfterCurrent':
|
|
||||||
if (this.prefOverriding) return;
|
|
||||||
aPrefName += '.override';
|
|
||||||
this.setPref(aPrefName, value);
|
|
||||||
case 'browser.link.open_newwindow.restriction.override':
|
|
||||||
case 'browser.tabs.loadFolderAndReplace.override':
|
|
||||||
case 'browser.tabs.insertRelatedAfterCurrent.override':
|
|
||||||
this.prefOverriding = true;
|
|
||||||
var target = aPrefName.replace('.override', '');
|
|
||||||
var originalValue = this.getPref(target);
|
|
||||||
if (originalValue !== null && originalValue != value)
|
|
||||||
this.setPref(target+'.backup', originalValue);
|
|
||||||
this.setPref(target, this.getPref(aPrefName));
|
|
||||||
this.prefOverriding = false;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'extensions.treestyletab.clickOnIndentSpaces.enabled':
|
|
||||||
this.shouldDetectClickOnIndentSpaces = this.getPref(aPrefName);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'extensions.treestyletab.tabbar.scroll.smooth':
|
|
||||||
this.smoothScrollEnabled = value;
|
|
||||||
break;
|
|
||||||
case 'extensions.treestyletab.tabbar.scroll.duration':
|
|
||||||
this.smoothScrollDuration = value;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'extensions.treestyletab.animation.enabled':
|
|
||||||
this.animationEnabled = value;
|
|
||||||
break;
|
|
||||||
case 'extensions.treestyletab.animation.indent.duration':
|
|
||||||
this.indentDuration = value;
|
|
||||||
break;
|
|
||||||
case 'extensions.treestyletab.animation.collapse.duration':
|
|
||||||
this.collapseDuration = value;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'extensions.treestyletab.tabbar.style':
|
case 'extensions.treestyletab.tabbar.style':
|
||||||
case 'extensions.treestyletab.tabbar.position':
|
case 'extensions.treestyletab.tabbar.position':
|
||||||
this.preLoadImagesForStyle([
|
this.preLoadImagesForStyle([
|
||||||
@ -1850,10 +1672,6 @@ catch(e) {
|
|||||||
].join('-'));
|
].join('-'));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'extensions.treestyletab.twisty.expandSensitiveArea':
|
|
||||||
this.expandTwistyArea = value;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'browser.ctrlTab.previews':
|
case 'browser.ctrlTab.previews':
|
||||||
TreeStyleTabBrowserAutoHide.updateKeyListeners();
|
TreeStyleTabBrowserAutoHide.updateKeyListeners();
|
||||||
case 'extensions.treestyletab.autoCollapseExpandSubtreeOnSelect.whileFocusMovingByShortcut':
|
case 'extensions.treestyletab.autoCollapseExpandSubtreeOnSelect.whileFocusMovingByShortcut':
|
||||||
|
228
modules/utils.js
228
modules/utils.js
@ -40,7 +40,7 @@ var Ci = Components.interfaces;
|
|||||||
|
|
||||||
var TreeStyleTabUtils = {
|
var TreeStyleTabUtils = {
|
||||||
|
|
||||||
/* attributes */
|
/* attributes */
|
||||||
kID : 'treestyletab-id',
|
kID : 'treestyletab-id',
|
||||||
kCHILDREN : 'treestyletab-children',
|
kCHILDREN : 'treestyletab-children',
|
||||||
kPARENT : 'treestyletab-parent',
|
kPARENT : 'treestyletab-parent',
|
||||||
@ -85,7 +85,7 @@ var TreeStyleTabUtils = {
|
|||||||
kTABBAR_MOVE_FORCE : 'force',
|
kTABBAR_MOVE_FORCE : 'force',
|
||||||
kTABBAR_MOVE_NORMAL : 'normal',
|
kTABBAR_MOVE_NORMAL : 'normal',
|
||||||
|
|
||||||
/* classes */
|
/* classes */
|
||||||
kTWISTY : 'treestyletab-twisty',
|
kTWISTY : 'treestyletab-twisty',
|
||||||
kTWISTY_CONTAINER : 'treestyletab-twisty-container',
|
kTWISTY_CONTAINER : 'treestyletab-twisty-container',
|
||||||
kDROP_MARKER : 'treestyletab-drop-marker',
|
kDROP_MARKER : 'treestyletab-drop-marker',
|
||||||
@ -97,6 +97,48 @@ var TreeStyleTabUtils = {
|
|||||||
|
|
||||||
kMENUITEM_REMOVESUBTREE_SELECTION : 'multipletab-selection-item-removeTabSubtree',
|
kMENUITEM_REMOVESUBTREE_SELECTION : 'multipletab-selection-item-removeTabSubtree',
|
||||||
|
|
||||||
|
/* other constant values */
|
||||||
|
kFOCUS_ALL : 0,
|
||||||
|
kFOCUS_VISIBLE : 1,
|
||||||
|
|
||||||
|
kDROP_BEFORE : -1,
|
||||||
|
kDROP_ON : 0,
|
||||||
|
kDROP_AFTER : 1,
|
||||||
|
|
||||||
|
kACTION_MOVE : 1 << 0,
|
||||||
|
kACTION_STAY : 1 << 1,
|
||||||
|
kACTION_DUPLICATE : 1 << 2,
|
||||||
|
kACTION_IMPORT : 1 << 3,
|
||||||
|
kACTION_NEWTAB : 1 << 4,
|
||||||
|
kACTION_ATTACH : 1 << 10,
|
||||||
|
kACTION_PART : 1 << 11,
|
||||||
|
kACTIONS_FOR_SOURCE : (1 << 0) | (1 << 1),
|
||||||
|
kACTIONS_FOR_DESTINATION : (1 << 2) | (1 << 3),
|
||||||
|
|
||||||
|
kTABBAR_TOP : 1 << 0,
|
||||||
|
kTABBAR_BOTTOM : 1 << 1,
|
||||||
|
kTABBAR_LEFT : 1 << 2,
|
||||||
|
kTABBAR_RIGHT : 1 << 3,
|
||||||
|
|
||||||
|
kTABBAR_HORIZONTAL : (1 << 0) | (1 << 1),
|
||||||
|
kTABBAR_VERTICAL : (1 << 2) | (1 << 3),
|
||||||
|
|
||||||
|
kINSERT_FISRT : 0,
|
||||||
|
kINSERT_LAST : 1,
|
||||||
|
|
||||||
|
/* base variables */
|
||||||
|
baseIndent : 12,
|
||||||
|
shouldDetectClickOnIndentSpaces : true,
|
||||||
|
|
||||||
|
smoothScrollEnabled : true,
|
||||||
|
smoothScrollDuration : 150,
|
||||||
|
|
||||||
|
animationEnabled : true,
|
||||||
|
indentDuration : 200,
|
||||||
|
collapseDuration : 150,
|
||||||
|
|
||||||
|
expandTwistyArea : true,
|
||||||
|
|
||||||
get SessionStore() {
|
get SessionStore() {
|
||||||
if (!this._SessionStore) {
|
if (!this._SessionStore) {
|
||||||
this._SessionStore = Cc['@mozilla.org/browser/sessionstore;1'].getService(Ci.nsISessionStore);
|
this._SessionStore = Cc['@mozilla.org/browser/sessionstore;1'].getService(Ci.nsISessionStore);
|
||||||
@ -176,11 +218,40 @@ var TreeStyleTabUtils = {
|
|||||||
.indexOf('mac') > -1;
|
.indexOf('mac') > -1;
|
||||||
|
|
||||||
this.addPrefListener(this);
|
this.addPrefListener(this);
|
||||||
|
this.ObserverService.addObserver(this, 'private-browsing-change-granted', false);
|
||||||
|
|
||||||
this._tabbarPositionHistory.push(this.currentTabbarPosition);
|
this._tabbarPositionHistory.push(this.currentTabbarPosition);
|
||||||
|
|
||||||
|
this.onPrefChange('extensions.treestyletab.indent');
|
||||||
|
this.onPrefChange('extensions.treestyletab.clickOnIndentSpaces.enabled');
|
||||||
|
this.onPrefChange('browser.link.open_newwindow.restriction.override');
|
||||||
|
this.onPrefChange('browser.tabs.loadFolderAndReplace.override');
|
||||||
|
this.onPrefChange('browser.tabs.insertRelatedAfterCurrent.override');
|
||||||
|
this.onPrefChange('extensions.treestyletab.tabbar.scroll.smooth');
|
||||||
|
this.onPrefChange('extensions.treestyletab.tabbar.scroll.duration');
|
||||||
|
this.onPrefChange('extensions.treestyletab.animation.enabled');
|
||||||
|
this.onPrefChange('extensions.treestyletab.animation.indent.duration');
|
||||||
|
this.onPrefChange('extensions.treestyletab.animation.collapse.duration');
|
||||||
|
this.onPrefChange('extensions.treestyletab.twisty.expandSensitiveArea');
|
||||||
},
|
},
|
||||||
_initialized : false,
|
_initialized : false,
|
||||||
|
|
||||||
// utilities
|
observe : function TSTUtils_observe(aSubject, aTopic, aData)
|
||||||
|
{
|
||||||
|
switch (aTopic)
|
||||||
|
{
|
||||||
|
case 'nsPref:changed':
|
||||||
|
this.onPrefChange(aData);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case 'private-browsing-change-granted':
|
||||||
|
if (aData == 'enter')
|
||||||
|
this.ObserverService.notifyObservers(window, 'TreeStyleTab:collapseExpandAllSubtree', 'expand-now');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/* utilities */
|
||||||
|
|
||||||
get browserWindow()
|
get browserWindow()
|
||||||
{
|
{
|
||||||
@ -319,6 +390,71 @@ var TreeStyleTabUtils = {
|
|||||||
return array;
|
return array;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/* Session Store API */
|
||||||
|
|
||||||
|
getTabValue : function TSTUtils_getTabValue(aTab, aKey)
|
||||||
|
{
|
||||||
|
var value = '';
|
||||||
|
try {
|
||||||
|
value = this.SessionStore.getTabValue(aTab, aKey);
|
||||||
|
}
|
||||||
|
catch(e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.useTMPSessionAPI) {
|
||||||
|
let TMPValue = aTab.getAttribute(this.kTMP_SESSION_DATA_PREFIX+aKey);
|
||||||
|
if (TMPValue) value = TMPValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
},
|
||||||
|
|
||||||
|
setTabValue : function TSTUtils_setTabValue(aTab, aKey, aValue)
|
||||||
|
{
|
||||||
|
if (!aValue) return this.deleteTabValue(aTab, aKey);
|
||||||
|
|
||||||
|
aTab.setAttribute(aKey, aValue);
|
||||||
|
try {
|
||||||
|
this.checkCachedSessionDataExpiration(aTab);
|
||||||
|
this.SessionStore.setTabValue(aTab, aKey, aValue);
|
||||||
|
}
|
||||||
|
catch(e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.useTMPSessionAPI)
|
||||||
|
aTab.setAttribute(this.kTMP_SESSION_DATA_PREFIX+aKey, aValue);
|
||||||
|
|
||||||
|
return aValue;
|
||||||
|
},
|
||||||
|
|
||||||
|
deleteTabValue : function TSTUtils_deleteTabValue(aTab, aKey)
|
||||||
|
{
|
||||||
|
aTab.removeAttribute(aKey);
|
||||||
|
try {
|
||||||
|
this.checkCachedSessionDataExpiration(aTab);
|
||||||
|
this.SessionStore.setTabValue(aTab, aKey, '');
|
||||||
|
this.SessionStore.deleteTabValue(aTab, aKey);
|
||||||
|
}
|
||||||
|
catch(e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.useTMPSessionAPI)
|
||||||
|
aTab.removeAttribute(this.kTMP_SESSION_DATA_PREFIX+aKey);
|
||||||
|
},
|
||||||
|
|
||||||
|
// workaround for http://piro.sakura.ne.jp/latest/blosxom/mozilla/extension/treestyletab/2009-09-29_debug.htm
|
||||||
|
checkCachedSessionDataExpiration : function TSTUtils_checkCachedSessionDataExpiration(aTab)
|
||||||
|
{
|
||||||
|
if (aTab.linkedBrowser.parentNode.__SS_data &&
|
||||||
|
aTab.linkedBrowser.parentNode.__SS_data._tabStillLoading &&
|
||||||
|
aTab.getAttribute('busy') != 'true')
|
||||||
|
aTab.linkedBrowser.parentNode.__SS_data._tabStillLoading = false;
|
||||||
|
},
|
||||||
|
|
||||||
|
useTMPSessionAPI : false,
|
||||||
|
|
||||||
|
kTMP_SESSION_DATA_PREFIX : 'tmp-session-data-',
|
||||||
|
|
||||||
// tab
|
// tab
|
||||||
|
|
||||||
getTabFromChild : function TSTUtils_getTabFromChild(aTab)
|
getTabFromChild : function TSTUtils_getTabFromChild(aTab)
|
||||||
@ -1114,7 +1250,7 @@ var TreeStyleTabUtils = {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
// tabbar position
|
/* tabbar position */
|
||||||
|
|
||||||
get currentTabbarPosition() /* PUBLIC API */
|
get currentTabbarPosition() /* PUBLIC API */
|
||||||
{
|
{
|
||||||
@ -1152,36 +1288,96 @@ var TreeStyleTabUtils = {
|
|||||||
|
|
||||||
_tabbarPositionHistory : [],
|
_tabbarPositionHistory : [],
|
||||||
|
|
||||||
// pref listener
|
/* Pref Listener */
|
||||||
|
|
||||||
domains : [
|
domains : [
|
||||||
'extensions.treestyletab.tabbar.position'
|
'extensions.treestyletab.',
|
||||||
|
'browser.link.open_newwindow.restriction',
|
||||||
|
'browser.tabs.loadFolderAndReplace',
|
||||||
|
'browser.tabs.insertRelatedAfterCurrent'
|
||||||
],
|
],
|
||||||
|
|
||||||
observe : function TSTUtils_observe(aSubject, aTopic, aData)
|
|
||||||
{
|
|
||||||
switch (aTopic)
|
|
||||||
{
|
|
||||||
case 'nsPref:changed':
|
|
||||||
this.onPrefChange(aData);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
onPrefChange : function TSTUtils_onPrefChange(aPrefName)
|
onPrefChange : function TSTUtils_onPrefChange(aPrefName)
|
||||||
{
|
{
|
||||||
var value = this.getPref(aPrefName);
|
var value = this.getPref(aPrefName);
|
||||||
switch (aPrefName)
|
switch (aPrefName)
|
||||||
{
|
{
|
||||||
|
case 'extensions.treestyletab.indent':
|
||||||
|
this.baseIndent = value;
|
||||||
|
this.ObserverService.notifyObservers(null, 'TreeStyleTab:indentModified', value);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'extensions.treestyletab.tabbar.width':
|
||||||
|
case 'extensions.treestyletab.tabbar.shrunkenWidth':
|
||||||
|
this.updateTabWidthPrefs(aPrefName);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'browser.link.open_newwindow.restriction':
|
||||||
|
case 'browser.tabs.loadFolderAndReplace':
|
||||||
|
case 'browser.tabs.insertRelatedAfterCurrent':
|
||||||
|
if (this.prefOverriding) return;
|
||||||
|
aPrefName += '.override';
|
||||||
|
this.setPref(aPrefName, value);
|
||||||
|
case 'browser.link.open_newwindow.restriction.override':
|
||||||
|
case 'browser.tabs.loadFolderAndReplace.override':
|
||||||
|
case 'browser.tabs.insertRelatedAfterCurrent.override':
|
||||||
|
this.prefOverriding = true;
|
||||||
|
var target = aPrefName.replace('.override', '');
|
||||||
|
var originalValue = this.getPref(target);
|
||||||
|
if (originalValue !== null && originalValue != value)
|
||||||
|
this.setPref(target+'.backup', originalValue);
|
||||||
|
this.setPref(target, this.getPref(aPrefName));
|
||||||
|
this.prefOverriding = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'extensions.treestyletab.clickOnIndentSpaces.enabled':
|
||||||
|
this.shouldDetectClickOnIndentSpaces = this.getPref(aPrefName);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'extensions.treestyletab.tabbar.scroll.smooth':
|
||||||
|
this.smoothScrollEnabled = value;
|
||||||
|
break;
|
||||||
|
case 'extensions.treestyletab.tabbar.scroll.duration':
|
||||||
|
this.smoothScrollDuration = value;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'extensions.treestyletab.animation.enabled':
|
||||||
|
this.animationEnabled = value;
|
||||||
|
break;
|
||||||
|
case 'extensions.treestyletab.animation.indent.duration':
|
||||||
|
this.indentDuration = value;
|
||||||
|
break;
|
||||||
|
case 'extensions.treestyletab.animation.collapse.duration':
|
||||||
|
this.collapseDuration = value;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'extensions.treestyletab.tabbar.position':
|
case 'extensions.treestyletab.tabbar.position':
|
||||||
this.onChangeTabbarPosition(value);
|
this.onChangeTabbarPosition(value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'extensions.treestyletab.twisty.expandSensitiveArea':
|
||||||
|
this.expandTwistyArea = value;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
updateTabWidthPrefs : function TSTUtils_updateTabWidthPrefs(aPrefName)
|
||||||
|
{
|
||||||
|
var expanded = this.getTreePref('tabbar.width');
|
||||||
|
var shrunken = this.getTreePref('tabbar.shrunkenWidth');
|
||||||
|
if (expanded <= shrunken) {
|
||||||
|
this.tabbarWidthResetting = true;
|
||||||
|
if (aPrefName == 'extensions.treestyletab.tabbar.width')
|
||||||
|
this.setTreePref('tabbar.shrunkenWidth', parseInt(expanded / 1.5));
|
||||||
|
else
|
||||||
|
this.setTreePref('tabbar.width', parseInt(shrunken * 1.5));
|
||||||
|
this.tabbarWidthResetting = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/* Save/Load Prefs */
|
/* Save/Load Prefs */
|
||||||
|
|
||||||
getTreePref : function TSTUtils_getTreePref(aPrefstring)
|
getTreePref : function TSTUtils_getTreePref(aPrefstring)
|
||||||
|
Loading…
Reference in New Issue
Block a user