<?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>dotnet thoughts &#187; Gadget API</title>
	<atom:link href="http://www.dotnetthoughts.net/tag/gadget-api/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dotnetthoughts.net</link>
	<description>a dotnet developer&#039;s technical blog</description>
	<lastBuildDate>Wed, 08 Feb 2012 03:18:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.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 &#8230; <a href="http://www.dotnetthoughts.net/2010/02/24/developing-simple-windows-7-gadget-part-2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></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; title: ; notranslate">
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; title: ; notranslate">
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; title: ; notranslate">
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; title: ; notranslate">
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; title: ; notranslate">
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>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2010/03/09/developing-simple-windows-7-gadget-part-3/" title="Permanent link to Developing simple Windows 7 Gadget &#8211; Part 3">Developing simple Windows 7 Gadget &#8211; Part 3</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/02/24/developing-simple-windows-7-gadget-part-1/" title="Permanent link to Developing simple Windows 7 Gadget &#8211; Part 1">Developing simple Windows 7 Gadget &#8211; Part 1</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/11/19/how-to-create-a-windows-live-writer-plugin-using-c-part-2/" title="Permanent link to How to create a Windows Live writer plugin using C# Part 2">How to create a Windows Live writer plugin using C# Part 2</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2007/05/23/clearing-combobox-items-using-javascript/" title="Permanent link to Clearing combobox items using javascript">Clearing combobox items using javascript</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2007/05/16/set-timeout-and-clear-timeout-in-javascript/" title="Permanent link to Set timeout and Clear timeout in Javascript">Set timeout and Clear timeout in Javascript</a>  </li>
</ol></div>]]></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>
	</channel>
</rss>

