Skip to content

Commit

Permalink
Add "stretch/shrink" toolbar button
Browse files Browse the repository at this point in the history
  • Loading branch information
Piro / SHIMODA Hiroshi committed Apr 20, 2012
1 parent 1afcd46 commit 66f431d
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 14 deletions.
4 changes: 4 additions & 0 deletions modules/const.js
Expand Up @@ -259,6 +259,10 @@ var exports = {
}
#foxsplitter-syncScroll-button { -moz-image-region: rect(0 112px 16px 96px); }
#foxsplitter-syncScroll-button[checked="true"] { -moz-image-region: rect(0 128px 16px 112px); }
#foxsplitter-toggleStretched-button[%TOGGLE_MODE%="stretch"] { -moz-image-region: rect(0 208px 16px 192px); }
#foxsplitter-toggleStretched-button[%TOGGLE_MODE%="stretch"][checked="true"] { -moz-image-region: rect(16px 208px 32px 192px); }
#foxsplitter-toggleStretched-button[%TOGGLE_MODE%="shrink"] { -moz-image-region: rect(0 224px 16px 208px); }
#foxsplitter-toggleStretched-button[%TOGGLE_MODE%="shrink"][checked="true"] { -moz-image-region: rect(16px 224px 32px 208px); }

/* shrink appmenu button */
:root[%MEMBER%="true"]:not([%MAIN%="true"]):not([%STRETCHED%="true"]) #appmenu-button {
Expand Down
75 changes: 62 additions & 13 deletions modules/ui.js
Expand Up @@ -220,6 +220,26 @@ FoxSplitterUI.prototype = {
}
}
);

this.toggleStretchedButton = ToolbarItem.create(
<>
<toolbarbutton id="foxsplitter-toggleStretched-button"
label={bundle.getString('ui.stretch.short')}
tooltiptext={bundle.getString('ui.stretch.long')}
class={ToolbarItem.BASIC_ITEM_CLASS + ' ' + this.TOOLBAR_ITEM}
foxsplitter-command="toggleStretched"
foxsplitter-toggle-mode="stretch"
oncommand="FoxSplitter.ui.handleEvent(event);"/>
</>,
toolbar,
{
onInit : function() {
self.onStretchedStateChange();
},
onDestroy : function() {
}
}
);
},

_createSplitItems : function FSUI_createSplitItems(aOptions)
Expand Down Expand Up @@ -316,6 +336,8 @@ FoxSplitterUI.prototype = {
delete this.generalButton;
this.syncScrollButton.destroy();
delete this.syncScrollButton;
this.toggleStretchedButton.destroy();
delete this.toggleStretchedButton;
},


Expand Down Expand Up @@ -1005,25 +1027,35 @@ FoxSplitterUI.prototype = {
aItem.setAttribute('disabled', true);
}, this);

var toggleStretched = aPopup.querySelector('.'+this.MENU_ITEM+'.toggleStretched');
var toggleStretchedItem = aPopup.querySelector('.'+this.MENU_ITEM+'.toggleStretched');
if (toggleStretchedItem) {
if (this.toggleStretchedButton.inserted &&
this.toggleStretchedButton.node.boxObject.width) {
toggleStretchedItem.setAttribute('hidden', true);
}
else {
toggleStretchedItem.removeAttribute('hidden');
}
}

