toolkit/mozapps/extensions/content/setting.xml

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/mozapps/extensions/content/setting.xml	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,498 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<!-- This Source Code Form is subject to the terms of the Mozilla Public
     1.6 +   - License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 +   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
     1.8 +
     1.9 +<!DOCTYPE page [
    1.10 +<!ENTITY % extensionsDTD SYSTEM "chrome://mozapps/locale/extensions/extensions.dtd">
    1.11 +%extensionsDTD;
    1.12 +]>
    1.13 +
    1.14 +<bindings xmlns="http://www.mozilla.org/xbl"
    1.15 +          xmlns:xbl="http://www.mozilla.org/xbl"
    1.16 +          xmlns:html="http://www.w3.org/1999/xhtml"
    1.17 +          xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.18 +
    1.19 +  <binding id="settings">
    1.20 +    <content orient="vertical">
    1.21 +      <xul:label class="settings-title" xbl:inherits="xbl:text=label" flex="1"/>
    1.22 +      <children/>
    1.23 +    </content>
    1.24 +  </binding>
    1.25 +
    1.26 +  <binding id="setting-base">
    1.27 +    <implementation>
    1.28 +      <constructor><![CDATA[
    1.29 +        this.preferenceChanged();
    1.30 +
    1.31 +        this.addEventListener("keypress", function(event) {
    1.32 +          event.stopPropagation();
    1.33 +        }, false);
    1.34 +        
    1.35 +        if (this.usePref)
    1.36 +          Services.prefs.addObserver(this.pref, this._observer, true);
    1.37 +      ]]></constructor>
    1.38 +
    1.39 +      <field name="_observer"><![CDATA[({
    1.40 +        _self: this,
    1.41 +
    1.42 +        QueryInterface: function(aIID) {
    1.43 +          const Ci = Components.interfaces;
    1.44 +          if (aIID.equals(Ci.nsIObserver) ||
    1.45 +              aIID.equals(Ci.nsISupportsWeakReference) ||
    1.46 +              aIID.equals(Ci.nsISupports))
    1.47 +            return this;
    1.48 +
    1.49 +          throw Components.Exception("No interface", Components.results.NS_ERROR_NO_INTERFACE);
    1.50 +        },
    1.51 +
    1.52 +        observe: function(aSubject, aTopic, aPrefName) {
    1.53 +          if (aTopic != "nsPref:changed")
    1.54 +            return;
    1.55 +
    1.56 +          if (this._self.pref == aPrefName)
    1.57 +            this._self.preferenceChanged();
    1.58 +        }
    1.59 +      })]]>
    1.60 +      </field>
    1.61 +
    1.62 +      <method name="fireEvent">
    1.63 +        <parameter name="eventName"/>
    1.64 +        <parameter name="funcStr"/>
    1.65 +        <body>
    1.66 +          <![CDATA[
    1.67 +            let body = funcStr || this.getAttribute(eventName);
    1.68 +            if (!body)
    1.69 +              return;
    1.70 +
    1.71 +            try {
    1.72 +              let event = document.createEvent("Events");
    1.73 +              event.initEvent(eventName, true, true);
    1.74 +              let f = new Function("event", body);
    1.75 +              f.call(this, event);
    1.76 +            }
    1.77 +            catch (e) {
    1.78 +              Cu.reportError(e);
    1.79 +            }
    1.80 +          ]]>
    1.81 +        </body>
    1.82 +      </method>
    1.83 +
    1.84 +      <method name="valueFromPreference">
    1.85 +        <body>
    1.86 +        <![CDATA[
    1.87 +          // Should be code to set the from the preference input.value
    1.88 +          throw Components.Exception("No valueFromPreference implementation",
    1.89 +                                     Components.results.NS_ERROR_NOT_IMPLEMENTED);
    1.90 +        ]]>
    1.91 +        </body>
    1.92 +      </method>
    1.93 +
    1.94 +      <method name="valueToPreference">
    1.95 +        <body>
    1.96 +        <![CDATA[
    1.97 +          // Should be code to set the input.value from the preference
    1.98 +          throw Components.Exception("No valueToPreference implementation",
    1.99 +                                     Components.results.NS_ERROR_NOT_IMPLEMENTED);
   1.100 +        ]]>
   1.101 +        </body>
   1.102 +      </method>
   1.103 +
   1.104 +      <method name="inputChanged">
   1.105 +        <body>
   1.106 +        <![CDATA[
   1.107 +          if (this.usePref && !this._updatingInput) {
   1.108 +            this.valueToPreference();
   1.109 +            this.fireEvent("oninputchanged");
   1.110 +          }
   1.111 +        ]]>
   1.112 +        </body>
   1.113 +      </method>
   1.114 +
   1.115 +      <method name="preferenceChanged">
   1.116 +        <body>
   1.117 +        <![CDATA[
   1.118 +          if (this.usePref) {
   1.119 +            this._updatingInput = true;
   1.120 +            try {
   1.121 +              this.valueFromPreference();
   1.122 +              this.fireEvent("onpreferencechanged");
   1.123 +            } catch (e) {}
   1.124 +            this._updatingInput = false;
   1.125 +          }
   1.126 +        ]]>
   1.127 +        </body>
   1.128 +      </method>
   1.129 +
   1.130 +      <property name="usePref" readonly="true" onget="return this.hasAttribute('pref');"/>
   1.131 +      <property name="pref" readonly="true" onget="return this.getAttribute('pref');"/>
   1.132 +      <property name="type" readonly="true" onget="return this.getAttribute('type');"/>
   1.133 +      <property name="value" onget="return this.input.value;" onset="return this.input.value = val;"/>
   1.134 +
   1.135 +      <field name="_updatingInput">false</field>
   1.136 +      <field name="input">document.getAnonymousElementByAttribute(this, "anonid", "input");</field>
   1.137 +      <field name="settings">
   1.138 +        this.parentNode.localName == "settings" ? this.parentNode : null;
   1.139 +      </field>
   1.140 +    </implementation>
   1.141 +  </binding>
   1.142 +
   1.143 +  <binding id="setting-bool" extends="chrome://mozapps/content/extensions/setting.xml#setting-base">
   1.144 +    <content>
   1.145 +      <xul:vbox>
   1.146 +        <xul:hbox class="preferences-alignment">
   1.147 +          <xul:label class="preferences-title" flex="1" xbl:inherits="xbl:text=title"/>
   1.148 +        </xul:hbox>
   1.149 +        <xul:description class="preferences-description" flex="1" xbl:inherits="xbl:text=desc"/>
   1.150 +      </xul:vbox>
   1.151 +      <xul:hbox class="preferences-alignment">
   1.152 +        <xul:checkbox anonid="input" xbl:inherits="disabled,onlabel,offlabel,label=checkboxlabel" oncommand="inputChanged();"/>
   1.153 +      </xul:hbox>
   1.154 +    </content>
   1.155 +
   1.156 +    <implementation>
   1.157 +      <method name="valueFromPreference">
   1.158 +        <body>
   1.159 +        <![CDATA[
   1.160 +          let val = Services.prefs.getBoolPref(this.pref);
   1.161 +          this.value = this.inverted ? !val : val;
   1.162 +         ]]>
   1.163 +        </body>
   1.164 +      </method>
   1.165 +
   1.166 +      <method name="valueToPreference">
   1.167 +        <body>
   1.168 +        <![CDATA[
   1.169 +          let val = this.value;
   1.170 +          Services.prefs.setBoolPref(this.pref, this.inverted ? !val : val);
   1.171 +        ]]>
   1.172 +        </body>
   1.173 +      </method>
   1.174 +
   1.175 +      <property name="value" onget="return this.input.checked;" onset="return this.input.setChecked(val);"/>
   1.176 +      <property name="inverted" readonly="true" onget="return this.getAttribute('inverted');"/>
   1.177 +    </implementation>
   1.178 +  </binding>
   1.179 +
   1.180 +  <binding id="setting-boolint" extends="chrome://mozapps/content/extensions/setting.xml#setting-bool">
   1.181 +    <implementation>
   1.182 +      <method name="valueFromPreference">
   1.183 +        <body>
   1.184 +        <![CDATA[
   1.185 +          let val = Services.prefs.getIntPref(this.pref);
   1.186 +          this.value = (val == this.getAttribute("on"));
   1.187 +         ]]>
   1.188 +        </body>
   1.189 +      </method>
   1.190 +
   1.191 +      <method name="valueToPreference">
   1.192 +        <body>
   1.193 +        <![CDATA[
   1.194 +          Services.prefs.setIntPref(this.pref, this.getAttribute(this.value ? "on" : "off"));
   1.195 +        ]]>
   1.196 +        </body>
   1.197 +      </method>
   1.198 +    </implementation>
   1.199 +  </binding>
   1.200 +
   1.201 +  <binding id="setting-localized-bool" extends="chrome://mozapps/content/extensions/setting.xml#setting-bool">
   1.202 +    <implementation>
   1.203 +      <method name="valueFromPreference">
   1.204 +        <body>
   1.205 +        <![CDATA[
   1.206 +          let val = Services.prefs.getComplexValue(this.pref, Components.interfaces.nsIPrefLocalizedString).data;
   1.207 +          if(this.inverted) val = !val;
   1.208 +          this.value = (val == "true");
   1.209 +         ]]>
   1.210 +        </body>
   1.211 +      </method>
   1.212 +
   1.213 +      <method name="valueToPreference">
   1.214 +        <body>
   1.215 +        <![CDATA[
   1.216 +          let val = this.value;
   1.217 +          if(this.inverted) val = !val;
   1.218 +          let pref = Components.classes["@mozilla.org/pref-localizedstring;1"].createInstance(Components.interfaces.nsIPrefLocalizedString);
   1.219 +          pref.data = this.inverted ? (!val).toString() : val.toString();
   1.220 +          Services.prefs.setComplexValue(this.pref, Components.interfaces.nsIPrefLocalizedString, pref);
   1.221 +        ]]>
   1.222 +        </body>
   1.223 +      </method>
   1.224 +    </implementation>
   1.225 +  </binding>
   1.226 +
   1.227 +  <binding id="setting-integer" extends="chrome://mozapps/content/extensions/setting.xml#setting-base">
   1.228 +    <content>
   1.229 +      <xul:vbox>
   1.230 +        <xul:hbox class="preferences-alignment">
   1.231 +          <xul:label class="preferences-title" flex="1" xbl:inherits="xbl:text=title"/>
   1.232 +        </xul:hbox>
   1.233 +        <xul:description class="preferences-description" flex="1" xbl:inherits="xbl:text=desc"/>
   1.234 +      </xul:vbox>
   1.235 +      <xul:hbox class="preferences-alignment">
   1.236 +        <xul:textbox type="number" anonid="input" oninput="inputChanged();" onchange="inputChanged();"
   1.237 +                     xbl:inherits="disabled,emptytext,min,max,increment,hidespinbuttons,wraparound,size"/>
   1.238 +      </xul:hbox>
   1.239 +    </content>
   1.240 +
   1.241 +    <implementation>
   1.242 +      <method name="valueFromPreference">
   1.243 +        <body>
   1.244 +        <![CDATA[
   1.245 +          let val = Services.prefs.getIntPref(this.pref);
   1.246 +          this.value = val;
   1.247 +         ]]>
   1.248 +        </body>
   1.249 +      </method>
   1.250 +
   1.251 +      <method name="valueToPreference">
   1.252 +        <body>
   1.253 +        <![CDATA[
   1.254 +          Services.prefs.setIntPref(this.pref, this.value);
   1.255 +        ]]>
   1.256 +        </body>
   1.257 +      </method>
   1.258 +    </implementation>
   1.259 +  </binding>
   1.260 +
   1.261 +  <binding id="setting-control" extends="chrome://mozapps/content/extensions/setting.xml#setting-base">
   1.262 +    <content>
   1.263 +      <xul:vbox>
   1.264 +        <xul:hbox class="preferences-alignment">
   1.265 +          <xul:label class="preferences-title" flex="1" xbl:inherits="xbl:text=title"/>
   1.266 +        </xul:hbox>
   1.267 +        <xul:description class="preferences-description" flex="1" xbl:inherits="xbl:text=desc"/>
   1.268 +      </xul:vbox>
   1.269 +      <xul:hbox class="preferences-alignment">
   1.270 +        <children/>
   1.271 +      </xul:hbox>
   1.272 +    </content>
   1.273 +  </binding>
   1.274 +
   1.275 +  <binding id="setting-string" extends="chrome://mozapps/content/extensions/setting.xml#setting-base">
   1.276 +    <content>
   1.277 +      <xul:vbox>
   1.278 +        <xul:hbox class="preferences-alignment">
   1.279 +          <xul:label class="preferences-title" flex="1" xbl:inherits="xbl:text=title"/>
   1.280 +        </xul:hbox>
   1.281 +        <xul:description class="preferences-description" flex="1" xbl:inherits="xbl:text=desc"/>
   1.282 +      </xul:vbox>
   1.283 +      <xul:hbox class="preferences-alignment">
   1.284 +        <xul:textbox anonid="input" flex="1" oninput="inputChanged();"
   1.285 +                     xbl:inherits="disabled,emptytext,type=inputtype,min,max,increment,hidespinbuttons,decimalplaces,wraparound"/>
   1.286 +      </xul:hbox>
   1.287 +    </content>
   1.288 +
   1.289 +    <implementation>
   1.290 +      <method name="valueFromPreference">
   1.291 +        <body>
   1.292 +        <![CDATA[
   1.293 +          const nsISupportsString = Components.interfaces.nsISupportsString;
   1.294 +          this.value = Services.prefs.getComplexValue(this.pref, nsISupportsString).data;
   1.295 +         ]]>
   1.296 +        </body>
   1.297 +      </method>
   1.298 +
   1.299 +      <method name="valueToPreference">
   1.300 +        <body>
   1.301 +        <![CDATA[
   1.302 +          const nsISupportsString = Components.interfaces.nsISupportsString;
   1.303 +          let iss = Components.classes["@mozilla.org/supports-string;1"].createInstance(nsISupportsString);
   1.304 +          iss.data = this.value;
   1.305 +          Services.prefs.setComplexValue(this.pref, nsISupportsString, iss);
   1.306 +        ]]>
   1.307 +        </body>
   1.308 +      </method>
   1.309 +    </implementation>
   1.310 +  </binding>
   1.311 +
   1.312 +  <binding id="setting-color" extends="chrome://mozapps/content/extensions/setting.xml#setting-base">
   1.313 +    <content>
   1.314 +      <xul:vbox>
   1.315 +        <xul:hbox class="preferences-alignment">
   1.316 +          <xul:label class="preferences-title" flex="1" xbl:inherits="xbl:text=title"/>
   1.317 +        </xul:hbox>
   1.318 +        <xul:description class="preferences-description" flex="1" xbl:inherits="xbl:text=desc"/>
   1.319 +      </xul:vbox>
   1.320 +      <xul:hbox class="preferences-alignment">
   1.321 +        <xul:colorpicker type="button" anonid="input" xbl:inherits="disabled" onchange="document.getBindingParent(this).inputChanged();"/>
   1.322 +      </xul:hbox>
   1.323 +    </content>
   1.324 +
   1.325 +    <implementation>
   1.326 +      <method name="valueFromPreference">
   1.327 +        <body>
   1.328 +        <![CDATA[
   1.329 +          // We must wait for the colorpicker's binding to be applied before setting the value
   1.330 +          if (!this.input.color)
   1.331 +            this.input.initialize();
   1.332 +          this.value = Services.prefs.getCharPref(this.pref);
   1.333 +        ]]>
   1.334 +        </body>
   1.335 +      </method>
   1.336 +
   1.337 +      <method name="valueToPreference">
   1.338 +        <body>
   1.339 +        <![CDATA[
   1.340 +          Services.prefs.setCharPref(this.pref, this.value);
   1.341 +        ]]>
   1.342 +        </body>
   1.343 +      </method>
   1.344 +
   1.345 +      <property name="value" onget="return this.input.color;" onset="return this.input.color = val;"/>
   1.346 +    </implementation>
   1.347 +  </binding>
   1.348 +
   1.349 +  <binding id="setting-path" extends="chrome://mozapps/content/extensions/setting.xml#setting-base">
   1.350 +    <content>
   1.351 +      <xul:vbox>
   1.352 +        <xul:hbox class="preferences-alignment">
   1.353 +          <xul:label class="preferences-title" flex="1" xbl:inherits="xbl:text=title"/>
   1.354 +        </xul:hbox>
   1.355 +        <xul:description class="preferences-description" flex="1" xbl:inherits="xbl:text=desc"/>
   1.356 +      </xul:vbox>
   1.357 +      <xul:hbox class="preferences-alignment">
   1.358 +        <xul:button type="button" anonid="button" label="&settings.path.button.label;" xbl:inherits="disabled" oncommand="showPicker();"/>
   1.359 +        <xul:label anonid="input" flex="1" crop="center" xbl:inherits="disabled"/>
   1.360 +      </xul:hbox>
   1.361 +    </content>
   1.362 +
   1.363 +    <implementation>
   1.364 +      <method name="showPicker">
   1.365 +        <body>
   1.366 +        <![CDATA[
   1.367 +          var filePicker = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
   1.368 +          filePicker.init(window, this.getAttribute("title"),
   1.369 +                          this.type == "file" ? Ci.nsIFilePicker.modeOpen : Ci.nsIFilePicker.modeGetFolder);
   1.370 +          if (this.value) {
   1.371 +            try {
   1.372 +              let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
   1.373 +              file.initWithPath(this.value);
   1.374 +              filePicker.displayDirectory = this.type == "file" ? file.parent : file;
   1.375 +              if (this.type == "file") {
   1.376 +                filePicker.defaultString = file.leafName;
   1.377 +              }
   1.378 +            } catch (e) {}
   1.379 +          }
   1.380 +          if (filePicker.show() != Ci.nsIFilePicker.returnCancel) {
   1.381 +            this.value = filePicker.file.path;
   1.382 +            this.inputChanged();
   1.383 +          }
   1.384 +        ]]>
   1.385 +        </body>
   1.386 +      </method>
   1.387 +
   1.388 +      <method name="valueFromPreference">
   1.389 +        <body>
   1.390 +        <![CDATA[
   1.391 +          this.value = Services.prefs.getCharPref(this.pref);
   1.392 +        ]]>
   1.393 +        </body>
   1.394 +      </method>
   1.395 +
   1.396 +      <method name="valueToPreference">
   1.397 +        <body>
   1.398 +        <![CDATA[
   1.399 +          Services.prefs.setCharPref(this.pref, this.value);
   1.400 +        ]]>
   1.401 +        </body>
   1.402 +      </method>
   1.403 +
   1.404 +      <field name="_value"></field>
   1.405 +
   1.406 +      <property name="value">
   1.407 +        <getter>
   1.408 +        <![CDATA[
   1.409 +          return this._value;
   1.410 +        ]]>
   1.411 +        </getter>
   1.412 +        <setter>
   1.413 +        <![CDATA[
   1.414 +          this._value = val;
   1.415 +          let label = "";
   1.416 +          if (val) {
   1.417 +            try {
   1.418 +              let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
   1.419 +              file.initWithPath(val);
   1.420 +              label = this.hasAttribute("fullpath") ? file.path : file.leafName;
   1.421 +            } catch (e) {}
   1.422 +          }
   1.423 +          this.input.tooltipText = val;
   1.424 +          return this.input.value = label;
   1.425 +       ]]>
   1.426 +        </setter>
   1.427 +      </property>
   1.428 +    </implementation>
   1.429 +  </binding>
   1.430 +
   1.431 +  <binding id="setting-multi" extends="chrome://mozapps/content/extensions/setting.xml#setting-base">
   1.432 +    <content>
   1.433 +      <xul:vbox>
   1.434 +        <xul:hbox class="preferences-alignment">
   1.435 +          <xul:label class="preferences-title" flex="1" xbl:inherits="xbl:text=title"/>
   1.436 +        </xul:hbox>
   1.437 +        <xul:description class="preferences-description" flex="1" xbl:inherits="xbl:text=desc"/>
   1.438 +      </xul:vbox>
   1.439 +      <xul:hbox class="preferences-alignment">
   1.440 +        <children includes="radiogroup|menulist"/>
   1.441 +      </xul:hbox>
   1.442 +    </content>
   1.443 +
   1.444 +    <implementation>
   1.445 +      <constructor>
   1.446 +      <![CDATA[
   1.447 +        this.control.addEventListener("command", this.inputChanged.bind(this), false);
   1.448 +      ]]>
   1.449 +      </constructor>
   1.450 +
   1.451 +      <method name="valueFromPreference">
   1.452 +        <body>
   1.453 +        <![CDATA[
   1.454 +          let val;
   1.455 +          switch (Services.prefs.getPrefType(this.pref)) {
   1.456 +            case Ci.nsIPrefBranch.PREF_STRING:
   1.457 +              val = Services.prefs.getCharPref(this.pref);
   1.458 +              break;
   1.459 +            case Ci.nsIPrefBranch.PREF_INT:
   1.460 +              val = Services.prefs.getIntPref(this.pref);
   1.461 +              break;
   1.462 +            case Ci.nsIPrefBranch.PREF_BOOL:
   1.463 +              val = Services.prefs.getBoolPref(this.pref).toString();
   1.464 +              break;
   1.465 +            default:
   1.466 +              return;
   1.467 +          }
   1.468 +
   1.469 +          if ("itemCount" in this.control) {
   1.470 +            for (let i = 0; i < this.control.itemCount; i++) {
   1.471 +              if (this.control.getItemAtIndex(i).value == val) {
   1.472 +                this.control.selectedIndex = i;
   1.473 +                break;
   1.474 +              }
   1.475 +            }
   1.476 +          } else {
   1.477 +            this.control.setAttribute("value", val);
   1.478 +          }
   1.479 +        ]]>
   1.480 +        </body>
   1.481 +      </method>
   1.482 +
   1.483 +      <method name="valueToPreference">
   1.484 +        <body>
   1.485 +        <![CDATA[
   1.486 +          // We might not have a pref already set, so we guess the type from the value attribute
   1.487 +          let val = this.control.selectedItem.value;
   1.488 +          if (val == "true" || val == "false")
   1.489 +            Services.prefs.setBoolPref(this.pref, val == "true");
   1.490 +          else if (/^-?\d+$/.test(val))
   1.491 +            Services.prefs.setIntPref(this.pref, val);
   1.492 +          else
   1.493 +            Services.prefs.setCharPref(this.pref, val);
   1.494 +        ]]>
   1.495 +        </body>
   1.496 +      </method>
   1.497 +
   1.498 +      <field name="control">this.getElementsByTagName(this.getAttribute("type") == "radio" ? "radiogroup" : "menulist")[0];</field>
   1.499 +    </implementation>
   1.500 +  </binding>
   1.501 +</bindings>

mercurial