home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Examples / AppKit / Yap / Controller.m < prev    next >
Text File  |  1996-08-30  |  3KB  |  112 lines

  1. /*
  2.  *  Controller.m
  3.  *  Author: Ali Ozer
  4.  *  Created: Mar 89 for 0.9 (YapApp.m)
  5.  *  Modified: Jul & Aug 89 for 1.0
  6.  *  Modified: Aug 90 for 2.0
  7.  *  Modified: Apr & Jun 91 for 3.0. Localized Jan 92.
  8.  *  Modified: Jan 96 for 4.0
  9.  *
  10.  *  Controller is the central controller class for Yap. It coordinates
  11.  *  the output and document windows, opens documents, responds to external requests, ...
  12.  *
  13.  *  You may freely copy, distribute and reuse the code in this example.
  14.  *  NeXT disclaims any warranty of any kind, expressed or implied,
  15.  *  as to its fitness for any particular use.
  16.  */
  17.  
  18. #import <AppKit/AppKit.h>
  19. #import "Controller.h"
  20. #import "YapDocument.h"
  21. #import "Preferences.h"
  22. #import "YapOutput.h"
  23.  
  24. @implementation Controller
  25.  
  26. /* Make sure all documents are saved before actually terminating the app...
  27. */
  28. - (BOOL)applicationShouldTerminate:(NSApplication *)app {
  29.     if (![YapDocument closeAllDocuments]) return NO;
  30.     [Preferences saveDefaults];
  31.     return YES;
  32. }
  33.  
  34. /* Set up some initial state for the output window.
  35. */
  36. - (void)applicationWillFinishLaunching:(NSNotification *)notification {
  37.     [[self outputView] updateSizeFromPreferences];
  38.     [[[self outputView] window] setFrameAutosaveName:@"Output Window"];
  39.     [[[self outputView] window] setMenu:nil];
  40.     [[[self outputView] window] setExcludedFromWindowsMenu:YES];
  41. }
  42.  
  43. - (BOOL)application:(NSApplication *)sender openFile:(NSString *)filename {
  44.     YapDocument *document = [YapDocument newWithPath:filename];
  45.     if (document) [document setOutputView:[self outputView]];
  46.     return document ? YES : NO;
  47. }
  48.  
  49. - (BOOL)application:(NSApplication *)sender openTempFile:(NSString *)filename {
  50.     return [self application:sender openFile:filename];
  51. }
  52.  
  53. - (BOOL)applicationOpenUntitledFile:(NSApplication *)sender {
  54.     YapDocument *newDocument = [YapDocument newUntitled];
  55.     if (newDocument) [newDocument setOutputView:[self outputView]];
  56.     return newDocument ? YES : NO;
  57. }
  58.  
  59. - (void)createNew:(id)sender {
  60.     YapDocument *newDocument = [YapDocument newUntitled];
  61.     if (newDocument) [newDocument setOutputView:[self outputView]];
  62. }
  63.  
  64. - (void)open:(id)sender {
  65.     NSArray *documents = [YapDocument documentsFromOpenPanel];
  66.     if (documents) [documents makeObjectsPerform:@selector(setOutputView:) withObject:[self outputView]];
  67. }
  68.  
  69. - (void)saveAll:(id)sender {
  70.     (void)[YapDocument saveAllDocuments];
  71. }
  72.  
  73. /**** PostScript output ****/
  74.  
  75. - (YapOutput *)outputView {
  76.     return outputView;
  77. }
  78.  
  79. /* A dummy outlet (without an actual instance variable).
  80. */   
  81. - (void)setScrollView:(id)anObject {
  82. #ifdef WIN32
  83.     [anObject setBorderType:NSBezelBorder];
  84. #endif
  85. }
  86.  
  87. /**** Info Panel related stuff ****/
  88.  
  89. - (void)showInfoPanel:(id)sender {
  90.     if (!infoPanel) {
  91.         if (![NSBundle loadNibNamed:@"Info" owner:self])  {
  92.             NSLog(@"Failed to load Info.nib");
  93.             NSBeep();
  94.             return;
  95.         }
  96.         [infoPanel center];
  97.     }
  98.     [infoPanel makeKeyAndOrderFront:nil];
  99. }
  100.  
  101. /* Another dummy outlet (without an actual instance variable).
  102. */   
  103. - (void)setVersionField:(id)versionField {
  104.     extern char Yap_VERS_NUM[];
  105.     if (strlen(Yap_VERS_NUM) > 0) {
  106.         NSString *versionString = [NSString stringWithFormat:NSLocalizedString(@"Release 4 (v%s)", @"Version string.  %s is replaced by the version number."), Yap_VERS_NUM];
  107.         [versionField setStringValue:versionString];
  108.     }
  109. }
  110.  
  111. @end
  112.