home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / AIMP2 / aimp_2.61.583.exe / $TEMP / YandexPackSetup.msi / filCA33185A6107B785B94E620BED65A7B4 < prev    next >
Extensible Markup Language  |  2010-07-12  |  5KB  |  124 lines

  1. <?xml version="1.0"?>
  2. <!DOCTYPE bindings [
  3.   <!ENTITY % yasearchDTD SYSTEM "chrome://yasearch/locale/yasearch.dtd">
  4.   %yasearchDTD;
  5. ]>
  6. <bindings xmlns="http://www.mozilla.org/xbl"
  7.           xmlns:xbl="http://www.mozilla.org/xbl"
  8.           xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  9.   
  10.   <binding id="extend-translate-toolbarbutton"
  11.            extends="chrome://yasearch/content/yasearch.xml#extend-toolbarbutton-base">
  12.     <resources>
  13.       <stylesheet src="chrome://yasearch/skin/translate/translate.css"/>
  14.     </resources>
  15.     
  16.     <implementation implements="nsIDOMEventListener">
  17.       <field name="_menuEnable">this.getElementsByAttribute("anonid", "translate-enable")[0]</field>
  18.       <field name="_menuReverse">this.getElementsByAttribute("anonid", "translate-reverse")[0]</field>
  19.       
  20.       <field name="ENABLE_PREF">"general.ui.translate.enabled"</field>
  21.       <field name="REVERSE_PREF">"general.ui.translate.reverse"</field>
  22.       <field name="FROM_PREF">"general.ui.translate.from"</field>
  23.       <field name="TO_PREF">"general.ui.translate.to"</field>
  24.       
  25.       <constructor><![CDATA[
  26.         if (!(typeof Ya == "object" && Ya.YaTranslate))
  27.           return;
  28.         
  29.         Components.utils.import("resource://yasearch/Preferences.jsm", this);
  30.         
  31.         this.onEnableChanged();
  32.         this.onReverseChanged();
  33.         
  34.         this.Prefs.observe(this.ENABLE_PREF, this.onEnableChanged, this);
  35.         this.Prefs.observe(this.REVERSE_PREF, this.onReverseChanged, this);
  36.         
  37.         Ya.YaTranslate.available = true;
  38.       ]]></constructor>
  39.       
  40.       <destructor><![CDATA[
  41.         this.yaDestroy();
  42.       ]]></destructor>
  43.       
  44.       <method name="yaDestroy">
  45.         <body><![CDATA[
  46.           if (this.Prefs) {
  47.             this.Prefs.ignore(this.ENABLE_PREF, this.onEnableChanged, this);
  48.             this.Prefs.ignore(this.REVERSE_PREF, this.onReverseChanged, this);
  49.           }
  50.           if ((typeof Ya == "object" && Ya.YaTranslate))
  51.             Ya.YaTranslate.available = false;
  52.         ]]></body>
  53.       </method>
  54.       
  55.       <method name="onEnableChanged">
  56.         <body><![CDATA[
  57.           this.checked = this.Prefs.get(this.ENABLE_PREF, false);
  58.           this._menuEnable.setAttribute("checked", this.checked);
  59.         ]]></body>
  60.       </method>
  61.       
  62.       <method name="onReverseChanged">
  63.         <body><![CDATA[
  64.           this._menuReverse.setAttribute("checked", this.Prefs.get(this.REVERSE_PREF, false));
  65.         ]]></body>
  66.       </method>
  67.       
  68.       <method name="handleEvent">
  69.         <parameter name="aEvent"/>
  70.         <body><![CDATA[
  71.           var target = aEvent.target;
  72.           
  73.           switch (aEvent.type) {
  74.             case "popupshowing":
  75.               var from = this.Prefs.get(this.FROM_PREF, "en");
  76.               var to = this.Prefs.get(this.TO_PREF, "ru");
  77.  
  78.               var directions = target.getElementsByAttribute("anonid", "translate-direction");
  79.               for (var i = directions.length; i--;) {
  80.                 var item = directions[i];
  81.                 if ((item.getAttribute("from") == from) && (item.getAttribute("to") == to)) {
  82.                   item.setAttribute("checked", "true");
  83.                 } else if (item.hasAttribute("checked")) {
  84.                   item.removeAttribute("checked");
  85.                 }
  86.               }
  87.               break;//case "popupshowing"
  88.             
  89.             case "command":
  90.               var action = target == this ? "translate-enable" : (target.hasAttribute("anonid") ? target.getAttribute("anonid") : null);
  91.  
  92.               switch (action) {
  93.                 case "translate-enable":
  94.                   this.checked = !this.checked;
  95.                   this.Prefs.set(this.ENABLE_PREF, this.checked);
  96.                   break;
  97.                 
  98.                 case "translate-reverse":
  99.                   this.Prefs.set(this.REVERSE_PREF, target.hasAttribute("checked"));
  100.                   break;
  101.                 
  102.                 case "translate-direction":
  103.                   this.Prefs.set(this.FROM_PREF, target.getAttribute("from"));
  104.                   this.Prefs.set(this.TO_PREF, target.getAttribute("to"));
  105.                   break;
  106.                 
  107.                 default:
  108.                   break;
  109.               }
  110.               break;//case "command"
  111.             
  112.             default:
  113.               break;
  114.           }
  115.         ]]></body>
  116.       </method>
  117.     </implementation>
  118.     
  119.     <handlers>
  120.       <handler event="command" action="this.handleEvent(event);"/>
  121.       <handler event="popupshowing" action="this.handleEvent(event);"/>
  122.     </handlers>
  123.   </binding>
  124. </bindings>