mozdev.org

Mozile (xhtml editing in your browser)    

resources:
Overview

options.xul

Summary

An "options" dialog for the Mozile Extension.

Version: 0.7

Author: James A. Overton


Method Summary
static Void mozileAddCode(<String> list, <String> code, <String> msg)
           Adds the pair of an enhancementList and enhancementCode entry.
static Boolean mozileAddItem(<String> pref, <String> msg)
           Prompts for a value and appends a listitem to the listbox.
static Void mozileClearList(<String> pref)
           Removes all children from a list.
static Void mozileDefaultList(<String> pref)
           Restores the default value for a given preference.
static Void mozileOptionsInit()
           Initializes the dialog.
static Void mozileRemoveCode(<String> list, <String> code)
           Removes the pair of an enhancementList and enhancementCode entry.
static Void mozileRemoveItem(<String> pref)
           Removes all selected items from the listbox.
static Void mozileSaveCode(<String> list, <String> code)
           Saves the content of the textbox in a position corresponding to the list item.
static Void mozileSetList(<String> pref)
           Populates a list for the given preference.
static Void mozileSetListPref(<String> pref)
           Takes a listbox and joins its values.
static Void mozileSetPref(<Element> element)
           Sets a preference corresponding to the given element.
static Void mozileShowCode(<String> list, <String> code)
           Shows the code the corresponds to the selected list item.

<?xml version="1.0" encoding="UTF-8"?>

<!--
/* ***** BEGIN LICENSE BLOCK *****
 * Licensed under Version: MPL 1.1/GPL 2.0/LGPL 2.1
 * Full Terms at http://mozile.mozdev.org/license2.html
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is James A. Overton's code (james@overton.ca).
 *
 * The Initial Developer of the Original Code is James A. Overton.
 * Portions created by the Initial Developer are Copyright (C) 2005-2006
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *	James A. Overton <james@overton.ca>
 *
 * ***** END LICENSE BLOCK ***** */

/** 
 * @fileoverview An "options" dialog for the Mozile Extension.
 * @link http://mozile.mozdev.org 
 * @author James A. Overton <james@overton.ca>
 * @version 0.7
 */
-->

<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<?xml-stylesheet href="chrome://mozile/content/core/interface.css" type="text/css"?>

<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
        xmlns:html="http://www.w3.org/1999/xhtml"
        id="MozilePreferences"
        class="mozileInterface"
        orient="vertical"
        title="Mozile Preferences"
        buttons="accept"
  	  	flex="1"
  	  	onload="this.moveToAlertPosition(); this.sizeToContent(); mozileOptionsInit()"
  	  	width="360px">




	<script type="application/x-javascript">	
	
		// Get preference service.

	netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

	var mozilePrefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefService).getBranch(null);	
	
		// Default enhancement code
