move some codes to JS module

git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@5631 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
piro 2009-12-25 18:45:52 +00:00
parent ed9af90859
commit 4d8455d8b9
4 changed files with 126 additions and 125 deletions

View File

@ -210,9 +210,7 @@ TreeStyleTabService.overrideExtensionsPreInit = function TSTService_overrideExte
// TooManyTabs // TooManyTabs
// https://addons.mozilla.org/firefox/addon/9429 // https://addons.mozilla.org/firefox/addon/9429
if ('tooManyTabs' in window) { if ('tooManyTabs' in window) {
this.registerExpandTwistyAreaAllowance(function(aTabBrowser) { this.registerExpandTwistyAreaBlocker('tooManyTabs');
return false;
});
} }
}; };

View File

@ -1,16 +1,5 @@
var TreeStyleTabService = { var TreeStyleTabService = {
get treeBundle() {
return window['piro.sakura.ne.jp']
.stringBundle
.get('chrome://treestyletab/locale/treestyletab.properties');
},
get tabbrowserBundle() {
return window['piro.sakura.ne.jp']
.stringBundle
.get('chrome://browser/locale/tabbrowser.properties');
},
/* API */ /* API */
changeTabbarPosition : function TSTService_changeTabbarPosition(aNewPosition) /* PUBLIC API (obsolete, for backward compatibility) */ changeTabbarPosition : function TSTService_changeTabbarPosition(aNewPosition) /* PUBLIC API (obsolete, for backward compatibility) */
@ -85,32 +74,6 @@ var TreeStyleTabService = {
window['piro.sakura.ne.jp'].stopRendering.start(); window['piro.sakura.ne.jp'].stopRendering.start();
}, },
isEventFiredOnTwisty : function TSTService_isEventFiredOnTwisty(aEvent)
{
var tab = this.getTabFromEvent(aEvent);
if (!tab || !this.hasChildTabs(tab)) return false;
var expression = 'ancestor-or-self::*[@class="'+this.kTWISTY+'"]';
if (this.canExpandTwistyArea(this.getTabBrowserFromChild(tab)))
expression += ' | ancestor-or-self::*[@class="tab-icon" and ancestor::xul:tabbrowser[@'+this.kMODE+'="vertical"]]';
return this.evaluateXPath(
expression,
aEvent.originalTarget || aEvent.target,
XPathResult.BOOLEAN_TYPE
).booleanValue;
},
canExpandTwistyArea : function TSTService_canExpandTwistyArea(aTabBrowser)
{
return (
this.expandTwistyArea &&
this._expandTwistyAreaAllowance.every(function(aFunc) {
return aFunc.call(this, aTabBrowser);
}, this)
);
},
getPropertyPixelValue : function TSTService_getPropertyPixelValue(aElementOrStyle, aProp) getPropertyPixelValue : function TSTService_getPropertyPixelValue(aElementOrStyle, aProp)
{ {
var style = aElementOrStyle instanceof Components.interfaces.nsIDOMCSSStyleDeclaration ? var style = aElementOrStyle instanceof Components.interfaces.nsIDOMCSSStyleDeclaration ?
@ -119,79 +82,6 @@ var TreeStyleTabService = {
return Number(style.getPropertyValue(aProp).replace(/px$/, '')); return Number(style.getPropertyValue(aProp).replace(/px$/, ''));
}, },
dropLinksOnTabBehavior : function TSTService_dropLinksOnTabBehavior()
{
var behavior = this.getTreePref('dropLinksOnTab.behavior');
if (behavior & this.kDROPLINK_FIXED) return behavior;
var checked = { value : false };
var newChildTab = this.PromptService.confirmEx(window,
this.treeBundle.getString('dropLinkOnTab.title'),
this.treeBundle.getString('dropLinkOnTab.text'),
(this.PromptService.BUTTON_TITLE_IS_STRING * this.PromptService.BUTTON_POS_0) +
(this.PromptService.BUTTON_TITLE_IS_STRING * this.PromptService.BUTTON_POS_1),
this.treeBundle.getString('dropLinkOnTab.openNewChildTab'),
this.treeBundle.getString('dropLinkOnTab.loadInTheTab'),
null,
this.treeBundle.getString('dropLinkOnTab.never'),
checked
) == 0;
behavior = newChildTab ? this.kDROPLINK_NEWTAB : this.kDROPLINK_LOAD ;
if (checked.value)
this.setTreePref('dropLinksOnTab.behavior', behavior);
return behavior
},
kDROPLINK_ASK : 0,
kDROPLINK_FIXED : 1 + 2,
kDROPLINK_LOAD : 1,
kDROPLINK_NEWTAB : 2,
openGroupBookmarkBehavior : function TSTService_openGroupBookmarkBehavior()
{
var behavior = this.getTreePref('openGroupBookmark.behavior');
if (behavior & this.kGROUP_BOOKMARK_FIXED) return behavior;
var dummyTabFlag = behavior & this.kGROUP_BOOKMARK_USE_DUMMY;
var checked = { value : false };
var button = this.PromptService.confirmEx(window,
this.treeBundle.getString('openGroupBookmarkBehavior.title'),
this.treeBundle.getString('openGroupBookmarkBehavior.text'),
(this.PromptService.BUTTON_TITLE_IS_STRING * this.PromptService.BUTTON_POS_0) +
(this.PromptService.BUTTON_TITLE_IS_STRING * this.PromptService.BUTTON_POS_1) +
(this.PromptService.BUTTON_TITLE_IS_STRING * this.PromptService.BUTTON_POS_2),
this.treeBundle.getString('openGroupBookmarkBehavior.subTree'),
this.treeBundle.getString('openGroupBookmarkBehavior.separate'),
this.treeBundle.getString('openGroupBookmarkBehavior.replace'),
this.treeBundle.getString('openGroupBookmarkBehavior.never'),
checked
);
if (button < 0) button = 1;
var behaviors = [
this.kGROUP_BOOKMARK_SUBTREE | dummyTabFlag,
this.kGROUP_BOOKMARK_SEPARATE,
this.kGROUP_BOOKMARK_REPLACE
];
behavior = behaviors[button];
if (checked.value) {
this.setTreePref('openGroupBookmark.behavior', behavior);
this.setPref('browser.tabs.loadFolderAndReplace', behavior & this.kGROUP_BOOKMARK_REPLACE ? true : false );
}
return behavior;
},
kGROUP_BOOKMARK_ASK : 0,
kGROUP_BOOKMARK_FIXED : 1 + 2 + 4,
kGROUP_BOOKMARK_SUBTREE : 1,
kGROUP_BOOKMARK_SEPARATE : 2,
kGROUP_BOOKMARK_REPLACE : 4,
kGROUP_BOOKMARK_USE_DUMMY : 256,
kGROUP_BOOKMARK_USE_DUMMY_FORCE : 1024,
kGROUP_BOOKMARK_DONT_RESTORE_TREE_STRUCTURE : 512,
/* Initializing */ /* Initializing */
preInit : function TSTService_preInit() preInit : function TSTService_preInit()
@ -1570,12 +1460,6 @@ catch(e) {
}, },
_tabFocusAllowance : [], _tabFocusAllowance : [],
registerExpandTwistyAreaAllowance : function TSTService_registerExpandTwistyAreaAllowance(aProcess) /* PUBLIC API */
{
this._expandTwistyAreaAllowance.push(aProcess);
},
_expandTwistyAreaAllowance : [],
tearOffSubtreeFromRemote : function TSTService_tearOffSubtreeFromRemote() tearOffSubtreeFromRemote : function TSTService_tearOffSubtreeFromRemote()
{ {
var remoteTab = window.arguments[0]; var remoteTab = window.arguments[0];

View File

@ -1,3 +1,6 @@
var EXPORTED_SYMBOLS = ['window'];
var window = {};
/* /*
string bundle utility string bundle utility

View File

@ -40,9 +40,15 @@ var Ci = Components.interfaces;
var prefs = {}; var prefs = {};
Components.utils.import('resource://treestyletab-modules/prefs.js', prefs); Components.utils.import('resource://treestyletab-modules/prefs.js', prefs);
prefs = prefs.window['piro.sakura.ne.jp'].prefs;
var boxObject = {}; var boxObject = {};
Components.utils.import('resource://treestyletab-modules/boxObject.js', boxObject); Components.utils.import('resource://treestyletab-modules/boxObject.js', boxObject);
boxObject = boxObject.window['piro.sakura.ne.jp'].boxObject;
var stringBundle = {};
Components.utils.import('resource://treestyletab-modules/stringBundle.js', stringBundle);
stringBundle = stringBundle.window['piro.sakura.ne.jp'].stringBundle;
var TreeStyleTabUtils = { var TreeStyleTabUtils = {
@ -143,7 +149,7 @@ var TreeStyleTabUtils = {
indentDuration : 200, indentDuration : 200,
collapseDuration : 150, collapseDuration : 150,
expandTwistyArea : true, shouldExpandTwistyArea : true,
get SessionStore() { get SessionStore() {
if (!this._SessionStore) { if (!this._SessionStore) {
@ -212,6 +218,15 @@ var TreeStyleTabUtils = {
}, },
_Comparator : null, _Comparator : null,
get treeBundle() {
return stringBundle
.get('chrome://treestyletab/locale/treestyletab.properties');
},
get tabbrowserBundle() {
return stringBundle
.get('chrome://browser/locale/tabbrowser.properties');
},
init : function TSTUtils_init() init : function TSTUtils_init()
{ {
if (this._initialized) return; if (this._initialized) return;
@ -261,7 +276,7 @@ var TreeStyleTabUtils = {
getBoxObjectFor : function TSTUtils_getBoxObjectFor(aNode) getBoxObjectFor : function TSTUtils_getBoxObjectFor(aNode)
{ {
return boxObject.window['piro.sakura.ne.jp'].boxObject.getBoxObjectFor(aNode); return boxObject.getBoxObjectFor(aNode);
}, },
get browserWindow() get browserWindow()
@ -277,6 +292,79 @@ var TreeStyleTabUtils = {
w.gBrowser ; w.gBrowser ;
}, },
dropLinksOnTabBehavior : function TSTUtils_dropLinksOnTabBehavior()
{
var behavior = this.getTreePref('dropLinksOnTab.behavior');
if (behavior & this.kDROPLINK_FIXED) return behavior;
var checked = { value : false };
var newChildTab = this.PromptService.confirmEx(this.browserWindow,
this.treeBundle.getString('dropLinkOnTab.title'),
this.treeBundle.getString('dropLinkOnTab.text'),
(this.PromptService.BUTTON_TITLE_IS_STRING * this.PromptService.BUTTON_POS_0) +
(this.PromptService.BUTTON_TITLE_IS_STRING * this.PromptService.BUTTON_POS_1),
this.treeBundle.getString('dropLinkOnTab.openNewChildTab'),
this.treeBundle.getString('dropLinkOnTab.loadInTheTab'),
null,
this.treeBundle.getString('dropLinkOnTab.never'),
checked
) == 0;
behavior = newChildTab ? this.kDROPLINK_NEWTAB : this.kDROPLINK_LOAD ;
if (checked.value)
this.setTreePref('dropLinksOnTab.behavior', behavior);
return behavior
},
kDROPLINK_ASK : 0,
kDROPLINK_FIXED : 1 + 2,
kDROPLINK_LOAD : 1,
kDROPLINK_NEWTAB : 2,
openGroupBookmarkBehavior : function TSTUtils_openGroupBookmarkBehavior()
{
var behavior = this.getTreePref('openGroupBookmark.behavior');
if (behavior & this.kGROUP_BOOKMARK_FIXED) return behavior;
var dummyTabFlag = behavior & this.kGROUP_BOOKMARK_USE_DUMMY;
var checked = { value : false };
var button = this.PromptService.confirmEx(this.browserWindow,
this.treeBundle.getString('openGroupBookmarkBehavior.title'),
this.treeBundle.getString('openGroupBookmarkBehavior.text'),
(this.PromptService.BUTTON_TITLE_IS_STRING * this.PromptService.BUTTON_POS_0) +
(this.PromptService.BUTTON_TITLE_IS_STRING * this.PromptService.BUTTON_POS_1) +
(this.PromptService.BUTTON_TITLE_IS_STRING * this.PromptService.BUTTON_POS_2),
this.treeBundle.getString('openGroupBookmarkBehavior.subTree'),
this.treeBundle.getString('openGroupBookmarkBehavior.separate'),
this.treeBundle.getString('openGroupBookmarkBehavior.replace'),
this.treeBundle.getString('openGroupBookmarkBehavior.never'),
checked
);
if (button < 0) button = 1;
var behaviors = [
this.kGROUP_BOOKMARK_SUBTREE | dummyTabFlag,
this.kGROUP_BOOKMARK_SEPARATE,
this.kGROUP_BOOKMARK_REPLACE
];
behavior = behaviors[button];
if (checked.value) {
this.setTreePref('openGroupBookmark.behavior', behavior);
this.setPref('browser.tabs.loadFolderAndReplace', behavior & this.kGROUP_BOOKMARK_REPLACE ? true : false );
}
return behavior;
},
kGROUP_BOOKMARK_ASK : 0,
kGROUP_BOOKMARK_FIXED : 1 + 2 + 4,
kGROUP_BOOKMARK_SUBTREE : 1,
kGROUP_BOOKMARK_SEPARATE : 2,
kGROUP_BOOKMARK_REPLACE : 4,
kGROUP_BOOKMARK_USE_DUMMY : 256,
kGROUP_BOOKMARK_USE_DUMMY_FORCE : 1024,
kGROUP_BOOKMARK_DONT_RESTORE_TREE_STRUCTURE : 512,
// event // event
isNewTabAction : function TSTUtils_isNewTabAction(aEvent) isNewTabAction : function TSTUtils_isNewTabAction(aEvent)
@ -315,6 +403,34 @@ var TreeStyleTabUtils = {
).booleanValue; ).booleanValue;
}, },
isEventFiredOnTwisty : function TSTUtils_isEventFiredOnTwisty(aEvent)
{
var tab = this.getTabFromEvent(aEvent);
if (!tab || !this.hasChildTabs(tab)) return false;
var expression = 'ancestor-or-self::*[@class="'+this.kTWISTY+'"]';
if (this.shouldExpandTwistyArea && !this._expandTwistyAreaBlockeds.length)
expression += ' | ancestor-or-self::*[@class="tab-icon" and ancestor::xul:tabbrowser[@'+this.kMODE+'="vertical"]]';
return this.evaluateXPath(
expression,
aEvent.originalTarget || aEvent.target,
XPathResult.BOOLEAN_TYPE
).booleanValue;
},
registerExpandTwistyAreaBlocker : function TSTUtils_registerExpandTwistyAreaBlocker(aBlocker) /* PUBLIC API */
{
if (this._expandTwistyAreaBlockeds.indexOf(aBlocker) < 0)
this._expandTwistyAreaBlockeds.push(aBlocker);
},
_expandTwistyAreaBlockeds : [],
registerExpandTwistyAreaAllowance : function TSTUtils_registerExpandTwistyAreaAllowance(aAllowance) /* PUBLIC API, obsolete, for backward compatibility */
{
this.registerExpandTwistyAreaBlocker(aAllowance.toSource());
},
// string // string
makeNewId : function TSTUtils_makeNewId() makeNewId : function TSTUtils_makeNewId()
@ -1367,7 +1483,7 @@ var TreeStyleTabUtils = {
break; break;
case 'extensions.treestyletab.twisty.expandSensitiveArea': case 'extensions.treestyletab.twisty.expandSensitiveArea':
this.expandTwistyArea = value; this.shouldExpandTwistyArea = value;
break; break;
default: default:
@ -1408,5 +1524,5 @@ var TreeStyleTabUtils = {
}; };
TreeStyleTabUtils.__proto__ = prefs.window['piro.sakura.ne.jp'].prefs; TreeStyleTabUtils.__proto__ = prefs;