home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / YellowBox / Programming / OSCVS / CVSPalette.m < prev    next >
Encoding:
Text File  |  1998-04-20  |  2.6 KB  |  82 lines

  1. /*
  2.  * Bob_Vadnais@pdh.com Sun Jun 27 13:46:11 PDT 1993
  3.  *
  4.  * Interface Builder palette that preserves the CVS directory inside a 
  5.  * nib documement.
  6.  *
  7.  * Wouldn't it be nice if all apps had a document controller paradigm?
  8.  * Then we could solve this same problem with Edit wiping out the CVS
  9.  * directory inside .rtfd documents.
  10.  */
  11.  
  12. #import "CVSPalette.h"
  13.  
  14. @implementation CVSPalette
  15.  
  16.     // Quick and dirty debugging code - I found that NSLog() and
  17.     // kin didn't work here.  This won't work, either, unless you
  18.     // create the logfile first.
  19. #define printf alterPrint
  20. void alterPrint( format, parm1, parm2)
  21. const char *format;
  22. {
  23. #if 0
  24.     char buf[ 1024];
  25.     static NSFileHandle *handle=nil;
  26.  
  27.     if( handle==nil) {
  28.         handle=[NSFileHandle fileHandleForWritingAtPath:@"/temp/logfile"];
  29.         handle=[handle retain];
  30.     }
  31.     sprintf( buf, format, parm1, parm2);
  32.     [handle writeData:[NSData dataWithBytesNoCopy:buf length:strlen( buf)]];
  33. #endif
  34. }
  35.  
  36.    // Register for @"IBDidSaveDocumentNotification"s.  Note that
  37.    // it _doesn't_ register for IBDidSaveDocumentNotification
  38.    // (as provided in IBDocuments.h).  For some reason that didn't
  39.    // work (perhaps we aren't fully loaded at this point?).  To
  40.    // find out the actual name, I just registered for all names
  41.    // on all objects, and stored the notification descriptions to
  42.    // the logfile.
  43. -(void)finishInstantiate;
  44. {
  45.     [[NSNotificationCenter defaultCenter]
  46.         addObserver:self
  47.              selector:@selector( didSaveDocument:)
  48.              name:@"IBDidSaveDocumentNotification"
  49.                object:nil];
  50. }
  51. -(void)didSaveDocument:(NSNotification *)aNotification
  52. {
  53.     NSString *source;
  54.  
  55.     source=[[aNotification object] documentPath];
  56.     source=[source stringByAppendingString:@"~/CVS"];
  57.  
  58.     if( [[NSFileManager defaultManager] fileExistsAtPath:source]) {
  59.         NSString *target;
  60.  
  61.         target=[[aNotification object] documentPath];
  62.         target=[target stringByAppendingString:@"/CVS"];
  63.         [[NSFileManager defaultManager] copyPath:source toPath:target handler:self];
  64.     }
  65. }
  66.  
  67.     // I honestly don't know if this "works".  I copied it directly
  68.     // from the documentation, and don't really want to think of a
  69.     // scenario to cause it to fire.
  70. -(BOOL)fileManager:(NSFileManager *)manager
  71.       shouldProceedAfterError:(NSDictionary *)errorDict
  72. {
  73.     int result;
  74.     result=NSRunAlertPanel( @"CVS", @"File operation error: %@ with file: %@",
  75.                             @"Proceed", @"Stop", NULL,
  76.                             [errorDict objectForKey:@"Error"],
  77.                             [errorDict objectForKey:@"Path"]);
  78.  
  79.     return result==NSAlertDefaultReturn;
  80. }
  81. @end
  82.