Rewriting the entire editor code. Hence introduced a PCEditorController and

cleaned up the PCServer class. Every project now has a controller which
controls all editors. Editors itself use an editor view to display the files
or external editors.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/projectcenter/trunk@12386 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Philippe C.D. Robert 2002-02-02 17:56:44 +00:00
parent d4bd4d3637
commit 7c264a098c
17 changed files with 355 additions and 180 deletions

View file

@ -61,7 +61,8 @@ ProjectEditor.h \
ProjectType.h \ ProjectType.h \
Server.h \ Server.h \
PCSplitView.h \ PCSplitView.h \
PCEditor.h PCEditor.h \
PCEditorController.h
# #
@ -80,7 +81,8 @@ PCProjectDebugger.m \
PCProjectManager.m \ PCProjectManager.m \
PCServer.m \ PCServer.m \
PCSplitView.m \ PCSplitView.m \
PCEditor.m PCEditor.m \
PCEditorController.m
# #

View file

@ -56,6 +56,3 @@
- (BOOL)browser:(NSBrowser *)sender selectCellWithString:(NSString *)title inColumn:(int)column; - (BOOL)browser:(NSBrowser *)sender selectCellWithString:(NSString *)title inColumn:(int)column;
@end @end
extern NSString *FileShouldOpenNotification;

View file

@ -28,8 +28,6 @@
#import "PCProject.h" #import "PCProject.h"
#import "PCFileManager.h" #import "PCFileManager.h"
NSString *FileShouldOpenNotification = @"FileShouldOpenNotification";
@implementation PCBrowserController @implementation PCBrowserController
- (void)dealloc - (void)dealloc
@ -52,33 +50,36 @@ NSString *FileShouldOpenNotification = @"FileShouldOpenNotification";
- (void)doubleClick:(id)sender - (void)doubleClick:(id)sender
{ {
if ([sender selectedColumn] != 0) { if ([sender selectedColumn] != 0)
{
NSString *category = [[[browser path] componentsSeparatedByString:@"/"] objectAtIndex:1]; NSString *category = [[[browser path] componentsSeparatedByString:@"/"] objectAtIndex:1];
NSString *k = [[project rootCategories] objectForKey:category]; NSString *k = [[project rootCategories] objectForKey:category];
if ([k isEqualToString:PCClasses] || if ([k isEqualToString:PCClasses] ||
[k isEqualToString:PCHeaders] || [k isEqualToString:PCHeaders] ||
[k isEqualToString:PCOtherSources]) { [k isEqualToString:PCOtherSources])
{
NSString *projectPath = [project projectPath]; NSString *projectPath = [project projectPath];
NSString *fn = [self nameOfSelectedFile]; NSString *fn = [self nameOfSelectedFile];
NSString *file = [projectPath stringByAppendingPathComponent:fn]; NSString *file = [projectPath stringByAppendingPathComponent:fn];
NSDictionary *ui =[NSDictionary dictionaryWithObjectsAndKeys:
file,@"FilePathKey",nil];
[[NSNotificationCenter defaultCenter] postNotificationName:FileShouldOpenNotification object:self userInfo:ui]; [[[project editorController] editorForFile:file] show];
} }
else { else
{
NSString *fi; NSString *fi;
NSString *sf = [self nameOfSelectedFile]; NSString *sf = [self nameOfSelectedFile];
fi = [[project projectPath] stringByAppendingPathComponent:sf]; fi = [[project projectPath] stringByAppendingPathComponent:sf];
if([[NSWorkspace sharedWorkspace] openFile:fi] == NO) { if([[NSWorkspace sharedWorkspace] openFile:fi] == NO)
{
NSRunAlertPanel(@"Attention!",@"Could not open %@.",@"OK",nil,nil,fi); NSRunAlertPanel(@"Attention!",@"Could not open %@.",@"OK",nil,nil,fi);
} }
} }
} }
else { else
{
[[PCFileManager fileManager] showAddFileWindow]; [[PCFileManager fileManager] showAddFileWindow];
} }
} }

