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
This commit is contained in:
Philippe C.D. Robert 2002-01-29 21:29:30 +00:00
parent 0b9b383d9c
commit e2a9d52ed5
6 changed files with 222 additions and 78 deletions

View file

@ -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
#

43
PCLib/PCEditor.h Normal file
View file

@ -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 <AppKit/AppKit.h>
@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_

130
PCLib/PCEditor.m Normal file
View file

@ -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

View file

@ -64,7 +64,7 @@ extern NSString *PCProjectBuildDidStopNotification;
@interface PCServer : NSObject <Server>
{
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

View file

@ -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];
}
//----------------------------------------------------------------------------

View file

@ -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;