|
|
1.1 ! root 1: /* Owner.m ! 2: * ! 3: * You may freely copy, distribute, and reuse the code in this example. ! 4: * NeXT disclaims any warranty of any kind, expressed or implied, as to its ! 5: * fitness for any particular use. ! 6: * ! 7: * ! 8: * ! 9: */ ! 10: ! 11: ! 12: #import <eointerface/eointerface.h> ! 13: #import "Owner.h" ! 14: #import "NSAuthor.h" ! 15: ! 16: #define ARCHIVE_FILE @"NSObjectArchive" ! 17: ! 18: @implementation Owner ! 19: ! 20: ! 21: - appDidInit:sender ! 22: { ! 23: EOAdaptorChannel *adaptorChannel; ! 24: ! 25: // Set up the adaptor channel for debugging ! 26: adaptorChannel = [[dataSource databaseChannel] adaptorChannel]; ! 27: [(EOAdaptorChannel *)adaptorChannel setDelegate: self]; ! 28: return self; ! 29: } ! 30: ! 31: ! 32: - (void)adaptorChannel:channel didEvaluateExpression:(NSString *)expression ! 33: { ! 34: NSLog (expression); ! 35: } ! 36: ! 37: ! 38: - writeObject:sender ! 39: { ! 40: eoArray = [controller selectedObjects]; ! 41: // Archive the first object in the array of selected objects. ! 42: // In this example, only one object is selected at a time. ! 43: if ([eoArray count] == 0) { ! 44: NXRunAlertPanel(NULL, "No object to archive!", NULL, NULL, NULL); ! 45: return self; ! 46: } ! 47: eoAuthor = [eoArray objectAtIndex:0]; ! 48: ! 49: [self archiveThisNSObject:eoAuthor]; ! 50: ! 51: return self; ! 52: } ! 53: ! 54: - readObject:sender ! 55: { ! 56: eoAuthor = (NSAuthor *)[self unarchiveNSObject]; ! 57: return self; ! 58: } ! 59: ! 60: ! 61: - (BOOL) archiveThisNSObject:(NSObject *)nsobject ! 62: { ! 63: BOOL b; ! 64: NSString *archivePath; ! 65: ! 66: if (!nsobject) ! 67: return NO; ! 68: ! 69: ! 70: archivePath = [NSString stringWithFormat:@"%@/%@", [self applicationPath], ARCHIVE_FILE]; ! 71: b = [NSArchiver archiveRootObject:nsobject toFile:archivePath]; ! 72: if (b == YES) ! 73: [textObject appendText:"NSObject archiving succeeded\n"]; ! 74: else ! 75: [textObject appendText:"NSObject archiving failed\n"]; ! 76: ! 77: return b; ! 78: } ! 79: ! 80: - (NSObject *) unarchiveNSObject ! 81: { ! 82: NSObject *nsobject; ! 83: char buf[1024]; ! 84: NSString *archivePath; ! 85: ! 86: archivePath = [NSString stringWithFormat:@"%@/%@", [self applicationPath], ARCHIVE_FILE]; ! 87: ! 88: nsobject = [NSUnarchiver unarchiveObjectWithFile:archivePath]; ! 89: if (nsobject) { ! 90: [textObject appendText:"NSObject unarchiving succeeded\n"]; ! 91: sprintf(buf, "%s\n",[[(NSAuthor *)nsobject description] cString]); ! 92: [textObject appendText: "Author contents:"]; ! 93: [textObject appendText:buf]; ! 94: } ! 95: else ! 96: [textObject appendText:"NSObject unarchiving failed\n"]; ! 97: ! 98: return nsobject; ! 99: } ! 100: ! 101: - (NSString *)applicationPath ! 102: { ! 103: int i; ! 104: NSString *appPathName = nil; ! 105: ! 106: for (i = strlen(NXArgv[0]) - 1; (i >= 0) && (NXArgv[0][i] != '/'); i--); ! 107: appPathName = [NSString stringWithCString:NXArgv[0] length:i]; ! 108: if (NXArgv[0][0] != '/') { ! 109: char path[MAXPATHLEN+1]; ! 110: appPathName = [NSString stringWithFormat:@"%s/%@", getwd(path), appPathName]; ! 111: } ! 112: return appPathName; ! 113: } ! 114: ! 115: ! 116: @end ! 117: ! 118: ! 119: @implementation Text(printResults) ! 120: ! 121: - appendText:(const char *)newText ! 122: { ! 123: int currentLength = [self textLength]; ! 124: ! 125: [self setSel:currentLength :currentLength]; ! 126: [self replaceSel:newText]; ! 127: [self scrollSelToVisible]; ! 128: return self; ! 129: } ! 130: ! 131: @end
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.