var mozileEnhancementList = "getClipboard;setClipboard";
var mozileEnhancementCode = [
	"this.setSharedData('clipboard', mozile.getModule('CopyCutPaste').getClipboard())",
	"mozile.getModule('CopyCutPaste').setClipboard(this.getSharedData('clipboard')); this.setSharedData('clipboard', '')"
];
	
	
	/**
	 * Initializes the dialog.
	 * @type Void
	 */
	function mozileOptionsInit() {
		var caretAlwaysOn = mozilePrefs.getBoolPref("mozile.caretAlwaysOn");
		if(caretAlwaysOn != null) document.getElementById("mozile.caretAlwaysOn").checked = caretAlwaysOn;
		
		var debugLevel = mozilePrefs.getCharPref("mozile.debugLevel");
		if(debugLevel != null) document.getElementById("mozile.debugLevel").value = debugLevel;
		
		var neverWarn = mozilePrefs.getBoolPref("mozile.neverWarn");
		if(neverWarn != null) document.getElementById("mozile.neverWarn").checked = neverWarn;
		
		var iconSize = mozilePrefs.getCharPref("mozile.iconSize");
		if(iconSize != null) document.getElementById("mozile.iconSize").value = iconSize;
		
		mozileSetList("mozile.enhancementList");
		mozileSetList("mozile.trustedSites");
		mozileSetList("mozile.autoEnhanceSites");
	}
	
	
	/**
	 * Restores the default value for a given preference.
	 * @param {String} pref The id of the list box to target.
	 * @type Void
	 */
	function mozileDefaultList(pref) {
		var value;
		switch(pref) {
			case "mozile.enhancementList":
				value = mozileEnhancementList;
				break;
			
			case "mozile.enhancementCode":
				for(var i=0; i &lt; mozileEnhancementCode.length; i++) {
					mozileEnhancementCode[i] = escape(mozileEnhancementCode[i]);
				}
				value = mozileEnhancementCode.join(";");
				break
			
			default:
				// do nothing
				break;
		}
		
		mozilePrefs.setCharPref(pref,value);
		document.getElementById(pref).value = "";
	}
	
	
	/**
	 * Populates a list for the given preference.
	 * @param {String} pref The id of the list box to target.
	 * @type Void
	 */
	function mozileSetList(pref) {
		var prefArray = mozilePrefs.getCharPref(pref).split(";");
		
		var listbox = document.getElementById(pref);
		while(listbox.childNodes.length) {
			listbox.removeChild(listbox.firstChild);
		}
		var listitem;
		for(var p=0; p &lt; prefArray.length; p++) {
			listitem = document.createElement("listitem");
			listitem.setAttribute("label", prefArray[p]);
			listitem.setAttribute("value", prefArray[p]);
			listbox.appendChild(listitem);
		}
	}
	
	/**
	 * Sets a preference corresponding to the given element.
	 * @param {Element} element The element with the id and value needed.
	 * @type Void
	 */
	function mozileSetPref(element) {
		var pref = element.id;
		var value;
		
		switch(element.localName) {
			case "checkbox":
				value = element.checked;
				//alert("Set Bool Pref "+ pref +" = "+ value);

				mozilePrefs.setBoolPref(pref, value);
				break;
			
			default:
				value = element.value;
				//alert("Set Char Pref "+ pref +" = "+ value);
				mozilePrefs.setCharPref(pref, value);
				break;
		
		}
		return true;
	}
	

	/**
	 * Shows the code the corresponds to the selected list item.
	 * @param {String} list The id of the listbox to target.
	 * @param {String} code The id of the textbox to target.
	 * @type Void
	 */	
	function mozileShowCode(list, code) {
		var entries = mozilePrefs.getCharPref(list).split(";");
		for(var p=0; p &lt; entries.length; p++) {
			if(entries[p] == document.getElementById(list).value) break;
		}
		if(entries[p] != document.getElementById(list).value) return;
		
		var codeBlocks = mozilePrefs.getCharPref(code).split(";");
		document.getElementById(code).value = unescape(codeBlocks[p]);
	}

	/**
	 * Saves the content of the textbox in a position corresponding to the list item.
	 * @param {String} list The id of the listbox to target.
	 * @param {String} code The id of the textbox to target.
	 * @type Void
	 */
	function mozileSaveCode(list, code) {
		var entries = mozilePrefs.getCharPref(list).split(";");
		for(var p=0; p &lt; entries.length; p++) {
			if(entries[p] == document.getElementById(list).value) break;
		}
		if(entries[p] != document.getElementById(list).value) return;
		
		var codeBlocks = mozilePrefs.getCharPref(code).split(";");
		codeBlocks[p] = escape(document.getElementById(code).value);
		mozilePrefs.setCharPref(code, codeBlocks.join(";"));
	}
	
	/**
	 * Adds the pair of an enhancementList and enhancementCode entry.
	 * @param {String} list The id of the listbox to target.
	 * @param {String} code The id of the textbox to target.
	 * @param {String} msg The message for the prompt.
	 * @type Void
	 */
	function mozileAddCode(list, code, msg) {
		if(!mozileAddItem(list, msg)) return;
		
		var codeBlocks = mozilePrefs.getCharPref(code).split(";");
		codeBlocks.push("");
		mozilePrefs.setCharPref(code, codeBlocks.join(";"));
		document.getElementById(code).value = "";
	}
	
	/**
	 * Removes the pair of an enhancementList and enhancementCode entry.
	 * @param {String} list The id of the listbox to target.
	 * @param {String} code The id of the textbox to target.
	 * @type Void
	 */
	function mozileRemoveCode(list, code) {
		var entries = mozilePrefs.getCharPref(list).split(";");
		for(var p=0; p &lt; entries.length; p++) {
			if(entries[p] == document.getElementById(list).value) break;
		}
		if(entries[p] != document.getElementById(list).value) return;
		
		var codeBlocks = mozilePrefs.getCharPref(code).split(";");
		codeBlocks[p] = undefined;
		mozilePrefs.setCharPref(code, codeBlocks.join(";"));
		document.getElementById(code).value = "";
		
		mozileRemoveItem(list);
	}
	
	
	/**
	 * Prompts for a value and appends a listitem to the listbox.
	 * @param {String} pref The id of the listbox to add to.
	 * @param {String} msg The message to prompt with.
	 * @type Boolean
	 */
	function mozileAddItem(pref, msg) {
		var add = prompt(msg);
		if(!add) return false;
		
		// Strip leading and trailing white space
		var stripWS = /^(\s+)(.*?)(\s+)$/;
		var result = stripWS.exec(add);
		if(result &amp;&amp; result[2]) add = result[2];
		
		var listbox = document.getElementById(pref);
		var listitem = document.createElement("listitem");
		listitem.setAttribute("label", add);
		listitem.setAttribute("value", add);
		listbox.appendChild(listitem);
				
		mozileSetListPref(pref);
		return true;
	}
	
	/**
	 * Removes all selected items from the listbox.
	 * @param {String} pref The id of the list box to target.
	 * @type Void
	 */
	function mozileRemoveItem(pref) {
		var listbox = document.getElementById(pref);
		var remove = new Array();
		for(var c=0; c &lt; listbox.childNodes.length; c++) {
			if(listbox.childNodes[c].selected) remove.push(listbox.childNodes[c]);
		}
		while(remove.length) {
			listbox.removeChild(remove.shift());
		}
		mozileSetListPref(pref);
	}
	
	/**
	 * Removes all children from a list.
	 * @param {String} pref The id of the element to clear.
	 * @type Void
	 */
	function mozileClearList(pref) {
		var listbox = document.getElementById(pref);
		while(listbox.childNodes.length) {
			listbox.removeChild(listbox.firstChild);
		}
		mozileSetListPref(pref);
	}
	
	/**
	 * Takes a listbox and joins its values. Store the result in a preference.
	 * @param {String} pref The name of the preference to set.
	 * @type Void
	 */
	function mozileSetListPref(pref) {
		var listbox = document.getElementById(pref);
		var values = new Array();
		for(var c=0; c &lt; listbox.childNodes.length; c++) {
			if(listbox.childNodes[c].value) values.push(listbox.childNodes[c].value);
		}
		mozilePrefs.setCharPref(pref, values.join(";"));
	}
	
	
	</script>
	
	<hbox class="header">
		<label value="Mozile Preferences" />
	</hbox>

	<tabbox>
		<tabs>
			<tab label="Basic" selected="true"/>
			<tab label="Enhancement"/>
			<tab label="Sites"/>
		</tabs>
		
		<tabpanels height="350px">
		
			<!-- Basic Preferences -->
			<tabpanel orient="vertical">
				<groupbox>
					<description>Mozile makes use of an editing caret (a cursor) when editing documents. When not editing, Mozile turns the editing caret off. Check the box below to ensure the editing caret is always on.</description>
					<checkbox id="mozile.caretAlwaysOn" label="Always show the editing caret (cursor)." checked="false" oncommand="mozileSetPref(this); mozilePrefs.setBoolPref('accessibility.browsewithcaret', this.checked);"/>
				</groupbox>
				
				<groupbox>
					<!-- <description>Use the settings below to control Mozile's debugging behaviour.</description> -->
					<label control="mozileDebugLevelMenulist" value="Set Mozile's debugging level:"/>
					<menulist id="mozile.debugLevel" value="0" oncommand="mozileSetPref(this)">
							<menupopup>
									<menuitem label="Debugging Disabled" value="4"/>
									<menuitem label="Critical Messages" value="3"/>
									<menuitem label="Serious Messages" value="2"/>
									<menuitem label="Significant Messages" value="1"/>
									<menuitem label="All Messages" value="0"/>
							</menupopup>
					</menulist>
				</groupbox>
				
				<groupbox>
					<description>Mozile can enhance editors to allow functions such as access to the system clipboard and saving to local files. You should only enhance sites that you trust. Mozile will warn you before enhancing unless you disable the warning.</description>
					<checkbox id="mozile.neverWarn" label="Do not show warnings." checked="false" oncommand="mozileSetPref(this)"/>
				</groupbox>
				
				<groupbox>
					<label control="mozileIconSizeMenulist" value="Set the size of the Mozile toolbar icon:"/>
					<menulist id="mozile.iconSize" value="0" oncommand="mozileSetPref(this)">
							<menupopup>
									<menuitem label="Large (32px)" value="32"/>
									<menuitem label="Medium (24px)" value="24"/>
									<menuitem label="Small (16px)" value="16"/>
							</menupopup>
					</menulist>
				</groupbox>
				
			</tabpanel>
			
		
			<!-- Advanced Preferences -->
			<tabpanel orient="vertical">
				<description>These settings allow you to control how the Mozile Extension installed in your browser can enhance the Mozile editors which are used in pages on the World Wide Web.</description>
				
				<!-- list of enhanced modules -->
				<groupbox>
					<label value="Enhancements:"/>
					<hbox>
						<listbox id="mozile.enhancementList" seltype="single" style="height: 60pt" flex="1" onselect="mozileShowCode('mozile.enhancementList', 'mozile.enhancementCode')">
						</listbox>
						<vbox pack="end">
							<button label="Add" oncommand="mozileAddCode('mozile.enhancementList','mozile.enhancementCode','Name of enhancement:')"/>
							<button label="Remove" oncommand="mozileRemoveCode('mozile.enhancementList','mozile.enhancementCode')"/>
							<button label="Default" oncommand="mozileDefaultList('mozile.enhancementList');mozileSetList('mozile.enhancementList');mozileDefaultList('mozile.enhancementCode')"/>
						</vbox>
					</hbox>
					<textbox id="mozile.enhancementCode" flex="1" multiline="true" rows="6" oninput="mozileSaveCode('mozile.enhancementList', 'mozile.enhancementCode')"/>
				</groupbox>
			
			</tabpanel>
			
			<tabpanel orient="vertical">
				<description>These settings allow you to control which sites Mozile always trusts to enhance, and which it will enhance as soon as they are made editable.</description>
				
				<!-- List of allowed sites -->
				<groupbox>
					<label value="Always trust these sites:"/>
					<hbox>
						<listbox id="mozile.trustedSites" seltype="multiple" style="height: 60pt" flex="1">
						</listbox>
						<vbox pack="end">
							<button label="Add" oncommand="mozileAddItem('mozile.trustedSites', 'Name of the site to add (e.g. mozile.mozdev.org):')"/>
							<button label="Remove" oncommand="mozileRemoveItem('mozile.trustedSites')"/>
							<button label="Clear" oncommand="mozileClearList('mozile.trustedSites')"/>
						</vbox>
					</hbox>
				</groupbox>
				
				<!-- List of forbidden sites -->
				<groupbox>
					<label value="Automatically enhance when editing these sites:"/>
					<hbox>
						<listbox id="mozile.autoEnhanceSites" seltype="multiple" style="height: 60pt" flex="1">
						</listbox>
						<vbox pack="end">
							<button label="Add" oncommand="mozileAddItem('mozile.autoEnhanceSites', 'Name of the site to add (e.g. mozile.mozdev.org):')"/>
							<button label="Remove" oncommand="mozileRemoveItem('mozile.autoEnhanceSites')"/>
							<button label="Clear" oncommand="mozileClearList('mozile.autoEnhanceSites')"/>
						</vbox>
					</hbox>
				</groupbox>
				
			</tabpanel>
		</tabpanels>
	</tabbox>

</dialog>


Documentation generated by JSDoc on Wed Nov 1 15:11:15 2006

The mozile project can be contacted through the mailing list or the member list.
Copyright © 2000-2019. All rights reserved. Terms of Use & Privacy Policy.