mirror of
https://github.com/gnustep/apps-projectcenter.git
synced 2025-02-21 19:01:18 +00:00
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/projectcenter/trunk@12551 72102866-910b-0410-8b05-ffd578937521
187 lines
4 KiB
Objective-C
187 lines
4 KiB
Objective-C
/*
|
|
* 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
|
|
{
|
|
[editorDict removeAllObjects];
|
|
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];
|
|
[[editor editorWindow] performClose:self];
|
|
}
|
|
[editorDict removeAllObjects];
|
|
}
|
|
|
|
- (void)editorDidClose:(id)sender
|
|
{
|
|
PCEditor *editor = (PCEditor*)sender;
|
|
|
|
[editorDict removeObjectForKey:[editor path]];
|
|
}
|
|
|
|
// ===========================================================================
|
|
// ==== File handling
|
|
// ===========================================================================
|
|
|
|
- (BOOL)saveFile
|
|
{
|
|
NSEnumerator *enumerator = [editorDict keyEnumerator];
|
|
PCEditor *editor;
|
|
NSString *key;
|
|
NSWindow *window;
|
|
|
|
while(( key = [enumerator nextObject] ))
|
|
{
|
|
editor = [editorDict objectForKey:key];
|
|
window = [editor editorWindow];
|
|
|
|
if( [window isKeyWindow] && [window isMainWindow] ||
|
|
[project isEditorActive] && [[project projectWindow] isKeyWindow])
|
|
{
|
|
return [editor saveFile];
|
|
}
|
|
}
|
|
|
|
return NO;
|
|
}
|
|
|
|
- (BOOL)revertFile
|
|
{
|
|
NSEnumerator *enumerator = [editorDict keyEnumerator];
|
|
PCEditor *editor;
|
|
NSString *key;
|
|
NSWindow *window;
|
|
|
|
while(( key = [enumerator nextObject] ))
|
|
{
|
|
editor = [editorDict objectForKey:key];
|
|
window = [editor editorWindow];
|
|
|
|
if( [window isKeyWindow] && [window isMainWindow] ||
|
|
[project isEditorActive] && [[project projectWindow] isKeyWindow])
|
|
{
|
|
return [editor revertFile];
|
|
}
|
|
}
|
|
|
|
return NO;
|
|
}
|
|
|
|
@end
|