2003-11-02 20:58:45 +00:00
|
|
|
/*
|
|
|
|
* PCProjectEditor.m created by probert on 2002-02-10 09:27:09 +0000
|
|
|
|
*
|
|
|
|
* Project ProjectCenter
|
|
|
|
*
|
|
|
|
* Created with ProjectCenter - http://www.gnustep.org
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "PCDefines.h"
|
2003-11-10 18:31:19 +00:00
|
|
|
#include "PCProject.h"
|
|
|
|
#include "PCProjectWindow.h"
|
|
|
|
#include "PCProjectBrowser.h"
|
|
|
|
#include "PCProjectEditor.h"
|
|
|
|
#include "PCEditor.h"
|
2003-11-02 20:58:45 +00:00
|
|
|
#include "PCEditorView.h"
|
|
|
|
#include "ProjectComponent.h"
|
|
|
|
|
|
|
|
@interface PCProjectEditor (CreateUI)
|
|
|
|
|
|
|
|
- (void) _createComponentView;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation PCProjectEditor (CreateUI)
|
|
|
|
|
|
|
|
- (void) _createComponentView
|
|
|
|
{
|
|
|
|
NSRect frame;
|
|
|
|
NSTextView *textView;
|
|
|
|
|
|
|
|
frame = NSMakeRect(0,0,562,248);
|
2003-11-10 18:31:19 +00:00
|
|
|
componentView = [[NSBox alloc] initWithFrame:frame];
|
|
|
|
[componentView setTitlePosition: NSNoTitle];
|
|
|
|
[componentView setBorderType: NSNoBorder];
|
|
|
|
[componentView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
|
|
|
|
[componentView setContentViewMargins: NSMakeSize(0.0,0.0)];
|
2003-11-02 20:58:45 +00:00
|
|
|
|
|
|
|
frame = NSMakeRect (0, 0, 562, 40);
|
2003-11-10 18:31:19 +00:00
|
|
|
scrollView = [[NSScrollView alloc] initWithFrame:frame];
|
|
|
|
[scrollView setHasHorizontalScroller: NO];
|
|
|
|
[scrollView setHasVerticalScroller: YES];
|
|
|
|
[scrollView setBorderType: NSBezelBorder];
|
|
|
|
[scrollView setAutoresizingMask:(NSViewWidthSizable|NSViewHeightSizable)];
|
2003-11-02 20:58:45 +00:00
|
|
|
|
|
|
|
// This is a placeholder!
|
2003-11-10 18:31:19 +00:00
|
|
|
frame = [[scrollView contentView] frame];
|
2003-11-02 20:58:45 +00:00
|
|
|
textView = [[NSTextView alloc] initWithFrame:frame];
|
|
|
|
[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 textContainer] setWidthTracksTextView: YES];
|
2003-11-10 18:31:19 +00:00
|
|
|
[scrollView setDocumentView: textView];
|
2003-11-02 20:58:45 +00:00
|
|
|
RELEASE(textView);
|
|
|
|
|
2003-11-10 18:31:19 +00:00
|
|
|
frame.size = NSMakeSize([scrollView contentSize].width,1e7);
|
2003-11-02 20:58:45 +00:00
|
|
|
[[textView textContainer] setContainerSize:frame.size];
|
|
|
|
|
2003-11-10 18:31:19 +00:00
|
|
|
[componentView addSubview:scrollView];
|
|
|
|
RELEASE(scrollView);
|
2003-11-02 20:58:45 +00:00
|
|
|
|
2003-11-10 18:31:19 +00:00
|
|
|
[componentView sizeToFit];
|
2003-11-02 20:58:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation PCProjectEditor
|
2003-11-10 18:31:19 +00:00
|
|
|
// ===========================================================================
|
|
|
|
// ==== 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];
|
|
|
|
NSString *app;
|
|
|
|
NSArray *ea = [editor componentsSeparatedByString: @" "];
|
|
|
|
|
|
|
|
args = [NSMutableArray arrayWithArray:ea];
|
|
|
|
app = [args objectAtIndex: 0];
|
|
|
|
|
|
|
|
if( [[app pathExtension] isEqualToString:@"app"] )
|
|
|
|
{
|
|
|
|
BOOL ret = [[NSWorkspace sharedWorkspace] openFile:path
|
|
|
|
withApplication:app];
|
|
|
|
|
|
|
|
if( ret == NO )
|
|
|
|
{
|
|
|
|
NSLog(@"Could not open %@ using %@",path,app);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
editorTask = [[NSTask alloc] init];
|
|
|
|
|
|
|
|
[editorTask setLaunchPath:app];
|
|
|
|
[args removeObjectAtIndex: 0];
|
|
|
|
[args addObject:path];
|
|
|
|
|
|
|
|
[editorTask setArguments:args];
|
|
|
|
|
|
|
|
AUTORELEASE( editorTask );
|
|
|
|
[editorTask launch];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PCEditor *editor;
|
|
|
|
|
|
|
|
editor = [[PCEditor alloc] initWithPath:path];
|
|
|
|
[editor setDelegate:self];
|
|
|
|
[editor show];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ===========================================================================
|
|
|
|
// ==== Initialisation
|
|
|
|
// ===========================================================================
|
2003-11-02 20:58:45 +00:00
|
|
|
|
|
|
|
- (id)initWithProject: (PCProject *)aProject
|
|
|
|
{
|
|
|
|
NSAssert(aProject, @"No project specified!");
|
|
|
|
|
|
|
|
if((self = [super init]))
|
|
|
|
{
|
2003-11-10 18:31:19 +00:00
|
|
|
project = aProject;
|
|
|
|
componentView = nil;
|
|
|
|
editorsDict = [[NSMutableDictionary alloc] init];
|
2003-11-02 20:58:45 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2003-11-10 18:31:19 +00:00
|
|
|
if (componentView)
|
2003-11-02 20:58:45 +00:00
|
|
|
{
|
2003-11-10 18:31:19 +00:00
|
|
|
RELEASE(componentView);
|
2003-11-02 20:58:45 +00:00
|
|
|
}
|
|
|
|
|
2003-11-10 18:31:19 +00:00
|
|
|
[editorsDict removeAllObjects];
|
|
|
|
RELEASE( editorsDict );
|
|
|
|
|
2003-11-02 20:58:45 +00:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2003-11-10 18:31:19 +00:00
|
|
|
- (NSView *)emptyEditorView
|
2003-11-02 20:58:45 +00:00
|
|
|
{
|
2003-11-10 18:31:19 +00:00
|
|
|
if (componentView == nil)
|
2003-11-02 20:58:45 +00:00
|
|
|
{
|
|
|
|
[self _createComponentView];
|
|
|
|
}
|
|
|
|
|
2003-11-10 18:31:19 +00:00
|
|
|
return componentView;
|
2003-11-02 20:58:45 +00:00
|
|
|
}
|
|
|
|
|
2003-11-10 18:31:19 +00:00
|
|
|
- (NSView *)componentView
|
|
|
|
{
|
|
|
|
if (componentView == nil)
|
|
|
|
{
|
|
|
|
[self _createComponentView];
|
|
|
|
}
|
|
|
|
|
|
|
|
return componentView;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setEditorView:(PCEditorView *)ev
|
2003-11-02 20:58:45 +00:00
|
|
|
{
|
|
|
|
NSRect frame;
|
|
|
|
|
2003-11-10 18:31:19 +00:00
|
|
|
editorView = ev;
|
2003-11-02 20:58:45 +00:00
|
|
|
|
2003-11-10 18:31:19 +00:00
|
|
|
[scrollView setDocumentView:editorView];
|
2003-11-02 20:58:45 +00:00
|
|
|
|
2003-11-10 18:31:19 +00:00
|
|
|
frame = [[scrollView contentView] frame];
|
|
|
|
frame.size = NSMakeSize([scrollView contentSize].width,1e7);
|
|
|
|
[editorView setFrame:frame];
|
|
|
|
[editorView sizeToFit];
|
2003-11-02 20:58:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (PCEditorView *) editorView
|
|
|
|
{
|
2003-11-10 18:31:19 +00:00
|
|
|
return editorView;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ===========================================================================
|
|
|
|
// ==== Project and Editor handling
|
|
|
|
// ===========================================================================
|
|
|
|
|
|
|
|
- (PCEditor *)internalEditorForFile:(NSString *)path
|
|
|
|
{
|
|
|
|
PCEditor *editor;
|
|
|
|
|
|
|
|
if ((editor = [editorsDict objectForKey:path]))
|
|
|
|
{
|
|
|
|
return editor;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
editor = [[PCEditor alloc] initWithPath:path];
|
|
|
|
|
|
|
|
[editor setDelegate:self];
|
|
|
|
|
|
|
|
[editorsDict setObject:editor forKey:path];
|
|
|
|
//RELEASE(editor);
|
|
|
|
|
|
|
|
return editor;
|
|
|
|
}
|
2003-11-02 20:58:45 +00:00
|
|
|
}
|
|
|
|
|
2003-11-10 18:31:19 +00:00
|
|
|
- (PCEditor *)editorForFile:(NSString *)path
|
|
|
|
{
|
|
|
|
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
|
|
|
|
|
|
|
|
if([[ud objectForKey:ExternalEditor] isEqualToString:@"YES"])
|
|
|
|
{
|
|
|
|
/* [self openFileInEditor:path];*/
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return [self internalEditorForFile:path];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (PCEditor *)activeEditor
|
|
|
|
{
|
|
|
|
NSEnumerator *enumerator = [editorsDict keyEnumerator];
|
|
|
|
PCEditor *editor;
|
|
|
|
NSString *key;
|
|
|
|
NSWindow *window;
|
|
|
|
|
|
|
|
while (( key = [enumerator nextObject] ))
|
|
|
|
{
|
|
|
|
editor = [editorsDict objectForKey:key];
|
|
|
|
window = [editor editorWindow];
|
|
|
|
|
|
|
|
if (([window isVisible] && [window isKeyWindow])
|
|
|
|
|| ([[editor internalView] superview]
|
|
|
|
&& [[project projectWindow] isKeyWindow]))
|
|
|
|
{
|
|
|
|
return editor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *)allEditors
|
|
|
|
{
|
|
|
|
return [editorsDict allValues];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)closeEditorForFile:(NSString *)file
|
|
|
|
{
|
|
|
|
PCEditor *editor;
|
|
|
|
|
|
|
|
editor = [editorsDict objectForKey:file];
|
|
|
|
[editor closeFile:self];
|
|
|
|
[editorsDict removeObjectForKey:file];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)closeAllEditors
|
|
|
|
{
|
|
|
|
NSEnumerator *enumerator = [editorsDict keyEnumerator];
|
|
|
|
PCEditor *editor;
|
|
|
|
NSString *key;
|
|
|
|
|
|
|
|
while ((key = [enumerator nextObject]))
|
|
|
|
{
|
|
|
|
editor = [editorsDict objectForKey:key];
|
|
|
|
[editor closeFile:self];
|
|
|
|
}
|
|
|
|
[editorsDict removeAllObjects];
|
|
|
|
}
|
|
|
|
|
|
|
|
// ===========================================================================
|
|
|
|
// ==== File handling
|
|
|
|
// ===========================================================================
|
|
|
|
|
|
|
|
- (BOOL)saveAllFiles
|
|
|
|
{
|
|
|
|
NSEnumerator *enumerator = [editorsDict keyEnumerator];
|
|
|
|
PCEditor *editor;
|
|
|
|
NSString *key;
|
|
|
|
BOOL ret = YES;
|
|
|
|
|
|
|
|
while(( key = [enumerator nextObject] ))
|
|
|
|
{
|
|
|
|
editor = [editorsDict objectForKey:key];
|
|
|
|
|
|
|
|
if( [editor saveFileIfNeeded] == NO )
|
|
|
|
{
|
|
|
|
ret = NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)saveFile
|
|
|
|
{
|
|
|
|
PCEditor *editor = [self activeEditor];
|
|
|
|
|
|
|
|
if (editor != nil)
|
|
|
|
{
|
|
|
|
return [editor saveFileIfNeeded];
|
|
|
|
}
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)saveFileAs:(NSString *)file
|
|
|
|
{
|
|
|
|
PCEditor *editor = [self activeEditor];
|
|
|
|
|
|
|
|
if (editor != nil)
|
|
|
|
{
|
|
|
|
BOOL res;
|
|
|
|
res = [editor saveFileTo:file];
|
|
|
|
[editor closeFile:self];
|
|
|
|
|
|
|
|
[[self internalEditorForFile:file]
|
|
|
|
showInProjectEditor:[project projectEditor]];
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)saveFileTo:(NSString *)file
|
|
|
|
{
|
|
|
|
PCEditor *editor = [self activeEditor];
|
|
|
|
|
|
|
|
if (editor != nil)
|
|
|
|
{
|
|
|
|
return [editor saveFileTo:file];
|
|
|
|
}
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)revertFileToSaved
|
|
|
|
{
|
|
|
|
PCEditor *editor = [self activeEditor];
|
|
|
|
|
|
|
|
if (editor != nil)
|
|
|
|
{
|
|
|
|
return [editor revertFileToSaved];
|
|
|
|
}
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)closeFile:(id)sender
|
|
|
|
{
|
|
|
|
[[self activeEditor] closeFile:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
// ===========================================================================
|
|
|
|
// ==== Delegate
|
|
|
|
// ===========================================================================
|
|
|
|
|
|
|
|
- (void)editorDidClose:(id)sender
|
|
|
|
{
|
|
|
|
PCEditor *editor = (PCEditor*)sender;
|
|
|
|
|
|
|
|
[editorsDict removeObjectForKey:[editor path]];
|
|
|
|
|
|
|
|
if ([editorsDict count])
|
|
|
|
{
|
|
|
|
editor = [editorsDict objectForKey: [[editorsDict allKeys] lastObject]];
|
|
|
|
[editor showInProjectEditor: [project projectEditor]];
|
|
|
|
[[project projectWindow] makeFirstResponder:[editor internalView]];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[[project projectEditor] setEditorView:nil];
|
|
|
|
// [[project browserController] projectDictDidChange:nil];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setBrowserPath:(NSString *)file category:(NSString *)category
|
|
|
|
{
|
|
|
|
[[project projectBrowser] setPathForFile:file category:category];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-02 20:58:45 +00:00
|
|
|
@end
|
|
|
|
|