XML
  Home arrow XML arrow Page 5 - Back to XUL: Completing the JavaScript Log...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 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

Back to XUL: Completing the JavaScript Logic
By: Dan Wellman
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2006-02-13

    Table of Contents:
  • Back to XUL: Completing the JavaScript Logic
  • Defining a Function
  • The Help Menu
  • The About Window
  • Making the Toolbar Work
  • Finishing up the Functions

  • 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


    Back to XUL: Completing the JavaScript Logic - Making the Toolbar Work


    (Page 5 of 6 )

    For some of the buttons that will simply mean adding a call to functions that we have already defined.  The Open and Save buttons can be enabled in this way. Just add oncommand handlers to the buttonOpen and buttonSave toolbarbuttons:

    <toolbarbutton id="buttonOpen" image="open.gif"
    tooltiptext="&openLabel;" oncommand="openFileDialog()"/>

    <toolbarbutton id="buttonSave" image="save.gif"
    tooltiptext="&saveLabel;" oncommand="saveFileDialog()"/>

    Next is the New file button; for this, we simply call the closeFile() function that we have already defined.

    Now for the buttons that add the XUL elements onto the document.  A simple document.write() call will not work in the context of an editor. What you need to do is get the editor (returned in the nsIPlaintextEditor interface) and call the insertText() method on it. 

    You also need to consider the number of strings that you want to insert into the document.  We have a total of thirteen elements that we are able to insert using the editor button bar, so the simplest way we could achieve it would be to add thirteen functions, that each inserted one element.  This would mean rather a lot of code, however, and it can be cut down using parameter passing; with each menuitem of the button bar passing a parameter into one main function, and then using an if statement to decide which string to insert, based on the parameter passed in. 

    Due to possibly a quirk of XPCOM or XUL, you cannot pass parameters to functions in the normal JavaScript way.  When you do this, the function expects a BarProp object instead of a normal string.  This is a special type of object used by Gecko to expose the visibility states of interface items.  There are only six BarProps defined (well, there are seven actually, but for some unknown reason one cannot be used) at this point, so our insert() function is only going to be able to take one of six different parameters passed by the menuitems.  In total then, we need three functions to handle our thirteen strings:

    function insert(str) {

    You first define the function and the parameter it is going to accept.  Next, define the text strings to be inserted into the document:

      var str1 = '<menubar id="">  </menubar>';
      var str2 = '<toolbar id="">  </toolbar>';
      var str3 = '<toolbarbutton id="">  </toolbarbutton>';
      var str4 = '<menuseparator/>';
      var str5 = '<textbox id=""/>';
      var str6 = '<listbox id="">  <listitem label=""/>  </listbox>';

    We now get the Editor element in the required interface:

      var editor = document.getElementById('mainContent');
      editor = editor.getEditor(editor.contentWindow).QueryInterface
    (Components.interfaces.nsIPlaintextEditor);

    Finally, set up the if statement that inserts the text string based on the parameter and close the function:

      if (str == menubar) {
        editor.insertText(str1);
      } else if (str == toolbar) {
        editor.insertText(str2);
      } else if (str == directories) {
         editor.insertText(str3);
      } else if (str == locationbar) {
        editor.insertText(str4);
      } else if (str == statusbar) {
        editor.insertText(str5);
      } else if (str == scrollbars) {
        editor.insertText(str6);
      }

    }

    More XML Articles
    More By Dan Wellman


       · Hi,This article follows on neatly from the last and shows you the code needed to...
     

    XML ARTICLES

    - Datatypes and More in RELAX NG
    - Providing Options in RELAX NG
    - An Introduction to RELAX NG
    - Path, Predicates, and XQuery
    - Using Predicates with XQuery
    - Navigating Input Documents Using Paths
    - XML Basics
    - Introduction to XPath
    - Simple Web Syndication with RSS 2.0
    - Java UI Design with an IDE
    - UI Design with Java and XML Toolkits
    - Displaying ADO Retrieved Data with XML Islan...
    - Widget Walkthrough
    - Introduction to Widgets
    - The Why and How of XML Data Islands






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