diff --git a/Modules/Debuggers/ProjectCenter/GNUmakefile b/Modules/Debuggers/ProjectCenter/GNUmakefile index 3b4fb43..0b66a5f 100644 --- a/Modules/Debuggers/ProjectCenter/GNUmakefile +++ b/Modules/Debuggers/ProjectCenter/GNUmakefile @@ -38,6 +38,7 @@ ProjectCenter_RESOURCE_FILES= \ ProjectCenter_HEADERS= \ PCDebugger.h \ PCDebugggerView.h \ + PCDebuggerViewDelegateProtocol.h \ PTYView.h # diff --git a/Modules/Debuggers/ProjectCenter/PCDebugger.m b/Modules/Debuggers/ProjectCenter/PCDebugger.m index 5058b9d..56b24a6 100644 --- a/Modules/Debuggers/ProjectCenter/PCDebugger.m +++ b/Modules/Debuggers/ProjectCenter/PCDebugger.m @@ -25,6 +25,8 @@ #import "PCDebuggerView.h" #import "Modules/Preferences/EditorFSC/PCEditorFSCPrefs.h" +#import "PCDebuggerViewDelegateProtocol.h" +#import "PTYView.h" #ifndef NOTIFICATION_CENTER #define NOTIFICATION_CENTER [NSNotificationCenter defaultCenter] @@ -122,6 +124,7 @@ static NSImage *downImage = nil; { if((self = [super init]) != nil) { + id viewDelegate; // initialization here... if([NSBundle loadNibNamed: @"PCDebugger" owner: self] == NO) { @@ -129,6 +132,10 @@ static NSImage *downImage = nil; } [(PCDebuggerView *)debuggerView setDebugger:self]; + viewDelegate = [[PipeDelegate alloc] init]; + [debuggerView setDelegate:viewDelegate]; + [viewDelegate setTextView:debuggerView]; + [viewDelegate release]; } return self; } diff --git a/Modules/Debuggers/ProjectCenter/PCDebuggerView.h b/Modules/Debuggers/ProjectCenter/PCDebuggerView.h index 7ce9c23..45ee294 100644 --- a/Modules/Debuggers/ProjectCenter/PCDebuggerView.h +++ b/Modules/Debuggers/ProjectCenter/PCDebuggerView.h @@ -1,9 +1,10 @@ /* ** PCDebuggerView ** -** Copyright (c) 2008 +** Copyright (c) 2008-2016 ** -** Author: Gregory Casamento +** Author: Gregory Casamento +** Riccardo Mottola ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by @@ -20,20 +21,32 @@ ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#import "PTYView.h" +#import +#import + +#import "PCDebuggerViewDelegateProtocol.h" @class PCDebugger; -@class NSString; -@interface PCDebuggerView : PTYView +@interface PCDebuggerView : NSTextView { PCDebugger *debugger; + id viewDelegate; NSString *currentFile; int subProcessId; } - (void) setDebugger:(PCDebugger *)theDebugger; +- (void) setDelegate:(id ) vd; - (void) setCurrentFile: (NSString *)fileName; - (NSString *) currentFile; - (int) subProcessId; + +- (void) runProgram: (NSString *)path + inCurrentDirectory: (NSString *)directory + withArguments: (NSArray *)array + logStandardError: (BOOL)logError; + +- (void) putString: (NSString *)string; + @end diff --git a/Modules/Debuggers/ProjectCenter/PCDebuggerView.m b/Modules/Debuggers/ProjectCenter/PCDebuggerView.m index 46151fb..ddf5c51 100644 --- a/Modules/Debuggers/ProjectCenter/PCDebuggerView.m +++ b/Modules/Debuggers/ProjectCenter/PCDebuggerView.m @@ -1,9 +1,10 @@ /* ** PCDebuggerView ** -** Copyright (c) 2008 +** Copyright (c) 2008-2016 ** -** Author: Gregory Casamento +** Author: Gregory Casamento +** Riccardo Mottola ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by @@ -40,6 +41,17 @@ debugger = theDebugger; } +- (void) setDelegate:(id ) vd +{ + if (viewDelegate != vd) + { + [viewDelegate release]; + viewDelegate = vd; + [viewDelegate retain]; + } +} + + /** * Log string to the view. */ @@ -144,7 +156,7 @@ // if the line is not filtered, print it... if(printLine) { - [super logString: str newLine: newLine withColor:debuggerColor]; + [viewDelegate logString: str newLine: newLine withColor:[viewDelegate debuggerColor]]; } } @@ -158,38 +170,6 @@ return currentFile; } -/** - * lookup the process id. - */ -/* -- (int) subProcessId -{ - int task_pid = [task processIdentifier]; - int child_pid = 0; - NSArray *entries = [[NSFileManager defaultManager] directoryContentsAtPath: @"/proc"]; - NSEnumerator *en = [entries objectEnumerator]; - NSString *entry = nil; - - // FIXME: I'm looking for a generic way to do this, what we have here is very /proc specific. - // which I don't like since it ties this functionality to systems which have /proc. - while((entry = [en nextObject]) != nil) - { - int pid = [entry intValue]; - if (pid != 0) - { - int ppid = getppid(pid); - if (ppid == task_pid) - { - child_pid = pid; - break; - } - } - } - - return child_pid; -} -*/ - - (int) subProcessId { return subProcessId; @@ -208,11 +188,36 @@ - (void) terminate { - [super terminate]; + [viewDelegate terminate]; } - (void) mouseDown: (NSEvent *)event { // do nothing... } + +/** + * Start the program. + */ +- (void) runProgram: (NSString *)path + inCurrentDirectory: (NSString *)directory + withArguments: (NSArray *)array + logStandardError: (BOOL)logError +{ + [viewDelegate runProgram: path + inCurrentDirectory: directory + withArguments: array + logStandardError: logError]; +} + +- (void) putString: (NSString *)string +{ + [viewDelegate putString:string]; +} + +- (void) keyDown: (NSEvent*)theEvent +{ + [viewDelegate keyDown:theEvent]; +} + @end diff --git a/Modules/Debuggers/ProjectCenter/PCDebuggerViewDelegateProtocol.h b/Modules/Debuggers/ProjectCenter/PCDebuggerViewDelegateProtocol.h new file mode 100644 index 0000000..5586eaf --- /dev/null +++ b/Modules/Debuggers/ProjectCenter/PCDebuggerViewDelegateProtocol.h @@ -0,0 +1,55 @@ +/* +** PCDebuggerViewDelegateProtocol.h +** +** Copyright (c) 2016 +** +** Author: Riccardo Mottola +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +@class NSColor; +@class NSTextView; +@class NSArray; +@class NSString; + +@protocol PCDebuggerViewDelegateProtocol + +- (NSColor *)userInputColor; +- (NSColor *)debuggerColor; +- (NSColor *)messageColor; +- (NSColor *)errorColor; + +- (NSTextView *)textView; +- (void)setTextView: (NSTextView *)tv; + +- (void) runProgram: (NSString *)path + inCurrentDirectory: (NSString *)directory + withArguments: (NSArray *)array + logStandardError: (BOOL)logError; + +- (void)logString:(NSString *)str + newLine:(BOOL)newLine + withColor:(NSColor *)color; + +- (void) terminate; + +- (void) interrupt; + +- (void) putString: (NSString *)string; + +- (void) keyDown: (NSEvent*)theEvent; + +@end diff --git a/Modules/Debuggers/ProjectCenter/PTYView.h b/Modules/Debuggers/ProjectCenter/PTYView.h index aa0f86d..5efdae5 100644 --- a/Modules/Debuggers/ProjectCenter/PTYView.h +++ b/Modules/Debuggers/ProjectCenter/PTYView.h @@ -1,9 +1,10 @@ /* -** PTYView +** PipeDelegate ** -** Copyright (c) 2008 +** Copyright (c) 2008-2016 ** -** Author: Gregory Casamento +** Author: Gregory Casamento +** Riccardo Mottola ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by @@ -23,8 +24,11 @@ #import #import -@interface PTYView : NSTextView +#import "PCDebuggerViewDelegateProtocol.h" + +@interface PipeDelegate : NSObject { + NSTextView *tView; NSTask *task; NSFileHandle *stdinHandle; NSFileHandle *stdoutHandle; @@ -36,10 +40,6 @@ NSColor *errorColor; } -- (void)logString:(NSString *)str - newLine:(BOOL)newLine - withColor:(NSColor *)color; - - (void)logStdOut:(NSNotification *)aNotif; - (void)logErrOut:(NSNotification *)aNotif; @@ -50,16 +50,6 @@ - (NSString *) stopMessage; -- (void) runProgram: (NSString *)path - inCurrentDirectory: (NSString *)directory - withArguments: (NSArray *)array - logStandardError: (BOOL)logError; - -- (void) terminate; - -- (void) interrupt; - -- (void) putString: (NSString *)string; - - (void) putChar:(unichar)ch; + @end diff --git a/Modules/Debuggers/ProjectCenter/PTYView.m b/Modules/Debuggers/ProjectCenter/PTYView.m index e661a04..75f09c2 100644 --- a/Modules/Debuggers/ProjectCenter/PTYView.m +++ b/Modules/Debuggers/ProjectCenter/PTYView.m @@ -1,5 +1,5 @@ /* -** PTYView +** PipeDelegate.m ** ** Copyright (c) 2008-2016 Free Software Foundation ** @@ -42,35 +42,55 @@ #endif -@implementation PTYView +@implementation PipeDelegate -- (void)commonInitCode -{ - userInputColor = [[NSColor blueColor] retain]; - debuggerColor = [[NSColor blackColor] retain]; - messageColor = [[NSColor brownColor] retain]; - errorColor = [[NSColor redColor] retain]; -} -- (id)initWithCoder:(NSCoder *)coder +- (id)init { - if ((self = [super initWithCoder:coder])) + if ((self = [super init])) { - [self commonInitCode]; + userInputColor = [[NSColor blueColor] retain]; + debuggerColor = [[NSColor blackColor] retain]; + messageColor = [[NSColor brownColor] retain]; + errorColor = [[NSColor redColor] retain]; } return self; } - -- (id)initWithFrame:(NSRect)frameRect textContainer:(NSTextContainer *)container +- (NSTextView *)textView { - if ((self = [super initWithFrame:frameRect textContainer:container])) - { - [self commonInitCode]; - } - return self; + return tView; } +- (void)setTextView: (NSTextView *)tv +{ + if (tView != tv) + { + [tView release]; + tView = tv; + [tView retain]; + } +} + +- (NSColor *)userInputColor +{ + return userInputColor; +} + +- (NSColor *)debuggerColor +{ + return debuggerColor; +} + +- (NSColor *)messageColor +{ + return messageColor; +} + +- (NSColor *)errorColor +{ + return errorColor; +} /** * Log string to the view. @@ -98,12 +118,12 @@ attrStr = [[NSAttributedString alloc] initWithString: str attributes: textAttributes]; - [[self textStorage] appendAttributedString: attrStr]; + [[tView textStorage] appendAttributedString: attrStr]; [attrStr release]; - [self scrollRangeToVisible:NSMakeRange([[self string] length], 0)]; - [self setNeedsDisplay:YES]; + [tView scrollRangeToVisible:NSMakeRange([[tView string] length], 0)]; + [tView setNeedsDisplay:YES]; } @@ -290,6 +310,7 @@ [debuggerColor release]; [messageColor release]; [errorColor release]; + [tView release]; [super dealloc]; } @@ -315,9 +336,9 @@ { NSUInteger textLen; - textLen = [[self string] length]; - [self setSelectedRange:NSMakeRange(textLen-1, 1)]; - [self delete:nil]; + textLen = [[tView string] length]; + [tView setSelectedRange:NSMakeRange(textLen-1, 1)]; + [tView delete:nil]; return; }