mirror of
https://github.com/gnustep/apps-projectcenter.git
synced 2025-03-14 06:31:31 +00:00
split view to delegate
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/projectcenter/branches/ptyview_with_pipes@39582 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
715c206bab
commit
be6efbe7ba
7 changed files with 177 additions and 85 deletions
|
@ -38,6 +38,7 @@ ProjectCenter_RESOURCE_FILES= \
|
|||
ProjectCenter_HEADERS= \
|
||||
PCDebugger.h \
|
||||
PCDebugggerView.h \
|
||||
PCDebuggerViewDelegateProtocol.h \
|
||||
PTYView.h
|
||||
|
||||
#
|
||||
|
|
|
@ -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 <PCDebuggerViewDelegateProtocol> 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;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
/*
|
||||
** PCDebuggerView
|
||||
**
|
||||
** Copyright (c) 2008
|
||||
** Copyright (c) 2008-2016
|
||||
**
|
||||
** Author: Gregory Casamento <greg_casamento@yahoo.com>
|
||||
** Author: Gregory Casamento <greg.casamento@gmail.com>
|
||||
** Riccardo Mottola <rm@gnu.org>
|
||||
**
|
||||
** 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 <Foundation/NSString.h>
|
||||
#import <AppKit/NSTextView.h>
|
||||
|
||||
#import "PCDebuggerViewDelegateProtocol.h"
|
||||
|
||||
@class PCDebugger;
|
||||
@class NSString;
|
||||
|
||||
@interface PCDebuggerView : PTYView
|
||||
@interface PCDebuggerView : NSTextView
|
||||
{
|
||||
PCDebugger *debugger;
|
||||
id <PCDebuggerViewDelegateProtocol> viewDelegate;
|
||||
NSString *currentFile;
|
||||
int subProcessId;
|
||||
}
|
||||
|
||||
- (void) setDebugger:(PCDebugger *)theDebugger;
|
||||
- (void) setDelegate:(id <PCDebuggerViewDelegateProtocol>) 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
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
/*
|
||||
** PCDebuggerView
|
||||
**
|
||||
** Copyright (c) 2008
|
||||
** Copyright (c) 2008-2016
|
||||
**
|
||||
** Author: Gregory Casamento <greg_casamento@yahoo.com>
|
||||
** Author: Gregory Casamento <greg.casamento@gmail.com>
|
||||
** Riccardo Mottola <rm@gnu.org>
|
||||
**
|
||||
** 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 <PCDebuggerViewDelegateProtocol>) 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
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
** PCDebuggerViewDelegateProtocol.h
|
||||
**
|
||||
** Copyright (c) 2016
|
||||
**
|
||||
** Author: Riccardo Mottola <rm@gnu.org>
|
||||
**
|
||||
** 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
|
|
@ -1,9 +1,10 @@
|
|||
/*
|
||||
** PTYView
|
||||
** PipeDelegate
|
||||
**
|
||||
** Copyright (c) 2008
|
||||
** Copyright (c) 2008-2016
|
||||
**
|
||||
** Author: Gregory Casamento <greg_casamento@yahoo.com>
|
||||
** Author: Gregory Casamento <greg.casamento@gmail.com>
|
||||
** Riccardo Mottola <rm@gnu.org>
|
||||
**
|
||||
** 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 <Foundation/Foundation.h>
|
||||
#import <AppKit/AppKit.h>
|
||||
|
||||
@interface PTYView : NSTextView
|
||||
#import "PCDebuggerViewDelegateProtocol.h"
|
||||
|
||||
@interface PipeDelegate : NSObject <PCDebuggerViewDelegateProtocol>
|
||||
{
|
||||
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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue