Skip to content

Commit

Permalink
3 options for toolbar placement (left-side, right-side, right-side wi…
Browse files Browse the repository at this point in the history
…th sidebar)
  • Loading branch information
gomita committed Jan 14, 2011
1 parent a40550f commit 1deaa4c
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 22 deletions.
25 changes: 14 additions & 11 deletions chrome/content/verticaltoolbar/options.js
Expand Up @@ -3,7 +3,6 @@ Components.utils.import("resource://gre/modules/Services.jsm");
var PrefsUI = {

_window: null,
_defaultDir: "",

init: function() {
this._window = Services.wm.getMostRecentWindow("navigator:browser");
Expand All @@ -19,23 +18,13 @@ var PrefsUI = {
button.hidden = false;
button.disabled = false;
}
// select proper radio button if direction pref has default empty value
var browser = this._window.VerticalToolbar.toolbox.parentNode;
this._defaultDir = this._window.getComputedStyle(browser, null).direction;
var direction = document.getElementById("direction");
if (!direction.value)
direction.value = this._defaultDir;
// show toolbar temporarily even if autohide is enabled
this._window.VerticalToolbar.handleEvent({ type: "dragenter" });
// focus the window if it is in background
window.focus();
},

done: function() {
// reset direction pref if the value equals to the original direction
var direction = document.getElementById("direction");
if (direction.value == this._defaultDir)
direction.reset();
this._window.VerticalToolbar.loadPrefs();
this._window = null;
},
Expand All @@ -50,6 +39,20 @@ var PrefsUI = {
document.getElementById("sidesync").disabled = !autohide;
},

readPlacement: function(aRadioGroup) {
var val = document.getElementById("placement").value;
aRadioGroup.selectedIndex = val == 0 ? 0 : 1;
aRadioGroup.lastChild.disabled = val == 0;
aRadioGroup.lastChild.checked = val == 2;
},

writePlacement: function(aRadioGroup) {
var val = aRadioGroup.selectedIndex;
if (val == 1 && aRadioGroup.lastChild.checked)
val = 2;
return val;
},

updateButtonMode: function(val) {
var toolbar = this._window.VerticalToolbar.toolbox.firstChild;
toolbar.setAttribute("mode", val.toString());
Expand Down
13 changes: 8 additions & 5 deletions chrome/content/verticaltoolbar/options.xul
Expand Up @@ -26,8 +26,8 @@

<prefpane id="paneMain" flex="1">
<preferences onchange="PrefsUI.onChange(event);">
<preference id="direction" name="extensions.verticaltoolbar.direction"
type="string" instantApply="true" />
<preference id="placement" name="extensions.verticaltoolbar.placement"
type="int" instantApply="true" />
<preference id="display" name="extensions.verticaltoolbar.display"
type="int" instantApply="true" />
<preference id="fullscreen" name="extensions.verticaltoolbar.display.fullscreen"
Expand All @@ -41,9 +41,12 @@
<caption label="&options.toolbar;" />
<hbox align="center">
<label value="&options.placement;:" />
<radiogroup preference="direction" orient="horizontal">
<radio label="&options.placement.left;" value="ltr" />
<radio label="&options.placement.right;" value="rtl" />
<radiogroup preference="placement" orient="horizontal"
onsyncfrompreference="return PrefsUI.readPlacement(this);"
onsynctopreference="return PrefsUI.writePlacement(this);">
<radio label="&options.placement.left;" />
<radio label="&options.placement.right;" />
<checkbox label="&options.placement.withsidebar;" />
</radiogroup>
</hbox>
<grid>
Expand Down
15 changes: 12 additions & 3 deletions chrome/content/verticaltoolbar/overlay.js
Expand Up @@ -43,8 +43,17 @@ var VerticalToolbar = {
// if aDisplay is specified, override the original display value
loadPrefs: function(aDisplay) {
var branch = Services.prefs.getBranch("extensions.verticaltoolbar.");
// direction
this.toolbox.parentNode.setAttribute("dir", branch.getCharPref("direction"));
// placement
var placement = branch.getIntPref("placement");
if (placement == 1)
this.toolbox.parentNode.appendChild(this.toolbox);
else
this.toolbox.parentNode.insertBefore(this.toolbox, this.sidebar);
if (placement == 2)
this.toolbox.parentNode.setAttribute("dir", "rtl");
else
this.toolbox.parentNode.removeAttribute("dir");
this.toolbox.setAttribute("placement", placement == 0 ? "left" : "right");
// display
var display = (aDisplay === undefined) ? branch.getIntPref("display") : aDisplay;
this._autohide = (display == 2);
Expand Down Expand Up @@ -79,7 +88,7 @@ var VerticalToolbar = {
// adjust toolbar margin to keep out of the screen
var dir = this.toolbox.parentNode.getAttribute("dir") ||
window.getComputedStyle(this.toolbox.parentNode, null).direction;
if (dir == "ltr")
if (dir == "ltr" && placement == 0)
this.toolbox.firstChild.style.marginLeft = (width * -1).toString() + "px";
else
this.toolbox.firstChild.style.marginRight = (width * -1).toString() + "px";
Expand Down
1 change: 1 addition & 0 deletions chrome/locale/en-US/verticaltoolbar/options.dtd
Expand Up @@ -3,6 +3,7 @@
<!ENTITY options.placement "Placement">
<!ENTITY options.placement.left "Left-side">
<!ENTITY options.placement.right "Right-side">
<!ENTITY options.placement.withsidebar "With sidebar">
<!ENTITY options.mode.normal "Normal">
<!ENTITY options.mode.fullscreen "Full Screen">
<!ENTITY options.show "Always show">
Expand Down
1 change: 1 addition & 0 deletions chrome/locale/ja/verticaltoolbar/options.dtd
Expand Up @@ -3,6 +3,7 @@
<!ENTITY options.placement "位置">
<!ENTITY options.placement.left "左側">
<!ENTITY options.placement.right "右側">
<!ENTITY options.placement.withsidebar "サイドバーも">
<!ENTITY options.mode.normal "通常時">
<!ENTITY options.mode.fullscreen "全画面表示時">
<!ENTITY options.show "常に表示する">
Expand Down
4 changes: 2 additions & 2 deletions chrome/skin/classic/verticaltoolbar/overlay.css
Expand Up @@ -18,11 +18,11 @@
position: fixed;
}

#browser[dir="ltr"] #vertical-toolbox[autohide]:not([sidesync]) {
#vertical-toolbox[placement="left"][autohide]:not([sidesync]) {
left: 0px;
}

#browser[dir="rtl"] #vertical-toolbox[autohide]:not([sidesync]) {
#vertical-toolbox[placement="right"][autohide]:not([sidesync]) {
right: 0px;
}

Expand Down
2 changes: 1 addition & 1 deletion defaults/preferences/verticaltoolbar-prefs.js
@@ -1,4 +1,4 @@
pref("extensions.verticaltoolbar.direction", "");
pref("extensions.verticaltoolbar.placement", 0);
pref("extensions.verticaltoolbar.display", 1);
pref("extensions.verticaltoolbar.display.fullscreen", 2);
pref("extensions.verticaltoolbar.animate", true);
Expand Down

0 comments on commit 1deaa4c

Please sign in to comment.