var setAsMainWindowItem = aPopup.querySelector('.'+this.MENU_ITEM+'.setAsMainWindow');
var separator = aPopup.querySelector('.'+this.MENU_ITEM+'.syncScrollSeparator');
var syncScrollSeparator = aPopup.querySelector('.'+this.MENU_ITEM+'.syncScrollSeparator');
var syncScrollItem = aPopup.querySelector('.'+this.MENU_ITEM+'.syncScroll');
if (this.owner.stretched) {
if (toggleStretched) {
toggleStretched.setAttribute('label', bundle.getString('ui.shrink.long'));
toggleStretched.setAttribute('accesskey', bundle.getString('ui.shrink.accesskey'));
toggleStretched.setAttribute(this.TOGGLE_MODE, 'shrink');
if (toggleStretchedItem) {
toggleStretchedItem.setAttribute('label', bundle.getString('ui.shrink.long'));
toggleStretchedItem.setAttribute('accesskey', bundle.getString('ui.shrink.accesskey'));
toggleStretchedItem.setAttribute(this.TOGGLE_MODE, 'shrink');
}
if (setAsMainWindowItem) setAsMainWindowItem.setAttribute('hidden', true);
if (separator) separator.setAttribute('hidden', true);
if (syncScrollSeparator) syncScrollSeparator.setAttribute('hidden', true);
if (syncScrollItem) syncScrollItem.setAttribute('hidden', true);
}
else {
if (toggleStretched) {
toggleStretched.setAttribute('label', bundle.getString('ui.stretch.long'));
toggleStretched.setAttribute('accesskey', bundle.getString('ui.stretch.accesskey'));
toggleStretched.setAttribute(this.TOGGLE_MODE, 'stretch');
if (toggleStretchedItem) {
toggleStretchedItem.setAttribute('label', bundle.getString('ui.stretch.long'));
toggleStretchedItem.setAttribute('accesskey', bundle.getString('ui.stretch.accesskey'));
toggleStretchedItem.setAttribute(this.TOGGLE_MODE, 'stretch');
}
if (setAsMainWindowItem) {
setAsMainWindowItem.removeAttribute('hidden');
Expand All @@ -1040,11 +1072,11 @@ FoxSplitterUI.prototype = {

if (this.syncScrollButton.inserted &&
this.syncScrollButton.node.boxObject.width) {
if (separator) separator.setAttribute('hidden', true);
if (syncScrollSeparator) syncScrollSeparator.setAttribute('hidden', true);
if (syncScrollItem) syncScrollItem.setAttribute('hidden', true);
}
else {
if (separator) separator.removeAttribute('hidden');
if (syncScrollSeparator) syncScrollSeparator.removeAttribute('hidden');
if (syncScrollItem) syncScrollItem.removeAttribute('hidden');
}

Expand Down Expand Up @@ -1113,6 +1145,23 @@ FoxSplitterUI.prototype = {
}
},

onStretchedStateChange : function FSUI_onStretchedStateChange()
{
var button = this.document.getElementById('foxsplitter-toggleStretched-button');
if (!button) return;

if (this.owner.stretched) {
button.setAttribute('label', bundle.getString('ui.shrink.short'));
button.setAttribute('tooltiptext', bundle.getString('ui.shrink.long'));
button.setAttribute(this.TOGGLE_MODE, 'shrink');
}
else {
button.setAttribute('label', bundle.getString('ui.stretch.short'));
button.setAttribute('tooltiptext', bundle.getString('ui.stretch.long'));
button.setAttribute(this.TOGGLE_MODE, 'stretch');
}
},

_onKeyboardShortcutCommand : function FSUI_onKeyboardShortcutCommand(aEvent)
{
var owner = this.owner;
Expand Down
8 changes: 7 additions & 1 deletion modules/window.js
Expand Up @@ -928,7 +928,7 @@ FoxSplitterWindow.prototype = {

stretch : function FSW_stretch()
{
if (!this.parent || this.stretched)
if (!this.parent || this.stretched || this.root.stretched)
return Deferred.next(function() {});

var root = this.root;
Expand Down Expand Up @@ -957,6 +957,9 @@ FoxSplitterWindow.prototype = {

self.clearGroupedAppearance();
self.saveState();

if (self.ui)
self.ui.onStretchedStateChange();
});
},

Expand Down Expand Up @@ -985,6 +988,9 @@ FoxSplitterWindow.prototype = {

self.setGroupedAppearance();
self.saveState();

if (self.ui)
self.ui.onStretchedStateChange();
});
},

Expand Down

0 comments on commit 66f431d

Please sign in to comment.