=================================================================== RCS file: /home/cvs/OpenXM/src/cfep/MyDocument.m,v retrieving revision 1.1.1.1 retrieving revision 1.10 diff -u -p -r1.1.1.1 -r1.10 --- OpenXM/src/cfep/MyDocument.m 2006/03/03 23:31:12 1.1.1.1 +++ OpenXM/src/cfep/MyDocument.m 2016/09/30 01:13:38 1.10 @@ -18,7 +18,17 @@ static int myDocumentSaidTheMessageAboutX = 0; @implementation MyDocument +static int NoEngine = 0; // experimental. +static NSMenuItem *menuItemNoEngine = nil; // NoEngine +// For OnState or OffState in the execution menu +static NSMenuItem *menuItemNotebookMode = nil; +static NSMenuItem *menuItemBasicMode = nil; +static NSMenuItem *menuItemRisaAsir = nil; +static NSMenuItem *menuItemKanSm1 = nil; +static NSMenuItem *menuItemOutputDebugMessages = nil; //cf. debugMyTunnel; +static NSMenuItem *menuItemPrettyPrint = nil; // prettyPrint. + - (void)dealloc { MyOutputWindowController *mowc; if (myDebug) NSLog(@"dealloc of MyDocument.\n"); @@ -63,6 +73,12 @@ static int myDocumentSaidTheMessageAboutX = 0; } [self addMenuExec]; // adding the execution menu. [textViewIn setAllowsUndo:YES]; + if ([textViewIn isContinuousSpellCheckingEnabled]) [textViewIn toggleContinuousSpellChecking: self]; // Turn off the spell checking. + if ([textViewIn isAutomaticQuoteSubstitutionEnabled]) [textViewIn toggleAutomaticQuoteSubstitution: self]; // Turn off the smart quote. + if ([MyEnvironment isX11Installed] != 1) + [self messageDialog: NSLocalizedString(@"X11 is not installed. To install it, insert MacOS DVD1 and open Optional install->Applications->X11",nil) with: 0]; +// if ([MyEnvironment isGccInstalled] != 1) +// [self messageDialog: NSLocalizedString(@"gcc is not installed. To install it, insert MacOS DVD1 and open Xcode Tools->XcodeTools.mpkg",nil) with: 0]; [self sayTheMessageAboutX]; [self initAux]; } @@ -139,8 +155,9 @@ static int myDocumentSaidTheMessageAboutX = 0; myDecoder = [[MyDecoder alloc] init]; [myDecoder retain]; [self openMyModel: myEnvironment ]; + [MyOpenGLController initMyOpenGLController]; // For the second execution, it will do nothing. } --(int) getMyDocumentKey { return myDocumentKey; } +-(NSString *) getMyDocumentKey { return myDocumentKey; } -(id) openMyModel: (MyEnvironment *) myEnvironment { [myEnvironment showForDebug]; // for debug. @@ -155,6 +172,8 @@ static int myDocumentSaidTheMessageAboutX = 0; [peerEndEvaluteMark retain]; [self stopIndicator]; + if (NoEngine && (!restartMode)) { task = nil; return self; } + // Initialization to call /bin/bash outboundPipe = [NSPipe pipe]; // since autorelease is called in pipe. inboundPipe = [NSPipe pipe]; @@ -217,6 +236,7 @@ static int myDocumentSaidTheMessageAboutX = 0; -(id) restartMyModel: (enum peer_type) peerType { MyEnvironment *myEnvironment; + restartMode = 1; [self closeMyModel]; myEnvironment = [[MyEnvironment alloc] initFor: peerType]; //BUG. leak memory? [myEnvironment retain]; @@ -230,8 +250,11 @@ static int myDocumentSaidTheMessageAboutX = 0; NSLog(@"myDocumentSaidTheMessageAboutX=%d\n",myDocumentSaidTheMessageAboutX); if (!myDocumentSaidTheMessageAboutX) { if ([MyEnvironment checkX] != 1) - [self messageDialog: - NSLocalizedString(@"A few commands (plot, ...) cannot be used, because X11 is not running.",nil) with: 0]; + // [self messageDialog: + // NSLocalizedString(@"A few commands (plot, ...) cannot be used, because X11 is not running.",nil) with: 0]; + [self changeOutputCounterFieldWithString: + [NSLocalizedString(@"Output mini-view: ",nil) stringByAppendingString: + NSLocalizedString(@"A few commands (plot, ...) cannot be used, because X11 is not running.",nil)]]; myDocumentSaidTheMessageAboutX = 1; } } @@ -241,6 +264,7 @@ static int myDocumentSaidTheMessageAboutX = 0; NSMutableString *cmd; NSRange r; + if (!task) return; if (inEvaluation) { NSLog(@"In evaluatioin. "); [self messageDialog: NSLocalizedString(@"Evaluating...",nil) with: 0]; @@ -273,7 +297,13 @@ static int myDocumentSaidTheMessageAboutX = 0; [textViewIn replaceCharactersInRange: NSMakeRange(pos,0) withString: @"\n"]; } cmd0 = [cmd0 substringWithRange:r ]; - } + } + [self outputBorderLine: [NSColor magentaColor]]; + [self outputString: cmd0]; + if ([cmd0 length] > 0) { + if ([cmd0 characterAtIndex: ([cmd0 length]-1)] != 0xa) [self outputString: @"\n"]; + } + [self outputBorderLine: [NSColor yellowColor]]; }else{ cmd0 = [textViewIn string]; MyOutputWindowController *mc; @@ -303,7 +333,7 @@ static int myDocumentSaidTheMessageAboutX = 0; [alert release]; fprintf(stderr,"Trying to interrupt.\n"); - [task interrupt]; + if (task) [task interrupt]; inputCounter = outputCounter = 0; [self stopIndicator]; [myDecoder reset]; @@ -360,6 +390,7 @@ static int myDocumentSaidTheMessageAboutX = 0; NSLog(@"Evaluating... "); NSLog(@"%@",cmd); // Evaluation is here. + if (!task) return -1; cmdInData = [cmd dataUsingEncoding: NSUTF8StringEncoding]; @try { //todo if (yes) [outboundFileHandle writeData: peerStartEvaluateMark]; @@ -387,9 +418,15 @@ static int myDocumentSaidTheMessageAboutX = 0; else { MyOutputWindowController *mc; mc = [MyOutputWindowController sharedMyOutputWindowController: self]; - [mc outputStringToOutputWindow: amt]; + if (prettyPrint) [mc outputStringToOutputWindow: amt withColor: [NSColor blueColor]]; + else [mc outputStringToOutputWindow: amt]; } } +-(void)outputBorderLine: (NSColor *)color { + MyOutputWindowController *mc; + mc = [MyOutputWindowController sharedMyOutputWindowController: self]; + [mc outputStringToOutputWindow: @"----------------------------------------\n" withColor: color]; +} - (void) outputErrorString: (NSString *) amt { int oldEnd; int newEnd; @@ -481,7 +518,7 @@ static int myDocumentSaidTheMessageAboutX = 0; //bug. temporary. path = [OpenXM_HOME stringByAppendingString: @"/doc/cfep/intro-ja.html"]; - ans = [[NSWorkspace sharedWorkspace] openFile:path withApplication: @"Help Viewer"]; + ans = [[NSWorkspace sharedWorkspace] openFile:path withApplication: @"Safari"]; //We do not use Help Viewer if (ans != YES) { [self messageDialog: NSLocalizedString(@"Help file is not found at cfep.app/OpenXM/doc/cfep",nil) with: 0]; } @@ -575,8 +612,10 @@ int debugInbound = 0; if (debugMyTunnel) [self outputErrorString: act]; // for debug. channel = [myDecoder getChannel]; if (channel == 0) [self errorActionFor: act]; + // cf. MyDecode.h for the list of channel numbers. else if (channel == 1) [self openGLActionFor: act]; else if (channel == 2) [self openGLInitActionFor: act]; + else if (channel == 10) [self pngActionFor: act]; } state = 0; break; default: @@ -973,6 +1012,8 @@ int debugInbound = 0; NSRange r; NSRange r3; int currentLine,i; + [self outputErrorString: NSLocalizedString(@"Move to the line ",nil)]; + [self outputErrorString: [NSString stringWithFormat: @"%d\n",line]]; // move the selection to the line line. s = [textViewIn string]; if (onlySelectedArea || notebookMode) r = [textViewIn selectedRange]; @@ -993,6 +1034,8 @@ int debugInbound = 0; } -(int) gotoNextError: (id) sender{ int n; + if (onlySelectedArea || notebookMode) + [self outputErrorString: NSLocalizedString(@"The next error action will not work properly in this mode.\n",nil)]; n = [self nextLine: 0]; if (n >= 0) { [self gotoLine: n]; return n;} else return -1; @@ -1008,6 +1051,7 @@ int debugInbound = 0; return -1; } gid = [[a objectAtIndex: 0] intValue]; + if ([[a objectAtIndex: 1] hasPrefix: @"meta"]) {[self openGLMeta: [a objectAtIndex: 1] to: gid]; return 0; } [MyOpenGLController addOglComm: [a objectAtIndex: 1] to: gid from: self]; return 0; } @@ -1023,7 +1067,88 @@ int debugInbound = 0; [MyOpenGLController addOglInitComm: [a objectAtIndex: 1] to: gid from: self]; return 0; } +-(void)openGLMeta: (NSString *) cmd to: (int) gid{ + MyOpenGLController *oglc; + oglc = [MyOpenGLController getOglWindow: gid]; + if (!oglc) {[self printErrorMessage: + [NSString stringWithFormat: @"Invalid gid %d in openGLMeta command %@\n",gid,cmd]]; return; } + if ([cmd hasPrefix: @"meta_showListOfOglComm"]) { + [self showListOfOglComm: gid]; return ; + }else if ([cmd hasPrefix: @"meta_removeAllInit"]) { // longer command must come first, because we use prefix. + [oglc removeAllOfOglInitComm]; + }else if ([cmd hasPrefix: @"meta_removeLastInit"]) { + [oglc removeLastOfOglInitComm]; + }else if ([cmd hasPrefix: @"meta_removeAll"]) { + [oglc removeAllOfOglComm]; + }else if ([cmd hasPrefix: @"meta_removeLast"]) { + [oglc removeLastOfOglComm]; + }else{ + [self printErrorMessage: [NSString stringWithFormat: @"Unknown OpenGL meta command %@\n",cmd]]; + } +} +-(void) showListOfOglComm: (int) gid { + MyDocument *md; + MyOpenGLController *oglc; + NSMutableArray *comm; + int i,n; + md = self; + oglc = [MyOpenGLController getOglWindow: gid]; + if (!oglc) {[self outputErrorString: @"Invalid gid in showListOfOglComm\n"]; return; } + comm = [oglc getListOfOglInitComm]; + n = [comm count]; + [md outputString: NSLocalizedString(@"OpenGL init commands\n",nil)]; + for (i=0; i