XML
  Home arrow XML arrow Page 3 - An Introduction to XUL Part 5
The Best Selling PC Migration Utility.
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
IBM Developerworks
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML

An Introduction to XUL Part 5
By: Dan Wellman
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 9
    2005-06-20

    Table of Contents:
  • An Introduction to XUL Part 5
  • Buttons, JavaScript, and XPCOM
  • The nsIFilePicker interface
  • The keyset element

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Virtual Tradeshows by Ziff Davis Enterprise - A Unique Opportunity to Connect with IT Experts, Access Information, and Gain Insight on today's Technology

    An Introduction to XUL Part 5 - The nsIFilePicker interface
    (Page 3 of 4 )

    The code needed to open the dialog box that you use to select which file to open is implemented using the nsIFilePicker interface. The file open dialog will be opened when the Open button on the menu is selected, so it will need to go into a function, which will be called when the Open button is selected. Add anoncommand="openDialog();"call to the open menu element. JavaScript would normally go into a file of its own, but for this example it can sit in the XUL file. Add the opening script tag and begin the function:

    <script>
      function openDialog() {

    The first line of the code inside the function sets a variable to hold the filePicker interface:

      var nsIFilePicker = Components.interfaces.nsIFilePicker;

    You then set a second variable to hold the component and request an instance of the interface:

      var fileChooser =                                  

    Components.classes["@mozilla.org/
      filepicker;1"].createInstance(nsIFilePicker);

    Next you set a variable that initializes the open file dialog, and pass it parameters that specify its type, its title and its mode:

       fileChooser.init(window, "Select a File to open",
    nsIFilePicker.modeOpen);

    Finally, you create a variable that calls the show() method of the open file dialog, which is what displays the box on screen:

    var fileBox = fileChooser.show();

    Don’t forget to add the closing curly brace to signify the end of the function. The code required to create the Save As dialog box is extremely similar. Create the following function and note that the only differences are the title and mode of the initialization variable:

    function saveDialog() {
      var nsIFilePicker = Components.interfaces.nsIFilePicker;
      var fileChooser =
        Components.classes["@mozilla.org/
        filepicker;1"].createInstance(nsIFilePicker);
     
    fileChooser.init(window, "Select a Location to save",
        nsIFilePicker.modeSave);
      var fileBox = fileChooser.show();

    Close off the script tag and save the file as opensave.xul in the same location as the rdf file describing it. Open the file from inside Mozilla using its chrome url and you should get your simple menu bar and simple menu. Selecting the Open will open the Select a File to open dialog box, and selecting Save will open the Select a Location to save dialog box.  The functionality to actually open or save files requires far more code and won’t be discussed here. Once you’re done, choose close on your menu and Mozilla should exit.

    More XML Articles
    More By Dan Wellman


     

       

    XML ARTICLES

    - How to Set Up Podcasting and Vodcasting
    - Creating an RSS Reader Application
    - Building an RSS File
    - An Introduction to XUL Part 6
    - An Introduction to XUL Part 5
    - An Introduction to XUL Part 4
    - An Introduction to XUL Part 3
    - An Introduction to XUL Part 2
    - An Introduction to XUL Part 1
    - XML Matters: Practical XML Data Design and M...
    - Practical XML Data Design and Manipulation f...
    - SimpleXML
    - XForms Basics, Part 3
    - XForms Basics, Part 2
    - XForms Basics




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway