Permalink
Browse files

3 options for toolbar placement (left-side, right-side, right-side wi…

…th sidebar)
  • Loading branch information...
1 parent a40550f commit 1deaa4cc898941fd6a52e1dcbdb7e12536ce7460 @gomita committed Jan 14, 2011
@@ -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");
@@ -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;
},
@@ -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());
@@ -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"
@@ -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>
@@ -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);
@@ -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";
@@ -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">
@@ -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 "常に表示する">
@@ -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;
}
@@ -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);

0 comments on commit 1deaa4c

Please sign in to comment.