开发者

how to store the preferences?

i have preferences like this :

<!DOCTYPE overlay SYSTEM "chrome://inlinetrans/locale/options.dtd">

<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  id="开发者_运维百科translate-preferences"
  title="&options.title;"
  buttons="accept, cancel"
  style="padding:0px; margin:0px;"
  ondialogaccept="options.save()"
  onload="options.init();"
  onunload="options.deconstruct();">

  <script src="chrome://inlinetrans/content/options.js" />

  <description value="&options.desc;"
    style="
    background: #fff url('chrome://inlinetrans/skin/options.png') no-repeat;
    min-width:400px;
    min-height:40px;
    padding-left:55px;
    padding-top:10px;
    margin:0px;
    border-bottom: 2px solid #757575;
    font-size:1.5em;"/>

  <vbox style="padding:10px;">
    <groupbox>
      <caption label="&options.ui;"/>
      <label value="&options.results.desc;"/>
    <radiogroup id="display.results" style="padding-left:20px;">
      <radio id="results.cat" value="currenttab" label="&options.results.cat;"/>
          <radio id="results.noncat"  value="newwindow" label="&options.results.noncat;"/>
      </radiogroup>
    </groupbox>
 </vbox>
</dialog>

and this is preference handler i made, but i'm not sure it works :

var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
var t_prefBranch = prefService.getBranch("extensions.inlinetrans.");

var options = {

  result : String,

  init : function() {
    this.updatePrefs()
    t_prefBranch.setCharPref("optionopen", true)

    var Displayresults = document.getElementById("results." + this.result)
        Displayresults.setAttribute("selected", true);
  },

  updatePrefs : function() {

    this.result = t_prefBranch.getCharPref("results")

  },

  save : function() {
    var savepref = document.getElementById("display.results").value

    if (savepref != "") {
        t_prefBranch.setCharPref("results", savepref)
    }

},

reloadOptions : function() {
  this.save()
  this.init()
}

}

thank you so much for your help

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