Kind of implemented saving and reverting of common files. A long way to go,

but for now it works...


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/projectcenter/trunk@12388 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Philippe C.D. Robert 2002-02-02 19:21:00 +00:00
parent 7c264a098c
commit 62f64889bd
11 changed files with 141 additions and 9 deletions

View file

@ -25,6 +25,8 @@
*/
#import "PCBrowserController.h"
#import "PCEditorController.h"
#import "PCEditor.h"
#import "PCProject.h"
#import "PCFileManager.h"

View file

@ -41,6 +41,9 @@
- (void)show;
- (void)close;
- (BOOL)saveFile;
- (BOOL)revertFile;
- (void)windowWillClose:(NSNotification *)aNotif;
@end

View file

@ -38,6 +38,7 @@
[window setMinSize:NSMakeSize(512,320)];
view = [[PCEditorView alloc] initWithFrame:NSMakeRect(0,0,498,306)];
[view setEditor:self];
[view setMinSize: NSMakeSize (0, 0)];
[view setMaxSize:NSMakeSize(1e7, 1e7)];
@ -155,7 +156,14 @@
if( ret == YES )
{
// SAVE
ret = [self saveFile];
if( ret == NO )
{
NSRunAlertPanel(@"Save Failed!",
@"Could not save file '%@'!",
@"OK",nil,nil,path);
}
}
[window setDocumentEdited:NO];
@ -164,14 +172,34 @@
{
}
[window performClose:self];
if( delegate && [delegate respondsToSelector:@selector(editorDidClose:)] )
{
[delegate editorDidClose:self];
}
}
- (BOOL)saveFile
{
if( isEmbedded == NO )
{
[window setDocumentEdited:NO];
}
return [[view text] writeToFile:path atomically:YES];
}
- (BOOL)revertFile
{
NSString *text = [NSString stringWithContentsOfFile:path];
if( isEmbedded == NO )
{
[window setDocumentEdited:NO];
}
[view setText:text];
}
- (void)windowWillClose:(NSNotification *)aNotif
{
if( [[aNotif object] isEqual:window] )

View file

@ -49,6 +49,13 @@
- (void)editorDidClose:(id)sender;
// ===========================================================================
// ==== File handling
// ===========================================================================
- (BOOL)saveFile;
- (BOOL)revertFile;
@end
#endif // _PCEDITORCONTROLLER_H_

View file

@ -124,6 +124,11 @@
editor = [editorDict objectForKey:key];
[editor close];
if( [editor isEmbedded] == NO )
{
[[editor editorWindow] performClose:self];
}
}
[editorDict removeAllObjects];
}
@ -135,4 +140,50 @@
[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] )
{
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] )
{
return [editor revertFile];
}
}
return NO;
}
@end

View file

@ -26,6 +26,8 @@
#import <AppKit/AppKit.h>
@class PCEditor;
@interface PCEditorView : NSTextView
{
NSScanner *scanner;
@ -33,11 +35,13 @@
@private
NSRange range;
NSArray *_keywords;
PCEditor *editor;
}
- (id)initWithFrame:(NSRect)frameRect;
- (void)dealloc;
- (void)setEditor:(PCEditor *)anEditor;
- (void)setString:(NSString *)aString;
- (void)colourise:(id)sender;

View file

@ -25,6 +25,7 @@
*/
#import "PCEditorView.h"
#import "PCEditor.h"
#define COLOURISE 0
#define SCANLOC [scanner scanLocation]
@ -79,7 +80,8 @@ static BOOL isInitialised = NO;
- (void)dealloc
{
if (scanner) {
if (scanner)
{
[scanner release];
}
[_keywords release];
@ -87,6 +89,11 @@ static BOOL isInitialised = NO;
[super dealloc];
}
- (void)setEditor:(PCEditor *)anEditor
{
editor = anEditor;
}
- (void)setString:(NSString *)aString
{
[scanner autorelease];
@ -358,8 +365,19 @@ static BOOL isInitialised = NO;
}
}
- (void)keyDown: (NSEvent *)anEvent
- (void)keyDown:(NSEvent *)anEvent
{
NSString *chars = [anEvent charactersIgnoringModifiers];
int modifiers = [anEvent modifierFlags];
if(([chars lossyCString][0] == 's') && (modifiers & NSAlternateKeyMask))
{
[editor saveFile];
return;
}
// Only if not embedded - FIXME!
if( [[self window] isDocumentEdited] == NO )
{
[[self window] setDocumentEdited:YES];

View file

@ -228,11 +228,13 @@ static NSString * const PCBuildTool = @"BUILDTOOL";
- (BOOL)save;
- (BOOL)saveAt:(NSString *)projPath;
- (BOOL)saveFileNamed:(NSString *)file;
- (BOOL)saveFile;
- (BOOL)saveAllFiles;
- (BOOL)saveAllFilesIfNeeded;
// Saves all the files that need to be saved.
- (BOOL)revertFile;
- (BOOL)writeSpecFile;
//=============================================================================

View file

@ -863,9 +863,9 @@
return NO;
}
- (BOOL)saveFileNamed:(NSString *)file
- (BOOL)saveFile
{
return NO;
return [editorController saveFile];
}
- (BOOL)saveAllFiles
@ -882,6 +882,11 @@
return ret;
}
- (BOOL)revertFile
{
return [editorController revertFile];
}
- (BOOL)writeSpecFile
{
NSString *name = [projectDict objectForKey:PCProjectName];

View file

@ -512,6 +512,12 @@ NSString *ActiveProjectDidChangeNotification = @"ActiveProjectDidChange";
- (BOOL)saveFile
{
if (!activeProject)
{
return NO;
}
return [activeProject saveFile];
}
- (BOOL)saveFileAs:(NSString *)path
@ -520,6 +526,12 @@ NSString *ActiveProjectDidChangeNotification = @"ActiveProjectDidChange";
- (BOOL)revertFile
{
if (!activeProject)
{
return NO;
}
return [activeProject revertFile];
}
- (BOOL)renameFileTo:(NSString *)path

View file

@ -54,7 +54,7 @@
[defaults setObject:_bundlePath forKey:BundlePaths];
[defaults setObject:@"/bin/vi" forKey:Editor];
[defaults setObject:@"/usr/bin/vim" forKey:Editor];
[defaults setObject:@"/usr/bin/gdb" forKey:Debugger];
[defaults setObject:@"/usr/bin/gcc" forKey:Compiler];