Water 5-Getting Started and Examples-Level 2 Examples
WaterPad Example using Water Rich UI
Version 1.4   By Andrew Roach
     Runs under v5.0 alpha i20050508 
     Creates simple text editor that allows to you edit, save the files
     you've created to disk and retrieve them for further editing.
     Uses Water Rich UI for making the user interface components.

 
<class WaterPad height=280 width=640 count=0>

 <method make>
 <!--  .<set thetextarea = ui.<textarea /> />  fry sez: this is never used -->
  .<set thetabs = ui.<tabs /> />
  <set my_app = _subject/>
  ui.<window name=<join ._name " " ._parent.<increment "count"/> />
         width=.width height=.height
  >
   ui.<menubar>
    ui.<menu name="File">
     ui.<menuitem name="New"
       click=<method null> my_app.<new/> </> />
     ui.<menuitem name="Open..."
       click=<method null> my_app.<open/> </> />
     ui.<menuitem name="Save As..."
       click=<method null> my_app.<save/> </> />
     ui.<menuitem name="Close tab"
       click=<method null> my_app.<close/> </> />
    </menu>
   </menubar>
   .thetabs
  </window>
  .<new />
  _subject
 </method>
 
 <method close>
   <echo "in close" .thetabs.selected_index />
   .thetabs.<remove .thetabs.selected_index/>
 </method>
 

 <method new>
    .thetabs.<insert ui.<scroll name=<join "T" .thetabs.<length/> />> 
                           ui.<textarea name="theTextArea"/>
                     </scroll>/>
    .thetabs.<set selected_index = "right" />
 </method>

 <method open>
    <set thefilename = ui.<show_file_dialog /> />
    <if> thefilename.<length/>.<more 0/> <do>
          .thetabs.<insert ui.<scroll <ui.<textarea name="theTextArea" />  /> 
                  name=.<filename_to_tabname thefilename.0/> /> />
          .thetabs.right.theTextArea.<set the_value=<resource a_uri=thefilename.0 />.content />
          .thetabs.<set selected_index = "right" />
          </do>
    </if>
 </method>
 
 <method save>
    <set thefilename = ui.<show_file_dialog /> />
    <if> thefilename.<length/>.<more 0/> <do>
          <set currentTab = .thetabs.selected_index />
          <resource a_uri=thefilename.0 />.<set content = .thetabs.<get currentTab />.theTextArea.the_value />
          .thetabs.<rename <do .<filename_to_tabname thefilename.0/>/>=.thetabs.<get currentTab/>.name/>
          </do>
    </if>
 </method>

  <method filename_to_tabname filename=req=string _return_type=string>
    <set begin_pos=filename.<key_of <char "/"/> returns="last"/>
           end_pos=filename.<key_of <char "."/> returns="last"/> >
     <if> begin_pos.<is false/> <set begin_pos=0/>
          else                  <set begin_pos=begin_pos.<plus 1/>/>
     </if>
     <if>end_pos.<is false/> <set end_pos=filename.<length/>/></if>
     filename.<subvector begin_pos end_pos/>
   </set>
  </method>
</class>

<WaterPad height=600/>
<doc on=WaterPad >

 <PRE>Version 1.4   By Andrew Roach
     Runs under v5.0 alpha i20050508 
     Creates simple text editor that allows to you edit, save the files
     you've created to disk and retrieve them for further editing.
     Uses Water Rich UI for making the user interface components.

     5/18/05  Roach     Added filedialog
     5/18/05  Fry       Cleaned up code
     5/26/05  Plusch    "Modularized" to put everything in Waterpad class
                        allows multiple application instances
     5/27/05  Roach     Added tabs 
     5/27/05  Fry       Made tabs work by
                        - fixing system software
                        - using "rename" to set tab name
                        - using new method filename_to_tabname to make short,
                             reaonable tab names without punctuation chars
 </PRE>
</doc>