<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Usingnamespace - Blog &#187; Javascript</title>
	<atom:link href="http://www.usingnamespace.org/category/javascript/feed" rel="self" type="application/rss+xml" />
	<link>http://www.usingnamespace.org</link>
	<description>C#, XUL, Javascript, C++ ...</description>
	<lastBuildDate>Tue, 17 Jul 2012 14:53:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>[XUL] Limit the number of characters in tree edit mode</title>
		<link>http://www.usingnamespace.org/xul-limit-chars-tree-edit.html</link>
		<comments>http://www.usingnamespace.org/xul-limit-chars-tree-edit.html#comments</comments>
		<pubDate>Fri, 16 Jul 2010 06:31:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[XUL]]></category>
		<category><![CDATA[characters]]></category>
		<category><![CDATA[edit mode]]></category>
		<category><![CDATA[editing]]></category>
		<category><![CDATA[limit]]></category>
		<category><![CDATA[tree]]></category>

		<guid isPermaLink="false">http://www.usingnamespace.org/?p=280</guid>
		<description><![CDATA[Unfortunately, there are no &#171;&#160;clean&#160;&#187; way to limit the maximum number of characters (or more generally apply constraints) in edit mode of a tree, unlike textbox elements.
Here is the trick : the oninput event of a tree is only fired when you are editing : 
Short tree example (limiting max number of characters to 10):

&#60;tree [...]]]></description>
			<content:encoded><![CDATA[<p>Unfortunately, there are no &laquo;&nbsp;clean&nbsp;&raquo; way to limit the maximum number of characters (or more generally apply constraints) in edit mode of a tree, unlike textbox elements.</p>
<p>Here is the trick : the <a href="https://developer.mozilla.org/en/XUL/Attribute/oninput">oninput</a> event of a tree <strong>is only fired when you are editing</strong> : </p>
<p><u>Short tree example (limiting max number of characters to 10):</u></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tree</span> <span style="color: #000066;">hidecolumnpicker</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">minwidth</span>=<span style="color: #ff0000;">&quot;100px&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;300&quot;</span> <span style="color: #000066;">editable</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">flex</span>=<span style="color: #ff0000;">&quot;1&quot;</span> </span>
<span style="color: #009900;"> <span style="color: #000066;">oninput</span>=<span style="color: #ff0000;">&quot;event.originalTarget.value = event.originalTarget.value.substring(0,10);&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;treecols<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;treecol</span> <span style="color: #000066;">primary</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">flex</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/treecols<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;treechildren</span> <span style="color: #000066;">context</span>=<span style="color: #ff0000;">&quot;&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;treeitem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;treerow<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;treecell</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;joe@somewhere.com&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/treerow<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/treeitem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;treeitem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;treerow<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;treecell</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;mel@whereever.com&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/treerow<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/treeitem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/treechildren<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tree<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.usingnamespace.org/xul-limit-chars-tree-edit.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[XUL] xml-combobox and xml-radiobox</title>
		<link>http://www.usingnamespace.org/xul-xml-combobox-and-xml-radiobox.html</link>
		<comments>http://www.usingnamespace.org/xul-xml-combobox-and-xml-radiobox.html#comments</comments>
		<pubDate>Wed, 17 Feb 2010 15:14:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[XBL]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XUL]]></category>

		<guid isPermaLink="false">http://www.usingnamespace.org/?p=36</guid>
		<description><![CDATA[I am pleased to share one creation of mine  .
The following widget is a XBL binding based on the XUL&#8217;s XNL templates technology.
https://developer.mozilla.org/en/XUL/Template_Guide/XML_Templates
If you need to display xml data into a xul menulist -combobox- or in a radiogroup -radiobox-, without having to implement an XML parser, here is the solution :
xml-combobox
xml-radiobox

&#60;xml-combobox id=&#34;myid&#34; datasources=&#34;chrome://application/pathtoxmlfile&#34; expr=&#34;&#34;/&#62;
&#60;xml-radiobox [...]]]></description>
			<content:encoded><![CDATA[<p>I am pleased to share one creation of mine <img src='http://www.usingnamespace.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>The following widget is a XBL binding based on the XUL&#8217;s XNL templates technology.<br />
<a href="https://developer.mozilla.org/en/XUL/Template_Guide/XML_Templates">https://developer.mozilla.org/en/XUL/Template_Guide/XML_Templates</a></p>
<p>If you need to display xml data into a xul menulist -combobox- or in a radiogroup -radiobox-, without having to implement an XML parser, here is the solution :</p>
<p><a href="http://www.usingnamespace.org/downloads/XUL/bindings/xml-combobox.xml">xml-combobox</a><br />
<a href="http://www.usingnamespace.org/downloads/XUL/bindings/xml-radiobox.xml">xml-radiobox</a></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xml-combobox</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;myid&quot;</span> <span style="color: #000066;">datasources</span>=<span style="color: #ff0000;">&quot;chrome://application/pathtoxmlfile&quot;</span> <span style="color: #000066;">expr</span>=<span style="color: #ff0000;">&quot;&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xml-radiobox</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;myid&quot;</span> <span style="color: #000066;">datasources</span>=<span style="color: #ff0000;">&quot;chrome://application/pathtoxmlfile&quot;</span> <span style="color: #000066;">expr</span>=<span style="color: #ff0000;">&quot;&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p><strong>Attributes : </strong></p>
<p><u>datasources</u> : URL of an XML document, either a local file or a remote web site.</p>
<p><u>expr</u> : the <em>expr</em> attribute is a very simple XPath expression which simply retrieves the root elements of your query within the <em>datasource</em>.</p>
<p><u>label</u> : </p>
<ul>
<li>starting with &laquo;&nbsp;!&nbsp;&raquo; : an XPath expression corresponding to the node you want to use as a <em>label</em>.</li>
<li>starting with &laquo;&nbsp;?&nbsp;&raquo; : a property of the node corresponding to the expr result, you want to use as a <em>label</em>.</li>
<li>Otherwise just a text used as a <em>label</em> for all the generated lines (can be empty).</li>
</ul>
<p><br/><br />
<u>value</u> : </p>
<ul>
<li>starting with &laquo;&nbsp;!&nbsp;&raquo; : an XPath expression corresponding to the node you want to use as a <em>value</em>.</li>
<li>starting with &laquo;&nbsp;?&nbsp;&raquo; : a property of the node corresponding to the expr result, you want to use as a <em>value</em>.</li>
<li>Otherwise just a text used as a <em>value</em> for all the generated lines (can be empty).</li>
</ul>
<p><br/><br />
<u>image</u> : </p>
<ul>
<li>starting with &laquo;&nbsp;!&nbsp;&raquo; : an XPath expression corresponding to the node you want to use as an <em>image</em>.</li>
<li>starting with &laquo;&nbsp;?&nbsp;&raquo; : a property of the node corresponding to the expr result, you want to use as an <em>image</em>.</li>
<li>Otherwise just a text used as an <em>image</em> for all the generated lines (can be empty).</li>
</ul>
<p><br/><br />
<u>imageBaseFolder</u> : if the attribute <em>image</em> is used, the base folder where to look the images for. Useful if the image query result is just a file name, or a relative path. Must contain the final &laquo;&nbsp;/&nbsp;&raquo; or &laquo;&nbsp;\&nbsp;&raquo;. Can be left empty.</p>
<p><u>orient</u> : (xml-radiobox only) : &laquo;&nbsp;horizontal&nbsp;&raquo; or &laquo;&nbsp;vertical&nbsp;&raquo;.</p>
<p><u>onselect</u>: occurs when selection changed.</p>
<p><strong>Examples :</strong></p>
<p><u>Example 1 :</u> simple example using the properties of a XML node</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;people<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;person</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Napoleon Bonaparte&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;NB&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;person</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Cleopatra&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;Cl&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;person</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Julius Caesar&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;JC&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;person</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Ferdinand Magellan&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;FM&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;person</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Laura Secord&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;LS&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/people<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xml-combobox</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;myid&quot;</span> <span style="color: #000066;">datasources</span>=<span style="color: #ff0000;">&quot;chrome://application/pathtoxmlfile&quot;</span> <span style="color: #000066;">expr</span>=<span style="color: #ff0000;">&quot;person/&quot;</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;?name&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;?id&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p><u>Example 2 :</u> using a node property for the id and a XPath from the targeted node for the label (here the text contained in the subnode &laquo;&nbsp;name&nbsp;&raquo;)</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;people<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;person</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;NB&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Napoleon Bonaparte<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gender<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Male<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/gender<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/person<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;person</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;Cl&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Cleopatra<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gender<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Female<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/gender<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/person<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;person</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;JC&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Julius Caesar<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gender<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Male<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/gender<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/person<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;person</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;FM&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Ferdinand Magellan<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gender<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Male<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/gender<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/person<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;person</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;LS&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Laura Secord<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gender<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Female<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/gender<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/person<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/people<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xml-radiobox</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;myid&quot;</span> <span style="color: #000066;">datasources</span>=<span style="color: #ff0000;">&quot;chrome://application/pathtoxmlfile&quot;</span> <span style="color: #000066;">expr</span>=<span style="color: #ff0000;">&quot;person/&quot;</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;!./name/text()&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;?id&quot;</span> <span style="color: #000066;">orient</span>=<span style="color: #ff0000;">&quot;horizontal&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p><u>Example 3 :</u> same as example 2 but with a xml-combobox and using the image property and imageBaseFolder to specify where the widget should look the images for</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;people<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;person</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;NB&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Napoleon Bonaparte<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gender<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Male<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/gender<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;picture<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>nap.png<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/picture<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/person<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;person</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;Cl&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Cleopatra<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gender<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Female<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/gender<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;picture<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>cleo.png<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/picture<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/person<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;person</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;JC&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Julius Caesar<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gender<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Male<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/gender<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;picture<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>julius.png<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/picture<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/person<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;person</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;FM&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Ferdinand Magellan<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gender<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Male<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/gender<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;picture<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>magellan.png<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/picture<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/person<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;person</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;LS&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Laura Secord<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gender<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Female<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/gender<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;picture<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>secord.png<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/picture<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/person<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/people<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xml-combobox</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;myid&quot;</span> <span style="color: #000066;">datasources</span>=<span style="color: #ff0000;">&quot;chrome://application/pathtoxmlfile&quot;</span> <span style="color: #000066;">expr</span>=<span style="color: #ff0000;">&quot;person/&quot;</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;!./name/text()&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;?id&quot;</span> <span style="color: #000066;">imageBaseFolder</span>=<span style="color: #ff0000;">&quot;chrome://application/skin/pic_small/&quot;</span> <span style="color: #000066;">image</span>=<span style="color: #ff0000;">&quot;!./picture/text()&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>And like all the XBL widgets, the bindings need to be done in a CSS :</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">xml-combobox<span style="color: #00AA00;">&#123;</span>
	-moz-binding<span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;chrome://application/content/bindings/xml-combobox.xml#xml-combobox&quot;</span><span style="color: #00AA00;">&#41;</span> !important<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
xml-radiobox<span style="color: #00AA00;">&#123;</span>
	-moz-binding<span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;chrome://application/content/bindings/xml-radiobox.xml#xml-radiobox&quot;</span><span style="color: #00AA00;">&#41;</span> !important<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.usingnamespace.org/xul-xml-combobox-and-xml-radiobox.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[XUL] Useful functions for file management</title>
		<link>http://www.usingnamespace.org/xul-useful-functions-for-file-management.html</link>
		<comments>http://www.usingnamespace.org/xul-useful-functions-for-file-management.html#comments</comments>
		<pubDate>Wed, 10 Feb 2010 19:24:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[XUL]]></category>

		<guid isPermaLink="false">http://www.usingnamespace.org/?p=22</guid>
		<description><![CDATA[Here are some useful functions I wrote or found on the web.
Suggestions are welcome  
Chrome url to file path :

function chromeToPath &#40;aChromePath&#41; &#123;
&#160;
   if &#40;!aChromePath&#41; &#124;&#124; !&#40;/^chrome:/.test&#40;aChromePath&#41;&#41;&#41;&#41;
      return; //not a chrome url
   var rv;
&#160;
   var ios = Components.classes&#91;'@mozilla.org/network/io-service;1'&#93;.getService&#40;Components.interfaces&#91;&#34;nsIIOService&#34;&#93;&#41;;
   var uri = [...]]]></description>
			<content:encoded><![CDATA[<p>Here are some useful functions I wrote or found on the web.<br />
Suggestions are welcome <img src='http://www.usingnamespace.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Chrome url to file path :</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> chromeToPath <span style="color: #009900;">&#40;</span>aChromePath<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
   <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>aChromePath<span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/^chrome:/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>aChromePath<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//not a chrome url</span>
   <span style="color: #003366; font-weight: bold;">var</span> rv<span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #003366; font-weight: bold;">var</span> ios <span style="color: #339933;">=</span> Components.<span style="color: #660066;">classes</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'@mozilla.org/network/io-service;1'</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">getService</span><span style="color: #009900;">&#40;</span>Components.<span style="color: #660066;">interfaces</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;nsIIOService&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #003366; font-weight: bold;">var</span> uri <span style="color: #339933;">=</span> ios.<span style="color: #660066;">newURI</span><span style="color: #009900;">&#40;</span>aPath<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;UTF-8&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #003366; font-weight: bold;">var</span> cr <span style="color: #339933;">=</span> Components.<span style="color: #660066;">classes</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'@mozilla.org/chrome/chrome-registry;1'</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">getService</span><span style="color: #009900;">&#40;</span>Components.<span style="color: #660066;">interfaces</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;nsIChromeRegistry&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   rv <span style="color: #339933;">=</span> cr.<span style="color: #660066;">convertChromeURL</span><span style="color: #009900;">&#40;</span>uri<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">spec</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/^file:/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>rv<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      rv <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">urlToPath</span><span style="color: #009900;">&#40;</span>rv<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000066; font-weight: bold;">else</span>
      rv <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">urlToPath</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;file://&quot;</span><span style="color: #339933;">+</span>rv<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000066; font-weight: bold;">return</span> rv<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>URL to file path :</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> urlToPath <span style="color: #009900;">&#40;</span>aURL<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
   <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>aURL <span style="color: #339933;">||</span> <span style="color: #339933;">!/^</span>file<span style="color: #339933;">:/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>aURL<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #339933;">;</span>
   <span style="color: #003366; font-weight: bold;">var</span> rv<span style="color: #339933;">;</span>
   <span style="color: #003366; font-weight: bold;">var</span> ph <span style="color: #339933;">=</span> Components.<span style="color: #660066;">classes</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;@mozilla.org/network/protocol;1?name=file&quot;</span><span style="color: #009900;">&#93;</span>
        .<span style="color: #660066;">createInstance</span><span style="color: #009900;">&#40;</span>Components.<span style="color: #660066;">interfaces</span>.<span style="color: #660066;">nsIFileProtocolHandler</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    rv <span style="color: #339933;">=</span> ph.<span style="color: #660066;">getFileFromURLSpec</span><span style="color: #009900;">&#40;</span>aPath<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">path</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> rv<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Get a nsILocalFile&#8217;s URL :</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> pathToUrl <span style="color: #009900;">&#40;</span>aFile<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #006600; font-style: italic;">//aFile must be an instance of nsILocalFile</span>
   <span style="color: #003366; font-weight: bold;">var</span> rv<span style="color: #339933;">;</span>
   <span style="color: #003366; font-weight: bold;">var</span> ph <span style="color: #339933;">=</span> Components.<span style="color: #660066;">classes</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;@mozilla.org/network/protocol;1?name=file&quot;</span><span style="color: #009900;">&#93;</span>
        .<span style="color: #660066;">createInstance</span><span style="color: #009900;">&#40;</span>Components.<span style="color: #660066;">interfaces</span>.<span style="color: #660066;">nsIFileProtocolHandler</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    rv <span style="color: #339933;">=</span> ph.<span style="color: #660066;">getURLSpecFromFile</span><span style="color: #009900;">&#40;</span>aFile<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> rv<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Check if file exists :</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> fileExists<span style="color: #009900;">&#40;</span>aPath<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
    netscape.<span style="color: #660066;">security</span>.<span style="color: #660066;">PrivilegeManager</span>.<span style="color: #660066;">enablePrivilege</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'UniversalXPConnect'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> file <span style="color: #339933;">=</span> Components.<span style="color: #660066;">classes</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;@mozilla.org/file/local;1&quot;</span><span style="color: #009900;">&#93;</span>
                         .<span style="color: #660066;">createInstance</span><span style="color: #009900;">&#40;</span>Components.<span style="color: #660066;">interfaces</span>.<span style="color: #660066;">nsILocalFile</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    file.<span style="color: #660066;">initWithPath</span><span style="color: #009900;">&#40;</span>aPath<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> file.<span style="color: #660066;">exists</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>ex<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Quit function :</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> quit <span style="color: #009900;">&#40;</span>aForceQuit<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  netscape.<span style="color: #660066;">security</span>.<span style="color: #660066;">PrivilegeManager</span>.<span style="color: #660066;">enablePrivilege</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'UniversalXPConnect'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> appStartup <span style="color: #339933;">=</span> Components.<span style="color: #660066;">classes</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'@mozilla.org/toolkit/app-startup;1'</span><span style="color: #009900;">&#93;</span>.
    <span style="color: #660066;">getService</span><span style="color: #009900;">&#40;</span>Components.<span style="color: #660066;">interfaces</span>.<span style="color: #660066;">nsIAppStartup</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// eAttemptQuit will try to close each XUL window, but the XUL window can cancel the quit</span>
  <span style="color: #006600; font-style: italic;">// process if there is unsaved data. eForceQuit will quit no matter what.</span>
  <span style="color: #003366; font-weight: bold;">var</span> quitSeverity <span style="color: #339933;">=</span> aForceQuit <span style="color: #339933;">?</span> Components.<span style="color: #660066;">interfaces</span>.<span style="color: #660066;">nsIAppStartup</span>.<span style="color: #660066;">eForceQuit</span> <span style="color: #339933;">:</span>
                                  Components.<span style="color: #660066;">interfaces</span>.<span style="color: #660066;">nsIAppStartup</span>.<span style="color: #660066;">eAttemptQuit</span><span style="color: #339933;">;</span>
  appStartup.<span style="color: #660066;">quit</span><span style="color: #009900;">&#40;</span>quitSeverity<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.usingnamespace.org/xul-useful-functions-for-file-management.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
