From e2a9d52ed54237216c9ba62c44bacadbe5bcca02 Mon Sep 17 00:00:00 2001 From: "Philippe C.D. Robert" Date: Tue, 29 Jan 2002 21:29:30 +0000 Subject: [PATCH] Cleaning up the internal editor code. More to come... git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/projectcenter/trunk@12265 72102866-910b-0410-8b05-ffd578937521 --- PCLib/GNUmakefile | 6 +- PCLib/PCEditor.h | 43 ++++++++++++ PCLib/PCEditor.m | 130 +++++++++++++++++++++++++++++++++++++ PCLib/PCServer.h | 6 +- PCLib/PCServer.m | 109 +++++++++++-------------------- PCLib/ProjectCenter.pcproj | 6 +- 6 files changed, 222 insertions(+), 78 deletions(-) create mode 100644 PCLib/PCEditor.h create mode 100644 PCLib/PCEditor.m diff --git a/PCLib/GNUmakefile b/PCLib/GNUmakefile index ca902ed..92cc4e5 100644 --- a/PCLib/GNUmakefile +++ b/PCLib/GNUmakefile @@ -60,7 +60,8 @@ ProjectDebugger.h \ ProjectEditor.h \ ProjectType.h \ Server.h \ -PCSplitView.h +PCSplitView.h \ +PCEditor.h # @@ -78,7 +79,8 @@ PCProjectBuilder.m \ PCProjectDebugger.m \ PCProjectManager.m \ PCServer.m \ -PCSplitView.m +PCSplitView.m \ +PCEditor.m # diff --git a/PCLib/PCEditor.h b/PCLib/PCEditor.h new file mode 100644 index 0000000..325c2a3 --- /dev/null +++ b/PCLib/PCEditor.h @@ -0,0 +1,43 @@ +/* + * PCEditor.h created by probert on 2002-01-29 20:37:28 +0000 + * + * Project ProjectCenter + * + * Created with ProjectCenter - http://www.gnustep.org + * + * $Id$ + */ + +#ifndef _PCEDITOR_H_ +#define _PCEDITOR_H_ + +#import + +@class PCEditorView; + +@interface PCEditor : NSObject +{ + PCEditorView *view; + NSWindow *window; + NSMutableString *path; + + id delegate; +} + +- (id)initWithPath:(NSString*)file; +- (void)dealloc; + +- (void)setDelegate:(id)aDelegate; +- (id)delegate; + +- (NSWindow *)editorWindow; + +- (void)show; +- (void)close; + +- (void)windowWillClose:(NSNotification *)aNotif; + +@end + +#endif // _PCEDITOR_H_ + diff --git a/PCLib/PCEditor.m b/PCLib/PCEditor.m new file mode 100644 index 0000000..cc54459 --- /dev/null +++ b/PCLib/PCEditor.m @@ -0,0 +1,130 @@ +/* + * PCEditor.m created by probert on 2002-01-29 20:37:27 +0000 + * + * Project ProjectCenter + * + * Created with ProjectCenter - http://www.gnustep.org + * + * $Id$ + */ + +#import "PCEditor.h" +#import "PCEditorView.h" + +@interface PCEditor (InitUI) + +- (void)_initUI; + +@end + +@implementation PCEditor (InitUI) + +- (void)_initUI +{ + NSScrollView *scrollView; + unsigned int style = NSTitledWindowMask + | NSClosableWindowMask + | NSMiniaturizableWindowMask + | NSResizableWindowMask; + + NSRect rect = NSMakeRect(100,100,512,320); + + window = [[NSWindow alloc] initWithContentRect:rect + styleMask:style + backing:NSBackingStoreBuffered + defer:YES]; + + [window setReleasedWhenClosed:NO]; + [window setMinSize:NSMakeSize(512,320)]; + + view = [[PCEditorView alloc] initWithFrame:NSMakeRect(0,0,498,306)]; + + [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] setContainerSize: + NSMakeSize ([view frame].size.width,1e7)]; + [[view textContainer] setWidthTracksTextView:YES]; + + scrollView = [[NSScrollView alloc] initWithFrame:NSMakeRect (-1,-1,514,322)]; + [scrollView setDocumentView:view]; + + [[view textContainer] setContainerSize:NSMakeSize([scrollView contentSize].width,1e7)]; + + [scrollView setHasHorizontalScroller: YES]; + [scrollView setHasVerticalScroller: YES]; + [scrollView setBorderType: NSBezelBorder]; + [scrollView setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)]; + + [window setContentView:scrollView]; + RELEASE(scrollView); +} + +@end + +@implementation PCEditor + +- (id)initWithPath:(NSString*)file +{ + if((self = [super init])) + { + NSString *text = [NSString stringWithContentsOfFile:file]; + + [self _initUI]; + + [window setTitle:file]; + [view setText:text]; + + path = [file copy]; + } + return self; +} + +- (void)dealloc +{ + RELEASE(window); + RELEASE(view); + RELEASE(path); + + [super dealloc]; +} + +- (void)setDelegate:(id)aDelegate +{ + delegate = aDelegate; +} + +- (id)delegate +{ + return delegate; +} + +- (NSWindow *)editorWindow +{ + return window; +} + +- (void)show +{ + [window makeKeyAndOrderFront:self]; +} + +- (void)close +{ + NSLog(@"Closing editor for file %@",path); +} + +- (void)windowWillClose:(NSNotification *)aNotif +{ + if( [[aNotif object] isEqual:window] ) + { + } +} + +@end diff --git a/PCLib/PCServer.h b/PCLib/PCServer.h index 3e3698e..9da1ae8 100644 --- a/PCLib/PCServer.h +++ b/PCLib/PCServer.h @@ -64,7 +64,7 @@ extern NSString *PCProjectBuildDidStopNotification; @interface PCServer : NSObject { NSMutableArray *clients; - NSMutableDictionary *openDocuments; + NSMutableDictionary *editors; } //---------------------------------------------------------------------------- @@ -83,8 +83,8 @@ extern NSString *PCProjectBuildDidStopNotification; - (void)openFileInExternalEditor:(NSString *)file; - (void)openFileInInternalEditor:(NSString *)file; -- (NSWindow *)editorForFile:(NSString *)aFile; -- (void)windowWillClose:(NSNotification *)aNotif; +- (void)closeEditorForFile:(NSString *)file; +- (void)closeAllEditors; //---------------------------------------------------------------------------- // Server diff --git a/PCLib/PCServer.m b/PCLib/PCServer.m index 84068a3..6df1ddd 100644 --- a/PCLib/PCServer.m +++ b/PCLib/PCServer.m @@ -27,6 +27,7 @@ #import "PCServer.h" #import "ProjectCenter.h" #import "PCBrowserController.h" +#import "PCEditor.h" @implementation PCServer @@ -36,9 +37,10 @@ - (id)init { - if ((self = [super init])) { + if ((self = [super init])) + { clients = [[NSMutableArray alloc] init]; - openDocuments = [[NSMutableDictionary alloc] init]; + editors = [[NSMutableDictionary alloc] init]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(fileShouldBeOpened:) name:FileShouldOpenNotification object:nil]; } @@ -49,8 +51,8 @@ { [[NSNotificationCenter defaultCenter] removeObserver:self]; - [openDocuments release]; - [clients release]; + RELEASE(editors); + RELEASE(clients); [super dealloc]; } @@ -74,11 +76,12 @@ - (void)openFileInExternalEditor:(NSString *)file { NSTask *editorTask; - NSMutableArray *args = [NSMutableArray array]; + NSMutableArray *args; NSUserDefaults *udef = [NSUserDefaults standardUserDefaults]; NSString *editor = [udef objectForKey:Editor]; - args = [editor componentsSeparatedByString: @" "]; + args = [NSMutableArray arrayWithArray: + [editor componentsSeparatedByString: @" "]]; editorTask = [[[NSTask alloc] init] autorelease]; [editorTask setLaunchPath:[args objectAtIndex: 0]]; @@ -91,82 +94,46 @@ - (void)openFileInInternalEditor:(NSString *)file { - NSWindow *editorWindow = nil; + PCEditor *editor = nil; - if ((editorWindow = [openDocuments objectForKey:file])) { - [editorWindow makeKeyAndOrderFront:self]; + if((editor = [editors objectForKey:file])) + { + [editor show]; } - else { - editorWindow = [self editorForFile:file]; - - [editorWindow setDelegate:self]; - [editorWindow center]; - [editorWindow makeKeyAndOrderFront:self]; - - [openDocuments setObject:editorWindow forKey:file]; + else + { + editor = [[PCEditor alloc] initWithPath:file]; + + [editor setDelegate:self]; + [editors setObject:editor forKey:file]; + [editor show]; + + RELEASE(editor); } } -- (NSWindow *)editorForFile:(NSString *)aFile +- (void)closeEditorForFile:(NSString *)file { - unsigned int style = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask; - NSRect rect = NSMakeRect(100,100,512,320); - NSWindow *window = [[NSWindow alloc] initWithContentRect:rect - styleMask:style - backing:NSBackingStoreBuffered - defer:YES]; - PCEditorView *textView; - NSScrollView *scrollView; + PCEditor *editor; - NSString *text = [NSString stringWithContentsOfFile:aFile]; - - [window setMinSize:NSMakeSize(512,320)]; - [window setTitle:aFile]; - - textView = [[PCEditorView alloc] initWithFrame:NSMakeRect(0,0,498,306)]; - [textView setMinSize: NSMakeSize (0, 0)]; - [textView setMaxSize:NSMakeSize(1e7, 1e7)]; - [textView setRichText:NO]; - [textView setEditable:NO]; - [textView setSelectable:YES]; - [textView setVerticallyResizable:YES]; - [textView setHorizontallyResizable:NO]; - [textView setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; - [textView setBackgroundColor:[NSColor whiteColor]]; - [[textView textContainer] setContainerSize: - NSMakeSize ([textView frame].size.width,1e7)]; - [[textView textContainer] setWidthTracksTextView:YES]; - - scrollView = [[NSScrollView alloc] initWithFrame:NSMakeRect (-1,-1,514,322)]; - [scrollView setDocumentView:textView]; - [textView release]; - //[textView setMinSize:NSMakeSize(0.0,[scrollView contentSize].height)]; - [[textView textContainer] setContainerSize:NSMakeSize([scrollView contentSize].width,1e7)]; - [scrollView setHasHorizontalScroller: YES]; - [scrollView setHasVerticalScroller: YES]; - [scrollView setBorderType: NSBezelBorder]; - [scrollView setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)]; - - [[window contentView] addSubview:scrollView]; - [scrollView release]; - - /* - * Will be replaced when a real editor is available... - */ - - [textView setText:text]; - - return [window autorelease]; + if((editor = [editors objectForKey:file])) + { + [editor close]; + [editors removeObjectForKey:file]; + } } -- (void)windowWillClose:(NSNotification *)aNotif +- (void)closeAllEditors { - // Otherwise it crashes when reopening the same file?... - NSWindow *window = [[aNotif object] retain]; + NSEnumerator *enumerator = [editors keyEnumerator]; + PCEditor *editor; - /* - [openDocuments removeObjectForKey:[window title]]; - */ + while((editor = [enumerator nextObject])) + { + [editor close]; + } + + [editors removeAllObjects]; } //---------------------------------------------------------------------------- diff --git a/PCLib/ProjectCenter.pcproj b/PCLib/ProjectCenter.pcproj index 661b425..2397441 100644 --- a/PCLib/ProjectCenter.pcproj +++ b/PCLib/ProjectCenter.pcproj @@ -12,7 +12,8 @@ PCProjectDebugger.m, PCProjectManager.m, PCServer.m, - PCSplitView.m + PCSplitView.m, + PCEditor.m ); COMPILEROPTIONS = ""; CREATION_DATE = ""; @@ -40,7 +41,8 @@ ProjectEditor.h, ProjectType.h, Server.h, - PCSplitView.h + PCSplitView.h, + PCEditor.h ); INSTALLDIR = "$(GNUSTEP_SYSTEM_ROOT)"; LANGUAGE = English;