mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 07:00:46 +00:00
Implement code for exportable, i.e., write-only, document types.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@28962 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
1e913741b4
commit
c7fee635d0
4 changed files with 66 additions and 82 deletions
11
ChangeLog
11
ChangeLog
|
@ -1,5 +1,16 @@
|
|||
2009-11-05 Wolfgang Lux <wolfgang.lux@gmail.com>
|
||||
|
||||
* Source/NSDocumentController.m (+initialize): Don't ignore types
|
||||
without an associated document class.
|
||||
* Source/NSDocument.m (+reaableTypes, +writableTypes):
|
||||
* Source/NSDocumentController.m(-_readableTypesForClass:,
|
||||
-_writableTypesForClass:): Add the exportable types to the
|
||||
writable types. Rename private NSDocumentController methods.
|
||||
* Source/NSDocument.m (-_addItemsToSpaButtonFromArray,
|
||||
-changeSaveType, _runSavePanelForSaveOperation): Save panel
|
||||
accessory pop up now allows the user to select one of the
|
||||
exportable types for NSSaveToOperation.
|
||||
|
||||
* KeyBindings/DefaultKeyBindings.dict: Enable Ctrl-l key binding
|
||||
and add Ctrl-o key binding as in Emacs and Cocoa.
|
||||
* Source/NSTextView_actions.m (-insertNewlineIgnoringFieldEditor:,
|
||||
|
|
|
@ -48,14 +48,14 @@
|
|||
{
|
||||
// FIXME: Should allow for filterable types
|
||||
return [[NSDocumentController sharedDocumentController]
|
||||
_editorAndViewerTypesForClass: self];
|
||||
_readableTypesForClass: self];
|
||||
}
|
||||
|
||||
+ (NSArray *) writableTypes
|
||||
{
|
||||
// FIXME: Should allow for filterable types
|
||||
return [[NSDocumentController sharedDocumentController]
|
||||
_editorTypesForClass: self];
|
||||
_writableTypesForClass: self];
|
||||
}
|
||||
|
||||
+ (BOOL) isNativeType: (NSString *)type
|
||||
|
@ -1016,10 +1016,9 @@ originalContentsURL: (NSURL *)orig
|
|||
{
|
||||
NSDocumentController *controller =
|
||||
[NSDocumentController sharedDocumentController];
|
||||
NSArray *extensions = nil;
|
||||
NSArray *extensions;
|
||||
|
||||
ASSIGN(_save_type, [controller _nameForHumanReadableType:
|
||||
[sender titleOfSelectedItem]]);
|
||||
ASSIGN(_save_type, [[sender selectedItem] representedObject]);
|
||||
extensions = [controller fileExtensionsFromType: _save_type];
|
||||
[(NSSavePanel *)[sender window] setAllowedFileTypes: extensions];
|
||||
}
|
||||
|
@ -1076,32 +1075,27 @@ originalContentsURL: (NSURL *)orig
|
|||
|
||||
- (void) _addItemsToSpaButtonFromArray: (NSArray *)types
|
||||
{
|
||||
NSEnumerator *en = [types objectEnumerator];
|
||||
NSString *title = nil;
|
||||
int i = 0;
|
||||
NSString *type, *title;
|
||||
int i, count = [types count];
|
||||
|
||||
while ((title = [en nextObject]) != nil)
|
||||
[_spa_button removeAllItems];
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
type = [types objectAtIndex: i];
|
||||
title = [[NSDocumentController sharedDocumentController]
|
||||
displayNameForType: type];
|
||||
[_spa_button addItemWithTitle: title];
|
||||
i++;
|
||||
[[_spa_button itemAtIndex: i] setRepresentedObject: type];
|
||||
}
|
||||
|
||||
// if it's more than one, then
|
||||
[_spa_button setEnabled: (i > 0)];
|
||||
[_spa_button setEnabled: (count > 0)];
|
||||
|
||||
// if we have some items, select the current filetype.
|
||||
if (i > 0)
|
||||
if (count > 0)
|
||||
{
|
||||
NSString *title = [[NSDocumentController sharedDocumentController]
|
||||
displayNameForType: [self fileType]];
|
||||
if ([_spa_button itemWithTitle: title] != nil)
|
||||
{
|
||||
[_spa_button selectItemWithTitle: title];
|
||||
}
|
||||
else
|
||||
{
|
||||
[_spa_button selectItemAtIndex: 0];
|
||||
}
|
||||
[_spa_button selectItemAtIndex:
|
||||
[_spa_button indexOfItemWithRepresentedObject: [self fileType]]];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1110,25 +1104,25 @@ originalContentsURL: (NSURL *)orig
|
|||
NSView *accessory = nil;
|
||||
NSString *title;
|
||||
NSString *directory;
|
||||
NSArray *displayNames;
|
||||
NSArray *types;
|
||||
NSDocumentController *controller;
|
||||
NSSavePanel *savePanel = [NSSavePanel savePanel];
|
||||
|
||||
ASSIGN(_save_type, [self fileType]);
|
||||
controller = [NSDocumentController sharedDocumentController];
|
||||
displayNames = [controller _displayNamesForClass: [self class]];
|
||||
|
||||
types = [self writableTypesForSaveOperation: saveOperation];
|
||||
|
||||
if ([self shouldRunSavePanelWithAccessoryView])
|
||||
{
|
||||
if (_save_panel_accessory == nil)
|
||||
[self _createPanelAccessory];
|
||||
|
||||
[self _addItemsToSpaButtonFromArray: displayNames];
|
||||
[self _addItemsToSpaButtonFromArray: types];
|
||||
|
||||
accessory = _save_panel_accessory;
|
||||
}
|
||||
|
||||
if ([displayNames count] > 0)
|
||||
if ([types count] > 0)
|
||||
{
|
||||
NSArray *extensions = [controller fileExtensionsFromType: [self fileType]];
|
||||
[savePanel setAllowedFileTypes: extensions];
|
||||
|
|
|
@ -56,6 +56,7 @@ static NSString *NSDOSExtensionsKey = @"NSDOSExtensions";
|
|||
//static NSString *NSMacOSTypesKey = @"NSMacOSTypes";
|
||||
//static NSString *NSMIMETypesKey = @"NSMIMETypes";
|
||||
static NSString *NSDocumentClassKey = @"NSDocumentClass";
|
||||
static NSString *NSExportableAsKey = @"NSExportableAs";
|
||||
|
||||
static NSString *CFBundleDocumentTypes = @"CFBundleDocumentTypes";
|
||||
static NSString *CFBundleTypeExtensions = @"CFBundleTypeExtensions";
|
||||
|
@ -196,19 +197,21 @@ TypeInfoForHumanReadableName (NSArray *types, NSString *typeName)
|
|||
if (YES == [types isKindOfClass: [NSArray class]])
|
||||
{
|
||||
unsigned count = [types count];
|
||||
unsigned src;
|
||||
unsigned dst = 0;
|
||||
unsigned i;
|
||||
unsigned nNames = 0;
|
||||
unsigned nValid = 0;
|
||||
NSString *names[count];
|
||||
NSDictionary *valid[count];
|
||||
|
||||
for (src = 0; src < count; src++)
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
NSDictionary *d = [types objectAtIndex: src];
|
||||
NSDictionary *d = [types objectAtIndex: i];
|
||||
|
||||
if (YES == [d isKindOfClass: [NSDictionary class]])
|
||||
{
|
||||
NSString *name = [d objectForKey: NSDocumentClassKey];
|
||||
|
||||
valid[nValid++] = d;
|
||||
/* Is this type handled by an NSDocument subclass?
|
||||
*/
|
||||
if (YES == [name isKindOfClass: [NSString class]])
|
||||
|
@ -217,8 +220,7 @@ TypeInfoForHumanReadableName (NSArray *types, NSString *typeName)
|
|||
|
||||
if (YES == [c isSubclassOfClass: [NSDocument class]])
|
||||
{
|
||||
names[dst] = name;
|
||||
valid[dst++] = d;
|
||||
names[nNames++] = name;
|
||||
}
|
||||
else if (c == 0)
|
||||
{
|
||||
|
@ -234,13 +236,17 @@ TypeInfoForHumanReadableName (NSArray *types, NSString *typeName)
|
|||
else
|
||||
{
|
||||
NSLog(@"Bad item at index %u in %@",
|
||||
src, CFBundleDocumentTypes);
|
||||
i, CFBundleDocumentTypes);
|
||||
}
|
||||
}
|
||||
if (dst > 0)
|
||||
if (nNames > 0)
|
||||
{
|
||||
classNames = [[NSArray alloc] initWithObjects: names count: dst];
|
||||
allTypes = [[NSArray alloc] initWithObjects: valid count: dst];
|
||||
classNames = [[NSArray alloc] initWithObjects: names
|
||||
count: nNames];
|
||||
}
|
||||
if (nValid > 0)
|
||||
{
|
||||
allTypes = [[NSArray alloc] initWithObjects: valid count: nValid];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1346,7 +1352,7 @@ static BOOL _shouldClose = YES;
|
|||
|
||||
@implementation NSDocumentController (Private)
|
||||
|
||||
- (NSArray *) _editorAndViewerTypesForClass: (Class)documentClass
|
||||
- (NSArray *) _readableTypesForClass: (Class)documentClass
|
||||
{
|
||||
int i, count = [_types count];
|
||||
NSMutableArray *types = [NSMutableArray arrayWithCapacity: count];
|
||||
|
@ -1382,7 +1388,7 @@ static BOOL _shouldClose = YES;
|
|||
return types;
|
||||
}
|
||||
|
||||
- (NSArray *) _editorTypesForClass: (Class)documentClass
|
||||
- (NSArray *) _writableTypesForClass: (Class)documentClass
|
||||
{
|
||||
int i, count = [_types count];
|
||||
NSMutableArray *types = [NSMutableArray arrayWithCapacity: count];
|
||||
|
@ -1393,6 +1399,7 @@ static BOOL _shouldClose = YES;
|
|||
NSDictionary *typeInfo = [_types objectAtIndex: i];
|
||||
NSString *className = [typeInfo objectForKey: NSDocumentClassKey];
|
||||
NSString *role = [typeInfo objectForKey: NSRoleKey];
|
||||
NSArray *exportableAs = [typeInfo objectForKey: NSExportableAsKey];
|
||||
|
||||
// if the standard one isn't filled... check the CF key.
|
||||
if (role == nil)
|
||||
|
@ -1411,48 +1418,24 @@ static BOOL _shouldClose = YES;
|
|||
}
|
||||
[types addObject: name];
|
||||
}
|
||||
|
||||
if ([exportableAs isKindOfClass: [NSArray class]])
|
||||
{
|
||||
int i, count = [exportableAs count];
|
||||
NSString *name;
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
name = [exportableAs objectAtIndex: i];
|
||||
if ([name isKindOfClass: [NSString class]])
|
||||
[types addObject: name];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
- (NSArray *) _exportableTypesForClass: (Class)documentClass
|
||||
{
|
||||
// Dunno what this method is for; maybe looks for filter types
|
||||
return [self _editorTypesForClass: documentClass];
|
||||
}
|
||||
|
||||
- (NSString *) _nameForHumanReadableType: (NSString *)typeHR
|
||||
{
|
||||
NSDictionary *typeInfo = HR_TYPE_INFO(typeHR);
|
||||
NSString *type = [typeInfo objectForKey: NSNameKey];
|
||||
|
||||
if (type == nil)
|
||||
{
|
||||
type = [typeInfo objectForKey: CFBundleTypeName];
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
- (NSArray *) _displayNamesForTypes: (NSArray *)types
|
||||
{
|
||||
NSEnumerator *en = [types objectEnumerator];
|
||||
NSString *type = nil;
|
||||
NSMutableArray *result = [NSMutableArray arrayWithCapacity: 10];
|
||||
while ((type = (NSString *)[en nextObject]) != nil)
|
||||
{
|
||||
NSString *name = [self displayNameForType: type];
|
||||
[result addObject: name];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
- (NSArray *) _displayNamesForClass: (Class)documentClass
|
||||
{
|
||||
return [self _displayNamesForTypes:
|
||||
[self _editorTypesForClass: documentClass]];
|
||||
}
|
||||
|
||||
static NSMapTable *autosavedDocuments = NULL;
|
||||
static NSString *processName = nil;
|
||||
|
||||
|
|
|
@ -35,12 +35,8 @@
|
|||
@class NSTimer;
|
||||
|
||||
@interface NSDocumentController (Private)
|
||||
- (NSArray *)_editorAndViewerTypesForClass:(Class)documentClass;
|
||||
- (NSArray *)_editorTypesForClass:(Class)fp12;
|
||||
- (NSArray *)_exportableTypesForClass:(Class)documentClass;
|
||||
- (NSString *)_nameForHumanReadableType: (NSString *)type;
|
||||
- (NSArray *)_displayNamesForTypes: (NSArray *)types;
|
||||
- (NSArray *)_displayNamesForClass: (Class)documentClass;
|
||||
- (NSArray *)_readableTypesForClass:(Class)documentClass;
|
||||
- (NSArray *)_writableTypesForClass:(Class)documentClass;
|
||||
- (NSString *)_autosaveDirectory: (BOOL)create;
|
||||
- (void)_autosaveDocuments: (NSTimer *)timer;
|
||||
- (BOOL)_reopenAutosavedDocuments;
|
||||
|
|
Loading…
Reference in a new issue