home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2006 March / PCpro_2006_03.ISO / files / freeware / greasemonkey-0.6.4-fx.xpi / chrome / chromeFiles / content / manage.xul < prev    next >
Encoding:
Extensible Markup Language  |  2005-11-30  |  7.1 KB  |  195 lines

  1. <?xml version="1.0"?>
  2. <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
  3. <?xul-overlay href="chrome://greasemonkey/content/pages-overlay.xul"?>
  4.  
  5.  
  6.  
  7. <dialog
  8.     id="manage-window"
  9.     buttons="accept,cancel"
  10.     ondialogaccept="return handleOkButton()"
  11.     title="Manage User Scripts"
  12.     orient="vertical"
  13.     style="max-width:650px;"
  14.     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  15.  
  16.     <script type="application/x-javascript" src="chrome://greasemonkey/content/utils.js" />
  17.     <script type="application/x-javascript" src="chrome://greasemonkey/content/prefmanager.js" />
  18.     <script type="application/x-javascript" src="chrome://greasemonkey/content/config.js" />
  19.     <script type="application/x-javascript">
  20.     <![CDATA[
  21.     var config = new Config(getScriptFile("config.xml"));
  22.     var uninstallList = [];
  23.  
  24.     function handleOkButton() {
  25.         for (var i = 0, script = null; (script = uninstallList[i]); i++) {
  26.             var idx = config.find(script.namespace, script.name);
  27.             config.scripts.splice(idx, 1);
  28.         }
  29.         config.save();
  30.  
  31.         var chkUninstallPrefs = document.getElementById('chkUninstallPrefs');        
  32.         for (var i = 0, script = null; (script = uninstallList[i]); i++) {
  33.             getScriptFile(script.filename).remove(false);
  34.             if (chkUninstallPrefs.checked) {
  35.                // Remove saved preferences
  36.                var scriptPrefRoot = ["scriptvals.",
  37.                                       script.namespace,
  38.                                       "/",
  39.                                       script.name,
  40.                                       "."].join("");                                
  41.                GM_prefRoot.remove(scriptPrefRoot);            
  42.             }   
  43.         }
  44.         return true;
  45.     }
  46.     var listbox, header, description, chkEnabled, btnEdit, btnUninstall;
  47.     var selectedScript;
  48.     var pagesControl;
  49.  
  50.     window.addEventListener("load", function(ev) {
  51.         config.load();
  52.         loadControls();
  53.         
  54.         if (!config.scripts.length == 0) {
  55.             populateChooser();
  56.             chooseScript(0);
  57.         }
  58.     }, false);
  59.  
  60.     function loadControls() {
  61.         listbox = document.getElementById("lstScripts");
  62.         header = document.getElementById("ctlHeader");
  63.         description = document.getElementById("ctlDescription");
  64.         btnEdit = document.getElementById("btnEdit");
  65.         btnUninstall = document.getElementById("btnUninstall");
  66.         pagesControl = new PagesControl(document.getElementById("pages-control"));
  67.         chkEnabled = document.getElementById("chkEnabled");
  68.  
  69.         listbox.addEventListener("select", function() { updateDetails(); }, false);
  70.         btnEdit.addEventListener("command", function() { handleEditButton(); }, false);
  71.         btnUninstall.addEventListener("command", function() { handleUninstallButton(); }, false);
  72.         chkEnabled.addEventListener("command", function() {
  73.            if (selectedScript) {
  74.              selectedScript.enabled = chkEnabled.checked;
  75.              if (selectedScript.enabled) {
  76.                  listbox.selectedItem.style.color = '';
  77.              } else {
  78.                  listbox.selectedItem.style.color = 'gray';
  79.              }
  80.            }
  81.         }, false);
  82.     }
  83.  
  84.     function updateDetails() {
  85.         if (listbox.selectedCount == 0) {
  86.             selectedScript = null;
  87.             header.textContent = " ";
  88.             description.textContent = " ";
  89.             chkEnabled.checked = true;
  90.             pagesControl.clear();
  91.             document.documentElement.getButton("accept").disabled = false;
  92.         }
  93.         else {
  94.             selectedScript = listbox.getSelectedItem(0).script;
  95.             header.textContent = selectedScript.name;
  96.             description.textContent = selectedScript.description;
  97.             chkEnabled.checked = selectedScript.enabled;
  98.             pagesControl.populate(selectedScript);
  99.         }
  100.     }
  101.     
  102.     function handleEditButton() {
  103.       openInEditor(getScriptFile(selectedScript.filename));
  104.     }
  105.  
  106.     function handleUninstallButton() {
  107.         uninstallList.push(selectedScript);
  108.         listbox.removeChild(listbox.childNodes[listbox.selectedIndex]);
  109.  
  110.         if (listbox.childNodes.length > 0) {
  111.             chooseScript(Math.max(Math.min(listbox.selectedIndex, listbox.childNodes.length - 1), 0));
  112.         }
  113.     }
  114.  
  115.     function populateChooser() {
  116.         for (var i = 0, script = null; (script = config.scripts[i]); i++) {
  117.             var listitem = document.createElement("listitem");
  118.  
  119.             listitem.setAttribute("label", script.name);
  120.             listitem.setAttribute("crop", "end");
  121.             listitem.script = script;
  122.             if (!script.enabled) {
  123.                 listitem.style.color = 'gray';
  124.             }
  125.             listbox.appendChild(listitem);
  126.         }
  127.     }
  128.  
  129.     function chooseScript(index) {
  130.         listbox.selectedIndex = index;            
  131.         listbox.focus();
  132.     }
  133.  
  134.     function toggleScript(index, enableFlag) {
  135.         var listitem = listbox.childNodes[index];
  136.         if (enableFlag) {
  137.             listitem.script.enabled = true;
  138.             listitem.style.color = '';
  139.         } else {
  140.             listitem.script.enabled = false;
  141.             listitem.style.color = 'gray';
  142.         }
  143.     }
  144.  
  145.     ]]>
  146.     </script>
  147.  
  148.     <grid style="margin-bottom:2em" flex="1" orient="vertical">
  149.       <columns>
  150.         <column flex="1"/>
  151.         <column flex="3"/>
  152.       </columns>
  153.       
  154.       <rows>
  155.         <row flex="1" orient="horizontal">
  156.           <listbox id="lstScripts" style="min-width:140px; margin-top:0" flex="1"/>
  157.           <vbox flex="3">
  158.             <description id="ctlHeader" style="  margin: 0px 5px 5px 5px; 
  159.                border: 2px solid; 
  160.                -moz-border-top-colors: ThreeDShadow ThreeDDarkShadow; 
  161.                -moz-border-right-colors: ThreeDHighlight ThreeDDarkShadow; 
  162.                -moz-border-bottom-colors: ThreeDHighlight ThreeDDarkShadow; 
  163.                -moz-border-left-colors: ThreeDShadow ThreeDDarkShadow; 
  164.                padding: 5px 8px; 
  165.                background-color: Highlight; 
  166.                color: HighlightText; 
  167.                font-size: 1.5em; 
  168.                height: 2em;"/>
  169.             <description id="ctlDescription" style="margin:.5em;
  170.                height:3em; 
  171.                max-height:3em;"/>
  172.             <vbox id="pages-control" />
  173.           </vbox>                
  174.         </row>
  175.         <row>
  176.           <hbox>
  177.             <hbox>
  178.               <checkbox id="chkEnabled" label="Enabled" checked="true" />               
  179.               <button flex="1" id="btnEdit" label="Edit" />
  180.             </hbox>
  181.           </hbox>
  182.           <hbox>
  183.                <hbox>
  184.                  <button flex="1" id="btnUninstall" label="Uninstall" />
  185.                  <checkbox id="chkUninstallPrefs" 
  186.                     label="Also uninstall associated preferences" checked="false" />          
  187.                </hbox>
  188.           </hbox>
  189.         </row>
  190.       </rows>          
  191.     </grid>
  192.  
  193. </dialog>
  194.  
  195.