home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.1 (Developer) [x86] / NeXT Step 3.1 Intel dev.cdr.dmg / NextDeveloper / Examples / IndexingKit / ToDoList / MainDelegate.m < prev    next >
Encoding:
Text File  |  1993-02-16  |  2.8 KB  |  111 lines

  1. /*
  2. MainDelegate.m - Copyright (c) 1992 NeXT Computer, Inc.
  3.  
  4. You may freely copy, distribute and reuse the code in this example.
  5. NeXT Computer, Inc. disclaims any warranty of any kind, expressed or implied, 
  6. as to its fitness for any particular use.
  7. */
  8.  
  9. #import "MainDelegate.h"
  10. #import "ListController.h"
  11. #import "CalendarView.h"
  12. #import "DailyBread.h"
  13.  
  14. #import <indexing/indexing.h>
  15.  
  16. @implementation MainDelegate
  17.  
  18. - appDidInit:sender
  19. {
  20.     char        oldDirectory[1 + MAXPATHLEN];
  21.     unsigned            handle;
  22.     id                  storeFile;
  23.  
  24.     strcpy(appDirectory, getenv("HOME"));
  25.     chdir(appDirectory);
  26.     getwd(oldDirectory);
  27.     windows = [[HashTable alloc] initKeyDesc:"*"];
  28.     if ((mainStore = [[IXRecordManager alloc] initFromName:"ToDoList"
  29.     inFile:"ToDoList.store"forWriting:YES])) {
  30.     /* just open the ToDoList */
  31.     [mainStore getBlock:&handle andStore:&storeFile];
  32.     } else {
  33.     /* create ToDoList */
  34.     mainStore = [[IXRecordManager alloc] initWithName:"ToDoList"
  35.              inFile:"ToDoList.store"];
  36.     [mainStore getBlock:&handle andStore:&storeFile];
  37.     [mainStore addAttributeNamed:"TheDate" forSelector:@selector(theDate)];
  38.      [mainStore addAttributeNamed:"TheContent" forSelector:@selector(stringValue)];
  39.     [mainStore setParser:[[IXAttributeParser alloc] init]
  40.         forAttributeNamed:"TheContent"];
  41.  
  42.     // the following two lines enable transactions
  43.     [storeFile startTransaction];
  44.     [storeFile commitTransaction];
  45.     }
  46.  
  47.     getwd(appDirectory);
  48.     chdir(oldDirectory);
  49.     [self dateDidChange:calView];
  50.     return self;
  51. }
  52.  
  53. - recordManager
  54. {
  55.     return mainStore;
  56. }
  57.  
  58. - appWillTerminate:sender
  59. {
  60.     id                  storeFile;
  61.     unsigned            handle;
  62.  
  63.     [mainStore getBlock:&handle andStore:&storeFile];
  64.  
  65.     // this is *VERY* important to be sure the changes make it into the store. 
  66.     [storeFile commitTransaction];
  67.  
  68.     [mainStore free];
  69.     return self;
  70. }
  71.  
  72. - popChooser:sender
  73. {
  74.     [chooser makeKeyAndOrderFront:sender];
  75.     return self;
  76. }
  77.  
  78. - dateDidChange:sender
  79. {
  80.     char    *theDate;
  81.     char    *theBlank;
  82.     id        newOne;
  83.  
  84.     theDate = NXCopyStringBuffer([sender stringValue]);
  85.     if (theBlank = strchr(theDate, ' ')) *theBlank = '\0';
  86.     if ([windows isKey:theDate] == YES) {
  87.         /* pull it out of the list and pop forward. */
  88.     [(ListController *)[windows valueForKey:theDate] orderUp:self];
  89.     } else {
  90.     newOne = [[ListController alloc] initForDateString:theDate andRecordManager:mainStore];
  91.     [windows insertKey:theDate value:newOne];
  92.     }
  93.  
  94.     return self;
  95. }
  96.  
  97. - windowWillDisappear:sender
  98. {
  99.     char    theDate[64]; // date should always be less than 64 bytes
  100.     char    *theBlank;
  101.  
  102.     strcpy(theDate, [sender theDate]);
  103.     if (theBlank = strchr(theDate, ' ')) *theBlank = '\0';
  104.     if ([windows isKey:theDate] == YES)
  105.     [windows removeKey:theDate];
  106.  
  107.     return self;
  108. }
  109.  
  110. @end
  111.