home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / RB3641.ZIP / EX1 / VIEWS.ST < prev   
Text File  |  1991-12-20  |  4KB  |  111 lines

  1.  
  2.       Solutions to exercises on ViewManager
  3.  
  4.       "The following expression ( evaluate with Do It ) results 
  5.       in an empty window with a single choice in action bar ( 
  6.       File -option ):"
  7.  
  8.         TopPane new open.
  9.  
  10.       "To find out where the action bar is defined, we 
  11.       have to look at the 'open' method. When you find it in that class, 
  12.       try to do it in the its superclass. It uses 'openWindow'
  13.       method, which uses 'openIn' method and 'openIn' uses 
  14.       the 'buildMenuBar' method.    
  15.  
  16.       In the last  method there is a line:"                                        
  17.     
  18.  
  19.         menuWindow addMenu: self fileMenu owner: self.
  20.  
  21.       "The 'addMenu: owner:' method of MenuWindow is used to add 
  22.       menus to the action bar. The method where the menu is 
  23.       defined in this case is 'fileMenu', which in turn calls 
  24.       'fileMenu' class method. If you select the 'class' 
  25.       radiobutton in Class Hierarchy Browser, you can see the 
  26.       final 'fileMenu' method."
  27.  
  28.       
  29.       "New subclasses a created by first selecting the parent 
  30.       class in Class Hierarchy Browser and then selecting 'Add 
  31.       Subclass...' option in 'Classes' pulldown. "
  32.  
  33.       "Create a subclass  of ViewManager (call it 'TestView').
  34.       Don't change  the default 'Indexed' and 'Contains' values!            
  35.       Before saving (Alt s) the class definition add a variable called   
  36.       PMConstants  to the poolDictionaries.                         
  37.      You can use  this new class the same way that  you use any other   
  38.       class. A new instance is created like this ( with a variable assigned 
  39.       to it ):"                                           
  40.  
  41.       "Check the TestView class is defined before DoIt !!! "
  42.  
  43.         | myView |
  44.         myView := TestView new open.
  45.  
  46.       "Did you find any error? Does the 'TestView' class have the 'open'       
  47.         method? How about its superclass?
  48.        So you need to add the 'open' method
  49.        to make an instance of the 'TestView' class. "
  50.       "The  'open' method should look something like 
  51.       this:"
  52.  
  53.         open
  54.         
  55.             self
  56.                 owner: self;
  57.                 label: 'My Window'.
  58.             self openWindow
  59.  
  60.       "You can also install  'open1.mth' file. 
  61.       or 'open2.mth' file."
  62.       "To install the those methods simply evaluate:"
  63.  
  64.         (File pathName: 'ex1\open1.mth') fileIn; close.
  65.  
  66.        "or"
  67.  
  68.        (File pathName: 'ex1\open2.mth') fileIn; close.
  69.  
  70.       "The result is just the same as in previous exercise, 
  71.       because your new class 'TestView' opens the window by using
  72.       the 'TopPane' class by default!"
  73.  
  74.       "Let's install your own menu in the window."
  75.       "The new 'myMenu' method should look like this:"
  76.  
  77.         myMenu
  78.                 "Our own menu"
  79.             ^Menu new
  80.                 appendItem: '~My Choice' selector: #myMenuMethod ;
  81.               title: '~My Menu'
  82.  
  83.       "You can also install  'mymenu.mth' file."
  84.  
  85.       "The modified 'open' method should look something like 
  86.       this:"
  87.  
  88.         open
  89.         
  90.             self
  91.                 owner: self;
  92.                 label: 'My Window'.
  93.             self openWindow
  94.         
  95.             menuWindow addMenu: self myMenu owner: self.
  96.  
  97.       "You can also evaluate the following to redefine this 
  98.       method without having to write the text above:"
  99.  
  100.         (File pathName: 'ex1\openmenu.mth') fileIn; close.       
  101.         
  102.  
  103.       "To install the 'myMenuMethod' method simply evaluate:"
  104.  
  105.         (File pathName: 'ex1\mymnmthd.mth') fileIn; close.
  106.  
  107.       "****** END OF EXERCISE ******"
  108.       
  109.  
  110.  
  111.