* Framework/PCEditorManager.m: Added.

* Headers/ProjectCenter/PCEditormanager.h: Added.
* PCMenuController.m: (-fileSaveAs:): move code to 
PCProjectManager.m.
* Headers/ProjectCenter/PCEditorManager.h: New file.
* Framework/PCEditorManager.m: New file. Superclass for
PCProjectEditor.
* Framework/PCProjectManager.m: Use PCEditorManager.
Implement opening files outside of projects (fixes bug #15992).
* Framework/PCProjectLoadedFiles.m: Use PCEditorManager.
* Framework/PCProject.m: (-setProjectManager:): Use new
method of initializing PCProjectEditor.
* Framework/GNUmakefile: Add PCEditorManager.[hm].
* Framework/PCProjectBrowser.m: Made use of 
PCProjectEditor's editorForFile: method.
* Framework/PCProjectEditor.m: Remove initializing of extern
variables (moved into PCEditorManager). Use '_componentView'
var instead of 'componentView'. The same with _scrollView and
_project.
(-initWithProject:): renamed into init. Removed code duplicated
with superclass' code.
(-dealloc): Removed code duplicated with superclass' code.
(-editorForFile🔑): Removed. Code moved into superclass'
editorForFile: method.
(-openEditorForCategoryPath:windowed:): Code that determines
existance of file and if file is plain text move into
[super openEditorForFile:editable:windowed:]. Changed file
opening coditions. Made use of [<CodeEditor> fileStructureItemSelected]
method. Code that determines classes and methods in category path
was removed.
(openEditorForFile:categoryPath:editable:windowed:): Removed in favour
of superclass' method.
(activeEditor): Ditto.
(allEditors): Ditto.
(closeActiveEditor:): Ditto.
(closeEditorForFile:): Ditto.
(saveFile): Ditto.
(saveFileTo:): Ditto.
(revertFileToSaved): Ditto.
(editorDidResignActive:): Ditto.
(editorDidChangeFileName:): Ditto.
(closeAllEditors:): Cleanup.
(saveFileAs:): Made use of new -openEditorForFile:editable:windowed:
method.
* Framework/PCProjectWindow.m: Made usage of editorManager method
of <CodeEditor> protocol.
* Modules/Editors/ProjectCenter/PCEditorView.m: 
(becomeFirstResponder): Use new -becomeFirstResponder: method of
PCEditor class.
* Modules/Editors/ProjectCenter/PCEditor.h: Change name of var 
projectEditor to _editorManager. Add parameter (PCEditorView *)view
to becomeFistResponder and resignFirstResponder methods. Add some
comments.
* Modules/Editors/ProjectCenter/PCEditor.m: Rename method
-openFileAtPath:categoryPath:projectEditor:editable: to
-openFileAtPath:editorManager:editable. Rename -projectEditor method
to -editorManager. Change becomeFistResponder and resignFirstResponder 
methods' definitions.
(fileStructureItemSelected:): Add initial implementation of action 
code according to the type of selected item.
* Headers/Protocols/CodeEditor.h: Change definition of
-openFileAtPath:categoryPath:projectEditor:editable: mathod to
-openFileAtPath:editorManager:editable. Remove methods
scrollToClassName: and scrollToMethodName:. Rename projectEditor
method into editorManager.
* Headers/ProjectCenter/PCProjectEditor.h: Made PCProjectEditor
as subclass of PCEditorManager. Add prefix '_' to variables.
(-initWithProject:): renamed into init.
(setProject:): Added.
Removed methods and variables duplicated with superclass.
* Headers/ProjectCenter/PCProjectManager.h: Add editorManager var.
(-saveFileAs:): renamed to saveFileAs. 



git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/projectcenter/trunk@25991 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Sergii Stoian 2008-01-21 22:26:36 +00:00
parent d2852f9571
commit 4e24cf3451
17 changed files with 805 additions and 471 deletions

View file

@ -1,3 +1,78 @@
2008-01-22 Sergii Stoian <stoyan255@gmail.com>
* Framework/PCEditorManager.m: Added.
* Headers/ProjectCenter/PCEditormanager.h: Added.
* PCMenuController.m: (-fileSaveAs:): move code to
PCProjectManager.m.
* Headers/ProjectCenter/PCEditorManager.h: New file.
* Framework/PCEditorManager.m: New file. Superclass for
PCProjectEditor.
* Framework/PCProjectManager.m: Use PCEditorManager.
Implement opening files outside of projects (fixes bug #15992).
* Framework/PCProjectLoadedFiles.m: Use PCEditorManager.
* Framework/PCProject.m: (-setProjectManager:): Use new
method of initializing PCProjectEditor.
* Framework/GNUmakefile: Add PCEditorManager.[hm].
* Framework/PCProjectBrowser.m: Made use of
PCProjectEditor's editorForFile: method.
* Framework/PCProjectEditor.m: Remove initializing of extern
variables (moved into PCEditorManager). Use '_componentView'
var instead of 'componentView'. The same with _scrollView and
_project.
(-initWithProject:): renamed into init. Removed code duplicated
with superclass' code.
(-dealloc): Removed code duplicated with superclass' code.
(-editorForFile:key:): Removed. Code moved into superclass'
editorForFile: method.
(-openEditorForCategoryPath:windowed:): Code that determines
existance of file and if file is plain text move into
[super openEditorForFile:editable:windowed:]. Changed file
opening coditions. Made use of [<CodeEditor> fileStructureItemSelected]
method. Code that determines classes and methods in category path
was removed.
(openEditorForFile:categoryPath:editable:windowed:): Removed in favour
of superclass' method.
(activeEditor): Ditto.
(allEditors): Ditto.
(closeActiveEditor:): Ditto.
(closeEditorForFile:): Ditto.
(saveFile): Ditto.
(saveFileTo:): Ditto.
(revertFileToSaved): Ditto.
(editorDidResignActive:): Ditto.
(editorDidChangeFileName:): Ditto.
(closeAllEditors:): Cleanup.
(saveFileAs:): Made use of new -openEditorForFile:editable:windowed:
method.
* Framework/PCProjectWindow.m: Made usage of editorManager method
of <CodeEditor> protocol.
* Modules/Editors/ProjectCenter/PCEditorView.m:
(becomeFirstResponder): Use new -becomeFirstResponder: method of
PCEditor class.
* Modules/Editors/ProjectCenter/PCEditor.h: Change name of var
projectEditor to _editorManager. Add parameter (PCEditorView *)view
to becomeFistResponder and resignFirstResponder methods. Add some
comments.
* Modules/Editors/ProjectCenter/PCEditor.m: Rename method
-openFileAtPath:categoryPath:projectEditor:editable: to
-openFileAtPath:editorManager:editable. Rename -projectEditor method
to -editorManager. Change becomeFistResponder and resignFirstResponder
methods' definitions.
(fileStructureItemSelected:): Add initial implementation of action
code according to the type of selected item.
* Headers/Protocols/CodeEditor.h: Change definition of
-openFileAtPath:categoryPath:projectEditor:editable: mathod to
-openFileAtPath:editorManager:editable. Remove methods
scrollToClassName: and scrollToMethodName:. Rename projectEditor
method into editorManager.
* Headers/ProjectCenter/PCProjectEditor.h: Made PCProjectEditor
as subclass of PCEditorManager. Add prefix '_' to variables.
(-initWithProject:): renamed into init.
(setProject:): Added.
Removed methods and variables duplicated with superclass.
* Headers/ProjectCenter/PCProjectManager.h: Add editorManager var.
(-saveFileAs:): renamed to saveFileAs.
2008-01-17 Sergii Stoian <stoyan255@gmail.com>
* Framework/PCProjectBrowser.m: (doubleClick:): open file with

View file

@ -29,6 +29,7 @@ ProjectCenter_HEADER_FILES = \
ProjectCenter.h \
\
PCBundleManager.h \
PCEditorManager.h \
PCFileManager.h \
PCAddFilesPanel.h \
PCFileCreator.h \
@ -58,6 +59,7 @@ ProjectCenter_HEADER_FILES = \
ProjectCenter_OBJC_FILES = \
PCBundleManager.m \
PCEditorManager.m \
PCMakefileFactory.m \
PCFileManager.m \
PCAddFilesPanel.m \

387
Framework/PCEditorManager.m Normal file
View file

@ -0,0 +1,387 @@
/*
GNUstep ProjectCenter - http://www.gnustep.org/experience/ProjectCenter.html
Copyright (C) 2002-2004 Free Software Foundation
Authors: Philippe C.D. Robert
Serg Stoyan
This file is part of GNUstep.
This application is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This application is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#import <ProjectCenter/PCDefines.h>
#import <ProjectCenter/PCFileManager.h>
#import <ProjectCenter/PCProjectManager.h>
#import <ProjectCenter/PCBundleManager.h>
#import <ProjectCenter/PCEditorManager.h>
#import <ProjectCenter/PCLogController.h>
NSString *PCEditorDidChangeFileNameNotification =
@"PCEditorDidChangeFileNameNotification";
NSString *PCEditorWillOpenNotification = @"PCEditorWillOpenNotification";
NSString *PCEditorDidOpenNotification = @"PCEditorDidOpenNotification";
NSString *PCEditorWillCloseNotification = @"PCEditorWillCloseNotification";
NSString *PCEditorDidCloseNotification = @"PCEditorDidCloseNotification";
NSString *PCEditorWillChangeNotification = @"PCEditorWillChangeNotification";
NSString *PCEditorDidChangeNotification = @"PCEditorDidChangeNotification";
NSString *PCEditorWillSaveNotification = @"PCEditorWillSaveNotification";
NSString *PCEditorDidSaveNotification = @"PCEditorDidSaveNotification";
NSString *PCEditorWillRevertNotification = @"PCEditorWillRevertNotification";
NSString *PCEditorDidRevertNotification = @"PCEditorDidRevertNotification";
NSString *PCEditorDidBecomeActiveNotification =
@"PCEditorDidBecomeActiveNotification";
NSString *PCEditorDidResignActiveNotification =
@"PCEditorDidResignActiveNotification";
@implementation PCEditorManager
// ===========================================================================
// ==== Initialisation
// ===========================================================================
- (id)init
{
if ((self = [super init]))
{
PCLogStatus(self, @"[init]");
_editorsDict = [[NSMutableDictionary alloc] init];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(editorDidOpen:)
name:PCEditorDidOpenNotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(editorDidClose:)
name:PCEditorDidCloseNotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(editorDidBecomeActive:)
name:PCEditorDidBecomeActiveNotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(editorDidResignActive:)
name:PCEditorDidResignActiveNotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(editorDidChangeFileName:)
name:PCEditorDidChangeFileNameNotification
object:nil];
}
return self;
}
- (void)dealloc
{
#ifdef DEVELOPMENT
#endif
NSLog (@"PCEditorManager: dealloc");
[[NSNotificationCenter defaultCenter] removeObserver:self];
RELEASE(_editorsDict);
[super dealloc];
}
- (PCProjectManager *)projectManager
{
return _projectManager;
}
- (void)setProjectManager:(PCProjectManager *)aProjectManager
{
_projectManager = aProjectManager;
}
// ===========================================================================
// ==== Project and Editor handling
// ===========================================================================
- (id<CodeEditor>)editorForFile:(NSString *)filePath
{
return [_editorsDict objectForKey:filePath];
}
- (id<CodeEditor>)openEditorForFile:(NSString *)filePath
editable:(BOOL)editable
windowed:(BOOL)windowed
{
NSFileManager *fm = [NSFileManager defaultManager];
BOOL isDir;
PCBundleManager *bundleManager = [_projectManager bundleManager];
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
NSString *ed = [ud objectForKey:Editor];
NSString *fileName = [filePath lastPathComponent];
id<CodeEditor> editor;
id<CodeParser> parser;
NSLog(@"EditorManager: openEditorForFile: \"%@\"", filePath);
// Determine if file not exist or file is directory
if (![fm fileExistsAtPath:filePath isDirectory:&isDir] || isDir)
{
NSLog(@"%@ doesn't exist!");
return nil;
}
// Determine if file is text file
if (![[PCFileManager defaultManager] isTextFile:filePath])
{
NSLog(@"%@ is not plan text file!");
return nil;
}
if (!(editor = [_editorsDict objectForKey:filePath]))
{
NSLog(@"Opening new editor");
// Editor
editor = [bundleManager objectForBundleWithName:ed
type:@"editor"
protocol:@protocol(CodeEditor)];
if (editor == nil)
{
editor = [bundleManager
objectForBundleWithName:@"ProjectCenter"
type:@"editor"
protocol:@protocol(CodeEditor)];
return nil;
}
// Parser
parser = [bundleManager objectForBundleType:@"parser"
protocol:@protocol(CodeParser)
fileName:fileName];
[editor setParser:parser];
[editor openFileAtPath:filePath
editorManager:self
editable:editable];
[_editorsDict setObject:editor forKey:filePath];
RELEASE(editor);
}
[editor setWindowed:windowed];
[self orderFrontEditorForFile:filePath];
NSLog(@"EditorManager: %@", _editorsDict);
return editor;
}
- (void)orderFrontEditorForFile:(NSString *)path
{
id<CodeEditor> editor = [_editorsDict objectForKey:path];
if (!editor)
{
return;
}
[editor show];
}
- (id<CodeEditor>)activeEditor
{
return _activeEditor;
}
- (void)setActiveEditor:(id<CodeEditor>)anEditor
{
if (anEditor != _activeEditor)
{
_activeEditor = anEditor;
}
}
- (NSArray *)allEditors
{
return [_editorsDict allValues];
}
- (void)closeActiveEditor:(id)sender
{
if (!_activeEditor)
{
return;
}
[_activeEditor closeFile:self save:YES];
}
- (void)closeEditorForFile:(NSString *)file
{
id<CodeEditor> editor;
if ([_editorsDict count] > 0 && (editor = [_editorsDict objectForKey:file]))
{
[editor closeFile:self save:YES];
[_editorsDict removeObjectForKey:file];
}
}
// ===========================================================================
// ==== Active editor file handling
// ===========================================================================
- (BOOL)saveFile
{
id<CodeEditor> editor = [self activeEditor];
if (editor != nil)
{
return [editor saveFileIfNeeded];
}
return NO;
}
- (BOOL)saveFileAs:(NSString *)file
{
id<CodeEditor> editor = [self activeEditor];
if (editor != nil)
{
BOOL res;
BOOL iw = [editor isWindowed];
res = [editor saveFileTo:file];
[editor closeFile:self save:NO];
[self openEditorForFile:file
editable:YES
windowed:iw];
return res;
}
return NO;
}
- (BOOL)saveFileTo:(NSString *)file
{
id<CodeEditor> editor = [self activeEditor];
if (editor != nil)
{
return [editor saveFileTo:file];
}
return NO;
}
- (BOOL)revertFileToSaved
{
id<CodeEditor> editor = [self activeEditor];
if (editor != nil)
{
return [editor revertFileToSaved];
}
return NO;
}
// ===========================================================================
// ==== Notifications
// ===========================================================================
- (void)editorDidOpen:(NSNotification *)aNotif
{
id editor = [aNotif object];
[self setActiveEditor:editor];
}
- (void)editorDidClose:(NSNotification *)aNotif
{
id editor = [aNotif object];
// It is not our editor
if (![[_editorsDict allValues] containsObject:editor])
{
return;
}
[_editorsDict removeObjectForKey:[editor path]];
if (![_editorsDict count])
{
[self setActiveEditor:nil];
}
}
- (void)editorDidBecomeActive:(NSNotification *)aNotif
{
id<CodeEditor> editor = [aNotif object];
if (![[_editorsDict allValues] containsObject:editor])
{
return;
}
[self setActiveEditor:editor];
}
- (void)editorDidResignActive:(NSNotification *)aNotif
{
// Clearing activeEditor blocks the ability to get some information from
// loaded and visible but not active editor
/* PCEditor *editor = [aNotif object];
if ([editor projectEditor] != self)
{
return;
}
[self setActiveEditor:nil];*/
}
- (void)editorDidChangeFileName:(NSNotification *)aNotif
{
NSDictionary *_editorDict = [aNotif object];
id<CodeEditor> _editor = [_editorDict objectForKey:@"Editor"];
NSString *_oldFileName = nil;
NSString *_newFileName = nil;
if (![[_editorsDict allValues] containsObject:_editor])
{
return;
}
_oldFileName = [_editorDict objectForKey:@"OldFile"];
_newFileName = [_editorDict objectForKey:@"NewFile"];
[_editorsDict removeObjectForKey:_oldFileName];
[_editorsDict setObject:_editor forKey:_newFileName];
}
@end

View file

@ -577,7 +577,9 @@ NSString
if (!projectEditor)
{
projectEditor = [[PCProjectEditor alloc] initWithProject:self];
projectEditor = [[PCProjectEditor alloc] init];
[projectEditor setProject:self];
[projectEditor setProjectManager:aManager];
}
if (!projectWindow)

View file

@ -547,8 +547,10 @@ NSString *PCBrowserDidSetPathNotification = @"PCBrowserDidSetPathNotification";
id<CodeEditor> editor = nil;
NSString *categoryName = [self nameOfSelectedCategory];
NSString *categoryKey = [project keyForCategory:categoryName];
NSString *filePath;
editor = [projectEditor editorForFile:fileName key:categoryKey];
filePath = [project pathForFile:fileName forKey:categoryKey];
editor = [projectEditor editorForFile:filePath];
if (editor != nil)
{
return [editor fileIcon];

View file

@ -35,26 +35,6 @@
#import <ProjectCenter/PCLogController.h>
NSString *PCEditorDidChangeFileNameNotification =
@"PCEditorDidChangeFileNameNotification";
NSString *PCEditorWillOpenNotification = @"PCEditorWillOpenNotification";
NSString *PCEditorDidOpenNotification = @"PCEditorDidOpenNotification";
NSString *PCEditorWillCloseNotification = @"PCEditorWillCloseNotification";
NSString *PCEditorDidCloseNotification = @"PCEditorDidCloseNotification";
NSString *PCEditorWillChangeNotification = @"PCEditorWillChangeNotification";
NSString *PCEditorDidChangeNotification = @"PCEditorDidChangeNotification";
NSString *PCEditorWillSaveNotification = @"PCEditorWillSaveNotification";
NSString *PCEditorDidSaveNotification = @"PCEditorDidSaveNotification";
NSString *PCEditorWillRevertNotification = @"PCEditorWillRevertNotification";
NSString *PCEditorDidRevertNotification = @"PCEditorDidRevertNotification";
NSString *PCEditorDidBecomeActiveNotification =
@"PCEditorDidBecomeActiveNotification";
NSString *PCEditorDidResignActiveNotification =
@"PCEditorDidResignActiveNotification";
@interface PCProjectEditor (CreateUI)
- (void) _createComponentView;
@ -69,21 +49,21 @@ NSString *PCEditorDidResignActiveNotification =
NSTextView *textView;
frame = NSMakeRect(0,0,562,248);
componentView = [[NSBox alloc] initWithFrame:frame];
[componentView setTitlePosition:NSNoTitle];
[componentView setBorderType:NSNoBorder];
[componentView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
[componentView setContentViewMargins:NSMakeSize(0.0,0.0)];
_componentView = [[NSBox alloc] initWithFrame:frame];
[_componentView setTitlePosition:NSNoTitle];
[_componentView setBorderType:NSNoBorder];
[_componentView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
[_componentView setContentViewMargins:NSMakeSize(0.0,0.0)];
frame = NSMakeRect (0, 0, 562, 40);
scrollView = [[NSScrollView alloc] initWithFrame:frame];
[scrollView setHasHorizontalScroller:NO];
[scrollView setHasVerticalScroller:YES];
[scrollView setBorderType:NSBezelBorder];
[scrollView setAutoresizingMask:(NSViewWidthSizable|NSViewHeightSizable)];
_scrollView = [[NSScrollView alloc] initWithFrame:frame];
[_scrollView setHasHorizontalScroller:NO];
[_scrollView setHasVerticalScroller:YES];
[_scrollView setBorderType:NSBezelBorder];
[_scrollView setAutoresizingMask:(NSViewWidthSizable|NSViewHeightSizable)];
// This is a placeholder!
frame = [[scrollView contentView] frame];
frame = [[_scrollView contentView] frame];
textView = [[NSTextView alloc] initWithFrame:frame];
[textView setMinSize:NSMakeSize (0, 0)];
[textView setMaxSize:NSMakeSize(1e7, 1e7)];
@ -94,16 +74,16 @@ NSString *PCEditorDidResignActiveNotification =
[textView setHorizontallyResizable:NO];
[textView setAutoresizingMask:(NSViewWidthSizable|NSViewHeightSizable)];
[[textView textContainer] setWidthTracksTextView:YES];
[scrollView setDocumentView:textView];
[_scrollView setDocumentView:textView];
RELEASE(textView);
frame.size = NSMakeSize([scrollView contentSize].width,1e7);
frame.size = NSMakeSize([_scrollView contentSize].width,1e7);
[[textView textContainer] setContainerSize:frame.size];
[componentView setContentView:scrollView];
// RELEASE(scrollView);
[_componentView setContentView:_scrollView];
// RELEASE(_scrollView);
[componentView sizeToFit];
[_componentView sizeToFit];
}
@end
@ -113,46 +93,12 @@ NSString *PCEditorDidResignActiveNotification =
// ==== Initialisation
// ===========================================================================
- (id)initWithProject:(PCProject *)aProject
- (id)init
{
NSAssert(aProject, @"No project specified!");
if ((self = [super init]))
{
PCLogStatus(self, @"[init]");
project = aProject;
componentView = nil;
editorsDict = [[NSMutableDictionary alloc] init];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(editorDidOpen:)
name:PCEditorDidOpenNotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(editorDidClose:)
name:PCEditorDidCloseNotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(editorDidBecomeActive:)
name:PCEditorDidBecomeActiveNotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(editorDidResignActive:)
name:PCEditorDidResignActiveNotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(editorDidChangeFileName:)
name:PCEditorDidChangeFileNameNotification
object:nil];
_componentView = nil;
}
return self;
@ -164,32 +110,37 @@ NSString *PCEditorDidResignActiveNotification =
#endif
NSLog (@"PCProjectEditor: dealloc");
[[NSNotificationCenter defaultCenter] removeObserver:self];
// [[NSNotificationCenter defaultCenter] removeObserver:self];
if (componentView)
if (_componentView)
{
RELEASE(scrollView);
RELEASE(componentView);
RELEASE(_scrollView);
RELEASE(_componentView);
}
RELEASE(editorsDict);
// RELEASE(_editorsDict);
[super dealloc];
}
- (NSView *)componentView
{
if (componentView == nil)
if (_componentView == nil)
{
[self _createComponentView];
}
return componentView;
return _componentView;
}
- (PCProject *)project
{
return project;
return _project;
}
- (void)setProject:(PCProject *)aProject
{
_project = aProject;
}
// ===========================================================================
@ -199,8 +150,8 @@ NSString *PCEditorDidResignActiveNotification =
// TODO: Should it be editor or parser?
- (BOOL)editorProvidesBrowserItemsForItem:(NSString *)item
{
NSString *file = [[project projectBrowser] nameOfSelectedFile];
PCBundleManager *bundleManager = [[project projectManager] bundleManager];
NSString *file = [[_project projectBrowser] nameOfSelectedFile];
PCBundleManager *bundleManager = [[_project projectManager] bundleManager];
NSDictionary *infoTable = nil;
// File selected and editor should already be loaded
@ -225,15 +176,7 @@ NSString *PCEditorDidResignActiveNotification =
return NO;
}
- (id<CodeEditor>)editorForFile:(NSString *)fileName key:(NSString *)key
{
NSString *filePath = nil;
filePath = [project pathForFile:fileName forKey:key];
return [editorsDict objectForKey:filePath];
}
// Called by PCProjectBrowser
// categoryPath:
// 1. "/Classes/Class.m/- init"
// 2. "/Subprojects/Project/Classes/Class.m/- init"
@ -241,134 +184,83 @@ NSString *PCEditorDidResignActiveNotification =
- (id<CodeEditor>)openEditorForCategoryPath:(NSString *)categoryPath
windowed:(BOOL)windowed
{
NSArray *pathArray = [categoryPath pathComponents];
PCProject *activeProject = [[project projectManager] activeProject];
NSString *category = [[project projectBrowser] nameOfSelectedCategory];
// NSArray *pathArray = [categoryPath pathComponents];
PCProject *activeProject = [[_project projectManager] activeProject];
NSString *category = [[_project projectBrowser] nameOfSelectedCategory];
NSString *categoryKey = [activeProject keyForCategory:category];
NSString *fileName = nil;
NSString *filePath = nil;
NSFileManager *fm = [NSFileManager defaultManager];
BOOL isDir;
BOOL editable = YES;
id<CodeEditor> editor;
NSString *pathLastObject = nil;
NSString *pathLastObject = [[categoryPath pathComponents] lastObject];
NSString *firstSymbol = nil;
fileName = [[[[project projectBrowser] pathFromSelectedCategory]
fileName = [[[[_project projectBrowser] pathFromSelectedCategory]
pathComponents] objectAtIndex:2];
filePath = [activeProject pathForFile:fileName forKey:categoryKey];
/* NSLog(@"PCPE: fileName: %@ filePath: %@ project: %@",
fileName, filePath, [activeProject projectName]);*/
// Determine if file not exist or file is directory
if (![fm fileExistsAtPath:filePath isDirectory:&isDir] || isDir)
{
return nil;
}
// Determine if file is text file
if (![[PCFileManager defaultManager] isTextFile:filePath])
{
return nil;
}
// Determine if file should be opened for read only
if (![project isEditableFile:fileName])
if (![_project isEditableFile:fileName])
{
editable = NO;
}
// NSLog(@"fileName: %@ > %@", fileName, listEntry);
editor = [self openEditorForFile:filePath
categoryPath:categoryPath
editable:editable
windowed:windowed];
if (!editor)
// Set the 'editor' var either by requesting already opened
// editor or by creating the new one.
editor = [self editorForFile:filePath];
if (editor)
{
NSLog(@"We don't have editor for file: %@", fileName);
// It seems double click occured in browser
if (windowed)
{
[editor setWindowed:windowed];
}
}
pathLastObject = [pathArray lastObject];
/* NSLog(@"pathArray: c: %i %@", [pathArray count], pathArray);
else
{
editor = [self openEditorForFile:filePath
editable:editable
windowed:windowed];
if (!editor)
{
NSLog(@"We don't have editor for file: %@", fileName);
return nil;
}
}
// Category path was changed by user's clicking inside browser.
// That's why new category path must be transfered to editor.
[editor setCategoryPath:categoryPath];
[self orderFrontEditorForFile:filePath];
/* pathLastObject = [pathArray lastObject];
NSLog(@"pathArray: c: %i %@", [pathArray count], pathArray);
NSLog(@"pathArray: lastObject %@", [pathArray lastObject]);
NSLog(@"lastObject[1]: %@",
[pathLastObject substringWithRange:NSMakeRange(0,1)]);*/
pathLastObject = [pathArray lastObject];
// pathLastObject = [pathArray lastObject];
firstSymbol = [pathLastObject substringToIndex:1];
if ([pathLastObject isEqualToString:@"/"]) // file selected
{
[[project projectBrowser] reloadLastColumnAndNotify:NO];
{ // Reload last column because editor has just been loaded
[[_project projectBrowser] reloadLastColumnAndNotify:NO];
}
else if ([firstSymbol isEqualToString:@"@"])
else
{
[editor fileStructureItemSelected:pathLastObject];
}
else if ([firstSymbol isEqualToString:@"-"]
|| [firstSymbol isEqualToString:@"+"])
{
[editor scrollToMethodName:pathLastObject];
}
return editor;
}
- (id<CodeEditor>)openEditorForFile:(NSString *)path
categoryPath:(NSString *)categoryPath
editable:(BOOL)editable
windowed:(BOOL)windowed
{
PCBundleManager *bundleManager = [[project projectManager] bundleManager];
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
NSString *ed = [ud objectForKey:Editor];
NSString *fileName = [path lastPathComponent];
id<CodeEditor> editor;
id<CodeParser> parser;
NSLog(@"PCPE: categoryPath: \"%@\"", categoryPath);
if (!(editor = [editorsDict objectForKey:path]))
{
// Editor
editor = [bundleManager objectForBundleWithName:ed
type:@"editor"
protocol:@protocol(CodeEditor)];
if (editor == nil)
{
editor = [bundleManager
objectForBundleWithName:@"ProjectCenter"
type:@"editor"
protocol:@protocol(CodeEditor)];
return nil;
}
// Parser
parser = [bundleManager objectForBundleType:@"parser"
protocol:@protocol(CodeParser)
fileName:fileName];
[editor setParser:parser];
[editor openFileAtPath:path
categoryPath:categoryPath
projectEditor:self
editable:editable];
[editorsDict setObject:editor forKey:path];
RELEASE(editor);
}
[editor setCategoryPath:categoryPath];
[editor setWindowed:windowed];
[self orderFrontEditorForFile:path];
return editor;
}
- (void)orderFrontEditorForFile:(NSString *)path
{
id<CodeEditor> editor = [editorsDict objectForKey:path];
id<CodeEditor> editor = [_editorsDict objectForKey:path];
if (!editor)
{
@ -381,48 +273,13 @@ NSString *PCEditorDidResignActiveNotification =
}
else
{
[componentView setContentView:[editor componentView]];
[[project projectWindow] setCustomContentView:componentView];
[[project projectWindow] makeFirstResponder:[editor editorView]];
}
}
[_componentView setContentView:[editor componentView]];
[[_project projectWindow] setCustomContentView:_componentView];
[[_project projectWindow] makeFirstResponder:[editor editorView]];
[[_project projectWindow] makeKeyAndOrderFront:self];
- (void)setActiveEditor:(id<CodeEditor>)anEditor
{
if (anEditor != activeEditor)
{
activeEditor = anEditor;
}
}
- (id<CodeEditor>)activeEditor
{
return activeEditor;
}
- (NSArray *)allEditors
{
return [editorsDict allValues];
}
- (void)closeActiveEditor:(id)sender
{
if (!activeEditor)
{
return;
}
[activeEditor closeFile:self save:YES];
}
- (void)closeEditorForFile:(NSString *)file
{
id<CodeEditor> editor;
if ([editorsDict count] > 0 && (editor = [editorsDict objectForKey:file]))
{
[editor closeFile:self save:YES];
[editorsDict removeObjectForKey:file];
NSLog(@"PCPE: categoryPath - %@", [editor categoryPath]);
[[_project projectBrowser] setPath:[editor categoryPath]];
}
}
@ -430,14 +287,14 @@ NSString *PCEditorDidResignActiveNotification =
// called by autorelease mechanism
- (BOOL)closeAllEditors
{
NSEnumerator *enumerator = [editorsDict keyEnumerator];
NSEnumerator *enumerator = [_editorsDict keyEnumerator];
id<CodeEditor> editor;
NSString *key = nil;
NSMutableArray *editedFiles = [[NSMutableArray alloc] init];
while ((key = [enumerator nextObject]))
{
editor = [editorsDict objectForKey:key];
editor = [_editorsDict objectForKey:key];
if ([editor isEdited])
{
[editedFiles addObject:[key lastPathComponent]];
@ -457,12 +314,7 @@ NSString *PCEditorDidResignActiveNotification =
}
}
[editorsDict removeAllObjects];
// Stop parser. It releases self.
// TODO: There should be a few parsers.
/* [aParser stop];
[parserConnection release];*/
[_editorsDict removeAllObjects];
return YES;
}
@ -500,16 +352,17 @@ NSString *PCEditorDidResignActiveNotification =
return YES;
}
// TODO: move to PCEditorManager
- (BOOL)saveAllFiles
{
NSEnumerator *enumerator = [editorsDict keyEnumerator];
NSEnumerator *enumerator = [_editorsDict keyEnumerator];
id<CodeEditor> editor;
NSString *key;
BOOL ret = YES;
while ((key = [enumerator nextObject]))
{
editor = [editorsDict objectForKey:key];
editor = [_editorsDict objectForKey:key];
if ([editor saveFileIfNeeded] == NO)
{
@ -520,18 +373,6 @@ NSString *PCEditorDidResignActiveNotification =
return ret;
}
- (BOOL)saveFile
{
id<CodeEditor> editor = [self activeEditor];
if (editor != nil)
{
return [editor saveFileIfNeeded];
}
return NO;
}
- (BOOL)saveFileAs:(NSString *)file
{
id<CodeEditor> editor = [self activeEditor];
@ -545,10 +386,10 @@ NSString *PCEditorDidResignActiveNotification =
res = [editor saveFileTo:file];
[editor closeFile:self save:NO];
[self openEditorForFile:file
categoryPath:categoryPath
editable:YES
windowed:iw];
editor = [self openEditorForFile:file
editable:YES // fixme
windowed:iw];
[editor setCategoryPath:categoryPath];
return res;
}
@ -556,30 +397,6 @@ NSString *PCEditorDidResignActiveNotification =
return NO;
}
- (BOOL)saveFileTo:(NSString *)file
{
id<CodeEditor> editor = [self activeEditor];
if (editor != nil)
{
return [editor saveFileTo:file];
}
return NO;
}
- (BOOL)revertFileToSaved
{
id<CodeEditor> editor = [self activeEditor];
if (editor != nil)
{
return [editor revertFileToSaved];
}
return NO;
}
// ===========================================================================
// ==== Notifications
// ===========================================================================
@ -587,7 +404,7 @@ NSString *PCEditorDidResignActiveNotification =
- (void)editorDidOpen:(NSNotification *)aNotif
{
/* PCEditor *editor = [aNotif object];
PCProjectBrowser *browser = [project projectBrowser];
PCProjectBrowser *browser = [_project projectBrowser];
NSString *path = [browser path];
// Active editor is set after PCEditorDidBecomeActiveNotification will be
@ -595,36 +412,36 @@ NSString *PCEditorDidResignActiveNotification =
[self setActiveEditor:editor];
[browser reloadLastColumnAndNotify:NO];
[browser setPath:path];*/
NSLog(@"PCProjectEditor editorDidOpen!");
}
- (void)editorDidClose:(NSNotification *)aNotif
{
// id<CodeEditor> editor = [aNotif object];
id editor = [aNotif object];
// It is not our editor
if ([editor projectEditor] != self)
if (![[_editorsDict allValues] containsObject:editor])
{
return;
}
[editorsDict removeObjectForKey:[editor path]];
[_editorsDict removeObjectForKey:[editor path]];
if ([editorsDict count])
if ([_editorsDict count])
{
NSString *lastEditorKey = [[editorsDict allKeys] lastObject];
id<CodeEditor> lastEditor = [editorsDict objectForKey:lastEditorKey];
NSString *lastEditorKey = [[_editorsDict allKeys] lastObject];
id<CodeEditor> lastEditor = [_editorsDict objectForKey:lastEditorKey];
lastEditorKey = [[editorsDict allKeys] lastObject];
[componentView setContentView:[lastEditor componentView]];
[[project projectWindow] makeFirstResponder:[lastEditor editorView]];
lastEditorKey = [[_editorsDict allKeys] lastObject];
[_componentView setContentView:[lastEditor componentView]];
[[_project projectWindow] makeFirstResponder:[lastEditor editorView]];
}
else
{
PCProjectBrowser *browser = [project projectBrowser];
PCProjectBrowser *browser = [_project projectBrowser];
[componentView setContentView:scrollView];
[[project projectWindow] makeFirstResponder:scrollView];
[_componentView setContentView:_scrollView];
[[_project projectWindow] makeFirstResponder:_scrollView];
[browser setPath:[browser pathToSelectedCategory]];
[self setActiveEditor:nil];
@ -634,55 +451,20 @@ NSString *PCEditorDidResignActiveNotification =
- (void)editorDidBecomeActive:(NSNotification *)aNotif
{
id<CodeEditor> editor = [aNotif object];
NSString *categoryPath = nil;
NSString *categoryPath = [editor categoryPath];
if ([editor projectEditor] != self)
if (![[_editorsDict allValues] containsObject:editor])
{
return;
}
categoryPath = [editor categoryPath];
[self setActiveEditor:editor];
if (categoryPath)
{
[[project projectBrowser] setPath:categoryPath];
[[_project projectBrowser] setPath:categoryPath];
}
}
- (void)editorDidResignActive:(NSNotification *)aNotif
{
// Clearing activeEditor blocks the ability to get some information from
// loaded and visible but not active editor
/* PCEditor *editor = [aNotif object];
if ([editor projectEditor] != self)
{
return;
}
[self setActiveEditor:nil];*/
}
- (void)editorDidChangeFileName:(NSNotification *)aNotif
{
NSDictionary *_editorDict = [aNotif object];
id<CodeEditor> _editor = [_editorDict objectForKey:@"Editor"];
NSString *_oldFileName = nil;
NSString *_newFileName = nil;
if ([_editor projectEditor] != self)
{
return;
}
_oldFileName = [_editorDict objectForKey:@"OldFile"];
_newFileName = [_editorDict objectForKey:@"NewFile"];
[editorsDict removeObjectForKey:_oldFileName];
[editorsDict setObject:_editor forKey:_newFileName];
}
@end

View file

@ -234,7 +234,7 @@
NSString *filePath = nil;
int row;
if ([editor projectEditor] != [project projectEditor])
if ([editor editorManager] != [project projectEditor])
{
PCLogWarning(self, @"File opened from other project");
return;
@ -263,7 +263,7 @@
id<CodeEditor> editor = [aNotif object];
NSString *filePath = [editor path];
if ([editor projectEditor] != [project projectEditor])
if ([editor editorManager] != [project projectEditor])
{
PCLogWarning(self, @"File from other project closed");
return;
@ -292,7 +292,7 @@
unsigned index;
unsigned filesCount;
if ([editor projectEditor] != [project projectEditor])
if ([editor editorManager] != [project projectEditor])
{
return;
}
@ -316,7 +316,7 @@
NSString *_newFileName = nil;
unsigned index;
if ([_editor projectEditor] != [project projectEditor])
if ([_editor editorManager] != [project projectEditor])
{
return;
}

View file

@ -29,6 +29,7 @@
#include <ProjectCenter/PCBundleManager.h>
#include <ProjectCenter/PCFileManager.h>
#include <ProjectCenter/PCEditorManager.h>
#include <ProjectCenter/PCProjectManager.h>
#include <ProjectCenter/PCProject.h>
@ -81,6 +82,8 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange";
object:nil];
fileManager = [[PCFileManager alloc] initWithProjectManager:self];
editorManager = [[PCEditorManager alloc] init];
[editorManager setProjectManager:self];
}
return self;
@ -108,6 +111,8 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange";
RELEASE(projectTypeAccessaryView);
RELEASE(fileTypeAccessaryView);
if (editorManager) RELEASE(editorManager);
if (projectInspector) RELEASE(projectInspector);
if (loadedFilesPanel) RELEASE(loadedFilesPanel);
if (buildPanel) RELEASE(buildPanel);
@ -1009,7 +1014,7 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange";
if (filePath != nil)
{
[self openFileWithEditor:filePath];
[editorManager openEditorForFile:filePath editable:YES windowed:YES];
}
}
@ -1023,9 +1028,46 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange";
return [[activeProject projectEditor] saveFile];
}
- (BOOL)saveFileAs:(NSString *)path
- (BOOL)saveFileAs
{
return [[activeProject projectEditor] saveFileAs:path];
NSArray *files = nil;
NSString *filePath = nil;
files = [fileManager filesOfTypes:nil
operation:PCSaveFileOperation
multiple:NO
title:@"Save As..."
accView:nil];
filePath = [files objectAtIndex:0];
if (filePath != nil && ![[activeProject projectEditor] saveFileAs:filePath])
{
NSRunAlertPanel(@"Alert", @"Couldn't save file to\n%@!",
@"OK", nil, nil, filePath);
return NO;
}
else
{
// TODO: implement 'Save File As' functionality wrt project and
// non-project files
/* PCProject *project = [projectManager activeProject];
NSString *categoryPath = nil;
categoryPath = [NSString stringWithString:@"/"];
categoryPath = [categoryPath stringByAppendingPathComponent:
[[project rootEntries] objectForKey:PCNonProject]];
[projectManager closeFile];
[project addFiles:[NSArray arrayWithObject:newFilePath]
forKey:PCNonProject
notify:YES];
[[activeProject projectEditor] openEditorForFile:newFilePath
categoryPath:categoryPath
editable:YES
windowed:NO];*/
}
return YES;
}
- (BOOL)saveFileTo

View file

@ -649,7 +649,7 @@
{
id<CodeEditor> editor = [aNotif object];
if ([editor projectEditor] != [project projectEditor])
if ([editor editorManager] != [project projectEditor])
{
return;
}
@ -661,7 +661,7 @@
{
id<CodeEditor> editor = [aNotif object];
if ([editor projectEditor] != [project projectEditor])
if ([editor editorManager] != [project projectEditor])
{
return;
}
@ -673,7 +673,7 @@
{
id<CodeEditor> editor = [aNotif object];
if ([editor projectEditor] != [project projectEditor])
if ([editor editorManager] != [project projectEditor])
{
return;
}

View file

@ -0,0 +1,113 @@
/*
GNUstep ProjectCenter - http://www.gnustep.org/experience/ProjectCenter.html
Copyright (C) 2002-2004 Free Software Foundation
Authors: Philippe C.D. Robert
Serg Stoyan
This file is part of GNUstep.
This application is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This application is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#ifndef _PCEditorManager_h_
#define _PCEditorManager_h_
#include <Foundation/Foundation.h>
#include <Protocols/CodeEditor.h>
#include <Protocols/CodeParser.h>
@class PCProjectManager;
@interface PCEditorManager : NSObject
{
PCProjectManager *_projectManager;
NSMutableDictionary *_editorsDict;
id<CodeEditor> _activeEditor;
}
// ===========================================================================
// ==== Initialisation
// ===========================================================================
- (id)init;
- (void)dealloc;
- (PCProjectManager *)projectManager;
- (void)setProjectManager:(PCProjectManager *)aProjectManager;
// ===========================================================================
// ==== Project and Editor handling
// ===========================================================================
// Returns nil if editor is not opened
- (id<CodeEditor>)editorForFile:(NSString *)filePath;
- (id<CodeEditor>)openEditorForFile:(NSString *)path
editable:(BOOL)editable
windowed:(BOOL)windowed;
- (void)orderFrontEditorForFile:(NSString *)path;
- (id<CodeEditor>)activeEditor;
- (void)setActiveEditor:(id<CodeEditor>)anEditor;
- (NSArray *)allEditors;
- (void)closeActiveEditor:(id)sender;
- (void)closeEditorForFile:(NSString *)file;
// ===========================================================================
// ==== File handling
// ===========================================================================
- (BOOL)saveFile;
- (BOOL)saveFileAs:(NSString *)file;
- (BOOL)saveFileTo:(NSString *)file;
- (BOOL)revertFileToSaved;
// ===========================================================================
// ==== Delegate
// ===========================================================================
- (void)editorDidOpen:(NSNotification *)aNotif;
- (void)editorDidClose:(NSNotification *)aNotif;
- (void)editorDidBecomeActive:(NSNotification *)aNotif;
- (void)editorDidResignActive:(NSNotification *)aNotif;
- (void)editorDidChangeFileName:(NSNotification *)aNotif;
@end
extern NSString *PCEditorDidChangeFileNameNotification;
extern NSString *PCEditorWillOpenNotification;
extern NSString *PCEditorDidOpenNotification;
extern NSString *PCEditorWillCloseNotification;
extern NSString *PCEditorDidCloseNotification;
extern NSString *PCEditorWillChangeNotification;
extern NSString *PCEditorDidChangeNotification;
extern NSString *PCEditorWillSaveNotification;
extern NSString *PCEditorDidSaveNotification;
extern NSString *PCEditorWillRevertNotification;
extern NSString *PCEditorDidRevertNotification;
extern NSString *PCEditorDidBecomeActiveNotification;
extern NSString *PCEditorDidResignActiveNotification;
/*
extern NSString *PCEditorSaveDidFailNotification;
*/
#endif

View file

@ -31,37 +31,35 @@
#include <Protocols/CodeEditor.h>
#include <Protocols/CodeParser.h>
#include <ProjectCenter/PCEditorManager.h>
@class PCProject;
@class PCEditor;
@class PCEditorView;
@class NSBox;
@class NSView;
@class NSScrollView;
@interface PCProjectEditor : NSObject
@interface PCProjectEditor : PCEditorManager
{
PCProject *project;
NSBox *componentView;
NSScrollView *scrollView;
PCProject *_project;
NSBox *_componentView;
NSScrollView *_scrollView;
NSDictionary *editorBundlesInfo;
NSDictionary *parserBundlesInfo;
NSMutableDictionary *editorsDict;
id<CodeEditor> activeEditor;
id<CodeParser> aParser;
NSConnection *parserConnection;
/* NSDictionary *_editorBundlesInfo;
NSDictionary *_parserBundlesInfo;
NSMutableDictionary *_editorsDict;
id<CodeEditor> _activeEditor;*/
}
// ===========================================================================
// ==== Initialisation
// ===========================================================================
- (id)initWithProject:(PCProject *)aProject;
- (id)init;
- (void)dealloc;
- (NSView *)componentView;
- (PCProject *)project;
- (void)setProject:(PCProject *)aProject;
// ===========================================================================
// ==== Project and Editor handling
@ -69,23 +67,10 @@
- (BOOL)editorProvidesBrowserItemsForItem:(NSString *)item;
// Returns nil if editor is not opened
- (id<CodeEditor>)editorForFile:(NSString *)fileName key:(NSString *)key;
- (id<CodeEditor>)openEditorForCategoryPath:(NSString *)categoryPath
windowed:(BOOL)windowed;
- (id<CodeEditor>)openEditorForFile:(NSString *)path
categoryPath:(NSString *)categoryPath
editable:(BOOL)editable
windowed:(BOOL)windowed;
- (void)orderFrontEditorForFile:(NSString *)path;
- (id<CodeEditor>)activeEditor;
- (void)setActiveEditor:(id<CodeEditor>)anEditor;
- (NSArray *)allEditors;
- (void)closeActiveEditor:(id)sender;
- (void)closeEditorForFile:(NSString *)file;
- (BOOL)closeAllEditors;
// ===========================================================================
@ -94,10 +79,7 @@
- (BOOL)saveEditedFiles:(NSArray *)files;
- (BOOL)saveAllFiles;
- (BOOL)saveFile;
- (BOOL)saveFileAs:(NSString *)file;
- (BOOL)saveFileTo:(NSString *)file;
- (BOOL)revertFileToSaved;
// ===========================================================================
// ==== Delegate
@ -105,30 +87,8 @@
- (void)editorDidClose:(NSNotification *)aNotif;
- (void)editorDidBecomeActive:(NSNotification *)aNotif;
- (void)editorDidResignActive:(NSNotification *)aNotif;
@end
extern NSString *PCEditorDidChangeFileNameNotification;
extern NSString *PCEditorWillOpenNotification;
extern NSString *PCEditorDidOpenNotification;
extern NSString *PCEditorWillCloseNotification;
extern NSString *PCEditorDidCloseNotification;
extern NSString *PCEditorWillChangeNotification;
extern NSString *PCEditorDidChangeNotification;
extern NSString *PCEditorWillSaveNotification;
extern NSString *PCEditorDidSaveNotification;
extern NSString *PCEditorWillRevertNotification;
extern NSString *PCEditorDidRevertNotification;
extern NSString *PCEditorDidBecomeActiveNotification;
extern NSString *PCEditorDidResignActiveNotification;
/*
extern NSString *PCEditorSaveDidFailNotification;
*/
#endif

View file

@ -30,6 +30,7 @@
@class PCBundleManager;
@class PCFileManager;
@class PCEditorManager;
@class PCProject;
@class PCProjectInspector;
@class PCProjectBuilder;
@ -50,6 +51,7 @@ extern NSString *PCActiveProjectDidChangeNotification;
NSMutableDictionary *projectTypes;
PCFileManager *fileManager;
PCEditorManager *editorManager;
PCProjectInspector *projectInspector;
NSPanel *buildPanel;
@ -170,7 +172,7 @@ extern NSString *PCActiveProjectDidChangeNotification;
- (void)openFile;
- (void)newFile;
- (BOOL)saveFile;
- (BOOL)saveFileAs:(NSString *)path;
- (BOOL)saveFileAs;
- (BOOL)saveFileTo;
- (BOOL)revertFileToSaved;
- (BOOL)renameFile;

View file

@ -35,9 +35,9 @@
// ===========================================================================
- (void)setParser:(id)parser;
- (id)openFileAtPath:(NSString *)file
categoryPath:(NSString *)categoryPath
projectEditor:(id)aProjectEditor
// Usually delegate is PCEditorManager or PCEditorManager
- (id)openFileAtPath:(NSString *)filePath
editorManager:(id)editorManager
editable:(BOOL)editable;
- (void)show;
@ -47,7 +47,7 @@
// ===========================================================================
// ==== Accessor methods
// ===========================================================================
- (id)projectEditor;
- (id)editorManager;
- (NSWindow *)editorWindow;
- (NSView *)editorView;
@ -81,8 +81,6 @@
// ===========================================================================
- (void)fileStructureItemSelected:(NSString *)item;
- (void)scrollToClassName:(NSString *)className;
- (void)scrollToMethodName:(NSString *)methodName;
- (void)scrollToLineNumber:(unsigned int)lineNumber;
@end

View file

@ -37,7 +37,7 @@
@interface PCEditor : NSObject <CodeEditor>
{
id projectEditor;
id _editorManager;
NSScrollView *_extScrollView;
PCEditorView *_extEditorView;
@ -107,8 +107,17 @@
- (void)editorTextViewWillPressKey:sender;
- (void)editorTextViewDidPressKey:sender;
- (BOOL)becomeFirstResponder;
- (BOOL)resignFirstResponder;
- (BOOL)becomeFirstResponder:(PCEditorView *)view;
- (BOOL)resignFirstResponder:(PCEditorView *)view;
// ===========================================================================
// ==== Parser and scrolling
// ===========================================================================
- (void)fileStructureItemSelected:(NSString *)item; // CodeEditor protocol
- (void)scrollToClassName:(NSString *)className;
- (void)scrollToMethodName:(NSString *)methodName;
- (void)scrollToLineNumber:(unsigned int)lineNumber; // CodeEditor protocol
@end

View file

@ -233,16 +233,14 @@
// [aParser retainCount], [parser retainCount]);
}
- (id)openFileAtPath:(NSString *)file
categoryPath:(NSString *)categoryPath
projectEditor:(id)aProjectEditor
- (id)openFileAtPath:(NSString *)filePath
editorManager:(id)editorManager
editable:(BOOL)editable
{
NSString *text;
NSAttributedString *attributedString = [NSAttributedString alloc];
NSMutableDictionary *attributes = [NSMutableDictionary new];
NSFont *font;
// NSColor *textBackground;
NSLog(@"PCEditor: openFileAtPath");
@ -250,9 +248,8 @@
[[NSNotificationCenter defaultCenter]
postNotificationName:PCEditorWillOpenNotification
object:self];
projectEditor = aProjectEditor;
_path = [file copy];
_categoryPath = [categoryPath copy];
_editorManager = editorManager;
_path = [filePath copy];
_isEditable = editable;
// Prepare
@ -269,7 +266,7 @@
[attributes setObject:font forKey:NSFontAttributeName];
[attributes setObject:textBackground forKey:NSBackgroundColorAttributeName];
text = [NSString stringWithContentsOfFile:file];
text = [NSString stringWithContentsOfFile:_path];
[attributedString initWithString:text attributes:attributes];
//
@ -277,7 +274,8 @@
[_storage setAttributedString:attributedString];
RELEASE(attributedString);
if (categoryPath) // category == nil if we're non project editor
[self _createInternalView];
/* if (categoryPath) // category == nil if we're non project editor
{
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
@ -285,7 +283,7 @@
{
[self _createInternalView];
}
}
}*/
// File open was finished
[[NSNotificationCenter defaultCenter]
@ -297,7 +295,7 @@
- (id)openExternalEditor:(NSString *)editor
withPath:(NSString *)file
projectEditor:(id)aProjectEditor
editorManager:(id)aDelegate
{
NSTask *editorTask = nil;
NSArray *ea = nil;
@ -309,7 +307,7 @@
return nil;
}
projectEditor = aProjectEditor;
_editorManager = aDelegate;
_path = [file copy];
// Task
@ -365,9 +363,9 @@
// --- Accessor methods
- (id)projectEditor
- (id)editorManager
{
return projectEditor;
return _editorManager;
}
- (NSWindow *)editorWindow
@ -772,20 +770,20 @@
editorTextViewIsPressingKey = NO;
}
- (BOOL)becomeFirstResponder
- (BOOL)becomeFirstResponder:(PCEditorView *)view
{
[[NSNotificationCenter defaultCenter]
postNotificationName:PCEditorDidBecomeActiveNotification
object:self];
object:self];
return YES;
}
- (BOOL)resignFirstResponder
- (BOOL)resignFirstResponder:(PCEditorView *)view
{
[[NSNotificationCenter defaultCenter]
postNotificationName:PCEditorDidResignActiveNotification
object:self];
object:self];
return YES;
}
@ -798,6 +796,19 @@
- (void)fileStructureItemSelected:(NSString *)item
{
NSString *firstSymbol;
NSLog(@"[PCEditor] selected file structure item: %@", item);
firstSymbol = [item substringToIndex:1];
if ([firstSymbol isEqualToString:@"@"]) // class selected
{
}
else if ([firstSymbol isEqualToString:@"-"] // method selected
|| [firstSymbol isEqualToString:@"+"])
{
[self scrollToMethodName:item];
}
}
- (void)scrollToClassName:(NSString *)className

View file

@ -415,12 +415,12 @@ static int ComputeIndentingOffset(NSString * string, unsigned int start)
// ---
- (BOOL)becomeFirstResponder
{
return [editor becomeFirstResponder];
return [editor becomeFirstResponder:self];
}
- (BOOL)resignFirstResponder
{
return [editor resignFirstResponder];
return [editor resignFirstResponder:self];
}
- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent

View file

@ -165,60 +165,9 @@
- (void)fileSaveAs:(id)sender
{
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
NSSavePanel *savePanel = [NSSavePanel savePanel];
NSString *oldFilePath = nil;
NSString *newFilePath = nil;
NSString *directory = nil;
int retval = NSOKButton;
oldFilePath =
[[[[projectManager rootActiveProject] projectEditor] activeEditor] path];
[savePanel setTitle: @"Save As..."];
while (![directory isEqualToString: [projectManager projectPath]]
&& retval != NSCancelButton)
{
retval = [savePanel
runModalForDirectory:[projectManager projectPath]
file:[projectManager selectedFileName]];
directory = [savePanel directory];
}
if (retval == NSOKButton)
{
[ud setObject:directory forKey:@"LastOpenDirectory"];
newFilePath = [savePanel filename];
if (![projectManager saveFileAs:newFilePath])
{
NSRunAlertPanel(@"Attention!",
@"Couldn't save file as\n%@!",
@"OK",nil,nil,newFilePath);
}
else
{
PCProject *project = [projectManager activeProject];
NSString *categoryPath = nil;
categoryPath = [NSString stringWithString:@"/"];
categoryPath = [categoryPath stringByAppendingPathComponent:
[[project rootEntries] objectForKey:PCNonProject]];
[projectManager closeFile];
[project addFiles:[NSArray arrayWithObject:newFilePath]
forKey:PCNonProject
notify:YES];
[[project projectEditor] openEditorForFile:newFilePath
categoryPath:categoryPath
editable:YES
windowed:NO];
}
}
[projectManager saveFileAs];
}
- (void)fileSaveTo:(id)sender
{
[projectManager saveFileTo];