Get Down and Glitzy With Gadgets (Continued)
You can debug your gadget's code by going to Tools | Options in Internet Explorer and enabling script debugging. The exact options vary, but the options IE7 provides are typical (Figure 6).
No doubt, some of you are saying: Script!? I hate script; I don't want to debug script!
I don't blame you. Fortunately, you can create an assembly, instantiate it, and use that to perform your debugging. Find the point in your code that you want to debug, and then add a debugger statement (Stop in VB script). When that line executes, you are asked which app you want to debug with. I used the current instance of Visual Studio (the instance that I have the source code open in) for my debugging, but you can use whatever debugger makes you feel comfortable. From this point, you debug your gadget as you would any other application.
You have two more steps you must complete before you can declare your application finished: It must be able to use different language sets and it must be packaged for distribution. Enabling localization for the gadget requires that you add a few more folders under you gadget folder. For the standard English version, you add an en-us folder, and place your English language files in it. The only files that must go there are the HTML and gadget files—those are the files with language-specific words. Where you place your script files, style-sheets, or images is a matter of preference. If your images and icons are the same for each language, then it's likely that you will want to keep them out of the main gadget folder and share them for different languages. If you have graphics specific to a particular language, you will need to keep them in a language-specific folder. Be sure to update your file paths to reflect the new location of your files if you move them after getting everything working.
You're now ready to wrap up and distribute your gadget to the world. Doing so is easy. The distribution file is a gadget file—myweather.gadget, in this case. The good thing is that a gadget file is a normal zip file, with the extension changed. You add all of your files, with the folder structure intact into a zip file. Change the extension from .zip to .gadget, and you are finished. Note that when you create the zip/gadget file, you don't include your folder, myweather.gadget. Vista takes care of creating the folder appropriate for your gadget and puts the files from the zip file in the correct folder.
Once a user installs your gadget, the source files used to create it are installed into the Windows Sidebar\Gadgets folder, just as they appear on your development machine. That means that whatever you put into your gadget, anybody can see and get out. In fact, if you download any gadget and install it, you can see the files and look at how they did something that you might find useful. If you want to see the code for the default Vista gadgets, go to Program Files\Windows Sidebar\Gadgets. The HTML, .js, and XML files are all there for you to look at, learn from, and enjoy.
About the Author
Dan Fergus is the principal technologist at Forest Software Group, which provides consulting and contracting services to companies throughout the United States. He is a Device Application Development MVP, a trainer, and the co-author of The Definitive Guide to the .NET Compact Framework. Dan has also written many articles, is a frequent speaker at conferences and user groups, and is a contributing editor for Visual Studio Magazine. Contact him at danf@forestsoftwaregroup.com.
Back to top
|