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 / filEE2615530CC3FAB3270E5EA505098103 < prev    next >
Extensible Markup Language  |  2010-07-12  |  17KB  |  395 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-spellchecker-toolbarbutton"
  11.            extends="chrome://yasearch/content/yasearch.xml#extend-toolbarbutton-base">
  12.     <resources>
  13.       <stylesheet src="chrome://yasearch/skin/spellchecker/spellchecker.css"/>
  14.     </resources>
  15.     
  16.     <implementation implements="nsIObserver, nsIDOMEventListener">
  17.       <field name="mDictList">[]</field>
  18.       <field name="mCurrentDict">null</field>
  19.       
  20.       <field name="_prefBranch"/>
  21.       <field name="_spellchecker"/>
  22.       
  23.       <field name="_agentSheetURI"/>
  24.       
  25.       <field name="PPEF_NAMES">({
  26.         dictionary: "spellchecker.dictionary",
  27.         spellcheckDefault: "layout.spellcheckDefault"
  28.       })</field>
  29.       
  30.       <property name="isNoDict">
  31.         <getter><![CDATA[
  32.           return this.mDictList.length == 0;
  33.         ]]></getter>
  34.       </property>
  35.       
  36.       <constructor><![CDATA[
  37.         this._spellchecker = Components.classes["@mozilla.org/spellchecker/" +
  38.                                 ("@mozilla.org/spellchecker/myspell;1" in Components.classes ? "myspell;1" : "engine;1")]
  39.                                 .createInstance(Components.interfaces.mozISpellCheckingEngine);
  40.         
  41.         var dictionaryList = {};
  42.         this._spellchecker.getDictionaryList(dictionaryList, {});
  43.         
  44.         var dictionaryListStr = dictionaryList.value.toString();
  45.         this.mDictList = dictionaryListStr ? dictionaryListStr.split(",") : [];
  46.         
  47.         this._prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
  48.                                      .getService(Components.interfaces.nsIPrefBranch2);
  49.         
  50.         if (this._prefBranch.getIntPref(this.PPEF_NAMES.spellcheckDefault) == 1)
  51.           this._prefBranch.setIntPref(this.PPEF_NAMES.spellcheckDefault, 2);
  52.         
  53.         if (this.isNoDict)
  54.           this._prefBranch.setIntPref(this.PPEF_NAMES.spellcheckDefault, 0);
  55.         
  56.         for each (var prefName in this.PPEF_NAMES)
  57.           this._prefBranch.addObserver(prefName, this, false);
  58.         
  59.         try {
  60.           this.checked = !!this._prefBranch.getIntPref(this.PPEF_NAMES.spellcheckDefault);
  61.         } catch(e) {}
  62.         
  63.         try {
  64.           this.mCurrentDict = this._prefBranch.getCharPref(this.PPEF_NAMES.dictionary);
  65.         } catch(e) {
  66.           if (!this.mCurrentDict && this.mDictList[0])
  67.             this._prefBranch.setCharPref(this.PPEF_NAMES.dictionary, this.mDictList[0]);
  68.           try {
  69.             this.mCurrentDict = this._prefBranch.getCharPref(this.PPEF_NAMES.dictionary);
  70.           } catch(ex) {}
  71.         }
  72.         
  73.         this.refreshDictMenuList();
  74.         
  75.         this._checkUserSheet();
  76.       ]]></constructor>
  77.       
  78.       <destructor><![CDATA[
  79.         for each (var prefName in this.PPEF_NAMES)
  80.           this._prefBranch.removeObserver(prefName, this);
  81.         
  82.         this._prefBranch = null;
  83.         this._spellchecker = null;
  84.       ]]></destructor>
  85.       
  86.       <method name="refreshDictMenuList">
  87.         <body><![CDATA[
  88.           var dictListSeparator = this.getElementsByAttribute("anonid", "spellchecker-dict-separator")[0];
  89.           if (!dictListSeparator)
  90.             return;
  91.           
  92.           Array.forEach(this.getElementsByAttribute("anonid", "spellchecker-dict"),
  93.             function(aDictItem) {
  94.               aDictItem.parentNode.removeChild(aDictItem);
  95.             });
  96.           
  97.           dictListSeparator.setAttribute("hidden", this.isNoDict ? "true" : "false");
  98.           if (this.isNoDict)
  99.             return;
  100.           
  101.           var bundleService = Components.classes["@mozilla.org/intl/stringbundle;1"]
  102.                                         .getService(Components.interfaces.nsIStringBundleService);
  103.           var languageBundle = bundleService.createBundle("chrome://global/locale/languageNames.properties");
  104.           var regionBundle = bundleService.createBundle("chrome://global/locale/regionNames.properties");
  105.           
  106.           var menupopup = this.getElementsByTagName("menupopup")[0];
  107.           
  108.           var dicts = [];
  109.           
  110.           this.mDictList.forEach(function(aDictName) {
  111.             var displayName = "",
  112.                 isoStrArray = aDictName.split("-");
  113.             
  114.             if (languageBundle && isoStrArray[0]) {
  115.               try {
  116.                 displayName = languageBundle.GetStringFromName(isoStrArray[0].toLowerCase());
  117.               } catch(e) {}
  118.               if (regionBundle && isoStrArray[1]) {
  119.                 try {
  120.                   displayName += " / " + regionBundle.GetStringFromName(isoStrArray[1].toLowerCase());
  121.                 } catch(e) {}
  122.                 if (isoStrArray[2])
  123.                   displayName += " (" + isoStrArray[2] + ")";
  124.               }
  125.             }
  126.             
  127.             if (!displayName)
  128.               displayName = aDictName;
  129.             
  130.             dicts.push({name: aDictName, displayName: displayName});
  131.             
  132.           }, this)
  133.           
  134.           dicts.sort(function(a,b) {
  135.             var aLower = a.displayName.toLowerCase(),
  136.                 bLower = b.displayName.toLowerCase();
  137.             
  138.             return (aLower < bLower) ? -1 : (aLower > bLower) ? 1 : ((a < b) ? -1 : (a > b) ? 1 : 0);
  139.           });
  140.           
  141.           dicts.forEach(function(aDictProps) {
  142.             const kXULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
  143.             
  144.             var menuitem = document.createElementNS(kXULNS, "menuitem");
  145.             menuitem.setAttribute("type", "radio");
  146.             menuitem.setAttribute("label", aDictProps.displayName);
  147.             menuitem.setAttribute("value", aDictProps.name);
  148.             menuitem.setAttribute("anonid", "spellchecker-dict");
  149.             
  150.             menupopup.insertBefore(menuitem, dictListSeparator);
  151.           }, this);
  152.           
  153.           delete dicts;
  154.         ]]></body>
  155.       </method>
  156.       
  157.       <method name="observe">
  158.         <parameter name="aSubject"/>
  159.         <parameter name="aTopic"/>
  160.         <parameter name="aData"/>
  161.         <body><![CDATA[
  162.           switch (aTopic) {
  163.             case "nsPref:changed":
  164.               
  165.               switch (aData) {
  166.                 case this.PPEF_NAMES.spellcheckDefault:
  167.                   this.checked = !!this._prefBranch.getIntPref(aData);
  168.                   this._checkUserSheet();
  169.                   break;
  170.                 
  171.                 case this.PPEF_NAMES.dictionary:
  172.                   this.mCurrentDict = this._prefBranch.getCharPref(aData);
  173.                   break;
  174.                 
  175.                 default:
  176.                   break;
  177.               }
  178.               
  179.               break;
  180.             
  181.             default:
  182.               break;
  183.           }
  184.         ]]></body>
  185.       </method>
  186.       
  187.       <method name="_checkUserSheet">
  188.         <body><![CDATA[
  189.           if (!this._agentSheetURI) {
  190.             let uriSpec = 'data:text/css;charset=utf-8,textarea%5Bspellcheck%3D%22false%22%5D%7B-moz-binding%3Aurl(\'data%3Atext%2Fxml%3Bcharset%3Dutf-8%2C%253C%253Fxml%2520version%253D%25221.0%2522%253F%253E%253Cbindings%2520xmlns%253D%2522http%253A%252F%252Fwww.mozilla.org%252Fxbl%2522%253E%253Cbinding%2520id%253D%2522textareaSpellchecker%2522%253E%253Cimplementation%253E%253Cconstructor%253E%253C!%255BCDATA%255B%2520if%2520(this.hasAttribute(%2522spellcheck%2522))%2520%257B%2520this.removeAttribute(%2522spellcheck%2522)%253B%2520%257D%2520%255D%255D%253E%253C%252Fconstructor%253E%253C%252Fimplementation%253E%253C%252Fbinding%253E%253C%252Fbindings%253E\')%3B%7D';
  191.             
  192.             this._agentSheetURI = Cc["@mozilla.org/network/io-service;1"]
  193.                                       .getService(Ci.nsIIOService)
  194.                                       .newURI(uriSpec, null, null);
  195.           }
  196.           
  197.           var sss = Cc["@mozilla.org/content/style-sheet-service;1"].getService(Ci.nsIStyleSheetService);
  198.           if (sss.sheetRegistered(this._agentSheetURI, sss.AGENT_SHEET))
  199.             sss.unregisterSheet(this._agentSheetURI, sss.AGENT_SHEET);
  200.           
  201.           if (this.checked)
  202.             sss.loadAndRegisterSheet(this._agentSheetURI, sss.AGENT_SHEET);
  203.         ]]></body>
  204.       </method>
  205.       
  206.       <method name="getEditorForNode">
  207.         <parameter name="aNode"/>
  208.         <body><![CDATA[
  209.           if (aNode instanceof HTMLHtmlElement)
  210.             aNode = aNode.ownerDocument.defaultView;
  211.           
  212.           if (aNode instanceof Window) {
  213.             try {
  214.               var editingSession = aNode.QueryInterface(Ci.nsIInterfaceRequestor)
  215.                                         .getInterface(Ci.nsIWebNavigation)
  216.                                         .QueryInterface(Ci.nsIInterfaceRequestor)
  217.                                         .getInterface(Ci.nsIEditingSession);
  218.               
  219.               if (editingSession.windowIsEditable(aNode))
  220.                 return editingSession.getEditorForWindow(aNode);
  221.             
  222.             } catch(ex) {}
  223.             
  224.           } else if (!aNode.readOnly) {
  225.             return aNode.QueryInterface(Ci.nsIDOMNSEditableElement).editor;
  226.           }
  227.           
  228.           return null;
  229.         ]]></body>
  230.       </method>
  231.       
  232.       <method name="getSpellCheckNodes">
  233.         <body><![CDATA[
  234.           var doc = gBrowser.mCurrentBrowser.docShell.QueryInterface(Ci.nsIWebNavigation).document;
  235.           
  236.           var nodes = Array.slice.call(doc.getElementsByTagName("textarea"));
  237.           Array.forEach(doc.getElementsByTagName("input"), function(aInput) {
  238.             if (!aInput.type || aInput.type == "text")
  239.               nodes.push(aInput);
  240.           });
  241.           
  242.           return nodes;
  243.         ]]></body>
  244.       </method>
  245.       
  246.       <method name="updatePageDictionary">
  247.         <body><![CDATA[
  248.           this.getSpellCheckNodes().forEach(function(aNode) {
  249.             var editor = this.getEditorForNode(aNode);
  250.             if (editor) {
  251.               var editorSChecker = editor.getInlineSpellChecker ? editor.getInlineSpellChecker(true) :
  252.                                                                   editor.inlineSpellChecker;
  253.               
  254.               if (editorSChecker && editorSChecker.spellChecker) {
  255.                 editorSChecker.spellChecker.SetCurrentDictionary(this.mCurrentDict);
  256.                 editorSChecker.spellCheckRange(null);
  257.               }
  258.             }
  259.           }, this);
  260.         ]]></body>
  261.       </method>
  262.       
  263.       <method name="toggleSpellCheckEnabled">
  264.         <body><![CDATA[
  265.           this.getSpellCheckNodes().forEach(function(aNode) {
  266.             var editor = this.getEditorForNode(aNode);
  267.             if (editor)
  268.               editor.setSpellcheckUserOverride(this.checked);
  269.           }, this);
  270.         ]]></body>
  271.       </method>
  272.       
  273.       <method name="getMoreDict">
  274.         <parameter name="event"/>
  275.         <body><![CDATA[
  276.           var uri = formatURL("browser.dictionaries.download.url", true);
  277.           var locale = "-";
  278.           
  279.           try {
  280.             locale = gPrefService.getComplexValue("intl.accept_languages", Components.interfaces.nsIPrefLocalizedString).data;
  281.           } catch(e) {}
  282.           
  283.           var version = "-";
  284.           
  285.           try {
  286.             version = Components.classes["@mozilla.org/xre/app-info;1"]
  287.                                 .getService(Components.interfaces.nsIXULAppInfo).version;
  288.           } catch(e) {}
  289.           
  290.           uri = uri.replace(/%LOCALE%/, escape(locale)).replace(/%VERSION%/, version);
  291.           Ya.loadURI((uri || "https://addons.mozilla.org"), event);
  292.         ]]></body>
  293.       </method>
  294.  
  295.       <method name="handleEvent">
  296.         <parameter name="aEvent"/>
  297.         <body><![CDATA[
  298.           var target = aEvent.target;
  299.           
  300.           switch (aEvent.type) {
  301.             case "popupshowing":
  302.               var spellcheckerEnabledItem = target.getElementsByAttribute("anonid", "spellchecker-enabled")[0];
  303.               if (spellcheckerEnabledItem)
  304.                 spellcheckerEnabledItem.setAttribute("checked", this.checked);
  305.               
  306.               if (this.mCurrentDict) {
  307.                 let dictItem = target.getElementsByAttribute("value", this.mCurrentDict);
  308.                 if (dictItem && dictItem[0])
  309.                   dictItem[0].setAttribute("checked", "true");
  310.               }
  311.               
  312.               break;
  313.             
  314.             case "command":
  315.               var action = (target == this) ?
  316.                                "spellchecker-enabled" :
  317.                                (target.hasAttribute("anonid") ? target.getAttribute("anonid") : null);
  318.               
  319.               switch (action) {
  320.                 case "spellchecker-enabled":
  321.                   if (this.isNoDict) {
  322.                     var stringBundle = Components.classes["@mozilla.org/intl/stringbundle;1"]
  323.                                                  .createInstance(Components.interfaces.nsIStringBundleService)
  324.                                                  .createBundle("chrome://yasearch/locale/spellchecker/spellchecker.properties");
  325.                     
  326.                     function getLocalizedString(aName) {
  327.                       return stringBundle.GetStringFromName(aName);
  328.                     }
  329.                     
  330.                     var prompter = Ya.nsIYa.promptService;
  331.                     var flags = prompter.BUTTON_POS_0 * prompter.BUTTON_TITLE_IS_STRING +
  332.                                 prompter.BUTTON_POS_1 * prompter.BUTTON_TITLE_IS_STRING +
  333.                                 prompter.BUTTON_POS_0_DEFAULT;
  334.                     
  335.                     var result = prompter.confirmEx(window,
  336.                                                     getLocalizedString("spellcheckerNoDictDialogTitle"),
  337.                                                     getLocalizedString("spellcheckerNoDictDialogMessage"),
  338.                                                     flags,
  339.                                                     getLocalizedString("spellcheckerNoDictDialogButtonOK"),
  340.                                                     getLocalizedString("spellcheckerNoDictDialogButtonCancel"),
  341.                                                     null, null, {});
  342.                     
  343.                     if (result !== 1)
  344.                       this.getMoreDict();
  345.  
  346.                     break;
  347.                   }
  348.  
  349.                   this._prefBranch.setIntPref(this.PPEF_NAMES.spellcheckDefault, this.checked ? 0 : 2);
  350.                   this.toggleSpellCheckEnabled();
  351.                   break;
  352.  
  353.                 case "spellchecker-dict":
  354.                   var dict = target.getAttribute("value");
  355.                   
  356.                   if (this.mCurrentDict != dict) {
  357.                     this._prefBranch.setCharPref(this.PPEF_NAMES.dictionary, dict);
  358.                     this.updatePageDictionary();
  359.                   }
  360.                   
  361.                   break;
  362.                 
  363.                 case "spellchecker-get-more-dict":
  364.                   this.getMoreDict();
  365.                   break;
  366.                 
  367.                 case "spellchecker-user-dict":
  368.                   const winType = "Yasearch:SpellcheckerUserDictDialog";
  369.                   
  370.                   var userDictWindow = Ya.nsIYa.getWindow(winType);
  371.                   if (userDictWindow)
  372.                     userDictWindow.focus();
  373.                   else
  374.                     window.openDialog(YaUtils.CHROME_CONTENT + "spellchecker/user-dict-dialog.xul", winType,
  375.                                       "centerscreen,chrome,dialog,resizable,dependent");
  376.                   break;
  377.                 
  378.                 default:
  379.                   break;
  380.               }
  381.               break;
  382.             
  383.             default:
  384.               break;
  385.           }
  386.         ]]></body>
  387.       </method>
  388.     </implementation>
  389.     
  390.     <handlers>
  391.       <handler event="command" action="this.handleEvent(event);"/>
  392.       <handler event="popupshowing" action="this.handleEvent(event);"/>
  393.     </handlers>
  394.   </binding>
  395. </bindings>