From 396f6b9751620884dee30abf4f83dea9a38f8b7c Mon Sep 17 00:00:00 2001 From: "Philippe C.D. Robert" Date: Mon, 11 Feb 2002 22:19:39 +0000 Subject: [PATCH] Began to work on support for an integrated editor, thus much has been rewritten related to editor handling. This is work in progress... Every PCProject component now has to conform to the ProjectComponent protocol. Syntax highlighting is disabled for now, this will undergo a major rewrite soon. Furthermore I separated the component handling stuff from the main class file and put it into PCProject+ComponentHandling. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/projectcenter/trunk@12499 72102866-910b-0410-8b05-ffd578937521 --- PCLib/GNUmakefile | 9 +- PCLib/PCEditor.h | 15 +- PCLib/PCEditor.m | 143 +++++++++----- PCLib/PCEditorController.m | 12 +- PCLib/PCEditorView.h | 13 +- PCLib/PCEditorView.m | 64 ++++-- PCLib/PCFileManager.m | 14 +- PCLib/PCProject+ComponentHandling.h | 40 ++++ PCLib/PCProject+ComponentHandling.m | 158 +++++++++++++++ PCLib/PCProject.h | 29 +-- PCLib/PCProject.m | 194 ++++--------------- PCLib/PCProjectBuilder.h | 3 +- PCLib/PCProjectBuilder.m | 1 + PCLib/PCProjectDebugger.h | 3 +- PCLib/PCProjectEditor.h | 40 ++++ PCLib/PCProjectEditor.m | 125 ++++++++++++ PCLib/ProjectCenter.h | 3 + PCLib/ProjectCenter.pcproj | 9 +- PCLib/ProjectComponent.h | 20 ++ ProjectCenter/PCAppController+MenuHandling.m | 5 +- 20 files changed, 625 insertions(+), 275 deletions(-) create mode 100644 PCLib/PCProject+ComponentHandling.h create mode 100644 PCLib/PCProject+ComponentHandling.m create mode 100644 PCLib/PCProjectEditor.h create mode 100644 PCLib/PCProjectEditor.m create mode 100644 PCLib/ProjectComponent.h diff --git a/PCLib/GNUmakefile b/PCLib/GNUmakefile index 55f54e8..2d7efcc 100644 --- a/PCLib/GNUmakefile +++ b/PCLib/GNUmakefile @@ -64,7 +64,10 @@ PCSplitView.h \ PCEditor.h \ PCEditorController.h \ PCDefines.h \ -PCTextFinder.h +PCTextFinder.h \ +PCProjectEditor.h \ +ProjectComponent.h \ +PCProject+ComponentHandling.h # @@ -85,7 +88,9 @@ PCServer.m \ PCSplitView.m \ PCEditor.m \ PCEditorController.m \ -PCTextFinder.m +PCTextFinder.m \ +PCProjectEditor.m \ +PCProject+ComponentHandling.m # diff --git a/PCLib/PCEditor.h b/PCLib/PCEditor.h index ba95997..8a46208 100644 --- a/PCLib/PCEditor.h +++ b/PCLib/PCEditor.h @@ -14,16 +14,19 @@ #import @class PCEditorView; +@class PCProjectEditor; @interface PCEditor : NSObject { - PCEditorView *view; - NSWindow *window; + PCEditorView *iView; + PCEditorView *eView; + NSTextStorage *storage; + NSWindow *window; NSMutableString *path; id delegate; - BOOL isEmbedded; + BOOL isEdited; } - (id)initWithPath:(NSString*)file; @@ -32,12 +35,12 @@ - (void)setDelegate:(id)aDelegate; - (id)delegate; -- (void)setEmbedded:(BOOL)yn; -- (BOOL)isEmbedded; - - (NSWindow *)editorWindow; - (NSString *)path; +- (void)setIsEdited:(BOOL)yn; + +- (void)showInProjectEditor:(PCProjectEditor *)pe; - (void)show; - (void)close; diff --git a/PCLib/PCEditor.m b/PCLib/PCEditor.m index c13c138..2861efb 100644 --- a/PCLib/PCEditor.m +++ b/PCLib/PCEditor.m @@ -10,6 +10,7 @@ #import "PCEditor.h" #import "PCEditorView.h" +#import "PCProjectEditor.h" NSString *PCEditorDidBecomeKeyNotification=@"PCEditorDidBecomeKeyNotification"; NSString *PCEditorDidResignKeyNotification=@"PCEditorDidResignKeyNotification"; @@ -25,6 +26,8 @@ NSString *PCEditorDidResignKeyNotification=@"PCEditorDidResignKeyNotification"; - (void)_initUI { NSScrollView *scrollView; + NSLayoutManager *lm; + NSTextContainer *tc; unsigned int style = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask @@ -47,30 +50,65 @@ NSString *PCEditorDidResignKeyNotification=@"PCEditorDidResignKeyNotification"; scrollView = [[NSScrollView alloc] initWithFrame:rect]; + // Now the text editing stuff + storage = [[NSTextStorage alloc] init]; + + lm = [[NSLayoutManager alloc] init]; + [storage addLayoutManager:lm]; + RELEASE(lm); + rect.origin.x = 0; rect.origin.y = 0; rect.size.height -= 24; rect.size.width -= 4; - view = [[PCEditorView alloc] initWithFrame:rect]; - [view setEditor:self]; + tc = [[NSTextContainer alloc] initWithContainerSize:rect.size]; + [lm addTextContainer:tc]; + RELEASE(tc); - [view setMinSize: NSMakeSize (0, 0)]; - [view setMaxSize:NSMakeSize(1e7, 1e7)]; - [view setRichText:NO]; - [view setEditable:YES]; - [view setSelectable:YES]; - [view setVerticallyResizable:YES]; - [view setHorizontallyResizable:NO]; - [view setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; - [view setBackgroundColor:[NSColor whiteColor]]; - [[view textContainer] setWidthTracksTextView:YES]; + iView = [[PCEditorView alloc] initWithFrame:rect + textContainer:tc]; + [iView setEditor:self]; - [scrollView setDocumentView:view]; - RELEASE(view); + [iView setMinSize:NSMakeSize (0, 0)]; + [iView setMaxSize:NSMakeSize(1e7, 1e7)]; + [iView setRichText:NO]; + [iView setEditable:YES]; + [iView setSelectable:YES]; + [iView setVerticallyResizable:YES]; + [iView setHorizontallyResizable:NO]; + [iView setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; + [iView setBackgroundColor:[NSColor whiteColor]]; + [[iView textContainer] setWidthTracksTextView:YES]; + + lm = [[NSLayoutManager alloc] init]; + [storage addLayoutManager:lm]; + RELEASE(lm); + + tc = [[NSTextContainer alloc] initWithContainerSize:rect.size]; + [lm addTextContainer:tc]; + RELEASE(tc); + + eView = [[PCEditorView alloc] initWithFrame:rect + textContainer:tc]; + [eView setEditor:self]; + + [eView setMinSize: NSMakeSize (0, 0)]; + [eView setMaxSize:NSMakeSize(1e7, 1e7)]; + [eView setRichText:NO]; + [eView setEditable:YES]; + [eView setSelectable:YES]; + [eView setVerticallyResizable:YES]; + [eView setHorizontallyResizable:NO]; + [eView setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; + [eView setBackgroundColor:[NSColor whiteColor]]; + [[eView textContainer] setWidthTracksTextView:YES]; + + [scrollView setDocumentView:eView]; + RELEASE(eView); rect.size = NSMakeSize([scrollView contentSize].width,1e7); - [[view textContainer] setContainerSize:rect.size]; + [[eView textContainer] setContainerSize:rect.size]; [scrollView setHasHorizontalScroller: YES]; [scrollView setHasVerticalScroller: YES]; @@ -79,7 +117,7 @@ NSString *PCEditorDidResignKeyNotification=@"PCEditorDidResignKeyNotification"; [window setContentView:scrollView]; [window setDelegate:self]; - [window makeFirstResponder:view]; + [window makeFirstResponder:eView]; RELEASE(scrollView); } @@ -92,22 +130,30 @@ NSString *PCEditorDidResignKeyNotification=@"PCEditorDidResignKeyNotification"; { if((self = [super init])) { - NSString *text = [NSString stringWithContentsOfFile:file]; + NSString *t = [NSString stringWithContentsOfFile:file]; + NSAttributedString *as = [[NSAttributedString alloc] initWithString:t]; - // Should take that from preferences! - isEmbedded = NO; + isEdited = NO; + path = [file copy]; [self _initUI]; [window setTitle:file]; - [view setText:text]; + [storage setAttributedString:as]; + RELEASE(as); - path = [file copy]; + [iView setNeedsDisplay:YES]; + [eView setNeedsDisplay:YES]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textDidChange:) name:NSTextDidChangeNotification - object:view]; + object:eView]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(textDidChange:) + name:NSTextDidChangeNotification + object:iView]; } return self; } @@ -119,6 +165,9 @@ NSString *PCEditorDidResignKeyNotification=@"PCEditorDidResignKeyNotification"; RELEASE(window); RELEASE(path); + RELEASE(iView); + RELEASE(storage); + [super dealloc]; } @@ -142,34 +191,32 @@ NSString *PCEditorDidResignKeyNotification=@"PCEditorDidResignKeyNotification"; return path; } -- (void)setEmbedded:(BOOL)yn +- (void)setIsEdited:(BOOL)yn { - isEmbedded = yn; + [window setDocumentEdited:yn]; + isEdited = yn; } -- (BOOL)isEmbedded +- (void)showInProjectEditor:(PCProjectEditor *)pe { - return isEmbedded; + [pe setEditorView:iView]; } - (void)show { - if( isEmbedded == NO ) - { - [window makeKeyAndOrderFront:self]; - } - else - { - } + [window makeKeyAndOrderFront:self]; } - (void)close { - if( isEmbedded == NO && [window isDocumentEdited] ) + if( isEdited ) { BOOL ret; - [window makeKeyAndOrderFront:self]; + if( [window isVisible] ) + { + [window makeKeyAndOrderFront:self]; + } ret = NSRunAlertPanel(@"Edited File!", @"Should the file be saved before closing?", @@ -189,9 +236,6 @@ NSString *PCEditorDidResignKeyNotification=@"PCEditorDidResignKeyNotification"; [window setDocumentEdited:NO]; } - else if( isEmbedded ) - { - } if( delegate && [delegate respondsToSelector:@selector(editorDidClose:)] ) { @@ -201,24 +245,25 @@ NSString *PCEditorDidResignKeyNotification=@"PCEditorDidResignKeyNotification"; - (BOOL)saveFile { - if( isEmbedded == NO ) - { - [window setDocumentEdited:NO]; - } + [self setIsEdited:NO]; - return [[view text] writeToFile:path atomically:YES]; + // Operate on the text storage! + return [[storage string] writeToFile:path atomically:YES]; } - (BOOL)revertFile { NSString *text = [NSString stringWithContentsOfFile:path]; + NSAttributedString *as = [[NSAttributedString alloc] initWithString:text]; - [view setText:text]; + [self setIsEdited:NO]; - if( isEmbedded == NO ) - { - [window setDocumentEdited:NO]; - } + // Operate on the text storage! + [storage setAttributedString:as]; + RELEASE(as); + + [iView setNeedsDisplay:YES]; + [eView setNeedsDisplay:YES]; } - (void)windowWillClose:(NSNotification *)aNotification @@ -247,7 +292,7 @@ NSString *PCEditorDidResignKeyNotification=@"PCEditorDidResignKeyNotification"; - (void)textDidChange:(NSNotification *)aNotification { - [window setDocumentEdited:YES]; + [self setIsEdited:YES]; } @end diff --git a/PCLib/PCEditorController.m b/PCLib/PCEditorController.m index 920fec2..598d599 100644 --- a/PCLib/PCEditorController.m +++ b/PCLib/PCEditorController.m @@ -124,11 +124,7 @@ editor = [editorDict objectForKey:key]; [editor close]; - - if( [editor isEmbedded] == NO ) - { - [[editor editorWindow] performClose:self]; - } + [[editor editorWindow] performClose:self]; } [editorDict removeAllObjects]; } @@ -156,7 +152,8 @@ editor = [editorDict objectForKey:key]; window = [editor editorWindow]; - if( [window isKeyWindow] && [window isMainWindow] ) + if( [window isKeyWindow] && [window isMainWindow] || + [project isEditorActive] && [[project projectWindow] isKeyWindow]) { return [editor saveFile]; } @@ -177,7 +174,8 @@ editor = [editorDict objectForKey:key]; window = [editor editorWindow]; - if( [window isKeyWindow] && [window isMainWindow] ) + if( [window isKeyWindow] && [window isMainWindow] || + [project isEditorActive] && [[project projectWindow] isKeyWindow]) { return [editor revertFile]; } diff --git a/PCLib/PCEditorView.h b/PCLib/PCEditorView.h index 8244b02..fce7589 100644 --- a/PCLib/PCEditorView.h +++ b/PCLib/PCEditorView.h @@ -36,15 +36,24 @@ NSRange range; NSArray *_keywords; PCEditor *editor; + BOOL shouldHighlight; } -- (id)initWithFrame:(NSRect)frameRect; +- (id)initWithFrame:(NSRect)frameRect textContainer:(NSTextContainer*)tc; - (void)dealloc; - (void)setEditor:(PCEditor *)anEditor; - (void)setString:(NSString *)aString; -- (void)colourise:(id)sender; +- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent; + +- (void)setShouldHighlight:(BOOL)yn; +- (BOOL)shouldHighlight; + +- (void)insertText:(id)aString; + +- (void)highlightText; +- (void)highlightTextInRange:(NSRange)range; - (void)colouriseKeyword:(NSString *)keyword; - (void)colouriseKeywords:(NSArray *)keywords; diff --git a/PCLib/PCEditorView.m b/PCLib/PCEditorView.m index 0581a4e..e6d68d9 100644 --- a/PCLib/PCEditorView.m +++ b/PCLib/PCEditorView.m @@ -40,10 +40,11 @@ static NSColor *cStringColor = nil; static NSFont *editorFont = nil; static BOOL isInitialised = NO; -- (id)initWithFrame:(NSRect)frameRect +- (id)initWithFrame:(NSRect)frameRect textContainer:(NSTextContainer*)tc { - if ((self = [super initWithFrame:frameRect])) + if ((self = [super initWithFrame:frameRect textContainer:tc])) { + shouldHighlight = NO; /* * Should move that to initialize... @@ -96,29 +97,65 @@ static BOOL isInitialised = NO; - (void)setString:(NSString *)aString { - [scanner autorelease]; - scanner = [[NSScanner alloc] initWithString:aString]; + [scanner autorelease]; + scanner = [[NSScanner alloc] initWithString:aString]; - [super setString:aString]; + [super setString:aString]; #ifdef COLOURISE - [self colourise:self]; + if( shouldHighlight ) + { + [self highlightText]; + } #endif //COLOURISE } -- (void)colourise:(id)sender +- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent +{ + return YES; +} + +- (void)setShouldHighlight:(BOOL)yn +{ + shouldHighlight = yn; +} + +- (BOOL)shouldHighlight +{ + return shouldHighlight; +} + +- (void)insertText:(id)aString +{ + NSRange txtRange = NSMakeRange(0, [[self textStorage] length]); + + [super insertText:aString]; + + if( shouldHighlight ) + { + [[self textStorage] invalidateAttributesInRange:txtRange]; + [self highlightTextInRange:txtRange]; + } +} + +- (void)highlightText +{ + NSRange txtRange = NSMakeRange(0, [[self textStorage] length]); + + [self highlightTextInRange:txtRange]; +} + +- (void)highlightTextInRange:(NSRange)txtRange { - NSRange aRange; NSDictionary *aDict; NSArray *keywords; - aRange = NSMakeRange(0,[_textStorage length]); aDict = [NSDictionary dictionaryWithObjectsAndKeys: editorFont, NSFontAttributeName, @"UnknownCodeType", @"PCCodeTypeAttributeName", nil]; [_textStorage beginEditing]; - [_textStorage setAttributes:aDict range:aRange]; + [_textStorage setAttributes:aDict range:txtRange]; // Scan the CodeType first... @@ -373,16 +410,9 @@ static BOOL isInitialised = NO; if(([chars lossyCString][0] == 's') && (modifiers & NSCommandKeyMask)) { [editor saveFile]; - return; } - // Only if not embedded - FIXME! - if( [[self window] isDocumentEdited] == NO ) - { - [[self window] setDocumentEdited:YES]; - } - [super keyDown:anEvent]; } diff --git a/PCLib/PCFileManager.m b/PCLib/PCFileManager.m index 2a66323..c274065 100644 --- a/PCLib/PCFileManager.m +++ b/PCLib/PCFileManager.m @@ -213,23 +213,20 @@ static PCFileManager *_mgr = nil; NSArray *types = nil; if (delegate && - [delegate respondsToSelector:@selector(fileManagerWillAddFiles:)]) { + [delegate respondsToSelector:@selector(fileManagerWillAddFiles:)]) + { - if (!(project = [delegate fileManagerWillAddFiles:self])) { - NSLog(@"No project to add files available..."); + if (!(project = [delegate fileManagerWillAddFiles:self])) + { return; } } key = [project selectedRootCategory]; - NSLog(@"Key: %@",key); - title = [[[project rootCategories] allKeysForObject:key] objectAtIndex:0]; title = [NSString stringWithFormat:@"Add to %@...",title]; - NSLog(@"Title is %@ (Key %@)",title,key); - types = [project fileExtensionsForCategory:key]; openPanel = [NSOpenPanel openPanel]; @@ -244,7 +241,8 @@ static PCFileManager *_mgr = nil; NSEnumerator *enumerator; NSString *file; - [[NSUserDefaults standardUserDefaults] setObject:[openPanel directory] forKey:@"LastOpenDirectory"]; + [[NSUserDefaults standardUserDefaults] setObject:[openPanel directory] + forKey:@"LastOpenDirectory"]; enumerator = [[openPanel filenames] objectEnumerator]; while (file = [enumerator nextObject]) { diff --git a/PCLib/PCProject+ComponentHandling.h b/PCLib/PCProject+ComponentHandling.h new file mode 100644 index 0000000..e7ef0bd --- /dev/null +++ b/PCLib/PCProject+ComponentHandling.h @@ -0,0 +1,40 @@ +/* + * PCProject+ComponentHandling.h created by probert on 2002-02-10 09:51:00 +0000 + * + * Project ProjectCenter + * + * Created with ProjectCenter - http://www.gnustep.org + * + * $Id$ + */ + +#ifndef _PCPROJECT_COMPONENTHANDLING_H_ +#define _PCPROJECT_COMPONENTHANDLING_H_ + +#import + +@interface PCProject (ComponentHandling) + +- (void)topButtonsPressed:(id)sender; +- (void)showBuildView:(id)sender; +- (void)showRunView:(id)sender; +- (void)showEditorView:(id)sender; + +- (void)showInspector:(id)sender; + +- (id)updatedAttributeView; +- (id)updatedProjectView; +- (id)updatedFilesView; + +- (void)showBuildTargetPanel:(id)sender; +- (void)setHost:(id)sender; +- (void)setArguments:(id)sender; + +- (NSDictionary *)buildOptions; + +- (BOOL)isEditorActive; + +@end + +#endif // _PCPROJECT_COMPONENTHANDLING_H_ + diff --git a/PCLib/PCProject+ComponentHandling.m b/PCLib/PCProject+ComponentHandling.m new file mode 100644 index 0000000..e35a4e8 --- /dev/null +++ b/PCLib/PCProject+ComponentHandling.m @@ -0,0 +1,158 @@ +/* + * PCProject+ComponentHandling.m created by probert on 2002-02-10 09:50:56 +0000 + * + * Project ProjectCenter + * + * Created with ProjectCenter - http://www.gnustep.org + * + * $Id$ + */ + +#import "PCProject+ComponentHandling.h" +#import "PCProjectBuilder.h" +#import "PCProjectDebugger.h" +#import "PCProjectEditor.h" +#import "PCEditor.h" + +@implementation PCProject (ComponentHandling) + +- (void)topButtonsPressed:(id)sender +{ + switch ([[sender selectedCell] tag]) + { + case 0: + [self showBuildView:self]; + break; + case 1: + [self showInspector:self]; + break; + case 2: + [self showBuildTargetPanel:self]; + break; + case 3: + if ([self isExecutable]) { + [self showRunView:self]; + } + else { + NSRunAlertPanel(@"Attention!", + @"This project type is not executable!", + @"OK",nil,nil); + } + break; + case 4: + [self showEditorView:self]; + break; + default: + break; + } +} + +- (void)showBuildView:(id)sender +{ + NSView *view = nil; + + [[NSNotificationCenter defaultCenter] postNotificationName:PCEditorDidResignKeyNotification object:self]; + + editorIsActive = NO; + + if (!projectBuilder) { + projectBuilder = [[PCProjectBuilder alloc] initWithProject:self]; + } + + view = [[projectBuilder componentView] retain]; + + [box setContentView:view]; + [box sizeToFit]; + [box display]; +} + +- (void)showRunView:(id)sender +{ + NSView *view = nil; + + [[NSNotificationCenter defaultCenter] postNotificationName:PCEditorDidResignKeyNotification object:self]; + + editorIsActive = NO; + + if (!projectDebugger) { + projectDebugger = [[PCProjectDebugger alloc] initWithProject:self]; + } + + view = [[projectDebugger componentView] retain]; + + [box setContentView:view]; + [box display]; +} + +- (void)showEditorView:(id)sender +{ + NSView *view = nil; + + [[NSNotificationCenter defaultCenter] postNotificationName:PCEditorDidBecomeKeyNotification object:self]; + + editorIsActive = YES; + + if (!projectEditor) { + projectEditor = [[PCProjectEditor alloc] initWithProject:self]; + } + + view = [[projectEditor componentView] retain]; + + [box setContentView:view]; + [box display]; +} + +- (void)showInspector:(id)sender +{ + [projectManager showInspectorForProject:self]; +} + +- (id)updatedAttributeView +{ + return projectAttributeInspectorView; +} + +- (id)updatedProjectView +{ + return projectProjectInspectorView; +} + +- (id)updatedFilesView +{ + return projectFileInspectorView; +} + +- (void)showBuildTargetPanel:(id)sender +{ + if (![buildTargetPanel isVisible]) + { + [buildTargetPanel center]; + } + + [buildTargetPanel makeKeyAndOrderFront:self]; +} + +- (void)setHost:(id)sender +{ + NSString *host = [buildTargetHostField stringValue]; + [buildOptions setObject:host forKey:BUILD_HOST_KEY]; +} + +- (void)setArguments:(id)sender +{ + NSString *args = [buildTargetArgsField stringValue]; + [buildOptions setObject:args forKey:BUILD_ARGS_KEY]; +} + +- (NSDictionary *)buildOptions +{ + return (NSDictionary *)buildOptions; +} + +- (BOOL)isEditorActive +{ + return editorIsActive; +} + +@end + diff --git a/PCLib/PCProject.h b/PCLib/PCProject.h index 5b2ae78..d91edfe 100644 --- a/PCLib/PCProject.h +++ b/PCLib/PCProject.h @@ -109,6 +109,7 @@ static NSString * const PCBuildTool = @"BUILDTOOL"; @class PCProjectBuilder; @class PCProjectDebugger; +@class PCProjectEditor; @class PCEditorController; @interface PCProject : NSObject @@ -118,8 +119,9 @@ static NSString * const PCBuildTool = @"BUILDTOOL"; id projectManager; id browserController; - PCProjectBuilder *projectBuilder; - PCProjectDebugger *projectDebugger; + PCProjectBuilder *projectBuilder; + PCProjectDebugger *projectDebugger; + PCProjectEditor *projectEditor; PCEditorController *editorController; NSBox *box; @@ -146,6 +148,8 @@ static NSString * const PCBuildTool = @"BUILDTOOL"; NSDictionary *rootCategories; // Needs to be initialised by subclasses! NSMutableDictionary *buildOptions; + + BOOL editorIsActive; } //============================================================================= @@ -272,26 +276,6 @@ static NSString * const PCBuildTool = @"BUILDTOOL"; @end -@interface PCProject (ProjectBuilding) - -- (void)topButtonsPressed:(id)sender; -- (void)showBuildView:(id)sender; -- (void)showRunView:(id)sender; - -- (void)showInspector:(id)sender; - -- (id)updatedAttributeView; -- (id)updatedProjectView; -- (id)updatedFilesView; - -- (void)showBuildTargetPanel:(id)sender; -- (void)setHost:(id)sender; -- (void)setArguments:(id)sender; - -- (NSDictionary *)buildOptions; - -@end - @interface PCProject (ProjectKeyPaths) - (NSArray *)contentAtKeyPath:(NSString *)keyPath; @@ -302,6 +286,7 @@ static NSString * const PCBuildTool = @"BUILDTOOL"; @interface PCProject (ProjectWindowDelegate) +- (void)windowDidResignKey:(NSNotification *)aNotification; - (void)windowDidBecomeKey:(NSNotification *)aNotification; - (void)windowDidBecomeMain:(NSNotification *)aNotification; - (void)windowWillClose:(NSNotification *)aNotification; diff --git a/PCLib/PCProject.m b/PCLib/PCProject.m index 02bd039..bbd7215 100644 --- a/PCLib/PCProject.m +++ b/PCLib/PCProject.m @@ -25,6 +25,8 @@ */ #import "PCProject.h" +#import "PCProject+ComponentHandling.h" + #import "ProjectCenter.h" #import "PCProjectBuilder.h" #import "PCSplitView.h" @@ -88,49 +90,6 @@ [box setContentViewMargins: NSMakeSize(0.0,0.0)]; [box setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; -/* - rect = [box frame]; - rect.origin.x = -1; - rect.origin.y = -1; - rect.size.width += 2; - - scrollView = [[NSScrollView alloc] initWithFrame:rect]; - - rect.origin.x = 0; - rect.origin.y = 0; - rect.size.height -= 24; - rect.size.width -= 4; - - textView = [[NSTextView alloc] initWithFrame:rect]; - [textView setText:@"This is a test"]; - [textView setDrawsBackground:YES]; - - [textView setMinSize: NSMakeSize (0, 0)]; - [textView setMaxSize:NSMakeSize(1e7, 1e7)]; - [textView setRichText:NO]; - [textView setEditable:YES]; - [textView setSelectable:YES]; - [textView setVerticallyResizable:YES]; - [textView setHorizontallyResizable:NO]; - [textView setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; - [textView setBackgroundColor:[NSColor whiteColor]]; - [[textView textContainer] setWidthTracksTextView:YES]; - - [scrollView setDocumentView:textView]; - [box addSubview:scrollView]; - - rect.size = NSMakeSize([scrollView contentSize].width,1e7); - [[textView textContainer] setContainerSize:rect.size]; - - [scrollView setHasHorizontalScroller: YES]; - [scrollView setHasVerticalScroller: YES]; - [scrollView setBorderType: NSBezelBorder]; - [scrollView setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)]; - - RELEASE(textView); - RELEASE(scrollView); -*/ - textField = [[NSTextField alloc] initWithFrame:NSMakeRect(16,200,500,21)]; [textField setAlignment: NSLeftTextAlignment]; [textField setBordered: NO]; @@ -162,12 +121,12 @@ * Left button matrix */ - rect = NSMakeRect(8,372,240,60); + rect = NSMakeRect(8,372,300,60); matrix = [[NSMatrix alloc] initWithFrame: rect mode: NSHighlightModeMatrix prototype: buttonCell numberOfRows: 1 - numberOfColumns: 4]; + numberOfColumns: 5]; [matrix sizeToCells]; [matrix setTarget:self]; [matrix setAction:@selector(topButtonsPressed:)]; @@ -204,6 +163,13 @@ [button setImage:IMAGE(@"ProjectCentre_run.tiff")]; [button setButtonType:NSMomentaryPushButton]; + button = [matrix cellAtRow:0 column:4]; + [button setTag:4]; + [button setImagePosition:NSImageAbove]; + [button setTitle:@"Editor"]; + [button setImage:IMAGE(@"ProjectCentre_files.tiff")]; + [button setButtonType:NSMomentaryPushButton]; + /* * Build Options Panel * @@ -443,6 +409,8 @@ { if ((self = [super init])) { + editorIsActive = NO; + buildOptions = [[NSMutableDictionary alloc] init]; [self _initUI]; @@ -672,7 +640,17 @@ - (void)browserDidSelectFileNamed:(NSString *)fileName { + NSString *p = [[self projectPath] stringByAppendingPathComponent:fileName]; + PCEditor *e; + + // Set the name in the inspector [fileNameField setStringValue:fileName]; + + // Show the file in the internal editor! + e = [editorController editorForFile:p]; + [e showInProjectEditor:projectEditor]; + [self showEditorView:self]; + [projectWindow makeFirstResponder:[projectEditor editorView]]; } - (BOOL)doesAcceptFile:(NSString *)file forKey:(NSString *)type @@ -1116,117 +1094,8 @@ @end -@implementation PCProject (ProjectBuilding) - -- (void)topButtonsPressed:(id)sender -{ - switch ([[sender selectedCell] tag]) { - case 0: - [self showBuildView:self]; - break; - case 1: - [self showInspector:self]; - break; - case 2: - [self showBuildTargetPanel:self]; - break; - case 3: - if ([self isExecutable]) { - [self showRunView:self]; - } - else { - NSRunAlertPanel(@"Attention!", - @"This project type is not executable!", - @"OK",nil,nil); - } - break; - case 4: - case 5: - case 6: - NSRunAlertPanel(@"Help!",@"This feature is not yet implemented! Please contact me if you are interested in volunteering.",@"Of course!",nil,nil); - break; - default: - break; - } -} - -- (void)showBuildView:(id)sender -{ - NSView *view = nil; - - if (!projectBuilder) { - projectBuilder = [[PCProjectBuilder alloc] initWithProject:self]; - } - - view = [[projectBuilder componentView] retain]; - - [box setContentView:view]; - [box sizeToFit]; - [box display]; -} - -- (void)showRunView:(id)sender -{ - NSView *view = nil; - - if (!projectDebugger) { - projectDebugger = [[PCProjectDebugger alloc] initWithProject:self]; - } - - view = [[projectDebugger componentView] retain]; - - [box setContentView:view]; - [box display]; -} - -- (void)showInspector:(id)sender -{ - [projectManager showInspectorForProject:self]; -} - -- (id)updatedAttributeView -{ - return projectAttributeInspectorView; -} - -- (id)updatedProjectView -{ - return projectProjectInspectorView; -} - -- (id)updatedFilesView -{ - return projectFileInspectorView; -} - -- (void)showBuildTargetPanel:(id)sender -{ - if (![buildTargetPanel isVisible]) - { - [buildTargetPanel center]; - } - - [buildTargetPanel makeKeyAndOrderFront:self]; -} - -- (void)setHost:(id)sender -{ - NSString *host = [buildTargetHostField stringValue]; - [buildOptions setObject:host forKey:BUILD_HOST_KEY]; -} - -- (void)setArguments:(id)sender -{ - NSString *args = [buildTargetArgsField stringValue]; - [buildOptions setObject:args forKey:BUILD_ARGS_KEY]; -} - -- (NSDictionary *)buildOptions -{ - return (NSDictionary *)buildOptions; -} - -@end +//============================================================================= +//============================================================================= @implementation PCProject (ProjectKeyPaths) @@ -1274,8 +1143,21 @@ @implementation PCProject (ProjectWindowDelegate) +- (void)windowDidResignKey:(NSNotification *)aNotification +{ + if( editorIsActive ) + { + [[NSNotificationCenter defaultCenter] postNotificationName:PCEditorDidResignKeyNotification object:self]; + } +} + - (void)windowDidBecomeKey:(NSNotification *)aNotification { + if( editorIsActive ) + { + [[NSNotificationCenter defaultCenter] postNotificationName:PCEditorDidBecomeKeyNotification object:self]; + } + [projectManager setActiveProject:self]; } diff --git a/PCLib/PCProjectBuilder.h b/PCLib/PCProjectBuilder.h index 3d7667c..fcdedc5 100644 --- a/PCLib/PCProjectBuilder.h +++ b/PCLib/PCProjectBuilder.h @@ -28,10 +28,11 @@ #define _PCPROJECTBUILDER_H #import +#import @class PCProject; -@interface PCProjectBuilder : NSObject +@interface PCProjectBuilder : NSObject { NSBox *componentView; NSPopUpButton *popup; diff --git a/PCLib/PCProjectBuilder.m b/PCLib/PCProjectBuilder.m index 0a39b2b..91a46fd 100644 --- a/PCLib/PCProjectBuilder.m +++ b/PCLib/PCProjectBuilder.m @@ -26,6 +26,7 @@ #import "PCProjectBuilder.h" #import "PCProject.h" +#import "PCProject+ComponentHandling.h" #import "PCProjectManager.h" #import diff --git a/PCLib/PCProjectDebugger.h b/PCLib/PCProjectDebugger.h index 87044b8..a302ffb 100644 --- a/PCLib/PCProjectDebugger.h +++ b/PCLib/PCProjectDebugger.h @@ -25,10 +25,11 @@ */ #import +#import @class PCProject; -@interface PCProjectDebugger : NSObject +@interface PCProjectDebugger : NSObject { NSBox *componentView; diff --git a/PCLib/PCProjectEditor.h b/PCLib/PCProjectEditor.h new file mode 100644 index 0000000..9a973ad --- /dev/null +++ b/PCLib/PCProjectEditor.h @@ -0,0 +1,40 @@ +/* + * PCProjectEditor.h created by probert on 2002-02-10 09:27:10 +0000 + * + * Project ProjectCenter + * + * Created with ProjectCenter - http://www.gnustep.org + * + * $Id$ + */ + +#ifndef _PCPROJECTEDITOR_H_ +#define _PCPROJECTEDITOR_H_ + +#import +#import + +@class NSBox; +@class NSScrollView; +@class PCEditorView; + +@interface PCProjectEditor : NSObject +{ + NSBox *componentView; + PCProject *currentProject; + PCEditorView *editor; + NSScrollView *scrollView; +} + +- (id)initWithProject:(PCProject *)aProject; +- (void)dealloc; + +- (NSView *)componentView; + +- (void)setEditorView:(PCEditorView *)ev; +- (PCEditorView *)editorView; + +@end + +#endif // _PCPROJECTEDITOR_H_ + diff --git a/PCLib/PCProjectEditor.m b/PCLib/PCProjectEditor.m new file mode 100644 index 0000000..8f97ece --- /dev/null +++ b/PCLib/PCProjectEditor.m @@ -0,0 +1,125 @@ +/* + * PCProjectEditor.m created by probert on 2002-02-10 09:27:09 +0000 + * + * Project ProjectCenter + * + * Created with ProjectCenter - http://www.gnustep.org + * + * $Id$ + */ + +#import "PCProjectEditor.h" +#import "PCEditorView.h" + +@interface PCProjectEditor (CreateUI) + +- (void)_createComponentView; + +@end + +@implementation PCProjectEditor (CreateUI) + +- (void)_createComponentView +{ + NSPopUpButton *methods; + NSRect frame; + NSTextView *etv; + + componentView = [[NSBox alloc] initWithFrame:NSMakeRect(-1,-1,562,248)]; + [componentView setTitlePosition:NSNoTitle]; + [componentView setBorderType:NSNoBorder]; + [componentView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable]; + [componentView setContentViewMargins: NSMakeSize(0.0,0.0)]; + + frame = NSMakeRect(20,16,240,16); + methods = [[NSPopUpButton alloc] initWithFrame:frame]; + [methods addItemWithTitle:@"No Method"]; + [methods setPullsDown:YES]; + [methods setTarget:self]; + [methods setAction:@selector(pullDownSelected:)]; + [componentView addSubview:methods]; + RELEASE(methods); + + frame = NSMakeRect (-1,32,562,40); + scrollView = [[NSScrollView alloc] initWithFrame:frame]; + [scrollView setHasHorizontalScroller: YES]; + [scrollView setHasVerticalScroller: YES]; + [scrollView setBorderType: NSBezelBorder]; + [scrollView setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)]; + + // This is a placeholder! + frame = [[scrollView contentView] frame]; + etv = [[NSTextView alloc] initWithFrame:frame]; + [etv setMinSize: NSMakeSize (0, 0)]; + [etv setMaxSize:NSMakeSize(1e7, 1e7)]; + [etv setRichText:NO]; + [etv setEditable:NO]; + [etv setSelectable:YES]; + [etv setVerticallyResizable:YES]; + [etv setHorizontallyResizable:NO]; + [etv setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; + [[etv textContainer] setWidthTracksTextView:YES]; + [scrollView setDocumentView:etv]; + RELEASE(etv); + + frame.size = NSMakeSize([scrollView contentSize].width,1e7); + [[etv textContainer] setContainerSize:frame.size]; + + [componentView addSubview:scrollView]; + RELEASE(scrollView); + [componentView sizeToFit]; +} + +@end + +@implementation PCProjectEditor + +- (id)initWithProject:(PCProject *)aProject +{ + NSAssert(aProject,@"No project specified!"); + + if((self = [super init])) + { + currentProject = aProject; + } + return self; +} + +- (void)dealloc +{ + RELEASE(componentView); + + [super dealloc]; +} + +- (NSView *)componentView +{ + if (!componentView) + { + [self _createComponentView]; + } + + return componentView; +} + +- (void)setEditorView:(PCEditorView *)ev +{ + NSRect frame; + + editor = ev; + + frame = [[scrollView contentView] frame]; + + [scrollView setDocumentView:editor]; + [editor setNeedsDisplay:YES]; + + frame.size = NSMakeSize([scrollView contentSize].width,1e7); + [[editor textContainer] setContainerSize:frame.size]; +} + +- (PCEditorView *)editorView +{ + return editor; +} + +@end diff --git a/PCLib/ProjectCenter.h b/PCLib/ProjectCenter.h index 0047a37..d027773 100644 --- a/PCLib/ProjectCenter.h +++ b/PCLib/ProjectCenter.h @@ -30,9 +30,11 @@ #import #import #import +#import #import #import #import +#import #import #import #import @@ -41,6 +43,7 @@ #import #import #import +#import #import #import #import diff --git a/PCLib/ProjectCenter.pcproj b/PCLib/ProjectCenter.pcproj index 763e70c..d45119b 100644 --- a/PCLib/ProjectCenter.pcproj +++ b/PCLib/ProjectCenter.pcproj @@ -15,7 +15,9 @@ PCSplitView.m, PCEditor.m, PCEditorController.m, - PCTextFinder.m + PCTextFinder.m, + PCProjectEditor.m, + PCProject+ComponentHandling.m ); COMPILEROPTIONS = ""; CREATION_DATE = ""; @@ -47,7 +49,10 @@ PCEditor.h, PCEditorController.h, PCDefines.h, - PCTextFinder.h + PCTextFinder.h, + PCProjectEditor.h, + ProjectComponent.h, + PCProject+ComponentHandling.h ); INSTALLDIR = "$(GNUSTEP_SYSTEM_ROOT)"; LANGUAGE = English; diff --git a/PCLib/ProjectComponent.h b/PCLib/ProjectComponent.h new file mode 100644 index 0000000..1e46136 --- /dev/null +++ b/PCLib/ProjectComponent.h @@ -0,0 +1,20 @@ +/* + * ProjectComponent.h created by probert on 2002-02-10 09:29:07 +0000 + * + * Project ProjectCenter + * + * Created with ProjectCenter - http://www.gnustep.org + * + * $Id$ + */ + +@class PCProject; +@class NSView; + +@protocol ProjectComponent + +- (id)initWithProject:(PCProject *)aProject; + +- (NSView *)componentView; + +@end diff --git a/ProjectCenter/PCAppController+MenuHandling.m b/ProjectCenter/PCAppController+MenuHandling.m index 8ae75d2..6f9cf26 100644 --- a/ProjectCenter/PCAppController+MenuHandling.m +++ b/ProjectCenter/PCAppController+MenuHandling.m @@ -29,8 +29,9 @@ #import "PCPrefController.h" #import "PCInfoController.h" -#import -#import +#import "PCProject+ComponentHandling.h" +#import "PCProjectManager.h" +#import "PCTextFinder.h" @implementation PCAppController (MenuHandling)