<?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>Dot Net Thoughts &#187; Sidebar Gadget</title>
	<atom:link href="http://www.dotnetthoughts.net/tag/sidebar-gadget/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dotnetthoughts.net</link>
	<description>thoughts about .Net, WPF, Sharepoint, Javascript and more.</description>
	<lastBuildDate>Wed, 01 Sep 2010 09:53:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Developing simple Windows 7 Gadget &#8211; Part 2</title>
		<link>http://www.dotnetthoughts.net/2010/02/24/developing-simple-windows-7-gadget-part-2/</link>
		<comments>http://www.dotnetthoughts.net/2010/02/24/developing-simple-windows-7-gadget-part-2/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 18:05:39 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Windows 7]]></category>
		<category><![CDATA[Gadget]]></category>
		<category><![CDATA[Gadget API]]></category>
		<category><![CDATA[Sidebar Gadget]]></category>
		<category><![CDATA[Windows Vista]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=787</guid>
		<description><![CDATA[In my last post I have created a simple Windows 7 Gadget for testing Regular expressions. In this post we look into the Gadget Options dialog and Gadget API, which helps to display the options dialog and save the preferences from the User. The options dialog is a nice feature used in Gadgets to manage [...]]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://www.dotnetthoughts.net/2010/02/24/developing-simple-windows-7-gadget-part-1/">last post </a>I have created a simple Windows 7 Gadget for testing Regular expressions. In this post we look into the Gadget Options dialog and Gadget API, which helps to display the options dialog and save the preferences from the User. The options dialog is a nice feature used in Gadgets to manage the user preferences. It is also an HTML file. Unlike the main Gadget HTML file, which is specified in the XML Definition file, the Options HTML File is specified in the main gadget file or in the main Javascript file, generally in the gadget initialization area of your script. In the RegEx Tester example, I am using the RegEx function flags as customization options.</p>
<div id="attachment_790" class="wp-caption alignnone" style="width: 240px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2010/02/settings_clicked.png"><img class="size-full wp-image-790" title="RegEx Tester Settings " src="http://www.dotnetthoughts.net/wp-content/uploads/2010/02/settings_clicked.png" alt="RegEx Tester Settings " width="230" height="327" /></a><p class="wp-caption-text">RegEx Tester Settings</p></div>
<p>So I have created an HTML File with 3 checkboxes and wrote a javascript function to get the user selected options, create the flags variable, and when closing the Options dialog, save the user preferences. To create the settings or options dialog, set the SettingsUI property.  </p>
<pre class="brush: jscript;">
System.Gadget.settingsUI = &quot;settings.html&quot;;
</pre>
<p>After setting the SettingsUI property, the Gadget will display a Options button in the Gadget handle.</p>
<div id="attachment_789" class="wp-caption alignnone" style="width: 240px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2010/02/RegExTester_Settings.png"><img src="http://www.dotnetthoughts.net/wp-content/uploads/2010/02/RegExTester_Settings.png" alt="Settings Button" title="Settings Button " width="230" height="280" class="size-full wp-image-789" /></a><p class="wp-caption-text">Settings Button </p></div>
<p>The Gadget API also supports various events / callback functions for the Options dialog, like SettingsClosing, SettingsClosed etc, which helps to save the Preferences and Read the preferences in the Gadget.</p>
<pre class="brush: jscript;">
System.Gadget.onSettingsClosed = settingsClosed;
function settingsClosed(event) {
	//OK Button clicked.
if (event.closeAction == event.Action.commit) {
	//Load settings here.
}
}
</pre>
<p>Gadget API supports various methods to read and write settings. For writing setting we can use System.Gadget.Settings.write or System.Gadget.Settings.writeString. Both the functions will expects a key/value pair. And for reading can use System.Gadget.Settings.read or System.Gadget.Settings.readString, both of these functions take a key and return a value. If the key does not exist (for instance if it has never been written) both will return a value of undefined. Use System.Gadget.Settings.xxxxString method, if you are working with string values. All the settings are stored in Settings.ini file. And it is available in the &#8220;C:\Users\\AppData\Local\Microsoft\Windows Sidebar&#8221; location.<br />
Saving the preferences</p>
<pre class="brush: jscript;">
System.Gadget.Settings.write(&quot;RegExOptionsSaved&quot;, &quot;true&quot;);
System.Gadget.Settings.write(&quot;RegExOption&quot;, escape(result));
</pre>
<p>And reading the Preferences </p>
<pre class="brush: jscript;">
if (System.Gadget.Settings.read(&quot;RegExOptionsSaved&quot;)) {
regExOptions = unescape(System.Gadget.Settings.read(&quot;RegExOption&quot;));
}
</pre>
<p><strong>RegEx Object constructor</strong> </p>
<pre class="brush: jscript;">
var re = new RegEx(&quot;Pattern&quot;,&quot;Flags&quot;);
</pre>
<p>And the Flags are</p>
<ol>
<li>
Global Search &#8211; g &#8211; The global search flag makes the RegExp search for a pattern throughout the string, creating an array of all occurrences it can find matching the given pattern.</li>
<li>Ignore Case &#8211; i &#8211; The ignore case flag makes a regular expression case insensitive. For international coders, note that this might not work on extended characters such as å, ü, ñ, æ.</li>
<li>Multiline Input &#8211; m &#8211; This flag makes the beginning of input (^) and end of input ($) codes also catch beginning and end of line respectively.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2010/02/24/developing-simple-windows-7-gadget-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Developing simple Windows 7 Gadget &#8211; Part 1</title>
		<link>http://www.dotnetthoughts.net/2010/02/24/developing-simple-windows-7-gadget-part-1/</link>
		<comments>http://www.dotnetthoughts.net/2010/02/24/developing-simple-windows-7-gadget-part-1/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 14:50:19 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Windows 7]]></category>
		<category><![CDATA[Gadget]]></category>
		<category><![CDATA[RegEx]]></category>
		<category><![CDATA[Regular Expressions]]></category>
		<category><![CDATA[Sidebar Gadget]]></category>
		<category><![CDATA[Windows Vista]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=777</guid>
		<description><![CDATA[Gadgets are simple and lightweight applications, which can be developed using HTML, Javascript and CSS. Gadgets can also include Image files. In Windows Vista, we can create Gadgets by zipping the files, and rename the it with .Gadget extension. In Windows 7 we can create Gadget by creating the .Gadget folder in C:\Program Files\Windows Sidebar\Gadgets\ [...]]]></description>
			<content:encoded><![CDATA[<p>Gadgets are simple and lightweight applications, which can be developed using HTML, Javascript and CSS. Gadgets can also include Image files. In Windows Vista, we can create Gadgets by zipping the files, and rename the it with .Gadget extension. In Windows 7 we can create Gadget by creating the .Gadget folder in C:\Program Files\Windows Sidebar\Gadgets\ folder. This folder contains all the default gadgets from Microsoft.</p>
<p><strong>Creating Simple RegEx Tester Gadget</strong></p>
<p>Regular Expressions are complex but efficient technique for processing text. And the RegEx functions are available in Javascript. So I am to creating simple regex tester gadget using Javascript. You can find a simple RegEx Tester using Javascript here : <a href="http://www.regular-expressions.info/javascriptexample.html" target="_blank">http://www.regular-expressions.info/javascriptexample.html</a>.</p>
<p>For creating a Gadget we require a XML Definition file, which contains the details about the Gadget File, Links to Icons, and Copyright information. Here is skeleton a XML Definition file.</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
&lt;gadget&gt;
&lt;name&gt;RegExTester&lt;/name&gt;
&lt;namespace&gt;dotnetthoughts&lt;/namespace&gt;
&lt;version&gt;1.0.0.0&lt;/version&gt;
&lt;author name=&quot;dotnetthoughts&quot;&gt;
&lt;info url=&quot;http://dotnetthoughts.net&quot; text=&quot;www.dotnetthoughts.net&quot; /&gt;
&lt;logo src=&quot;logo.png&quot; /&gt;
&lt;/author&gt;
&lt;copyright&gt;&amp;#0169; 2010&lt;/copyright&gt;
&lt;description&gt;For Testing Regular Expressions&lt;/description&gt;
&lt;icons&gt;
&lt;icon width=&quot;64&quot; height=&quot;64&quot; src=&quot;icon.png&quot; /&gt;
&lt;/icons&gt;
&lt;hosts&gt;
&lt;host name=&quot;sidebar&quot;&gt;
&lt;base type=&quot;HTML&quot; apiVersion=&quot;1.0.0&quot; src=&quot;RegExTester.html&quot; /&gt;
&lt;permissions&gt;full&lt;/permissions&gt;
&lt;platform minPlatformVersion=&quot;0.3&quot; /&gt;
&lt;/host&gt;
&lt;/hosts&gt;
&lt;/gadget&gt;
</pre>
<p>And the Tags details are</p>
<p>name: Title of your gadget.<br />
version: Version number of your gadget.<br />
author: Your name or your company’s name.<br />
info url: Web site address.<br />
info text: Friendly name for your Web site.<br />
logo src: Name of company’s logo image file.<br />
copyright: Copyright notice.<br />
description: Description of the gadget.<br />
icon src: Name of icon image file for the gadget.<br />
base src: Name of gadget’s main HTML file.</p>
<div id="attachment_780" class="wp-caption alignnone" style="width: 469px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2010/02/details.png"><img class="size-full wp-image-780" title="Gadget Details." src="http://www.dotnetthoughts.net/wp-content/uploads/2010/02/details.png" alt="Gadget Details." width="459" height="300" /></a><p class="wp-caption-text">Gadget Details.</p></div>
<p>Save this file as Gadget.xml. Next we need to create the RegExTester.html, which is the main file, nothing but simple HTML file with some UI components.</p>
<pre class="brush: xml;">

&lt;html&gt;
&lt;head&gt;
&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;style.css&quot; /&gt;
&lt;script type=&quot;text/vbscript&quot; src=&quot;message.vbs&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;regexcheck.js&quot;&gt;&lt;/script&gt;
&lt;title&gt;RegEx Tester&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form&gt;
&lt;table border=&quot;1&quot; cellpadding=&quot;1&quot; cellspacing=&quot;5&quot; bordercolor=&quot;red&quot;&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;&lt;u&gt;RegEx Tester&lt;/u&gt;&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;label&gt;Regular Expression&lt;/label&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;textarea id=&quot;txtRegExp&quot; cols=&quot;25&quot; rows=&quot;4&quot;&gt;&lt;/textarea&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;label&gt;Subject String&lt;/label&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;textarea id=&quot;txtSubject&quot; cols=&quot;25&quot; rows=&quot;4&quot;&gt;&lt;/textarea&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;button onclick=&quot;javascript:demoMatchClick();&quot;&gt;Test Match&lt;/button&gt;&amp;nbsp;&amp;nbsp;
&lt;button onclick=&quot;javascript:demoShowMatchClick();&quot;&gt;Show Match&lt;/button&gt;&lt;/td&gt;&lt;/tr&gt; &lt;/table&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>You may noticed that I have included a message.vbs file, it helps to display alert() boxes from Javascript. I don&#8217;t know why alert and prompt functions are not available in Gadgets. Also we don&#8217;t need to worry about cross platform compatibility issues in Gadgets, we can write anything supported by Microsoft Internet Explorer.</p>
<p>Here is the code of Message.vbs file.</p>
<pre class="brush: vb;">
sub alert(prompt)
MsgBox prompt, 48 , &quot;RegEx Tester&quot;
end sub
</pre>
<p>And here is the contents of regexcheck.js file.</p>
<pre class="brush: jscript;">
function demoMatchClick() {
var regExCtrl = document.getElementById(&quot;txtRegExp&quot;);
var subjectCtrl = document.getElementById(&quot;txtSubject&quot;);
var re = new RegExp(regExCtrl.value);
if (subjectCtrl.value.match(re)) {
	alert(&quot;Successful match&quot;);
} else {
	alert(&quot;No match&quot;);
}
}
function demoShowMatchClick() {
var regExCtrl = document.getElementById(&quot;txtRegExp&quot;);
var subjectCtrl = document.getElementById(&quot;txtSubject&quot;);
var re = new RegExp(regExCtrl.value);
var m = re.exec(subjectCtrl.value);
if (m == null) {
	alert(&quot;No match&quot;);
} else {
	var s = &quot;Match at position &quot; + m.index + &quot;:\n&quot;;
	for (i = 0; i &lt; m.length; i++) {
		s = s + m[i] + &quot;\n&quot;;
	}
	alert(s);
}
}
</pre>
<p>Also I added a CSS file for styling the components. Also to specify the Height and Width of the Gadget. In Windows Vista, we need to limit the size of the Gadget, because the Gadget can only place in the Sidebar, but in Windows 7 we can place the Gadget anywhere in the desktop. Also I have added icon.png and logo.png files, as specified in the XML definition file.<br />
The current folder structure is like this.</p>
<div id="attachment_781" class="wp-caption alignnone" style="width: 600px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2010/02/folder_struct.png"><img class="size-full wp-image-781" title="Folder Structure" src="http://www.dotnetthoughts.net/wp-content/uploads/2010/02/folder_struct.png" alt="Folder Structure" width="590" height="166" /></a><p class="wp-caption-text">Folder Structure</p></div>
<p>Now using any compression tool, compress the files, and Rename it as RegExTester.Gadget. Double click on the Gadget file, Windows will ask for a confirmation.</p>
<div id="attachment_779" class="wp-caption alignnone" style="width: 424px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2010/02/confirm.png"><img class="size-full wp-image-779" title="Gadget install Confirmation" src="http://www.dotnetthoughts.net/wp-content/uploads/2010/02/confirm.png" alt="Gadget install Confirmation" width="414" height="266" /></a><p class="wp-caption-text">Gadget install Confirmation</p></div>
<p>Click Install. It will start the Gadget. Here is the screenshot of RegExTester gadget running on my Windows 7 machine.</p>
<div id="attachment_782" class="wp-caption alignnone" style="width: 240px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2010/02/RegExTester_Running.png"><img class="size-full wp-image-782" title="RegExTester Running on Windows 7" src="http://www.dotnetthoughts.net/wp-content/uploads/2010/02/RegExTester_Running.png" alt="RegExTester Running on Windows 7" width="230" height="280" /></a><p class="wp-caption-text">RegExTester Running on Windows 7</p></div>
<p>This is an introduction only, I will try to post about Gadget API, Gadget Settings etc in the next post.</p>
<p>Happy Coding <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2010/02/24/developing-simple-windows-7-gadget-part-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
