mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-25 07:21:08 +00:00
Fun fixes.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@4877 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
4026532377
commit
3d2b84054e
6 changed files with 697 additions and 639 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,4 +1,12 @@
|
|||
1999-09-10 Pedro Ivo Andrade Tavares <ptavares@iname.com>
|
||||
1999-09-11 Michael Hanni <mhanni@sprintmail.com>
|
||||
|
||||
* Source/NSMenu.m: many small fixes and optimizations for quicker
|
||||
display. In addition several small fixes which should improve
|
||||
functionality as well as usablity.
|
||||
* Source/NSMenuView.m: ditto.
|
||||
* Source/NSHelpManager.m: a small bugfix to allow for compilation.
|
||||
|
||||
1999-09-11 Pedro Ivo Andrade Tavares <ptavares@iname.com>
|
||||
|
||||
* NSResponder.m ([NSResponder -helpRequested:]):
|
||||
Now the application exits context help mode regardless of whether
|
||||
|
|
|
@ -17,148 +17,149 @@
|
|||
|
||||
+ (NSArray *)readableTypes
|
||||
{
|
||||
return [[NSDocumentController sharedDocumentController]
|
||||
_editorAndViewerTypesForClass:self];
|
||||
return [[NSDocumentController sharedDocumentController]
|
||||
_editorAndViewerTypesForClass:self];
|
||||
}
|
||||
|
||||
+ (NSArray *)writableTypes
|
||||
{
|
||||
return [[NSDocumentController sharedDocumentController] _editorTypesForClass:self];
|
||||
return [[NSDocumentController sharedDocumentController] _editorTypesForClass:self];
|
||||
}
|
||||
|
||||
+ (BOOL)isNativeType:(NSString *)type
|
||||
{
|
||||
return ([[self readableTypes] containsObject:type] &&
|
||||
[[self writableTypes] containsObject:type]);
|
||||
return ([[self readableTypes] containsObject:type] &&
|
||||
[[self writableTypes] containsObject:type]);
|
||||
}
|
||||
|
||||
|
||||
- (id)init
|
||||
{
|
||||
static int untitledCount = 1;
|
||||
|
||||
[super init];
|
||||
_documentIndex = untitledCount++;
|
||||
return self;
|
||||
static int untitledCount = 1;
|
||||
|
||||
[super init];
|
||||
_documentIndex = untitledCount++;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithContentsOfFile:(NSString *)fileName ofType:(NSString *)fileType
|
||||
{
|
||||
[super init];
|
||||
[super init];
|
||||
|
||||
if ([self readFromFile:fileName ofType:fileType])
|
||||
{
|
||||
[self setFileType:fileType];
|
||||
[self setFileName:fileName];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self release];
|
||||
return nil;
|
||||
}
|
||||
if ([self readFromFile:fileName ofType:fileType])
|
||||
{
|
||||
[self setFileType:fileType];
|
||||
[self setFileName:fileName];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self release];
|
||||
return nil;
|
||||
}
|
||||
|
||||
return self;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithContentsOfURL:(NSURL *)url ofType:(NSString *)fileType
|
||||
{
|
||||
[super init];
|
||||
[super init];
|
||||
|
||||
if ([self readFromURL:url ofType:fileType])
|
||||
{
|
||||
[self setFileType:fileType];
|
||||
[self setFileName:[url path]];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self release];
|
||||
return nil;
|
||||
}
|
||||
|
||||
return self;
|
||||
if ([self readFromURL:url ofType:fileType])
|
||||
{
|
||||
[self setFileType:fileType];
|
||||
[self setFileName:[url path]];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self release];
|
||||
return nil;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
[(NSObject*)_undoManager release];
|
||||
[_fileName release];
|
||||
[_fileType release];
|
||||
[_windowControllers release];
|
||||
[_window release];
|
||||
[_printInfo release];
|
||||
[savePanelAccessory release];
|
||||
[spaButton release];
|
||||
[super dealloc];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
[(NSObject*)_undoManager release];
|
||||
[_fileName release];
|
||||
[_fileType release];
|
||||
[_windowControllers release];
|
||||
[_window release];
|
||||
[_printInfo release];
|
||||
[savePanelAccessory release];
|
||||
[spaButton release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSString *)fileName
|
||||
{
|
||||
return _fileName;
|
||||
return _fileName;
|
||||
}
|
||||
|
||||
- (void)setFileName:(NSString *)fileName
|
||||
{
|
||||
[fileName retain];
|
||||
[_fileName release];
|
||||
_fileName = fileName;
|
||||
[fileName retain];
|
||||
[_fileName release];
|
||||
_fileName = fileName;
|
||||
|
||||
[_windowControllers makeObjectsPerformSelector:
|
||||
@selector(_synchronizeWindowTitleWithDocumentName)];
|
||||
[_windowControllers makeObjectsPerformSelector:
|
||||
@selector(_synchronizeWindowTitleWithDocumentName)];
|
||||
}
|
||||
|
||||
- (NSString *)fileType
|
||||
{
|
||||
return _fileType;
|
||||
return _fileType;
|
||||
}
|
||||
|
||||
- (void)setFileType:(NSString *)type
|
||||
{
|
||||
[type retain];
|
||||
[_fileType release];
|
||||
_fileType = type;
|
||||
[type retain];
|
||||
[_fileType release];
|
||||
_fileType = type;
|
||||
}
|
||||
|
||||
- (NSArray *)windowControllers
|
||||
{
|
||||
return _windowControllers;
|
||||
return _windowControllers;
|
||||
}
|
||||
|
||||
- (void)addWindowController:(NSWindowController *)windowController
|
||||
{
|
||||
if (_windowControllers == nil) _windowControllers = [[NSMutableArray alloc] init];
|
||||
if (_windowControllers == nil) _windowControllers = [[NSMutableArray alloc] init];
|
||||
|
||||
[_windowControllers addObject:windowController];
|
||||
if ([windowController document] != self)
|
||||
[windowController setDocument:self];
|
||||
[_windowControllers addObject:windowController];
|
||||
if ([windowController document] != self)
|
||||
[windowController setDocument:self];
|
||||
}
|
||||
|
||||
- (void)_removeWindowController:(NSWindowController *)windowController
|
||||
{
|
||||
if ([_windowControllers containsObject:windowController])
|
||||
{
|
||||
BOOL autoClose = [windowController shouldCloseDocument];
|
||||
|
||||
[windowController setDocument:nil];
|
||||
[_windowControllers removeObject:windowController];
|
||||
|
||||
if (autoClose || [_windowControllers count] == 0)
|
||||
if ([_windowControllers containsObject:windowController])
|
||||
{
|
||||
BOOL autoClose = [windowController shouldCloseDocument];
|
||||
|
||||
[windowController setDocument:nil];
|
||||
[_windowControllers removeObject:windowController];
|
||||
|
||||
if (autoClose || [_windowControllers count] == 0)
|
||||
{
|
||||
[self close];
|
||||
}
|
||||
[self close];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)windowNibName
|
||||
{
|
||||
return nil;
|
||||
return nil;
|
||||
}
|
||||
|
||||
// private; called during nib load. // we do not retain the window, since it should
|
||||
// private; called during nib load.
|
||||
// we do not retain the window, since it should
|
||||
// already have a retain from the nib.
|
||||
- (void)setWindow:(NSWindow *)window
|
||||
{
|
||||
_window = window;
|
||||
_window = window;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -169,178 +170,181 @@
|
|||
*/
|
||||
- (NSWindow *)_transferWindowOwnership
|
||||
{
|
||||
NSWindow *window = _window;
|
||||
_window = nil;
|
||||
return [window autorelease];
|
||||
NSWindow *window = _window;
|
||||
_window = nil;
|
||||
return [window autorelease];
|
||||
}
|
||||
|
||||
- (void)makeWindowControllers
|
||||
{
|
||||
NSString *name = [self windowNibName];
|
||||
NSString *name = [self windowNibName];
|
||||
|
||||
if ([name length] > 0)
|
||||
{
|
||||
NSWindowController *controller;
|
||||
controller = [[NSWindowController alloc] initWithWindowNibName:name owner:self];
|
||||
[self addWindowController:controller];
|
||||
[controller release];
|
||||
}
|
||||
else
|
||||
{
|
||||
[NSException raise:NSInternalInconsistencyException
|
||||
format:@"%@ must override either -windowNibName or -makeWindowControllers",
|
||||
NSStringFromClass([self class])];
|
||||
}
|
||||
if ([name length] > 0)
|
||||
{
|
||||
NSWindowController *controller;
|
||||
controller = [[NSWindowController alloc] initWithWindowNibName:name owner:self];
|
||||
[self addWindowController:controller];
|
||||
[controller release];
|
||||
}
|
||||
else
|
||||
{
|
||||
[NSException raise:NSInternalInconsistencyException
|
||||
format:@"%@ must override either -windowNibName or -makeWindowControllers",
|
||||
NSStringFromClass([self class])];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)showWindows
|
||||
{
|
||||
[_windowControllers makeObjectsPerformSelector:@selector(showWindow:) withObject:self];
|
||||
[_windowControllers makeObjectsPerformSelector:@selector(showWindow:) withObject:self];
|
||||
}
|
||||
|
||||
- (BOOL)isDocumentEdited
|
||||
{
|
||||
return _changeCount != 0;
|
||||
return _changeCount != 0;
|
||||
}
|
||||
|
||||
- (void)updateChangeCount:(NSDocumentChangeType)change
|
||||
{
|
||||
int i, count = [_windowControllers count];
|
||||
BOOL isEdited;
|
||||
|
||||
switch (change)
|
||||
{
|
||||
case NSChangeDone: _changeCount++; break;
|
||||
case NSChangeUndone: _changeCount--; break;
|
||||
case NSChangeCleared: _changeCount = 0; break;
|
||||
}
|
||||
|
||||
int i, count = [_windowControllers count];
|
||||
BOOL isEdited;
|
||||
|
||||
switch (change)
|
||||
{
|
||||
case NSChangeDone: _changeCount++; break;
|
||||
case NSChangeUndone: _changeCount--; break;
|
||||
case NSChangeCleared: _changeCount = 0; break;
|
||||
}
|
||||
|
||||
/*
|
||||
* NOTE: Apple's implementation seems to not call -isDocumentEdited
|
||||
* here but directly checks to see if _changeCount == 0. It seems it
|
||||
* would be better to call the method in case it's overridden by a
|
||||
* subclass, but we may want to keep Apple's behavior.
|
||||
*/
|
||||
isEdited = [self isDocumentEdited];
|
||||
isEdited = [self isDocumentEdited];
|
||||
|
||||
for (i=0; i<count; i++)
|
||||
{
|
||||
[[[_windowControllers objectAtIndex:i] window] setDocumentEdited:isEdited];
|
||||
}
|
||||
for (i=0; i<count; i++)
|
||||
{
|
||||
[[[_windowControllers objectAtIndex:i] window] setDocumentEdited:isEdited];
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)canCloseDocument
|
||||
{
|
||||
int result;
|
||||
int result;
|
||||
|
||||
if (![self isDocumentEdited]) return YES;
|
||||
|
||||
//FIXME -- localize.
|
||||
result = NSRunAlertPanel(@"Close", @"%@ has changed. Save?",
|
||||
@"Save", @"Cancel", @"Don't Save", [self displayName]);
|
||||
if (![self isDocumentEdited])
|
||||
return YES;
|
||||
|
||||
//FIXME -- localize.
|
||||
result = NSRunAlertPanel(@"Close", @"%@ has changed. Save?",
|
||||
@"Save", @"Cancel", @"Don't Save", [self displayName]);
|
||||
|
||||
#define Save NSAlertDefaultReturn
|
||||
#define Cancel NSAlertAlternateReturn
|
||||
#define DontSave NSAlertOtherReturn
|
||||
|
||||
switch (result)
|
||||
{
|
||||
// return NO if save failed
|
||||
case Save: [self saveDocument:nil]; return ![self isDocumentEdited];
|
||||
case DontSave: return YES;
|
||||
case Cancel:
|
||||
default: return NO;
|
||||
}
|
||||
switch (result)
|
||||
{
|
||||
// return NO if save failed
|
||||
case Save: [self saveDocument:nil]; return ![self isDocumentEdited];
|
||||
case DontSave: return YES;
|
||||
case Cancel:
|
||||
default: return NO;
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)shouldCloseWindowController:(NSWindowController *)windowController
|
||||
{
|
||||
if (![_windowControllers containsObject:windowController]) return YES;
|
||||
if (![_windowControllers containsObject:windowController]) return YES;
|
||||
|
||||
/* If it's the last window controller, pop up a warning */
|
||||
/* maybe we should count only loaded window controllers (or visible windows). */
|
||||
if ([windowController shouldCloseDocument] || [_windowControllers count] == 1)
|
||||
{
|
||||
return [self canCloseDocument];
|
||||
}
|
||||
/* If it's the last window controller, pop up a warning */
|
||||
/* maybe we should count only loaded window controllers (or visible windows). */
|
||||
if ([windowController shouldCloseDocument]
|
||||
|| [_windowControllers count] == 1)
|
||||
{
|
||||
return [self canCloseDocument];
|
||||
}
|
||||
|
||||
return YES;
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
- (NSString *)displayName
|
||||
{
|
||||
if ([self fileName] != nil)
|
||||
{
|
||||
return [[[self fileName] lastPathComponent] stringByDeletingPathExtension];
|
||||
}
|
||||
else
|
||||
{
|
||||
//FIXME -- localize.
|
||||
return [NSString stringWithFormat:@"Untitled-%d", _documentIndex];
|
||||
}
|
||||
if ([self fileName] != nil)
|
||||
{
|
||||
return [[[self fileName] lastPathComponent] stringByDeletingPathExtension];
|
||||
}
|
||||
else
|
||||
{
|
||||
//FIXME -- localize.
|
||||
return [NSString stringWithFormat:@"Untitled-%d", _documentIndex];
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)keepBackupFile
|
||||
{
|
||||
return NO;
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (NSData *)dataRepresentationOfType:(NSString *)type
|
||||
{
|
||||
[NSException raise:NSInternalInconsistencyException format:@"%@ must implement %@",
|
||||
NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
|
||||
return nil;
|
||||
[NSException raise:NSInternalInconsistencyException format:@"%@ must implement %@",
|
||||
NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)type
|
||||
{
|
||||
[NSException raise:NSInternalInconsistencyException format:@"%@ must implement %@",
|
||||
NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
|
||||
return NO;
|
||||
[NSException raise:NSInternalInconsistencyException format:@"%@ must implement %@",
|
||||
NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (NSFileWrapper *)fileWrapperRepresentationOfType:(NSString *)type
|
||||
{
|
||||
NSData *data = [self dataRepresentationOfType:type];
|
||||
|
||||
if (data == nil) return nil;
|
||||
|
||||
return [[[NSFileWrapper alloc] initRegularFileWithContents:data] autorelease];
|
||||
NSData *data = [self dataRepresentationOfType:type];
|
||||
|
||||
if (data == nil)
|
||||
return nil;
|
||||
|
||||
return [[[NSFileWrapper alloc] initRegularFileWithContents:data] autorelease];
|
||||
}
|
||||
|
||||
- (BOOL)loadFileWrapperRepresentation:(NSFileWrapper *)wrapper ofType:(NSString *)type
|
||||
{
|
||||
if ([wrapper isRegularFile])
|
||||
if ([wrapper isRegularFile])
|
||||
{
|
||||
return [self loadDataRepresentation:[wrapper regularFileContents] ofType:type];
|
||||
}
|
||||
|
||||
return [self loadDataRepresentation:[wrapper regularFileContents] ofType:type];
|
||||
}
|
||||
|
||||
/*
|
||||
* This even happens on a symlink. May want to use
|
||||
* -stringByResolvingAllSymlinksInPath somewhere, but Apple doesn't.
|
||||
*/
|
||||
NSLog(@"%@ must be overridden if your document deals with file packages.",
|
||||
NSStringFromSelector(_cmd));
|
||||
NSLog(@"%@ must be overridden if your document deals with file packages.",
|
||||
NSStringFromSelector(_cmd));
|
||||
|
||||
return NO;
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)writeToFile:(NSString *)fileName ofType:(NSString *)type
|
||||
{
|
||||
return [[self fileWrapperRepresentationOfType:type]
|
||||
writeToFile:fileName atomically:YES updateFilenames:YES];
|
||||
return [[self fileWrapperRepresentationOfType:type]
|
||||
writeToFile:fileName atomically:YES updateFilenames:YES];
|
||||
}
|
||||
|
||||
- (BOOL)readFromFile:(NSString *)fileName ofType:(NSString *)type
|
||||
{
|
||||
NSFileWrapper *wrapper = [[[NSFileWrapper alloc] initWithPath:fileName] autorelease];
|
||||
return [self loadFileWrapperRepresentation:wrapper ofType:type];
|
||||
NSFileWrapper *wrapper = [[[NSFileWrapper alloc] initWithPath:fileName] autorelease];
|
||||
return [self loadFileWrapperRepresentation:wrapper ofType:type];
|
||||
}
|
||||
|
||||
- (BOOL)revertToSavedFromFile:(NSString *)fileName ofType:(NSString *)type
|
||||
{
|
||||
return [self readFromFile:fileName ofType:type];
|
||||
return [self readFromFile:fileName ofType:type];
|
||||
}
|
||||
|
||||
- (IBAction)changeSaveType:(id)sender
|
||||
|
@ -349,13 +353,13 @@
|
|||
|
||||
- (int)runModalSavePanel:(NSSavePanel *)savePanel withAccessoryView:(NSView *)accessoryView
|
||||
{
|
||||
[savePanel setAccessoryView:accessoryView];
|
||||
return [savePanel runModal];
|
||||
[savePanel setAccessoryView:accessoryView];
|
||||
return [savePanel runModal];
|
||||
}
|
||||
|
||||
- (BOOL)shouldRunSavePanelWithAccessoryView
|
||||
{
|
||||
return YES;
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)_loadPanelAccessoryNib
|
||||
|
@ -369,80 +373,81 @@
|
|||
|
||||
- (NSString *)fileNameFromRunningSavePanelForSaveOperation:(NSSaveOperationType)saveOperation
|
||||
{
|
||||
NSView *accessory = nil;
|
||||
NSString *title = @"save";
|
||||
NSSavePanel *savePanel = [NSSavePanel savePanel];
|
||||
NSArray *extensions = [[NSDocumentController sharedDocumentController]
|
||||
fileExtensionsFromType:[self fileType]];
|
||||
|
||||
if ([self shouldRunSavePanelWithAccessoryView])
|
||||
NSView *accessory = nil;
|
||||
NSString *title = @"save";
|
||||
NSSavePanel *savePanel = [NSSavePanel savePanel];
|
||||
NSArray *extensions = [[NSDocumentController sharedDocumentController]
|
||||
fileExtensionsFromType:[self fileType]];
|
||||
|
||||
if ([self shouldRunSavePanelWithAccessoryView])
|
||||
{
|
||||
if (savePanelAccessory == nil)
|
||||
[self _loadPanelAccessoryNib];
|
||||
|
||||
[self _addItemsToSpaButtonFromArray:extensions];
|
||||
|
||||
accessory = savePanelAccessory;
|
||||
if (savePanelAccessory == nil)
|
||||
[self _loadPanelAccessoryNib];
|
||||
|
||||
[self _addItemsToSpaButtonFromArray:extensions];
|
||||
|
||||
accessory = savePanelAccessory;
|
||||
}
|
||||
|
||||
if ([extensions count] > 0)
|
||||
[savePanel setRequiredFileType:[extensions objectAtIndex:0]];
|
||||
if ([extensions count] > 0)
|
||||
[savePanel setRequiredFileType:[extensions objectAtIndex:0]];
|
||||
|
||||
switch (saveOperation)
|
||||
{
|
||||
// FIXME -- localize.
|
||||
case NSSaveOperation: title = @"Save"; break;
|
||||
case NSSaveAsOperation: title = @"Save As"; break;
|
||||
case NSSaveToOperation: title = @"Save To"; break;
|
||||
}
|
||||
switch (saveOperation)
|
||||
{
|
||||
// FIXME -- localize.
|
||||
case NSSaveOperation: title = @"Save"; break;
|
||||
case NSSaveAsOperation: title = @"Save As"; break;
|
||||
case NSSaveToOperation: title = @"Save To"; break;
|
||||
}
|
||||
|
||||
[savePanel setTitle:title];
|
||||
|
||||
[savePanel setTitle:title];
|
||||
if ([self fileName])
|
||||
[savePanel setDirectory:[[self fileName] stringByDeletingLastPathComponent]];
|
||||
if ([self fileName])
|
||||
[savePanel setDirectory:[[self fileName] stringByDeletingLastPathComponent]];
|
||||
|
||||
if ([self runModalSavePanel:savePanel withAccessoryView:accessory])
|
||||
{
|
||||
return [savePanel filename];
|
||||
}
|
||||
|
||||
return nil;
|
||||
if ([self runModalSavePanel:savePanel withAccessoryView:accessory])
|
||||
{
|
||||
return [savePanel filename];
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (BOOL)shouldChangePrintInfo:(NSPrintInfo *)newPrintInfo
|
||||
{
|
||||
return YES;
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (NSPrintInfo *)printInfo
|
||||
{
|
||||
return _printInfo? _printInfo : [NSPrintInfo sharedPrintInfo];
|
||||
return _printInfo? _printInfo : [NSPrintInfo sharedPrintInfo];
|
||||
}
|
||||
|
||||
- (void)setPrintInfo:(NSPrintInfo *)printInfo
|
||||
{
|
||||
[printInfo retain];
|
||||
[_printInfo release];
|
||||
_printInfo = printInfo;
|
||||
[printInfo retain];
|
||||
[_printInfo release];
|
||||
_printInfo = printInfo;
|
||||
}
|
||||
|
||||
|
||||
// Page layout panel (Page Setup)
|
||||
// Page layout panel (Page Setup)
|
||||
|
||||
- (int)runModalPageLayoutWithPrintInfo:(NSPrintInfo *)printInfo
|
||||
{
|
||||
return [[NSPageLayout pageLayout] runModalWithPrintInfo:printInfo];
|
||||
return [[NSPageLayout pageLayout] runModalWithPrintInfo:printInfo];
|
||||
}
|
||||
|
||||
- (IBAction)runPageLayout:(id)sender
|
||||
{
|
||||
NSPrintInfo *printInfo = [self printInfo];
|
||||
|
||||
if ([self runModalPageLayoutWithPrintInfo:printInfo] &&
|
||||
[self shouldChangePrintInfo:printInfo])
|
||||
{
|
||||
[self setPrintInfo:printInfo];
|
||||
[self updateChangeCount:NSChangeDone];
|
||||
}
|
||||
NSPrintInfo *printInfo = [self printInfo];
|
||||
|
||||
if ([self runModalPageLayoutWithPrintInfo:printInfo]
|
||||
&& [self shouldChangePrintInfo:printInfo])
|
||||
{
|
||||
[self setPrintInfo:printInfo];
|
||||
[self updateChangeCount:NSChangeDone];
|
||||
}
|
||||
}
|
||||
|
||||
/* This is overridden by subclassers; the default implementation does nothing. */
|
||||
|
@ -457,114 +462,114 @@
|
|||
|
||||
- (BOOL)validateMenuItem:(NSMenuItem *)anItem
|
||||
{
|
||||
if ([anItem action] == @selector(revertDocumentToSaved:))
|
||||
return ([self fileName] != nil && [self isDocumentEdited]);
|
||||
if ([anItem action] == @selector(revertDocumentToSaved:))
|
||||
return ([self fileName] != nil && [self isDocumentEdited]);
|
||||
|
||||
// FIXME should validate spa popup items; return YES if it's a native type.
|
||||
// FIXME should validate spa popup items; return YES if it's a native type.
|
||||
|
||||
return YES;
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (NSString *)saveFileType
|
||||
{
|
||||
// FIXME this should return type picked on save accessory
|
||||
// return [spaPopupButton title];
|
||||
return [self fileType];
|
||||
// FIXME this should return type picked on save accessory
|
||||
// return [spaPopupButton title];
|
||||
return [self fileType];
|
||||
}
|
||||
|
||||
- (void)_doSaveAs:(NSSaveOperationType)saveOperation
|
||||
{
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
NSString *filename = [self fileName];
|
||||
NSString *backupFilename = nil;
|
||||
|
||||
if (filename == nil || saveOperation != NSSaveOperation)
|
||||
{
|
||||
filename = [self fileNameFromRunningSavePanelForSaveOperation:saveOperation];
|
||||
if (saveOperation == NSSaveOperation) saveOperation = NSSaveAsOperation;
|
||||
}
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
NSString *filename = [self fileName];
|
||||
NSString *backupFilename = nil;
|
||||
|
||||
if (filename == nil || saveOperation != NSSaveOperation)
|
||||
{
|
||||
filename = [self fileNameFromRunningSavePanelForSaveOperation:saveOperation];
|
||||
if (saveOperation == NSSaveOperation) saveOperation = NSSaveAsOperation;
|
||||
}
|
||||
|
||||
if (filename)
|
||||
if (filename)
|
||||
{
|
||||
if ([fileManager fileExistsAtPath:filename])
|
||||
{
|
||||
if ([fileManager fileExistsAtPath:filename])
|
||||
{
|
||||
NSString *extension = [filename pathExtension];
|
||||
NSString *extension = [filename pathExtension];
|
||||
|
||||
backupFilename = [filename stringByDeletingPathExtension];
|
||||
backupFilename = [backupFilename stringByAppendingString:@"~"];
|
||||
backupFilename = [backupFilename stringByAppendingPathExtension:extension];
|
||||
|
||||
backupFilename = [filename stringByDeletingPathExtension];
|
||||
backupFilename = [backupFilename stringByAppendingString:@"~"];
|
||||
backupFilename = [backupFilename stringByAppendingPathExtension:extension];
|
||||
/* Save panel has already asked if the user wants to replace it */
|
||||
|
||||
/* Save panel has already asked if the user wants to replace it */
|
||||
/* NSFileManager movePath: will fail if destination exists */
|
||||
if ([fileManager fileExistsAtPath:backupFilename])
|
||||
[fileManager removeFileAtPath:backupFilename handler:nil];
|
||||
|
||||
/* NSFileManager movePath: will fail if destination exists */
|
||||
if ([fileManager fileExistsAtPath:backupFilename])
|
||||
[fileManager removeFileAtPath:backupFilename handler:nil];
|
||||
|
||||
// Move or copy?
|
||||
if (![fileManager movePath:filename toPath:backupFilename handler:nil] &&
|
||||
[self keepBackupFile])
|
||||
// Move or copy?
|
||||
if (![fileManager movePath:filename toPath:backupFilename handler:nil] &&
|
||||
[self keepBackupFile])
|
||||
{
|
||||
//FIXME -- localize.
|
||||
int result = NSRunAlertPanel(@"File Error",
|
||||
@"Can't create backup file. Save anyways?",
|
||||
@"Save", @"Cancel", nil);
|
||||
|
||||
if (result != NSAlertDefaultReturn) return;
|
||||
//FIXME -- localize.
|
||||
int result = NSRunAlertPanel(@"File Error",
|
||||
@"Can't create backup file. Save anyways?",
|
||||
@"Save", @"Cancel", nil);
|
||||
|
||||
if (result != NSAlertDefaultReturn) return;
|
||||
}
|
||||
}
|
||||
if ([self writeToFile:filename ofType:[self saveFileType]])
|
||||
{
|
||||
if (saveOperation != NSSaveToOperation)
|
||||
{
|
||||
[self setFileName:filename];
|
||||
[self setFileType:[self saveFileType]];
|
||||
[self updateChangeCount:NSChangeCleared];
|
||||
}
|
||||
|
||||
if (backupFilename && ![self keepBackupFile])
|
||||
{
|
||||
[fileManager removeFileAtPath:backupFilename handler:nil];
|
||||
}
|
||||
}
|
||||
}
|
||||
if ([self writeToFile:filename ofType:[self saveFileType]])
|
||||
{
|
||||
if (saveOperation != NSSaveToOperation)
|
||||
{
|
||||
[self setFileName:filename];
|
||||
[self setFileType:[self saveFileType]];
|
||||
[self updateChangeCount:NSChangeCleared];
|
||||
}
|
||||
|
||||
if (backupFilename && ![self keepBackupFile])
|
||||
{
|
||||
[fileManager removeFileAtPath:backupFilename handler:nil];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)saveDocument:(id)sender
|
||||
{
|
||||
[self _doSaveAs:NSSaveOperation];
|
||||
[self _doSaveAs:NSSaveOperation];
|
||||
}
|
||||
|
||||
- (IBAction)saveDocumentAs:(id)sender
|
||||
{
|
||||
[self _doSaveAs:NSSaveAsOperation];
|
||||
[self _doSaveAs:NSSaveAsOperation];
|
||||
}
|
||||
|
||||
- (IBAction)saveDocumentTo:(id)sender
|
||||
{
|
||||
[self _doSaveAs:NSSaveToOperation];
|
||||
[self _doSaveAs:NSSaveToOperation];
|
||||
}
|
||||
|
||||
- (IBAction)revertDocumentToSaved:(id)sender
|
||||
{
|
||||
int result;
|
||||
int result;
|
||||
|
||||
//FIXME -- localize.
|
||||
result = NSRunAlertPanel(@"Revert",
|
||||
@"%@ has been edited. Are you sure you want to undo changes?",
|
||||
@"Revert", @"Cancel", nil, [self displayName]);
|
||||
|
||||
if (result == NSAlertDefaultReturn &&
|
||||
[self revertToSavedFromFile:[self fileName] ofType:[self fileType]])
|
||||
{
|
||||
[self updateChangeCount:NSChangeCleared];
|
||||
}
|
||||
//FIXME -- localize.
|
||||
result = NSRunAlertPanel(@"Revert",
|
||||
@"%@ has been edited. Are you sure you want to undo changes?",
|
||||
@"Revert", @"Cancel", nil, [self displayName]);
|
||||
|
||||
if (result == NSAlertDefaultReturn &&
|
||||
[self revertToSavedFromFile:[self fileName] ofType:[self fileType]])
|
||||
{
|
||||
[self updateChangeCount:NSChangeCleared];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)close
|
||||
{
|
||||
// We have an _docFlags.inClose flag, but I don't think we need to use it.
|
||||
[_windowControllers makeObjectsPerformSelector:@selector(close)];
|
||||
[[NSDocumentController sharedDocumentController] _removeDocument:self];
|
||||
// We have an _docFlags.inClose flag, but I don't think we need to use it.
|
||||
[_windowControllers makeObjectsPerformSelector:@selector(close)];
|
||||
[[NSDocumentController sharedDocumentController] _removeDocument:self];
|
||||
}
|
||||
|
||||
- (void)windowControllerWillLoadNib:(NSWindowController *)windowController {}
|
||||
|
@ -572,82 +577,86 @@
|
|||
|
||||
- (NSUndoManager *)undoManager
|
||||
{
|
||||
if (_undoManager == nil && [self hasUndoManager])
|
||||
{
|
||||
[self setUndoManager:[[[NSUndoManager alloc] init] autorelease]];
|
||||
}
|
||||
|
||||
return _undoManager;
|
||||
if (_undoManager == nil && [self hasUndoManager])
|
||||
{
|
||||
[self setUndoManager:[[[NSUndoManager alloc] init] autorelease]];
|
||||
}
|
||||
|
||||
return _undoManager;
|
||||
}
|
||||
|
||||
- (void)setUndoManager:(NSUndoManager *)undoManager
|
||||
{
|
||||
if (undoManager != _undoManager)
|
||||
{
|
||||
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
|
||||
|
||||
if (_undoManager)
|
||||
if (undoManager != _undoManager)
|
||||
{
|
||||
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
|
||||
|
||||
if (_undoManager)
|
||||
{
|
||||
[center removeObserver:self
|
||||
name:NSUndoManagerWillCloseUndoGroupNotification
|
||||
object:_undoManager];
|
||||
[center removeObserver:self
|
||||
name:NSUndoManagerDidUndoChangeNotification
|
||||
object:_undoManager];
|
||||
[center removeObserver:self
|
||||
name:NSUndoManagerDidRedoChangeNotification
|
||||
object:_undoManager];
|
||||
[center removeObserver:self
|
||||
name:NSUndoManagerWillCloseUndoGroupNotification
|
||||
object:_undoManager];
|
||||
[center removeObserver:self
|
||||
name:NSUndoManagerDidUndoChangeNotification
|
||||
object:_undoManager];
|
||||
[center removeObserver:self
|
||||
name:NSUndoManagerDidRedoChangeNotification
|
||||
object:_undoManager];
|
||||
}
|
||||
|
||||
[(NSObject*)undoManager retain];
|
||||
[(NSObject*)_undoManager release];
|
||||
_undoManager = undoManager;
|
||||
|
||||
if (_undoManager == nil)
|
||||
|
||||
[(NSObject*)undoManager retain];
|
||||
[(NSObject*)_undoManager release];
|
||||
_undoManager = undoManager;
|
||||
|
||||
if (_undoManager == nil)
|
||||
{
|
||||
[self setHasUndoManager:NO];
|
||||
[self setHasUndoManager:NO];
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
[center addObserver:self
|
||||
selector:@selector(_changeWasDone:)
|
||||
name:NSUndoManagerWillCloseUndoGroupNotification
|
||||
object:_undoManager];
|
||||
[center addObserver:self
|
||||
selector:@selector(_changeWasUndone:)
|
||||
name:NSUndoManagerDidUndoChangeNotification
|
||||
object:_undoManager];
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver:self
|
||||
selector:@selector(_changeWasRedone:)
|
||||
name:NSUndoManagerDidRedoChangeNotification
|
||||
object:_undoManager];
|
||||
[center addObserver:self
|
||||
selector:@selector(_changeWasDone:)
|
||||
name:NSUndoManagerWillCloseUndoGroupNotification
|
||||
object:_undoManager];
|
||||
[center addObserver:self
|
||||
selector:@selector(_changeWasUndone:)
|
||||
name:NSUndoManagerDidUndoChangeNotification
|
||||
object:_undoManager];
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver:self
|
||||
selector:@selector(_changeWasRedone:)
|
||||
name:NSUndoManagerDidRedoChangeNotification
|
||||
object:_undoManager];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)hasUndoManager
|
||||
{
|
||||
return _docFlags.hasUndoManager;
|
||||
return _docFlags.hasUndoManager;
|
||||
}
|
||||
|
||||
- (void)setHasUndoManager:(BOOL)flag
|
||||
{
|
||||
if (_undoManager && !flag)
|
||||
[self setUndoManager:nil];
|
||||
|
||||
_docFlags.hasUndoManager = flag;
|
||||
if (_undoManager && !flag)
|
||||
[self setUndoManager:nil];
|
||||
|
||||
_docFlags.hasUndoManager = flag;
|
||||
}
|
||||
|
||||
- (void)_changeWasDone:(NSNotification *)notification
|
||||
{ [self updateChangeCount:NSChangeDone];
|
||||
{
|
||||
[self updateChangeCount:NSChangeDone];
|
||||
}
|
||||
|
||||
- (void)_changeWasUndone:(NSNotification *)notification
|
||||
{ [self updateChangeCount:NSChangeUndone];
|
||||
{
|
||||
[self updateChangeCount:NSChangeUndone];
|
||||
}
|
||||
|
||||
- (void)_changeWasRedone:(NSNotification *)notification
|
||||
{ [self updateChangeCount:NSChangeDone];
|
||||
{
|
||||
[self updateChangeCount:NSChangeDone];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -22,15 +22,16 @@ static NSString *NSDocumentClassKey = @"NSDocumentClass";
|
|||
|
||||
static NSDictionary *TypeInfoForName(NSArray *types, NSString *typeName)
|
||||
{
|
||||
int i, count = [types count];
|
||||
for (i=0; i<count;i++)
|
||||
{
|
||||
NSDictionary *dict = [types objectAtIndex:i];
|
||||
if ([[dict objectForKey:NSNameKey] isEqualToString:typeName])
|
||||
return dict;
|
||||
}
|
||||
|
||||
return nil;
|
||||
int i, count = [types count];
|
||||
for (i=0; i<count;i++)
|
||||
{
|
||||
NSDictionary *dict = [types objectAtIndex:i];
|
||||
|
||||
if ([[dict objectForKey:NSNameKey] isEqualToString:typeName])
|
||||
return dict;
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
@implementation NSDocumentController
|
||||
|
@ -41,281 +42,291 @@ static NSDictionary *TypeInfoForName(NSArray *types, NSString *typeName)
|
|||
|
||||
+ (id)documentController //private
|
||||
{
|
||||
return [self sharedDocumentController];
|
||||
return [self sharedDocumentController];
|
||||
}
|
||||
|
||||
+ (id)allocWithZone:(NSZone *)zone
|
||||
{
|
||||
return [self sharedDocumentController];
|
||||
return [self sharedDocumentController];
|
||||
}
|
||||
|
||||
+ (id)sharedDocumentController
|
||||
{
|
||||
static id instance = nil;
|
||||
static id instance = nil;
|
||||
|
||||
if (instance == nil)
|
||||
instance = [[super allocWithZone:NULL] init];
|
||||
|
||||
if (instance == nil) instance = [[super allocWithZone:NULL] init];
|
||||
return instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
- init
|
||||
{
|
||||
NSDictionary *customDict = [[NSBundle mainBundle] infoDictionary];
|
||||
NSDictionary *customDict = [[NSBundle mainBundle] infoDictionary];
|
||||
|
||||
_types = [[customDict objectForKey:NSTypesKey] retain];
|
||||
_documents = [[NSMutableArray alloc] init];
|
||||
[self setShouldCreateUI:YES];
|
||||
_types = [[customDict objectForKey:NSTypesKey] retain];
|
||||
_documents = [[NSMutableArray alloc] init];
|
||||
[self setShouldCreateUI:YES];
|
||||
|
||||
[[[NSWorkspace sharedWorkspace] notificationCenter]
|
||||
addObserver:self
|
||||
selector:@selector(_workspaceWillPowerOff:)
|
||||
name:NSWorkspaceWillPowerOffNotification
|
||||
object:nil];
|
||||
[[[NSWorkspace sharedWorkspace] notificationCenter]
|
||||
addObserver:self
|
||||
selector:@selector(_workspaceWillPowerOff:)
|
||||
name:NSWorkspaceWillPowerOffNotification
|
||||
object:nil];
|
||||
|
||||
return self;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self];
|
||||
[_documents release];
|
||||
[_types release];
|
||||
[super dealloc];
|
||||
[[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self];
|
||||
[_documents release];
|
||||
[_types release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (BOOL)shouldCreateUI
|
||||
{
|
||||
return _controllerFlags.shouldCreateUI;
|
||||
return _controllerFlags.shouldCreateUI;
|
||||
}
|
||||
|
||||
- (void)setShouldCreateUI:(BOOL)flag
|
||||
{
|
||||
_controllerFlags.shouldCreateUI = flag;
|
||||
_controllerFlags.shouldCreateUI = flag;
|
||||
}
|
||||
|
||||
- (id)makeUntitledDocumentOfType:(NSString *)type
|
||||
{
|
||||
Class documentClass = [self documentClassForType:type];
|
||||
return [[[documentClass alloc] init] autorelease];
|
||||
Class documentClass = [self documentClassForType:type];
|
||||
return [[[documentClass alloc] init] autorelease];
|
||||
}
|
||||
|
||||
- (id)makeDocumentWithContentsOfFile:(NSString *)fileName ofType:(NSString *)type
|
||||
{
|
||||
Class documentClass = [self documentClassForType:type];
|
||||
return [[[documentClass alloc] initWithContentsOfFile:fileName ofType:type] autorelease];
|
||||
Class documentClass = [self documentClassForType:type];
|
||||
return [[[documentClass alloc] initWithContentsOfFile:fileName ofType:type] autorelease];
|
||||
}
|
||||
|
||||
- (id)makeDocumentWithContentsOfURL:(NSURL *)url ofType:(NSString *)type
|
||||
{
|
||||
Class documentClass = [self documentClassForType:type];
|
||||
return [[[documentClass alloc] initWithContentsOfURL:url ofType:type] autorelease];
|
||||
Class documentClass = [self documentClassForType:type];
|
||||
return [[[documentClass alloc] initWithContentsOfURL:url ofType:type] autorelease];
|
||||
}
|
||||
|
||||
- _defaultType
|
||||
{
|
||||
if ([_types count] == 0) return nil; // raise exception?
|
||||
return [[_types objectAtIndex:0] objectForKey:NSNameKey];
|
||||
if ([_types count] == 0)
|
||||
return nil; // raise exception?
|
||||
|
||||
return [[_types objectAtIndex:0] objectForKey:NSNameKey];
|
||||
}
|
||||
|
||||
/* These next two should really have been public. */
|
||||
- (void)_addDocument:(NSDocument *)document
|
||||
{
|
||||
[_documents addObject:document];
|
||||
[_documents addObject:document];
|
||||
}
|
||||
|
||||
- (void)_removeDocument:(NSDocument *)document
|
||||
{
|
||||
[_documents removeObject:document];
|
||||
[_documents removeObject:document];
|
||||
}
|
||||
|
||||
- (id)openUntitledDocumentOfType:(NSString*)type display:(BOOL)display
|
||||
{
|
||||
NSDocument *document = [self makeUntitledDocumentOfType:type];
|
||||
|
||||
if (document == nil) return nil;
|
||||
NSDocument *document = [self makeUntitledDocumentOfType:type];
|
||||
|
||||
if (document == nil)
|
||||
return nil;
|
||||
|
||||
[self _addDocument:document];
|
||||
if ([self shouldCreateUI])
|
||||
[self _addDocument:document];
|
||||
if ([self shouldCreateUI])
|
||||
{
|
||||
[document makeWindowControllers];
|
||||
if (display)
|
||||
[document showWindows];
|
||||
[document makeWindowControllers];
|
||||
if (display)
|
||||
[document showWindows];
|
||||
}
|
||||
|
||||
return document;
|
||||
return document;
|
||||
}
|
||||
|
||||
- (id)openDocumentWithContentsOfFile:(NSString *)fileName display:(BOOL)display
|
||||
{
|
||||
NSDocument *document = [self documentForFileName:fileName];
|
||||
|
||||
if (document == nil)
|
||||
NSDocument *document = [self documentForFileName:fileName];
|
||||
|
||||
if (document == nil)
|
||||
{
|
||||
NSString *type = [self typeFromFileExtension:[fileName pathExtension]];
|
||||
NSString *type = [self typeFromFileExtension:[fileName pathExtension]];
|
||||
|
||||
if ((document = [self makeDocumentWithContentsOfFile:fileName ofType:type]))
|
||||
[self _addDocument:document];
|
||||
|
||||
if ((document = [self makeDocumentWithContentsOfFile:fileName ofType:type]))
|
||||
[self _addDocument:document];
|
||||
if ([self shouldCreateUI])
|
||||
[document makeWindowControllers];
|
||||
if ([self shouldCreateUI])
|
||||
[document makeWindowControllers];
|
||||
}
|
||||
|
||||
if (display && [self shouldCreateUI])
|
||||
|
||||
if (display && [self shouldCreateUI])
|
||||
{
|
||||
[document showWindows];
|
||||
[document showWindows];
|
||||
}
|
||||
|
||||
return document;
|
||||
return document;
|
||||
}
|
||||
|
||||
- (id)openDocumentWithContentsOfURL:(NSURL *)url display:(BOOL)display
|
||||
{
|
||||
// Should we only do this if [url isFileURL] is YES?
|
||||
NSDocument *document = [self documentForFileName:[url path]];
|
||||
|
||||
if (document == nil)
|
||||
// Should we only do this if [url isFileURL] is YES?
|
||||
NSDocument *document = [self documentForFileName:[url path]];
|
||||
|
||||
if (document == nil)
|
||||
{
|
||||
NSString *type = [self typeFromFileExtension:[[url path] pathExtension]];
|
||||
|
||||
document = [self makeDocumentWithContentsOfURL:url ofType:type];
|
||||
if (document == nil) return nil;
|
||||
NSString *type = [self typeFromFileExtension:[[url path] pathExtension]];
|
||||
|
||||
document = [self makeDocumentWithContentsOfURL:url ofType:type];
|
||||
|
||||
if (document == nil)
|
||||
return nil;
|
||||
|
||||
[self _addDocument:document];
|
||||
|
||||
[self _addDocument:document];
|
||||
if ([self shouldCreateUI])
|
||||
if ([self shouldCreateUI])
|
||||
{
|
||||
[document makeWindowControllers];
|
||||
[document makeWindowControllers];
|
||||
}
|
||||
}
|
||||
|
||||
if (display && [self shouldCreateUI])
|
||||
|
||||
if (display && [self shouldCreateUI])
|
||||
{
|
||||
[document showWindows];
|
||||
[document showWindows];
|
||||
}
|
||||
|
||||
return document;
|
||||
|
||||
return document;
|
||||
}
|
||||
|
||||
- _setupOpenPanel
|
||||
{
|
||||
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
|
||||
[openPanel setDirectory:[self currentDirectory]];
|
||||
[openPanel setAllowsMultipleSelection:YES];
|
||||
return openPanel;
|
||||
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
|
||||
[openPanel setDirectory:[self currentDirectory]];
|
||||
[openPanel setAllowsMultipleSelection:YES];
|
||||
return openPanel;
|
||||
}
|
||||
|
||||
- (int)runModalOpenPanel:(NSOpenPanel *)openPanel forTypes:(NSArray *)openableFileExtensions
|
||||
{
|
||||
return [openPanel runModalForTypes:openableFileExtensions];
|
||||
return [openPanel runModalForTypes:openableFileExtensions];
|
||||
}
|
||||
|
||||
- (NSArray *)_openableFileExtensions
|
||||
{
|
||||
int i, count = [_types count];
|
||||
NSMutableArray *array = [NSMutableArray arrayWithCapacity:count];
|
||||
int i, count = [_types count];
|
||||
NSMutableArray *array = [NSMutableArray arrayWithCapacity:count];
|
||||
|
||||
for (i=0; i<count; i++)
|
||||
{
|
||||
NSDictionary *typeInfo = [_types objectAtIndex:i];
|
||||
[array addObjectsFromArray:[typeInfo objectForKey:NSUnixExtensionsKey]];
|
||||
[array addObjectsFromArray:[typeInfo objectForKey:NSDOSExtensionsKey]];
|
||||
}
|
||||
|
||||
return array;
|
||||
for (i=0; i<count; i++)
|
||||
{
|
||||
NSDictionary *typeInfo = [_types objectAtIndex:i];
|
||||
[array addObjectsFromArray:[typeInfo objectForKey:NSUnixExtensionsKey]];
|
||||
[array addObjectsFromArray:[typeInfo objectForKey:NSDOSExtensionsKey]];
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
- (NSArray *)fileNamesFromRunningOpenPanel
|
||||
{
|
||||
NSArray *types = [self _openableFileExtensions];
|
||||
NSOpenPanel *openPanel = [self _setupOpenPanel];
|
||||
NSArray *types = [self _openableFileExtensions];
|
||||
NSOpenPanel *openPanel = [self _setupOpenPanel];
|
||||
|
||||
if ([self runModalOpenPanel:openPanel forTypes:types])
|
||||
{
|
||||
return [openPanel filenames];
|
||||
}
|
||||
if ([self runModalOpenPanel:openPanel forTypes:types])
|
||||
{
|
||||
return [openPanel filenames];
|
||||
}
|
||||
|
||||
return nil;
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSArray *)URLsFromRunningOpenPanel
|
||||
{
|
||||
NSArray *types = [self _openableFileExtensions];
|
||||
NSOpenPanel *openPanel = [self _setupOpenPanel];
|
||||
|
||||
if ([self runModalOpenPanel:openPanel forTypes:types])
|
||||
NSArray *types = [self _openableFileExtensions];
|
||||
NSOpenPanel *openPanel = [self _setupOpenPanel];
|
||||
|
||||
if ([self runModalOpenPanel:openPanel forTypes:types])
|
||||
{
|
||||
return [openPanel URLs];
|
||||
return [openPanel URLs];
|
||||
}
|
||||
|
||||
return nil;
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
- (IBAction)saveAllDocuments:(id)sender
|
||||
{
|
||||
NSDocument *document;
|
||||
NSEnumerator *docEnum = [_documents objectEnumerator];
|
||||
NSDocument *document;
|
||||
NSEnumerator *docEnum = [_documents objectEnumerator];
|
||||
|
||||
while ((document = [docEnum nextObject]))
|
||||
while ((document = [docEnum nextObject]))
|
||||
{
|
||||
if ([document isDocumentEdited]) //maybe we should save regardless...
|
||||
{
|
||||
if ([document isDocumentEdited]) //maybe we should save regardless...
|
||||
{
|
||||
[document saveDocument:sender];
|
||||
}
|
||||
[document saveDocument:sender];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (IBAction)openDocument:(id)sender
|
||||
{
|
||||
NSEnumerator *fileEnum = [[self fileNamesFromRunningOpenPanel] objectEnumerator];
|
||||
NSString *filename;
|
||||
NSEnumerator *fileEnum = [[self fileNamesFromRunningOpenPanel] objectEnumerator];
|
||||
NSString *filename;
|
||||
|
||||
while ((filename = [fileEnum nextObject]))
|
||||
{
|
||||
[self openDocumentWithContentsOfFile:filename display:YES];
|
||||
}
|
||||
while ((filename = [fileEnum nextObject]))
|
||||
{
|
||||
[self openDocumentWithContentsOfFile:filename display:YES];
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)newDocument:(id)sender
|
||||
{
|
||||
[self openUntitledDocumentOfType:[self _defaultType] display:YES];
|
||||
[self openUntitledDocumentOfType:[self _defaultType] display:YES];
|
||||
}
|
||||
|
||||
|
||||
- (BOOL)closeAllDocuments
|
||||
{
|
||||
NSDocument *document;
|
||||
NSEnumerator *docEnum = [_documents objectEnumerator];
|
||||
|
||||
while ((document = [docEnum nextObject]))
|
||||
{
|
||||
if (![document canCloseDocument]) return NO;
|
||||
[document close];
|
||||
[self _removeDocument:document];
|
||||
}
|
||||
|
||||
return YES;
|
||||
NSDocument *document;
|
||||
NSEnumerator *docEnum = [_documents objectEnumerator];
|
||||
|
||||
while ((document = [docEnum nextObject]))
|
||||
{
|
||||
if (![document canCloseDocument]) return NO;
|
||||
[document close];
|
||||
[self _removeDocument:document];
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)reviewUnsavedDocumentsWithAlertTitle:(NSString *)title cancellable:(BOOL)cancellable
|
||||
{
|
||||
//FIXME -- localize.
|
||||
NSString *cancelString = (cancellable)? @"Cancel" : nil;
|
||||
int result;
|
||||
|
||||
if (![self hasEditedDocuments]) return YES;
|
||||
//FIXME -- localize.
|
||||
NSString *cancelString = (cancellable)? @"Cancel" : nil;
|
||||
int result;
|
||||
|
||||
if (![self hasEditedDocuments]) return YES;
|
||||
|
||||
result = NSRunAlertPanel(title, @"You have unsaved documents.",
|
||||
@"Review Unsaved", cancelString, @"Quit Anyways");
|
||||
result = NSRunAlertPanel(title, @"You have unsaved documents.",
|
||||
@"Review Unsaved", cancelString, @"Quit Anyways");
|
||||
|
||||
#define ReviewUnsaved NSAlertDefaultReturn
|
||||
#define Cancel NSAlertAlternateReturn
|
||||
#define QuitAnyways NSAlertOtherReturn
|
||||
|
||||
switch (result)
|
||||
{
|
||||
case ReviewUnsaved: return [self closeAllDocuments];
|
||||
case QuitAnyways: return YES;
|
||||
case Cancel:
|
||||
default: return NO;
|
||||
}
|
||||
switch (result)
|
||||
{
|
||||
case ReviewUnsaved: return [self closeAllDocuments];
|
||||
case QuitAnyways: return YES;
|
||||
case Cancel:
|
||||
default: return NO;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef OPENSTEP_ONLY
|
||||
|
@ -326,148 +337,157 @@ static NSDictionary *TypeInfoForName(NSArray *types, NSString *typeName)
|
|||
*/
|
||||
- (BOOL)application:(NSApplication *)sender openFile:(NSString *)filename
|
||||
{
|
||||
return [self openDocumentWithContentsOfFile:filename display:YES] ? YES : NO;
|
||||
return [self openDocumentWithContentsOfFile:filename display:YES] ? YES : NO;
|
||||
}
|
||||
|
||||
- (BOOL)application:(NSApplication *)sender openTempFile:(NSString *)filename;
|
||||
{
|
||||
return [self openDocumentWithContentsOfFile:filename display:YES] ? YES : NO;
|
||||
return [self openDocumentWithContentsOfFile:filename display:YES] ? YES : NO;
|
||||
}
|
||||
|
||||
- (BOOL)applicationOpenUntitledFile:(NSApplication *)sender
|
||||
{
|
||||
return [self openUntitledDocumentOfType:[self _defaultType] display:YES] ? YES : NO;
|
||||
return [self openUntitledDocumentOfType:[self _defaultType] display:YES] ? YES : NO;
|
||||
}
|
||||
|
||||
- (BOOL)application:(id)sender openFileWithoutUI:(NSString *)filename
|
||||
{
|
||||
return [self openDocumentWithContentsOfFile:filename display:NO] ? YES : NO;
|
||||
return [self openDocumentWithContentsOfFile:filename display:NO] ? YES : NO;
|
||||
}
|
||||
|
||||
- (BOOL)applicationShouldTerminate:(NSApplication *)sender
|
||||
{
|
||||
return [self reviewUnsavedDocumentsWithAlertTitle:@"Quit" cancellable:YES];
|
||||
return [self reviewUnsavedDocumentsWithAlertTitle:@"Quit" cancellable:YES];
|
||||
}
|
||||
#endif
|
||||
|
||||
- (void)_workspaceWillPowerOff:(NSNotification *)notification
|
||||
{
|
||||
// FIXME -- localize.
|
||||
[self reviewUnsavedDocumentsWithAlertTitle:@"Power" cancellable:NO];
|
||||
// FIXME -- localize.
|
||||
[self reviewUnsavedDocumentsWithAlertTitle:@"Power" cancellable:NO];
|
||||
}
|
||||
|
||||
|
||||
- (NSArray *)documents
|
||||
{
|
||||
return _documents;
|
||||
return _documents;
|
||||
}
|
||||
|
||||
- (BOOL)hasEditedDocuments;
|
||||
{
|
||||
int i, count = [_documents count];
|
||||
int i, count = [_documents count];
|
||||
|
||||
for (i=0; i<count; i++)
|
||||
{
|
||||
if ([[_documents objectAtIndex:i] isDocumentEdited])
|
||||
return YES;
|
||||
}
|
||||
|
||||
for (i=0; i<count; i++)
|
||||
{
|
||||
if ([[_documents objectAtIndex:i] isDocumentEdited]) return YES;
|
||||
}
|
||||
|
||||
return NO;
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (id)currentDocument
|
||||
{
|
||||
return [self documentForWindow:[[NSApplication sharedApplication] mainWindow]];
|
||||
return [self documentForWindow:[[NSApplication sharedApplication] mainWindow]];
|
||||
}
|
||||
|
||||
- (NSString *)currentDirectory
|
||||
{
|
||||
NSFileManager *manager = [NSFileManager defaultManager];
|
||||
NSDocument *currentDocument = [self currentDocument];
|
||||
NSString *directory = [[currentDocument fileName] stringByDeletingLastPathComponent];
|
||||
BOOL isDir = NO;
|
||||
NSFileManager *manager = [NSFileManager defaultManager];
|
||||
NSDocument *currentDocument = [self currentDocument];
|
||||
NSString *directory = [[currentDocument fileName] stringByDeletingLastPathComponent];
|
||||
BOOL isDir = NO;
|
||||
|
||||
if (directory &&
|
||||
[manager fileExistsAtPath:directory isDirectory:&isDir] && isDir) return directory;
|
||||
//FIXME -- need to remember last saved directory, and return that here.
|
||||
//Only return NSHomeDirectory if nothing's been saved yet.
|
||||
return NSHomeDirectory();
|
||||
if (directory &&
|
||||
[manager fileExistsAtPath:directory isDirectory:&isDir] && isDir)
|
||||
return directory;
|
||||
|
||||
//FIXME -- need to remember last saved directory, and return that here.
|
||||
//Only return NSHomeDirectory if nothing's been saved yet.
|
||||
return NSHomeDirectory();
|
||||
}
|
||||
|
||||
- (id)documentForWindow:(NSWindow *)window
|
||||
{
|
||||
id document;
|
||||
id document;
|
||||
|
||||
if (window == nil) return nil;
|
||||
if (![[window windowController] isKindOfClass:[NSWindowController class]]) return nil;
|
||||
if (window == nil)
|
||||
return nil;
|
||||
|
||||
document = [[window windowController] document];
|
||||
if (![document isKindOfClass:[NSDocument class]]) return nil;
|
||||
return document;
|
||||
if (![[window windowController] isKindOfClass:[NSWindowController class]])
|
||||
return nil;
|
||||
|
||||
document = [[window windowController] document];
|
||||
|
||||
if (![document isKindOfClass:[NSDocument class]])
|
||||
return nil;
|
||||
|
||||
return document;
|
||||
}
|
||||
|
||||
- (id)documentForFileName:(NSString *)fileName
|
||||
{
|
||||
int i, count = [_documents count];
|
||||
int i, count = [_documents count];
|
||||
|
||||
for (i=0; i<count; i++)
|
||||
{
|
||||
NSDocument *document = [_documents objectAtIndex:i];
|
||||
|
||||
if ([[document fileName] isEqualToString:fileName])
|
||||
return document;
|
||||
}
|
||||
for (i=0; i<count; i++)
|
||||
{
|
||||
NSDocument *document = [_documents objectAtIndex:i];
|
||||
|
||||
if ([[document fileName] isEqualToString:fileName])
|
||||
return document;
|
||||
}
|
||||
|
||||
return nil;
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (BOOL)validateMenuItem:(NSMenuItem *)anItem
|
||||
{
|
||||
if ([anItem action] == @selector(saveAllDocuments:))
|
||||
return [self hasEditedDocuments];
|
||||
return YES;
|
||||
if ([anItem action] == @selector(saveAllDocuments:))
|
||||
return [self hasEditedDocuments];
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (NSString *)displayNameForType:(NSString *)type
|
||||
{
|
||||
NSString *name = [TYPE_INFO(type) objectForKey:NSHumanReadableNameKey];
|
||||
|
||||
return name? name : type;
|
||||
NSString *name = [TYPE_INFO(type) objectForKey:NSHumanReadableNameKey];
|
||||
|
||||
return name? name : type;
|
||||
}
|
||||
|
||||
- (NSString *)typeFromFileExtension:(NSString *)fileExtension
|
||||
{
|
||||
int i, count = [_types count];
|
||||
int i, count = [_types count];
|
||||
|
||||
for (i=0; i<count;i++)
|
||||
for (i=0; i<count;i++)
|
||||
{
|
||||
NSDictionary *typeInfo = [_types objectAtIndex:i];
|
||||
|
||||
if ([[typeInfo objectForKey:NSUnixExtensionsKey] containsObject:fileExtension] ||
|
||||
[[typeInfo objectForKey:NSDOSExtensionsKey] containsObject:fileExtension])
|
||||
{
|
||||
NSDictionary *typeInfo = [_types objectAtIndex:i];
|
||||
|
||||
if ([[typeInfo objectForKey:NSUnixExtensionsKey] containsObject:fileExtension] ||
|
||||
[[typeInfo objectForKey:NSDOSExtensionsKey] containsObject:fileExtension])
|
||||
{
|
||||
return [typeInfo objectForKey:NSNameKey];
|
||||
}
|
||||
return [typeInfo objectForKey:NSNameKey];
|
||||
}
|
||||
}
|
||||
|
||||
return nil;
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSArray *)fileExtensionsFromType:(NSString *)type
|
||||
{
|
||||
NSDictionary *typeInfo = TYPE_INFO(type);
|
||||
NSArray *unixExtensions = [typeInfo objectForKey:NSUnixExtensionsKey];
|
||||
NSArray *dosExtensions = [typeInfo objectForKey:NSDOSExtensionsKey];
|
||||
|
||||
if (!dosExtensions) return unixExtensions;
|
||||
if (!unixExtensions) return dosExtensions;
|
||||
return [unixExtensions arrayByAddingObjectsFromArray:dosExtensions];
|
||||
NSDictionary *typeInfo = TYPE_INFO(type);
|
||||
NSArray *unixExtensions = [typeInfo objectForKey:NSUnixExtensionsKey];
|
||||
NSArray *dosExtensions = [typeInfo objectForKey:NSDOSExtensionsKey];
|
||||
|
||||
if (!dosExtensions) return unixExtensions;
|
||||
if (!unixExtensions) return dosExtensions;
|
||||
return [unixExtensions arrayByAddingObjectsFromArray:dosExtensions];
|
||||
}
|
||||
|
||||
- (Class)documentClassForType:(NSString *)type
|
||||
{
|
||||
NSString *className = [TYPE_INFO(type) objectForKey:NSDocumentClassKey];
|
||||
NSString *className = [TYPE_INFO(type) objectForKey:NSDocumentClassKey];
|
||||
|
||||
return className? NSClassFromString(className) : Nil;
|
||||
return className? NSClassFromString(className) : Nil;
|
||||
}
|
||||
|
||||
static NSString *NSEditorRole = @"Editor";
|
||||
|
@ -476,52 +496,52 @@ static NSString *NSNoRole = @"None";
|
|||
|
||||
- (NSArray *)_editorAndViewerTypesForClass:(Class)documentClass
|
||||
{
|
||||
int i, count = [_types count];
|
||||
NSMutableArray *types = [NSMutableArray arrayWithCapacity:count];
|
||||
NSString *docClassName = NSStringFromClass(documentClass);
|
||||
int i, count = [_types count];
|
||||
NSMutableArray *types = [NSMutableArray arrayWithCapacity:count];
|
||||
NSString *docClassName = NSStringFromClass(documentClass);
|
||||
|
||||
for (i=0; i<count; i++)
|
||||
for (i=0; i<count; i++)
|
||||
{
|
||||
NSDictionary *typeInfo = [_types objectAtIndex:i];
|
||||
NSString *className = [typeInfo objectForKey:NSDocumentClassKey];
|
||||
NSString *role = [typeInfo objectForKey:NSRoleKey];
|
||||
|
||||
if ([docClassName isEqualToString:className] &&
|
||||
(role == nil || [role isEqual:NSEditorRole] || [role isEqual:NSViewerRole]))
|
||||
{
|
||||
NSDictionary *typeInfo = [_types objectAtIndex:i];
|
||||
NSString *className = [typeInfo objectForKey:NSDocumentClassKey];
|
||||
NSString *role = [typeInfo objectForKey:NSRoleKey];
|
||||
|
||||
if ([docClassName isEqualToString:className] &&
|
||||
(role == nil || [role isEqual:NSEditorRole] || [role isEqual:NSViewerRole]))
|
||||
{
|
||||
[types addObject:[typeInfo objectForKey:NSNameKey]];
|
||||
}
|
||||
[types addObject:[typeInfo objectForKey:NSNameKey]];
|
||||
}
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
- (NSArray *)_editorTypesForClass:(Class)documentClass
|
||||
{
|
||||
int i, count = [_types count];
|
||||
NSMutableArray *types = [NSMutableArray arrayWithCapacity:count];
|
||||
NSString *docClassName = NSStringFromClass(documentClass);
|
||||
|
||||
for (i=0; i<count; i++)
|
||||
int i, count = [_types count];
|
||||
NSMutableArray *types = [NSMutableArray arrayWithCapacity:count];
|
||||
NSString *docClassName = NSStringFromClass(documentClass);
|
||||
|
||||
for (i=0; i<count; i++)
|
||||
{
|
||||
NSDictionary *typeInfo = [_types objectAtIndex:i];
|
||||
NSString *className = [typeInfo objectForKey:NSDocumentClassKey];
|
||||
NSString *role = [typeInfo objectForKey:NSRoleKey];
|
||||
|
||||
if ([docClassName isEqualToString:className] &&
|
||||
(role == nil || [role isEqual:NSEditorRole]))
|
||||
{
|
||||
NSDictionary *typeInfo = [_types objectAtIndex:i];
|
||||
NSString *className = [typeInfo objectForKey:NSDocumentClassKey];
|
||||
NSString *role = [typeInfo objectForKey:NSRoleKey];
|
||||
|
||||
if ([docClassName isEqualToString:className] &&
|
||||
(role == nil || [role isEqual:NSEditorRole]))
|
||||
{
|
||||
[types addObject:[typeInfo objectForKey:NSNameKey]];
|
||||
}
|
||||
[types addObject:[typeInfo objectForKey:NSNameKey]];
|
||||
}
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
- (NSArray *)_exportableTypesForClass:(Class)documentClass
|
||||
{
|
||||
// Dunno what this method is for; maybe looks for filter types
|
||||
return [self _editorTypesForClass:documentClass];
|
||||
// Dunno what this method is for; maybe looks for filter types
|
||||
return [self _editorTypesForClass:documentClass];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -105,7 +105,6 @@ static NSString* NSMenuLocationsKey = @"NSMenuLocations";
|
|||
menu_follow_transient = NO;
|
||||
menu_is_beholdenToPopUpButton = YES;
|
||||
ASSIGN(menu_popb, popb);
|
||||
// menu_popb = popb;
|
||||
|
||||
menu_changed = YES;
|
||||
/* According to the spec, menus do autoenable by default */
|
||||
|
@ -171,8 +170,8 @@ static NSString* NSMenuLocationsKey = @"NSMenuLocations";
|
|||
defer: NO];
|
||||
|
||||
titleView = [NSMenuWindowTitleView new];
|
||||
[titleView setFrameOrigin: NSMakePoint(0, winRect.size.height-21)];
|
||||
[titleView setFrameSize: NSMakeSize (winRect.size.width, 21)];
|
||||
[titleView setFrameOrigin: NSMakePoint(0, winRect.size.height-22)];
|
||||
[titleView setFrameSize: NSMakeSize (winRect.size.width, 22)];
|
||||
[[aWindow contentView] addSubview:menu_view];
|
||||
[[aWindow contentView] addSubview:titleView];
|
||||
[titleView setMenu: self];
|
||||
|
@ -515,7 +514,7 @@ static NSString* NSMenuLocationsKey = @"NSMenuLocations";
|
|||
NSPoint subOrigin = [win_link convertBaseToScreen: NSMakePoint(aRect.origin.x, aRect.origin.y)];
|
||||
|
||||
return NSMakePoint (frame.origin.x + frame.size.width + 1,
|
||||
subOrigin.y - (submenuFrame.size.height - 41));
|
||||
subOrigin.y - (submenuFrame.size.height - 42));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -727,20 +726,17 @@ static NSString* NSMenuLocationsKey = @"NSMenuLocations";
|
|||
|
||||
if (!menu_is_beholdenToPopUpButton)
|
||||
{
|
||||
size.height += 21;
|
||||
size.height += 22;
|
||||
[aWindow setContentSize: size];
|
||||
[bWindow setContentSize: size];
|
||||
[menu_view setFrameOrigin: NSMakePoint(0, 0)];
|
||||
[titleView setFrame: NSMakeRect(0,size.height-21,size.width,21)];
|
||||
[titleView setFrame: NSMakeRect(0,size.height-22,size.width,22)];
|
||||
}
|
||||
else
|
||||
{
|
||||
[aWindow setContentSize: size];
|
||||
}
|
||||
|
||||
// FIXME, popup sets itself up.
|
||||
// [menu_view setNeedsDisplay:YES];
|
||||
|
||||
[aWindow display];
|
||||
|
||||
menu_changed = NO;
|
||||
|
@ -862,11 +858,9 @@ NSArray* array;
|
|||
if (menu_changed)
|
||||
[self sizeToFit];
|
||||
|
||||
if (menu_supermenu && ![self isTornOff]) // query super menu for
|
||||
if (menu_supermenu && ![self isTornOff]) // query super menu for
|
||||
{ // position
|
||||
NSPoint location = [menu_supermenu locationForSubmenu: self];
|
||||
|
||||
[aWindow setFrameOrigin: location];
|
||||
[aWindow setFrameOrigin:[menu_supermenu locationForSubmenu: self]];
|
||||
menu_supermenu->menu_attached_menu = self;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -130,65 +130,94 @@ static float GSMenuBarHeight = 25.0; // a guess.
|
|||
|
||||
[self lockFocus];
|
||||
|
||||
if (index == -1) {
|
||||
if (menuv_highlightedItemIndex != -1) {
|
||||
anItem = [menuv_items_link objectAtIndex: menuv_highlightedItemIndex];
|
||||
if (index == -1)
|
||||
{
|
||||
if (menuv_highlightedItemIndex != -1)
|
||||
{
|
||||
NSRect aRect = [self rectOfItemAtIndex: menuv_highlightedItemIndex];
|
||||
|
||||
[anItem highlight: NO
|
||||
withFrame: [self rectOfItemAtIndex: menuv_highlightedItemIndex]
|
||||
inView: self];
|
||||
anItem = [menuv_items_link objectAtIndex: menuv_highlightedItemIndex];
|
||||
|
||||
[anItem highlight: NO
|
||||
withFrame: aRect
|
||||
inView: self];
|
||||
|
||||
if ([anItem hasSubmenu] && ![[anItem target] isTornOff])
|
||||
[[anItem target] close];
|
||||
else if ([anItem hasSubmenu] && [[anItem target] isTornOff])
|
||||
[[anItem target] closeTransient];
|
||||
[self setNeedsDisplayInRect: aRect];
|
||||
|
||||
[anItem setState: 0];
|
||||
menuv_highlightedItemIndex = -1;
|
||||
}
|
||||
} else if (index >= 0) {
|
||||
if ( menuv_highlightedItemIndex != -1 ) {
|
||||
[window flushWindow];
|
||||
|
||||
anItem = [menuv_items_link objectAtIndex: menuv_highlightedItemIndex];
|
||||
if ([anItem hasSubmenu]
|
||||
&& ![[anItem target] isTornOff])
|
||||
[[anItem target] close];
|
||||
else if ([anItem hasSubmenu]
|
||||
&& [[anItem target] isTornOff])
|
||||
[[anItem target] closeTransient];
|
||||
|
||||
[anItem highlight: NO
|
||||
withFrame: [self rectOfItemAtIndex: menuv_highlightedItemIndex]
|
||||
inView: self];
|
||||
[anItem setState: 0];
|
||||
menuv_highlightedItemIndex = -1;
|
||||
}
|
||||
}
|
||||
else if (index >= 0)
|
||||
{
|
||||
if ( menuv_highlightedItemIndex != -1)
|
||||
{
|
||||
NSRect aRect = [self rectOfItemAtIndex: menuv_highlightedItemIndex];
|
||||
|
||||
if ([anItem hasSubmenu] && ![[anItem target] isTornOff])
|
||||
[[anItem target] close];
|
||||
else if ([anItem hasSubmenu] && [[anItem target] isTornOff])
|
||||
[[anItem target] closeTransient];
|
||||
anItem = [menuv_items_link objectAtIndex: menuv_highlightedItemIndex];
|
||||
|
||||
[anItem setState: 0];
|
||||
}
|
||||
[anItem highlight: NO
|
||||
withFrame: aRect
|
||||
inView: self];
|
||||
|
||||
if (menuv_highlightedItemIndex != index) {
|
||||
[self setNeedsDisplayInRect: aRect];
|
||||
|
||||
anItem = [menuv_items_link objectAtIndex: index];
|
||||
[window flushWindow];
|
||||
|
||||
if ([anItem isEnabled])
|
||||
{
|
||||
[anItem highlight: YES
|
||||
withFrame: [self rectOfItemAtIndex: index]
|
||||
inView: self];
|
||||
if ([anItem hasSubmenu]
|
||||
&& ![[anItem target] isTornOff])
|
||||
[[anItem target] close];
|
||||
else if ([anItem hasSubmenu]
|
||||
&& [[anItem target] isTornOff])
|
||||
[[anItem target] closeTransient];
|
||||
|
||||
[anItem setState: 1];
|
||||
|
||||
if ([anItem hasSubmenu] && ![[anItem target] isTornOff])
|
||||
[[anItem target] display];
|
||||
else if ([anItem hasSubmenu] && [[anItem target] isTornOff])
|
||||
[[anItem target] displayTransient];
|
||||
[anItem setState: 0];
|
||||
}
|
||||
|
||||
// set ivar to new index
|
||||
menuv_highlightedItemIndex = index;
|
||||
} else {
|
||||
menuv_highlightedItemIndex = -1;
|
||||
if (index != menuv_highlightedItemIndex)
|
||||
{
|
||||
anItem = [menuv_items_link objectAtIndex: index];
|
||||
|
||||
if ([anItem isEnabled])
|
||||
{
|
||||
NSRect aRect = [self rectOfItemAtIndex: index];
|
||||
|
||||
[anItem highlight: YES
|
||||
withFrame: aRect
|
||||
inView: self];
|
||||
[self setNeedsDisplayInRect: aRect];
|
||||
|
||||
[window flushWindow];
|
||||
|
||||
if ([anItem hasSubmenu]
|
||||
&& ![[anItem target] isTornOff])
|
||||
[[anItem target] display];
|
||||
else if ([anItem hasSubmenu]
|
||||
&& [[anItem target] isTornOff])
|
||||
[[anItem target] displayTransient];
|
||||
|
||||
[anItem setState: 1];
|
||||
}
|
||||
|
||||
// set ivar to new index
|
||||
menuv_highlightedItemIndex = index;
|
||||
}
|
||||
else if (menuv_highlightedItemIndex == index)
|
||||
{
|
||||
menuv_highlightedItemIndex = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[self unlockFocus];
|
||||
[window flushWindow];
|
||||
}
|
||||
|
||||
- (int)highlightedItemIndex
|
||||
|
@ -522,16 +551,18 @@ static float GSMenuBarHeight = 25.0; // a guess.
|
|||
{ // Recursive menu close & deselect.
|
||||
if ([aMenu supermenu] && aMenu != menuv_menu)
|
||||
{
|
||||
[[[aMenu supermenu] menuView] setHighlightedItemIndex: -1];
|
||||
[[aMenu menuView] setHighlightedItemIndex: -1];
|
||||
aMenu = [aMenu supermenu];
|
||||
}
|
||||
else
|
||||
finished = YES;
|
||||
|
||||
[window flushWindow];
|
||||
// [window flushWindow];
|
||||
}
|
||||
}
|
||||
|
||||
[self setHighlightedItemIndex: index];
|
||||
|
||||
lastIndex = index;
|
||||
}
|
||||
|
||||
|
@ -726,8 +757,6 @@ cell do the following */
|
|||
}
|
||||
else
|
||||
finished = YES;
|
||||
|
||||
[window flushWindow];
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -770,7 +799,7 @@ cell do the following */
|
|||
{ // Recursive menu close & deselect.
|
||||
if ([aMenu supermenu])
|
||||
{
|
||||
[[[aMenu supermenu] menuView] setHighlightedItemIndex: -1];
|
||||
[[aMenu menuView] setHighlightedItemIndex: -1];
|
||||
aMenu = [aMenu supermenu];
|
||||
}
|
||||
else
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#include <AppKit/NSCStringText.h>
|
||||
#include <AppKit/NSEvent.h>
|
||||
|
||||
|
||||
/*
|
||||
* Dummy definitions provided here to avoid errors when not linking with
|
||||
* a back end.
|
||||
|
@ -302,4 +301,3 @@ float NSLinkFrameThickness(void)
|
|||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue