home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / RB3641.ZIP / EX2 / TODOLIST.CLS < prev    next >
Text File  |  1991-12-18  |  3KB  |  120 lines

  1.  
  2. OrderedCollection subclass: #ToDoList
  3.   instanceVariableNames: 
  4.     'sortKey '
  5.   classVariableNames: ''
  6.   poolDictionaries: ''    !
  7.  
  8.  
  9. !ToDoList class methods !
  10.  
  11. template
  12. "12/12 update"
  13.         "Give a template"
  14.     | tempItem tmpList|
  15.       tempItem:= ToDoItem new.
  16.                    tempItem type: 'Personal'.
  17.                 tempItem deadline: '99.12.31'.
  18.                 tempItem description: 'Celebrate!!'.
  19.                 "tempItem priority: 'High'."
  20.                 tempItem priority: 1.
  21.                 tempItem completed: false.
  22.         tmpList:=OrderedCollection new.
  23.         tmpList add: tempItem .
  24.  ^(self replaceFrom:1 to:(self size) with: tmpList)! !
  25.  
  26.  
  27.  
  28. !ToDoList methods !
  29.  
  30. addItem: anItem
  31.  
  32.     "Add the item to the list.  "
  33.  
  34.     self add: anItem .
  35.     self sortList. 
  36.      ^self.!
  37.    
  38. readList
  39.  
  40.     "Read the ToDo list from disk.
  41.      The list is stored as a binary data using the 
  42.      ObjectFiler. so a new collection
  43.     can be built by loading the contents of the file 
  44.      by using the ObjectFiler.
  45.      This method is used in two places:
  46.     - when ToDo application window is opened.
  47.     - when Open is selected in File-pulldown. "
  48.  
  49.     | input tmpList testItem |
  50.  
  51.     input := Disk file: 'TODOFILE.OBJ'.
  52.     input close.
  53.     input := Disk file: 'TODOFILE.OBJ'.
  54.     ((input contents) = '') ifTrue: [            
  55.                 tmpList := OrderedCollection new.
  56.                 testItem := ToDoItem new.
  57.                 testItem type: 'Personal'.
  58.                 testItem deadline: '99.12.31'.
  59.                 testItem description: 'Celebrate!!'.
  60.                 "testItem priority: 'High'."
  61.                 testItem priority: 1.
  62.                 testItem completed: false.
  63.                 5 timesRepeat: [ tmpList add: testItem ].    
  64.     ]
  65.     ifFalse: [
  66.         tmpList := ObjectFiler loadFromPathName: 'TODOFILE.OBJ'.
  67.     ].
  68.     input close.
  69.  
  70.  ^(self replaceFrom:1 to:(self size) with: tmpList)!
  71.  
  72. removeAll
  73.       " Remove the contents of the ToDoList"
  74.  
  75.        ^( super removeAll: self ) .!
  76.  
  77. removeItem:anItemIndex
  78.  
  79.     "Remove an item.  "
  80.  
  81.      super removeIndex: anItemIndex .
  82.  
  83.     ^self.!
  84.    
  85. sortList
  86.  
  87.     "Resort the list of items and return the list. "
  88.  
  89.       | tempList returnList |
  90.  
  91.       ( sortKey isNil ) 
  92.                 ifTrue: [ sortKey := 'priority'].
  93.  
  94.       ( self size  > 0 )
  95.              ifTrue: [ tempList := self asSortedCollection:
  96.                                     [ :a :b | a compareTo: b using: sortKey ] .
  97.                           self replaceFrom:1 to: (self size) with: tempList.
  98.                             ].
  99.       ^ self.!
  100.  
  101. sortList: aSortKey
  102.  
  103.     "Update the sortKey "
  104.  
  105.         sortKey := aSortKey .
  106.         ^ self.!
  107.   
  108. updateItem:anItem at:anIndex
  109.  
  110.     "Change an item in the list.  "
  111.  
  112.     self at: anIndex  put: anItem .
  113.     self sortList.
  114.     ^self.!
  115.  
  116. writeList
  117.     "Write the ToDo list on disk. "
  118.  
  119.     ObjectFiler dump: self newFile: 'TODOFILE.OBJ'.! !
  120.