home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / OPENSTEP / Utilities / Comics-1.0-MIS / VerifyController.m < prev   
Encoding:
Text File  |  1997-09-25  |  4.2 KB  |  139 lines

  1. /*
  2.  File:       VerifyController.m
  3.  
  4.  Contains:   Source code for the Controller of the "Verify" window
  5.  
  6.  Written by: Eric Simenel
  7.  
  8.  Created:    May 1997
  9.  
  10.  Copyright:  (c)1997 by Apple Computer, Inc., all rights reserved.
  11.  
  12.  Change History (most recent first):
  13.  
  14.  You may incorporate this sample code into your applications without
  15.  restriction, though the sample code has been provided "AS IS" and the
  16.  responsibility for its operation is 100% yours.  However, what you are
  17.  not permitted to do is to redistribute the source as "DSC Sample Code"
  18.  after having made changes. If you're going to re-distribute the source,
  19.  we require that you make it clear in the source that the code was
  20.  descended from Apple Sample Code, but that you've made changes.
  21. */
  22.  
  23. #import "VerifyController.h"
  24. #import "BrowserController.h"
  25. #import "CalendarController.h"
  26. #import "TitleLongevityController.h"
  27. #import "ComicsObj.h"
  28.  
  29. @implementation VerifyController
  30.  
  31. // private helper method: update the UI when the data array has changed
  32. - (void)_update
  33. {
  34.     [verifyView noteNumberOfRowsChanged];
  35.     [verifyView reloadData];
  36. }
  37.  
  38. - (void)selChanged
  39. {
  40.     // get the right array of titles
  41.     [comicsBase sortArray:array withBrand:brand withSeries:series withKind:kind withState:state withSort:sort];
  42.     nbRows = [array count];
  43.     [nbSelTitles setIntValue:nbRows];
  44.     [self _update];
  45. }
  46.  
  47. - (void)brandSelect:(id)sender
  48. {
  49.     short newBrand = [sender indexOfSelectedItem];
  50.     if (newBrand != brand) { brand = newBrand; [self selChanged]; }
  51. }
  52. - (void)kindSelect:(id)sender
  53. {
  54.     short newKind = [sender indexOfSelectedItem];
  55.     if (newKind != kind) { kind = newKind; [self selChanged]; }
  56. }
  57. - (void)seriesSelect:(id)sender
  58. {
  59.     short newSeries = [sender indexOfSelectedItem];
  60.     if (newSeries != series) { series = newSeries; [self selChanged]; }
  61. }
  62. - (void)stateSelect:(id)sender
  63. {
  64.     short newState = [sender indexOfSelectedItem];
  65.     if (newState != state) { state = newState; [self selChanged]; }
  66. }
  67. - (void)sortSelect:(id)sender
  68. {
  69.     short newSort = [sender indexOfSelectedItem];
  70.     if (newSort != sort) { sort = newSort; [self selChanged]; }
  71. }
  72.  
  73. - (id)init
  74. {
  75.     if (self = [super init])
  76.       {
  77.         nbRows = 0;
  78.         brand = 0;
  79.         series = 0;
  80.         kind = 0;
  81.         state = 0;
  82.         sort = 0;
  83.         // I have a lttle less than 1500 titles currently, hence the following capacity...
  84.         array = [[NSMutableArray alloc] initWithCapacity:1500];
  85.         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(comicsChanged:) name:ComicsDidChangeNotification object:nil];
  86.       }
  87.     return self;
  88. }
  89. - (void)comicsChanged:(NSNotification *)note
  90. {
  91.     [nbIssues setIntValue:[comicsBase nbIssues]];
  92.     [nbTitles setIntValue:[comicsBase nbTitles]];
  93.     [self selChanged];
  94. }
  95. - (void)dealloc
  96. {
  97.     [[NSNotificationCenter defaultCenter] removeObserver:self name:ComicsDidChangeNotification object:nil];
  98.     [array release];
  99.     [super dealloc];
  100. }
  101. - (void)awakeFromNib
  102. {
  103.     [self comicsChanged:nil];
  104. }
  105.  
  106. // Since numberOfRowsInTableView is called a ZILLION times by the NSTableView object methods,
  107. // do the number of rows calculation in selChanged, and save off the value in the nbRows field
  108. // so that I can just return the value.
  109. - (int)numberOfRowsInTableView:(NSTableView *)tableView
  110. {
  111.     return nbRows;
  112. }
  113.  
  114. - (id)tableView:(NSTableView *)tv objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row
  115. {
  116.     CTitle *thisTitle = [array objectAtIndex:row];
  117.     NSString *identifier = [tableColumn identifier];
  118.  
  119.     if ([identifier isEqualToString:@"Abb"])
  120.         return [thisTitle abb];
  121.     else if ([identifier isEqualToString:@"Title"])
  122.         return [thisTitle title];
  123.     else return [thisTitle listIssues];
  124. }
  125.  
  126. // loading subprojects
  127. - (void)newBrowser:(id)sender { [[BrowserController alloc] init]; }
  128. - (void)newCalendar:(id)sender { [[CalendarController alloc] init]; }
  129. - (void)newTitleLongevity:(id)sender { [[TitleLongevityController alloc] init]; }
  130.  
  131. // NSApp delegate: ask the InputController if the comics database has been modified or not,
  132. // and if the user has then saved it or not or cancelled the quit process.
  133. - (BOOL)applicationShouldTerminate:(id)sender
  134. {
  135.     return [inputWindow windowShouldClose:nil]?YES:NO;
  136. }
  137.  
  138. @end
  139.