From 975469ff718ce8ee9ec8da2bc37e43eda10d8584 Mon Sep 17 00:00:00 2001 From: gcasa Date: Thu, 7 Aug 2008 05:17:32 +0000 Subject: [PATCH] * Headers/AppKit/NSTokenFieldCell.h * Headers/AppKit/NSTokenField.h: Headers for new class. * Source/GNUmakefile * Source/NSDocumentController.m: Added code to handle the CF keys as well as the NS keys for document oriented apps. * Source/NSTokenFieldCell.m * Source/NSTokenField.m: Start of implementation for this class git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@26801 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 10 +++ Headers/AppKit/NSTokenField.h | 53 +++++++++++ Headers/AppKit/NSTokenFieldCell.h | 66 ++++++++++++++ Source/GNUmakefile | 4 + Source/NSDocumentController.m | 63 ++++++++++++-- Source/NSTokenField.m | 140 ++++++++++++++++++++++++++++++ Source/NSTokenFieldCell.m | 122 ++++++++++++++++++++++++++ 7 files changed, 452 insertions(+), 6 deletions(-) create mode 100644 Headers/AppKit/NSTokenField.h create mode 100644 Headers/AppKit/NSTokenFieldCell.h create mode 100644 Source/NSTokenField.m create mode 100644 Source/NSTokenFieldCell.m diff --git a/ChangeLog b/ChangeLog index a0086a0b4..83f77960c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2008-08-07 18:23-EDT Gregory John Casamento + + * Headers/AppKit/NSTokenFieldCell.h + * Headers/AppKit/NSTokenField.h: Headers for new class. + * Source/GNUmakefile + * Source/NSDocumentController.m: Added code to handle the + CF keys as well as the NS keys for document oriented apps. + * Source/NSTokenFieldCell.m + * Source/NSTokenField.m: Start of implementation for this class. + 2008-08-02 Fred Kiefer * Source/NSScrollView.m (-initWithCoder:): Handle non-retained diff --git a/Headers/AppKit/NSTokenField.h b/Headers/AppKit/NSTokenField.h new file mode 100644 index 000000000..838c39b96 --- /dev/null +++ b/Headers/AppKit/NSTokenField.h @@ -0,0 +1,53 @@ +/* + NSTokenField.h + + Token field control class for text entry + + Copyright (C) 2008 Free Software Foundation, Inc. + + Author: Gregory Casamento + Date: 2008 + + This file is part of the GNUstep GUI Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; see the file COPYING.LIB. + If not, see or write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef _GNUstep_H_NSTokenField +#define _GNUstep_H_NSTokenField + +#import +#include +#include + +@interface NSTokenField : NSTextField +// Style... +- (NSTokenStyle)tokenStyle; +- (void)setTokenStyle:(NSTokenStyle)style; + +// Completion delay... ++ (NSTimeInterval)defaultCompletionDelay; +- (NSTimeInterval)completionDelay; +- (void)setCompletionDelay:(NSTimeInterval)delay; + +// Character set... ++ (NSCharacterSet *)defaultTokenizingCharacterSet; +- (void)setTokenizingCharacterSet:(NSCharacterSet *)characterSet; +- (NSCharacterSet *)tokenizingCharacterSet; +@end; + +#endif // _GNUstep_H_NSTokenField diff --git a/Headers/AppKit/NSTokenFieldCell.h b/Headers/AppKit/NSTokenFieldCell.h new file mode 100644 index 000000000..a3924bb80 --- /dev/null +++ b/Headers/AppKit/NSTokenFieldCell.h @@ -0,0 +1,66 @@ +/* + NSTokenFieldCell.h + + Cell class for the token field entry control + + Copyright (C) 2008 Free Software Foundation, Inc. + + Author: Gregory Casamento + Date: 2008 + + This file is part of the GNUstep GUI Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; see the file COPYING.LIB. + If not, see or write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef _GNUstep_H_NSTokenFieldCell +#define _GNUstep_H_NSTokenFieldCell +#import + +#include + +typedef enum _NSTokenStyle +{ + NSDefaultTokenStyle = 0, + NSPlainTextTokenStyle, + NSRoundedTokenStyle +} NSTokenStyle; + + +@interface NSTokenFieldCell : NSTextFieldCell +{ + NSTokenStyle tokenStyle; + NSTimeInterval completionDelay; + NSCharacterSet *tokenizingCharacterSet; +} + +// Style... +- (NSTokenStyle)tokenStyle; +- (void)setTokenStyle:(NSTokenStyle)style; + +// Completion delay... ++ (NSTimeInterval)defaultCompletionDelay; +- (NSTimeInterval)completionDelay; +- (void)setCompletionDelay:(NSTimeInterval)delay; + +// Character set... ++ (NSCharacterSet *)defaultTokenizingCharacterSet; +- (void)setTokenizingCharacterSet:(NSCharacterSet *)characterSet; +- (NSCharacterSet *)tokenizingCharacterSet; +@end + +#endif // _GNUstep_H_NSTokenFieldCell diff --git a/Source/GNUmakefile b/Source/GNUmakefile index 14fd71d94..09ffd924f 100644 --- a/Source/GNUmakefile +++ b/Source/GNUmakefile @@ -175,6 +175,8 @@ NSTextTable.m \ NSTextTableBlock.m \ NSToolbar.m \ NSToolbarItem.m \ +NSTokenField.m \ +NSTokenFieldCell.m \ NSUserDefaultsController.m \ NSView.m \ NSWindow+Toolbar.m \ @@ -365,6 +367,8 @@ NSTextTable.h \ NSTextView.h \ NSToolbar.h \ NSToolbarItem.h \ +NSTokenField.h \ +NSTokenFieldCell.h \ NSUserDefaultsController.h \ NSView.h \ NSWindow.h \ diff --git a/Source/NSDocumentController.m b/Source/NSDocumentController.m index 7431e0e0f..936c97371 100644 --- a/Source/NSDocumentController.m +++ b/Source/NSDocumentController.m @@ -54,6 +54,11 @@ static NSString *NSDOSExtensionsKey = @"NSDOSExtensions"; //static NSString *NSMIMETypesKey = @"NSMIMETypes"; static NSString *NSDocumentClassKey = @"NSDocumentClass"; +static NSString *CFBundleDocumentTypes = @"CFBundleDocumentTypes"; +static NSString *CFBundleTypeExtensions = @"CFBundleTypeExtensions"; +static NSString *CFBundleTypeName = @"CFBundleTypeName"; +static NSString *CFBundleTypeRole = @"CFBundleTypeRole"; + static NSString *NSRecentDocuments = @"NSRecentDocuments"; static NSString *NSDefaultOpenDirectory = @"NSDefaultOpenDirectory"; @@ -73,6 +78,10 @@ static NSDictionary *TypeInfoForName (NSArray *types, NSString *typeName) { return dict; } + else if ([[dict objectForKey: CFBundleTypeName] isEqualToString: typeName]) + { + return dict; + } } return nil; @@ -89,6 +98,10 @@ static NSDictionary *TypeInfoForHumanReadableName (NSArray *types, NSString *typ { return dict; } + else if ([[dict objectForKey: CFBundleTypeName] isEqualToString: typeName]) + { + return dict; + } } return nil; @@ -156,8 +169,9 @@ static NSDictionary *TypeInfoForHumanReadableName (NSArray *types, NSString *typ */ + (BOOL) isDocumentBasedApplication { - return ([[[NSBundle mainBundle] infoDictionary] objectForKey: NSTypesKey]) - ? YES : NO; + return ([[[NSBundle mainBundle] infoDictionary] objectForKey: NSTypesKey] || + [[[NSBundle mainBundle] infoDictionary] objectForKey: CFBundleDocumentTypes]) + ? YES : NO; } /** Initializes the document controller class. The first @@ -169,6 +183,12 @@ static NSDictionary *TypeInfoForHumanReadableName (NSArray *types, NSString *typ NSDictionary *customDict = [[NSBundle mainBundle] infoDictionary]; ASSIGN (_types, [customDict objectForKey: NSTypesKey]); + + if(_types == nil) + { + ASSIGN(_types, [customDict objectForKey: CFBundleDocumentTypes]); + } + _documents = [[NSMutableArray alloc] init]; /* Get list of recent documents */ @@ -344,12 +364,19 @@ static NSDictionary *TypeInfoForHumanReadableName (NSArray *types, NSString *typ - (NSString*) defaultType { + NSString *defaultName = nil; if ([_types count] == 0) { return nil; // raise exception? } - return [(NSDictionary*)[_types objectAtIndex: 0] objectForKey: NSNameKey]; + defaultName = [(NSDictionary*)[_types objectAtIndex: 0] objectForKey: NSNameKey]; + if(defaultName == nil) + { + defaultName = [(NSDictionary*)[_types objectAtIndex: 0] objectForKey: CFBundleTypeName]; + } + + return defaultName; } - (void) addDocument: (NSDocument *)document @@ -577,6 +604,7 @@ static NSDictionary *TypeInfoForHumanReadableName (NSArray *types, NSString *typ NSDictionary *typeInfo = [_types objectAtIndex: i]; [array addObjectsFromArray: [typeInfo objectForKey: NSUnixExtensionsKey]]; [array addObjectsFromArray: [typeInfo objectForKey: NSDOSExtensionsKey]]; + [array addObjectsFromArray: [typeInfo objectForKey: CFBundleTypeExtensions]]; } return array; @@ -943,9 +971,16 @@ static NSDictionary *TypeInfoForHumanReadableName (NSArray *types, NSString *typ if ([[typeInfo objectForKey:NSUnixExtensionsKey] containsObject: fileExtension] || [[typeInfo objectForKey:NSDOSExtensionsKey] + containsObject: fileExtension] || + [[typeInfo objectForKey:CFBundleTypeExtensions] containsObject: fileExtension]) { - return [typeInfo objectForKey: NSNameKey]; + NSString *type = [typeInfo objectForKey: NSNameKey]; + if(type == nil) + { + type = [typeInfo objectForKey: CFBundleTypeName]; + } + return type; } } @@ -1072,12 +1107,23 @@ static NSString *NSViewerRole = @"Viewer"; NSString *className = [typeInfo objectForKey: NSDocumentClassKey]; NSString *role = [typeInfo objectForKey: NSRoleKey]; + // if the standard one isn't filled... check the CF key. + if(role == nil) + { + role = [typeInfo objectForKey: CFBundleTypeRole]; + } + if ([docClassName isEqualToString: className] && (role == nil || [role isEqual: NSEditorRole] || [role isEqual: NSViewerRole])) { - [types addObject: [typeInfo objectForKey: NSNameKey]]; + NSString *name = [typeInfo objectForKey: NSNameKey]; + if(name == nil) + { + name = [typeInfo objectForKey: CFBundleTypeName]; + } + [types addObject: name]; } } @@ -1099,7 +1145,12 @@ static NSString *NSViewerRole = @"Viewer"; if ([docClassName isEqualToString: className] && (role == nil || [role isEqual: NSEditorRole])) { - [types addObject: [typeInfo objectForKey: NSNameKey]]; + NSString *name = [typeInfo objectForKey: NSNameKey]; + if(name == nil) + { + name = [typeInfo objectForKey: CFBundleTypeName]; + } + [types addObject: name]; } } diff --git a/Source/NSTokenField.m b/Source/NSTokenField.m new file mode 100644 index 000000000..78b7540c3 --- /dev/null +++ b/Source/NSTokenField.m @@ -0,0 +1,140 @@ +/** NSTokenField + + + Token field control class for token entry. The default token is ",". + + + Copyright (C) 2008 Free Software Foundation, Inc. + + Author: Gregory Casamento + Date: July 2008 + + This file is part of the GNUstep GUI Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; see the file COPYING.LIB. + If not, see or write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#include "AppKit/NSApplication.h" +#include "AppKit/NSCursor.h" +#include "AppKit/NSGraphics.h" +#include "AppKit/NSTokenField.h" +#include "AppKit/NSTokenFieldCell.h" +#include "AppKit/NSWindow.h" +#include "AppKit/NSKeyValueBinding.h" +#include +#include "GSBindingHelpers.h" + +static NSNotificationCenter *nc = nil; + +/* + * Class variables + */ +static Class usedCellClass; +static Class tokenFieldCellClass; + +@implementation NSTokenField + +// +// Class methods +// ++ (void) initialize +{ + if (self == [NSTokenField class]) + { + [self setVersion: 1]; + tokenFieldCellClass = [NSTokenFieldCell class]; + usedCellClass = tokenFieldCellClass; + nc = [NSNotificationCenter defaultCenter]; + + [self exposeBinding: NSEditableBinding]; + [self exposeBinding: NSTextColorBinding]; + } +} + +- (id) initWithFrame: (NSRect)frame +{ + if((self = [super initWithFrame: frame]) == nil) + { + return nil; + } + + // initialize... + [_cell setTokenStyle: NSDefaultTokenStyle]; + [_cell setCompletionDelay: [_cell defaultCompletionDelay]]; + [_cell setTokenizingCharacterSet: [_cell defaultTokenizingCharacterSet]]; + + return self; +} + +/* + * Setting the Cell class + */ ++ (Class) cellClass +{ + return usedCellClass; +} + ++ (void) setCellClass: (Class)factoryId +{ + usedCellClass = factoryId ? factoryId : tokenFieldCellClass; +} + +// Style... +- (NSTokenStyle)tokenStyle +{ + return [_cell tokenStyle]; +} + +- (void)setTokenStyle:(NSTokenStyle)style +{ + [_cell setTokenStyle: style]; +} + +// Completion delay... ++ (NSTimeInterval)defaultCompletionDelay +{ + return [usedCellClass defaultCompletionDelay]; +} + +- (NSTimeInterval)completionDelay +{ + return [_cell completionDelay]; +} + +- (void)setCompletionDelay:(NSTimeInterval)delay +{ + [_cell setCompletionDelay: delay]; +} + +// Character set... ++ (NSCharacterSet *)defaultTokenizingCharacterSet +{ + return [usedCellClass defaultTokenizingCharacterSet]; +} + +- (void)setTokenizingCharacterSet:(NSCharacterSet *)characterSet +{ + [_cell setTokenizingCharacterSet: characterSet]; +} + +- (NSCharacterSet *)tokenizingCharacterSet +{ + return [_cell tokenizingCharacterSet]; +} +@end diff --git a/Source/NSTokenFieldCell.m b/Source/NSTokenFieldCell.m new file mode 100644 index 000000000..5a3613a25 --- /dev/null +++ b/Source/NSTokenFieldCell.m @@ -0,0 +1,122 @@ +/** NSTokenFieldCell + + Cell class for the token field entry control + + Copyright (C) 2008 Free Software Foundation, Inc. + + Author: Gregory Casamento + Date: July 2008 + This file is part of the GNUstep GUI Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; see the file COPYING.LIB. + If not, see or write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" +#include +#include +#include "AppKit/NSControl.h" +#include "AppKit/NSEvent.h" +#include "AppKit/NSTokenField.h" +#include "AppKit/NSTokenFieldCell.h" + + +@implementation NSTokenFieldCell ++ (void) initialize +{ + if (self == [NSTokenFieldCell class]) + { + [self setVersion: 1]; + } +} + +- (void) dealloc +{ + RELEASE(tokenizingCharacterSet); + [super dealloc]; +} + +// +// NSCoding protocol +// +- (void) encodeWithCoder: (NSCoder*)aCoder +{ + [super encodeWithCoder: aCoder]; + + if ([aCoder allowsKeyedCoding]) + { + } + else + { + } +} + +- (id) initWithCoder: (NSCoder*)aDecoder +{ + self = [super initWithCoder: aDecoder]; + + if ([aDecoder allowsKeyedCoding]) + { + } + else + { + } + + return self; +} +// Style... +- (NSTokenStyle)tokenStyle +{ + return tokenStyle; +} + +- (void)setTokenStyle:(NSTokenStyle)style +{ + tokenStyle = style; +} + +// Completion delay... ++ (NSTimeInterval)defaultCompletionDelay +{ + return 0; +} + +- (NSTimeInterval)completionDelay +{ + return completionDelay; +} + +- (void)setCompletionDelay:(NSTimeInterval)delay +{ + completionDelay = delay; +} + +// Character set... ++ (NSCharacterSet *)defaultTokenizingCharacterSet +{ + return [NSCharacterSet characterSetWithCharactersInString: @","]; +} + +- (void)setTokenizingCharacterSet:(NSCharacterSet *)characterSet +{ + ASSIGN(tokenizingCharacterSet, characterSet); +} + +- (NSCharacterSet *)tokenizingCharacterSet +{ + return tokenizingCharacterSet; +} +@end