View file

@ -31,6 +31,7 @@
defaults under the key BundlePaths. defaults under the key BundlePaths.
*/ */
#import <AppKit/AppKit.h> #import <AppKit/AppKit.h>
#import "PreferenceController.h" #import "PreferenceController.h"
@ -60,17 +61,6 @@
- (NSArray *)loadedBundles; - (NSArray *)loadedBundles;
// Returns all loaded ProjectCenter bundles. // Returns all loaded ProjectCenter bundles.
//----------------------------------------------------------------------------
// BundleLoader
//----------------------------------------------------------------------------
- (BOOL)registerProjectSubmenu:(NSMenu *)menu;
- (BOOL)registerFileSubmenu:(NSMenu *)menu;
- (BOOL)registerToolsSubmenu:(NSMenu *)menu;
- (BOOL)registerPrefController:(id<PreferenceController>)prefs;
- (BOOL)registerEditor:(id<ProjectEditor>)anEditor;
- (BOOL)registerDebugger:(id<ProjectDebugger>)aDebugger;
@end @end
@interface NSObject (BundleLoaderDelegates) @interface NSObject (BundleLoaderDelegates)

View file

@ -45,18 +45,21 @@
NSLog([NSString stringWithFormat:@"Loading bundle %@...",path]); NSLog([NSString stringWithFormat:@"Loading bundle %@...",path]);
#endif// DEBUG #endif// DEBUG
if ((bundle = [NSBundle bundleWithPath:path])) { if ((bundle = [NSBundle bundleWithPath:path]))
{
[loadedBundles addObject:bundle]; [loadedBundles addObject:bundle];
#ifdef DEBUG #ifdef DEBUG
NSLog([NSString stringWithFormat:@"Bundle %@ successfully loaded!",path]); NSLog([NSString stringWithFormat:@"Bundle %@ successfully loaded!",path]);
#endif// DEBUG #endif// DEBUG
if (delegate && [delegate respondsToSelector:@selector(bundleLoader: didLoadBundle:)]) { if (delegate && [delegate respondsToSelector:@selector(bundleLoader: didLoadBundle:)])
{
[delegate bundleLoader:self didLoadBundle:bundle]; [delegate bundleLoader:self didLoadBundle:bundle];
} }
} }
else { else
{
NSRunAlertPanel(@"Attention!",@"Could not load %@!",@"OK",nil,nil,path); NSRunAlertPanel(@"Attention!",@"Could not load %@!",@"OK",nil,nil,path);
} }
} }
@ -101,14 +104,17 @@
NSArray *dir; NSArray *dir;
NSString *path = [[NSUserDefaults standardUserDefaults] objectForKey:BundlePaths]; NSString *path = [[NSUserDefaults standardUserDefaults] objectForKey:BundlePaths];
if (!path || [path isEqualToString:@""]) { if (!path || [path isEqualToString:@""])
{
NSDictionary *env = [[NSProcessInfo processInfo] environment]; NSDictionary *env = [[NSProcessInfo processInfo] environment];
NSString *prefix = [env objectForKey:@"GNUSTEP_SYSTEM_ROOT"]; NSString *prefix = [env objectForKey:@"GNUSTEP_SYSTEM_ROOT"];
if (prefix && ![prefix isEqualToString:@""]) { if (prefix && ![prefix isEqualToString:@""])
{
path =[prefix stringByAppendingPathComponent:@"Library/ProjectCenter"]; path =[prefix stringByAppendingPathComponent:@"Library/ProjectCenter"];
} }
else { else
{
path = [NSString stringWithString:@"/usr/GNUstep/System/Library/ProjectCenter"]; path = [NSString stringWithString:@"/usr/GNUstep/System/Library/ProjectCenter"];
} }
@ -116,22 +122,29 @@
[[NSUserDefaults standardUserDefaults] synchronize]; [[NSUserDefaults standardUserDefaults] synchronize];
} }
if (![[NSFileManager defaultManager] fileExistsAtPath:path]) { if (![[NSFileManager defaultManager] fileExistsAtPath:path])
[NSException raise:@"PCBundleLoaderPathException" format:@"No valid bundle path specified:\n%@",path]; {
[NSException raise:@"PCBundleLoaderPathException"
format:@"No valid bundle path specified:\n%@",path];
return; return;
} }
#ifdef DEBUG #ifdef DEBUG
else { else
{
NSLog([NSString stringWithFormat:@"Loading bundles at %@",path]); NSLog([NSString stringWithFormat:@"Loading bundles at %@",path]);
} }
#endif// DEBUG #endif// DEBUG
dir = [[NSFileManager defaultManager] directoryContentsAtPath:path]; dir = [[NSFileManager defaultManager] directoryContentsAtPath:path];
enumerator = [dir objectEnumerator]; enumerator = [dir objectEnumerator];
while (bundleName = [enumerator nextObject]) {
if ([[bundleName pathExtension] isEqualToString:@"bundle"]) { while (bundleName = [enumerator nextObject])
NSString *fullPath = [NSString stringWithFormat:@"%@/%@",path,bundleName]; {
if ([[bundleName pathExtension] isEqualToString:@"bundle"])
{
NSString *fullPath;
fullPath = [NSString stringWithFormat:@"%@/%@",path,bundleName];
[self loadAdditionalBundlesAt:fullPath]; [self loadAdditionalBundlesAt:fullPath];
} }
} }

View file

@ -36,6 +36,7 @@
- (BOOL)isEmbedded; - (BOOL)isEmbedded;
- (NSWindow *)editorWindow; - (NSWindow *)editorWindow;
- (NSString *)path;
- (void)show; - (void)show;
- (void)close; - (void)close;
@ -44,5 +45,11 @@
@end @end
@interface NSObject (PCEditorDelegate )
- (void)editorDidClose:(id)sender;
@end
#endif // _PCEDITOR_H_ #endif // _PCEDITOR_H_

View file

@ -63,6 +63,8 @@
[scrollView setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)]; [scrollView setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)];
[window setContentView:scrollView]; [window setContentView:scrollView];
[window setDelegate:self];
RELEASE(scrollView); RELEASE(scrollView);
} }
@ -113,6 +115,11 @@
return window; return window;
} }
- (NSString *)path
{
return path;
}
- (void)setEmbedded:(BOOL)yn - (void)setEmbedded:(BOOL)yn
{ {
isEmbedded = yn; isEmbedded = yn;
@ -136,13 +143,40 @@
- (void)close - (void)close
{ {
NSLog(@"Closing editor for file %@",path); if( isEmbedded == NO && [window isDocumentEdited] )
{
BOOL ret;
[window makeKeyAndOrderFront:self];
ret = NSRunAlertPanel(@"Edited File!",
@"Should the file be saved before closing?",
@"Yes",@"No",nil);
if( ret == YES )
{
// SAVE
}
[window setDocumentEdited:NO];
}
else if( isEmbedded )
{
}
[window performClose:self];
if( delegate && [delegate respondsToSelector:@selector(editorDidClose:)] )
{
[delegate editorDidClose:self];
}
} }
- (void)windowWillClose:(NSNotification *)aNotif - (void)windowWillClose:(NSNotification *)aNotif
{ {
if( [[aNotif object] isEqual:window] ) if( [[aNotif object] isEqual:window] )
{ {
[self close];
} }
} }

View file

@ -0,0 +1,55 @@
/*
* PCEditorController.h created by probert on 2002-02-02 15:28:33 +0000
*
* Project ProjectCenter
*
* Created with ProjectCenter - http://www.gnustep.org
*
* $Id$
*/
#ifndef _PCEDITORCONTROLLER_H_
#define _PCEDITORCONTROLLER_H_
#import <Foundation/Foundation.h>
@class PCProject;
@class PCEditor;
@interface PCEditorController : NSObject
{
PCProject *project;
NSMutableDictionary *editorDict;
}
// ===========================================================================
// ==== Class Methods
// ===========================================================================
+ (void)openFileInEditor:(NSString *)path;
// ===========================================================================
// ==== Initialisation
// ===========================================================================
- (id)init;
- (void)dealloc;
// ===========================================================================
// ==== Project and Editor handling
// ===========================================================================
- (void)setProject:(PCProject *)aProject;
- (PCEditor *)editorForFile:(NSString *)path;
- (NSArray *)allEditors;
- (void)closeAllEditors;
- (void)editorDidClose:(id)sender;
@end
#endif // _PCEDITORCONTROLLER_H_

138
PCLib/PCEditorController.m Normal file
View file

@ -0,0 +1,138 @@
/*
* PCEditorController.m created by probert on 2002-02-02 15:28:31 +0000
*
* Project ProjectCenter
*
* Created with ProjectCenter - http://www.gnustep.org
*
* $Id$
*/
#import "PCEditorController.h"
#import "PCEditor.h"
#import "PCProject.h"
#import "ProjectCenter.h"
@implementation PCEditorController
// ===========================================================================
// ==== Class Methods
// ===========================================================================
+ (void)openFileInEditor:(NSString *)path
{
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
if([[ud objectForKey:ExternalEditor] isEqualToString:@"YES"])
{
NSTask *editorTask;
NSMutableArray *args;
NSString *editor = [ud objectForKey:Editor];
NSArray *ea = [editor componentsSeparatedByString: @" "];
args = [NSMutableArray arrayWithArray:ea];
editorTask = [[NSTask alloc] init];
[editorTask setLaunchPath:[args objectAtIndex: 0]];
[args removeObjectAtIndex: 0];
[args addObject:path];
[editorTask setArguments:args];
AUTORELEASE( editorTask );
[editorTask launch];
}
else
{
PCEditor *editor;
editor = [[PCEditor alloc] initWithPath:path];
[editor show];
}
}
// ===========================================================================
// ==== Initialisation
// ===========================================================================
- (id)init
{
if((self = [super init]))
{
editorDict = [[NSMutableDictionary alloc] init];
}
return self;
}
- (void)dealloc
{
RELEASE( editorDict );
[super dealloc];
}
// ===========================================================================
// ==== Project and Editor handling
// ===========================================================================
- (void)setProject:(PCProject *)aProject
{
project = aProject;
}
- (PCEditor *)editorForFile:(NSString *)path
{
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
if([[ud objectForKey:ExternalEditor] isEqualToString:@"YES"])
{
[PCEditorController openFileInEditor:path];
}
else
{
PCEditor *editor;
if( editor = [editorDict objectForKey:path] )
{
return editor;
}
else
{
editor = [[PCEditor alloc] initWithPath:path];
[editor setDelegate:self];
[editorDict setObject:editor forKey:path];
//RELEASE(editor);
return editor;
}
}
}
- (NSArray *)allEditors
{
return [editorDict allValues];
}
- (void)closeAllEditors
{
NSEnumerator *enumerator = [editorDict keyEnumerator];
PCEditor *editor;
NSString *key;
while(( key = [enumerator nextObject] ))
{
editor = [editorDict objectForKey:key];
[editor close];
}
[editorDict removeAllObjects];
}
- (void)editorDidClose:(id)sender
{
PCEditor *editor = (PCEditor*)sender;
[editorDict removeObjectForKey:[editor path]];
}
@end

View file

@ -50,4 +50,6 @@
- (void)colouriseComments; - (void)colouriseComments;
- (void)colouriseCPPComments; - (void)colouriseCPPComments;
- (void)keyDown: (NSEvent *)anEvent;
@end @end

View file

@ -41,7 +41,8 @@ static BOOL isInitialised = NO;
- (id)initWithFrame:(NSRect)frameRect - (id)initWithFrame:(NSRect)frameRect
{ {
if ((self = [super initWithFrame:frameRect])) { if ((self = [super initWithFrame:frameRect]))
{
/* /*
* Should move that to initialize... * Should move that to initialize...
@ -357,6 +358,16 @@ static BOOL isInitialised = NO;
} }
} }
- (void)keyDown: (NSEvent *)anEvent
{
if( [[self window] isDocumentEdited] == NO )
{
[[self window] setDocumentEdited:YES];
}
[super keyDown:anEvent];
}
@end @end

View file

@ -106,6 +106,7 @@ static NSString * const PCBuildTool = @"BUILDTOOL";
@class PCProjectBuilder; @class PCProjectBuilder;
@class PCProjectDebugger; @class PCProjectDebugger;
@class PCEditorController;
@interface PCProject : NSObject @interface PCProject : NSObject
{ {
@ -116,6 +117,7 @@ static NSString * const PCBuildTool = @"BUILDTOOL";
PCProjectBuilder *projectBuilder; PCProjectBuilder *projectBuilder;
PCProjectDebugger *projectDebugger; PCProjectDebugger *projectDebugger;
PCEditorController *editorController;
NSBox *box; NSBox *box;
id projectAttributeInspectorView; id projectAttributeInspectorView;
@ -167,6 +169,8 @@ static NSString * const PCBuildTool = @"BUILDTOOL";
- (Class)principalClass; - (Class)principalClass;
- (PCEditorController*)editorController;
//============================================================================= //=============================================================================
// ==== Delegate and manager // ==== Delegate and manager
//============================================================================= //=============================================================================

View file

@ -28,6 +28,7 @@
#import "ProjectCenter.h" #import "ProjectCenter.h"
#import "PCProjectBuilder.h" #import "PCProjectBuilder.h"
#import "PCSplitView.h" #import "PCSplitView.h"
#import "PCEditorController.h"
#if defined(GNUSTEP) #if defined(GNUSTEP)
#import <AppKit/IMLoading.h> #import <AppKit/IMLoading.h>
@ -399,15 +400,19 @@
@implementation PCProject @implementation PCProject
//=========================================================================================== //==============================================================================
// ==== Init and free // ==== Init and free
//=========================================================================================== //==============================================================================
- (id)init - (id)init
{ {
if ((self = [super init])) { if ((self = [super init]))
{
buildOptions = [[NSMutableDictionary alloc] init]; buildOptions = [[NSMutableDictionary alloc] init];
[self _initUI]; [self _initUI];
editorController = [[PCEditorController alloc] init];
[editorController setProject:self];
} }
return self; return self;
} }
@ -416,7 +421,8 @@
{ {
NSAssert(dict,@"No valid project dictionary!"); NSAssert(dict,@"No valid project dictionary!");
if ((self = [self init])) { if ((self = [self init]))
{
if ([[path lastPathComponent] isEqualToString:@"PC.project"]) { if ([[path lastPathComponent] isEqualToString:@"PC.project"]) {
projectPath = [[path stringByDeletingLastPathComponent] copy]; projectPath = [[path stringByDeletingLastPathComponent] copy];
} }
@ -466,13 +472,14 @@
RELEASE(changeFileNameButton); RELEASE(changeFileNameButton);
RELEASE(box); RELEASE(box);
RELEASE(editorController);
[super dealloc]; [super dealloc];
} }
//=========================================================================================== //==============================================================================
// ==== Accessor methods // ==== Accessor methods
//=========================================================================================== //==============================================================================
- (id)browserController - (id)browserController
{ {
@ -534,9 +541,14 @@
return [self class]; return [self class];
} }
//=========================================================================================== - (PCEditorController*)editorController
{
return editorController;
}
//==============================================================================
// ==== Delegate and manager // ==== Delegate and manager
//=========================================================================================== //==============================================================================
- (id)delegate - (id)delegate
{ {
@ -548,7 +560,7 @@
delegate = aDelegate; delegate = aDelegate;
} }
- (void)setProjectBuilder:(id<ProjectBuilder>)aBuilder - (void)setProjectBuilder:(id<ProjectBuilder,NSObject>)aBuilder
{ {
AUTORELEASE(projectManager); AUTORELEASE(projectManager);
projectManager = RETAIN(aBuilder); projectManager = RETAIN(aBuilder);
@ -559,9 +571,9 @@
return projectManager; return projectManager;
} }
//=========================================================================================== //==============================================================================
// ==== To be overriden // ==== To be overriden
//=========================================================================================== //==============================================================================
- (Class)builderClass - (Class)builderClass
{ {
@ -655,7 +667,7 @@
if ([type isEqualToString:PCLibraries]) { if ([type isEqualToString:PCLibraries]) {
[newFile deleteCharactersInRange:NSMakeRange(0,3)]; [newFile deleteCharactersInRange:NSMakeRange(0,3)];
newFile = [newFile stringByDeletingPathExtension]; newFile = (NSMutableString*)[newFile stringByDeletingPathExtension];
} }
if ([files containsObject:newFile]) { if ([files containsObject:newFile]) {
@ -807,7 +819,6 @@
- (BOOL)save - (BOOL)save
{ {
BOOL ret = NO; BOOL ret = NO;
//NSString *file = [projectPath stringByAppendingPathComponent:@"PC.project"];
NSString *file = [[projectPath stringByAppendingPathComponent:projectName] stringByAppendingPathExtension:@"pcproj"]; NSString *file = [[projectPath stringByAppendingPathComponent:projectName] stringByAppendingPathExtension:@"pcproj"];
NSString *backup = [file stringByAppendingPathExtension:@"backup"]; NSString *backup = [file stringByAppendingPathExtension:@"backup"];
NSFileManager *fm = [NSFileManager defaultManager]; NSFileManager *fm = [NSFileManager defaultManager];
@ -1237,17 +1248,22 @@
{ {
id object = [aNotification object]; id object = [aNotification object];
if (object == buildTargetPanel) { if (object == buildTargetPanel)
{
} }
else if (object == [self projectWindow]) { else if (object == [self projectWindow])
if ([[self projectWindow] isDocumentEdited]) { {
if ([[self projectWindow] isDocumentEdited])
{
if (NSRunAlertPanel(@"Project changed!", if (NSRunAlertPanel(@"Project changed!",
@"The project %@ has unsaved files! Should they be saved before closing?", @"The project %@ has been edited! Should it be saved before closing?",
@"Yes", @"No", nil,[self projectName])) @"Yes", @"No", nil,[self projectName]))
{ {
[self save]; [self save];
} }
} }
[editorController closeAllEditors];
// The PCProjectController is our delegate! // The PCProjectController is our delegate!
[[NSNotificationCenter defaultCenter] removeObserver:browserController]; [[NSNotificationCenter defaultCenter] removeObserver:browserController];

View file

@ -25,6 +25,7 @@
*/ */
#import "PCProjectManager.h" #import "PCProjectManager.h"
#import "PCEditorController.h"
#import "ProjectCenter.h" #import "ProjectCenter.h"
#if defined(GNUSTEP) #if defined(GNUSTEP)
@ -130,8 +131,8 @@ NSString *ActiveProjectDidChangeNotification = @"ActiveProjectDidChange";
- (void)dealloc - (void)dealloc
{ {
[rootBuildPath release]; RELEASE(rootBuildPath);
[loadedProjects release]; RELEASE(loadedProjects);
if( [saveTimer isValid] ) if( [saveTimer isValid] )
{ {
@ -142,9 +143,9 @@ NSString *ActiveProjectDidChangeNotification = @"ActiveProjectDidChange";
if (_needsReleasing) if (_needsReleasing)
{ {
[inspector release]; RELEASE(inspector);
[inspectorView release]; RELEASE(inspectorView);
[inspectorPopup release]; RELEASE(inspectorPopup);
} }
[super dealloc]; [super dealloc];
@ -265,12 +266,14 @@ NSString *ActiveProjectDidChangeNotification = @"ActiveProjectDidChange";
- (PCProject *)loadProjectAt:(NSString *)aPath - (PCProject *)loadProjectAt:(NSString *)aPath
{ {
if (delegate && [delegate respondsToSelector:@selector(projectTypes)]) { if (delegate && [delegate respondsToSelector:@selector(projectTypes)])
NSDictionary *builders = [delegate projectTypes]; {
NSEnumerator *enumerator = [builders keyEnumerator]; NSDictionary *builders = [delegate projectTypes];
NSString *builderKey; NSEnumerator *enumerator = [builders keyEnumerator];
NSString *builderKey;
while (builderKey = [enumerator nextObject]) { while (builderKey = [enumerator nextObject])
{
id<ProjectType> concretBuilder; id<ProjectType> concretBuilder;
PCProject *project; PCProject *project;
@ -280,19 +283,17 @@ NSString *ActiveProjectDidChangeNotification = @"ActiveProjectDidChange";
concretBuilder = [NSClassFromString([builders objectForKey:builderKey]) sharedCreator]; concretBuilder = [NSClassFromString([builders objectForKey:builderKey]) sharedCreator];
if ((project = [concretBuilder openProjectAt:aPath])) { if ((project = [concretBuilder openProjectAt:aPath]))
{
[[project projectWindow] center]; [[project projectWindow] center];
return project; return project;
} }
} }
} }
#ifdef DEBUG
else { NSRunAlertPanel(@"Loading Project Failed!",@"Could not load project '%@'!",@"OK",nil,nil,aPath);
NSLog(@"No project manager delegate available!");
}
#endif // DEBUG
return nil; return nil;
} }
@ -466,7 +467,7 @@ NSString *ActiveProjectDidChangeNotification = @"ActiveProjectDidChange";
key = [path stringByAppendingPathComponent:projectName]; key = [path stringByAppendingPathComponent:projectName];
key = [key stringByAppendingPathExtension:@"pcproj"]; key = [key stringByAppendingPathExtension:@"pcproj"];
currentProject = [[loadedProjects objectForKey:key] retain]; currentProject = RETAIN( [loadedProjects objectForKey:key] );
if( !currentProject ) if( !currentProject )
{ {
@ -482,7 +483,7 @@ NSString *ActiveProjectDidChangeNotification = @"ActiveProjectDidChange";
[inspector performClose:self]; [inspector performClose:self];
} }
AUTORELEASE(currentProject); AUTORELEASE( currentProject );
} }
- (void)closeProject - (void)closeProject
@ -498,11 +499,11 @@ NSString *ActiveProjectDidChangeNotification = @"ActiveProjectDidChange";
{ {
BOOL isDir; BOOL isDir;
NSFileManager *fm = [NSFileManager defaultManager]; NSFileManager *fm = [NSFileManager defaultManager];
NSDictionary *ui =[NSDictionary dictionaryWithObjectsAndKeys:path,@"FilePathKey", nil];
if ([fm fileExistsAtPath:path isDirectory:&isDir] && !isDir) if ([fm fileExistsAtPath:path isDirectory:&isDir] && !isDir)
{ {
[[NSNotificationCenter defaultCenter] postNotificationName:FileShouldOpenNotification object:self userInfo:ui]; [PCEditorController openFileInEditor:path];
return YES; return YES;
} }

View file

@ -64,7 +64,6 @@ extern NSString *PCProjectBuildDidStopNotification;
@interface PCServer : NSObject <Server> @interface PCServer : NSObject <Server>
{ {
NSMutableArray *clients; NSMutableArray *clients;
NSMutableDictionary *editors;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -74,18 +73,6 @@ extern NSString *PCProjectBuildDidStopNotification;
- (id)init; - (id)init;
- (void)dealloc; - (void)dealloc;
//----------------------------------------------------------------------------
// Miscellaneous
//----------------------------------------------------------------------------
- (void)fileShouldBeOpened:(NSNotification *)aNotif;
- (void)openFileInExternalEditor:(NSString *)file;
- (void)openFileInInternalEditor:(NSString *)file;
- (void)closeEditorForFile:(NSString *)file;
- (void)closeAllEditors;
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// Server // Server
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View file

@ -40,102 +40,17 @@
if ((self = [super init])) if ((self = [super init]))
{ {
clients = [[NSMutableArray alloc] init]; clients = [[NSMutableArray alloc] init];
editors = [[NSMutableDictionary alloc] init];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(fileShouldBeOpened:) name:FileShouldOpenNotification object:nil];
} }
return self; return self;
} }
- (void)dealloc - (void)dealloc
{ {
[[NSNotificationCenter defaultCenter] removeObserver:self];
RELEASE(editors);
RELEASE(clients); RELEASE(clients);
[super dealloc]; [super dealloc];
} }
//----------------------------------------------------------------------------
// Miscellaneous
//----------------------------------------------------------------------------
- (void)fileShouldBeOpened:(NSNotification *)aNotif
{
NSString *file = [[aNotif userInfo] objectForKey:@"FilePathKey"];
if ([[[NSUserDefaults standardUserDefaults] objectForKey:ExternalEditor] isEqualToString:@"YES"]) {
[self openFileInExternalEditor:file];
}
else {
[self openFileInInternalEditor:file];
}
}
- (void)openFileInExternalEditor:(NSString *)file
{
NSTask *editorTask;
NSMutableArray *args;
NSUserDefaults *udef = [NSUserDefaults standardUserDefaults];
NSString *editor = [udef objectForKey:Editor];
args = [NSMutableArray arrayWithArray:
[editor componentsSeparatedByString: @" "]];
editorTask = [[[NSTask alloc] init] autorelease];
[editorTask setLaunchPath:[args objectAtIndex: 0]];
[args removeObjectAtIndex: 0];
[args addObject:file];
[editorTask setArguments:args];
[editorTask launch];
}
- (void)openFileInInternalEditor:(NSString *)file
{
PCEditor *editor = nil;
if((editor = [editors objectForKey:file]))
{
[editor show];
}
else
{
editor = [[PCEditor alloc] initWithPath:file];
[editor setDelegate:self];
[editors setObject:editor forKey:file];
[editor show];
RELEASE(editor);
}
}
- (void)closeEditorForFile:(NSString *)file
{
PCEditor *editor;
if((editor = [editors objectForKey:file]))
{
[editor close];
[editors removeObjectForKey:file];
}
}
- (void)closeAllEditors
{
NSEnumerator *enumerator = [editors keyEnumerator];
PCEditor *editor;
while((editor = [enumerator nextObject]))
{
[editor close];
}
[editors removeAllObjects];
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// Server // Server
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View file

@ -13,7 +13,8 @@
PCProjectManager.m, PCProjectManager.m,
PCServer.m, PCServer.m,
PCSplitView.m, PCSplitView.m,
PCEditor.m PCEditor.m,
PCEditorController.m
); );
COMPILEROPTIONS = ""; COMPILEROPTIONS = "";
CREATION_DATE = ""; CREATION_DATE = "";
@ -42,7 +43,8 @@
ProjectType.h, ProjectType.h,
Server.h, Server.h,
PCSplitView.h, PCSplitView.h,
PCEditor.h PCEditor.h,
PCEditorController.h
); );
INSTALLDIR = "$(GNUSTEP_SYSTEM_ROOT)"; INSTALLDIR = "$(GNUSTEP_SYSTEM_ROOT)";
LANGUAGE = English; LANGUAGE = English;