mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 20:00:48 +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
aa77a425fa
commit
5046158db9
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>
|
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
|
* KeyBindings/DefaultKeyBindings.dict: Enable Ctrl-l key binding
|
||||||
and add Ctrl-o key binding as in Emacs and Cocoa.
|
and add Ctrl-o key binding as in Emacs and Cocoa.
|
||||||
* Source/NSTextView_actions.m (-insertNewlineIgnoringFieldEditor:,
|
* Source/NSTextView_actions.m (-insertNewlineIgnoringFieldEditor:,
|
||||||
|
|
|
@ -48,14 +48,14 @@
|
||||||
{
|
{
|
||||||
// FIXME: Should allow for filterable types
|
// FIXME: Should allow for filterable types
|
||||||
return [[NSDocumentController sharedDocumentController]
|
return [[NSDocumentController sharedDocumentController]
|
||||||
_editorAndViewerTypesForClass: self];
|
_readableTypesForClass: self];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSArray *) writableTypes
|
+ (NSArray *) writableTypes
|
||||||
{
|
{
|
||||||
// FIXME: Should allow for filterable types
|
// FIXME: Should allow for filterable types
|
||||||
return [[NSDocumentController sharedDocumentController]
|
return [[NSDocumentController sharedDocumentController]
|
||||||
_editorTypesForClass: self];
|
_writableTypesForClass: self];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (BOOL) isNativeType: (NSString *)type
|
+ (BOOL) isNativeType: (NSString *)type
|
||||||
|
@ -1016,10 +1016,9 @@ originalContentsURL: (NSURL *)orig
|
||||||
{
|
{
|
||||||
NSDocumentController *controller =
|
NSDocumentController *controller =
|
||||||
[NSDocumentController sharedDocumentController];
|
[NSDocumentController sharedDocumentController];
|
||||||
NSArray *extensions = nil;
|
NSArray *extensions;
|
||||||
|
|
||||||
ASSIGN(_save_type, [controller _nameForHumanReadableType:
|
ASSIGN(_save_type, [[sender selectedItem] representedObject]);
|
||||||
[sender titleOfSelectedItem]]);
|
|
||||||
extensions = [controller fileExtensionsFromType: _save_type];
|
extensions = [controller fileExtensionsFromType: _save_type];
|
||||||
[(NSSavePanel *)[sender window] setAllowedFileTypes: extensions];
|
[(NSSavePanel *)[sender window] setAllowedFileTypes: extensions];
|
||||||
}
|
}
|
||||||
|
@ -1076,32 +1075,27 @@ originalContentsURL: (NSURL *)orig
|
||||||
|
|
||||||
- (void) _addItemsToSpaButtonFromArray: (NSArray *)types
|
- (void) _addItemsToSpaButtonFromArray: (NSArray *)types
|
||||||
{
|
{
|
||||||
NSEnumerator *en = [types objectEnumerator];
|
NSString *type, *title;
|
||||||
NSString *title = nil;
|
int i, count = [types count];
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
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];
|
[_spa_button addItemWithTitle: title];
|
||||||
i++;
|
[[_spa_button itemAtIndex: i] setRepresentedObject: type];
|
||||||
}
|
}
|
||||||
|
|
||||||
// if it's more than one, then
|
// 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 we have some items, select the current filetype.
|
||||||
if (i > 0)
|
if (count > 0)
|
||||||
{
|
{
|
||||||
NSString *title = [[NSDocumentController sharedDocumentController]
|
[_spa_button selectItemAtIndex:
|
||||||
displayNameForType: [self fileType]];
|
[_spa_button indexOfItemWithRepresentedObject: [self fileType]]];
|
||||||
if ([_spa_button itemWithTitle: title] != nil)
|
|
||||||
{
|
|
||||||
[_spa_button selectItemWithTitle: title];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
[_spa_button selectItemAtIndex: 0];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1110,25 +1104,25 @@ originalContentsURL: (NSURL *)orig
|
||||||
NSView *accessory = nil;
|
NSView *accessory = nil;
|
||||||
NSString *title;
|
NSString *title;
|
||||||
NSString *directory;
|
NSString *directory;
|
||||||
NSArray *displayNames;
|
NSArray *types;
|
||||||
NSDocumentController *controller;
|
NSDocumentController *controller;
|
||||||
NSSavePanel *savePanel = [NSSavePanel savePanel];
|
NSSavePanel *savePanel = [NSSavePanel savePanel];
|
||||||
|
|
||||||
ASSIGN(_save_type, [self fileType]);
|
ASSIGN(_save_type, [self fileType]);
|
||||||
controller = [NSDocumentController sharedDocumentController];
|
controller = [NSDocumentController sharedDocumentController];
|
||||||
displayNames = [controller _displayNamesForClass: [self class]];
|
types = [self writableTypesForSaveOperation: saveOperation];
|
||||||
|
|
||||||
if ([self shouldRunSavePanelWithAccessoryView])
|
if ([self shouldRunSavePanelWithAccessoryView])
|
||||||
{
|
{
|
||||||
if (_save_panel_accessory == nil)
|
if (_save_panel_accessory == nil)
|
||||||
[self _createPanelAccessory];
|
[self _createPanelAccessory];
|
||||||
|
|
||||||
[self _addItemsToSpaButtonFromArray: displayNames];
|
[self _addItemsToSpaButtonFromArray: types];
|
||||||
|
|
||||||
accessory = _save_panel_accessory;
|
accessory = _save_panel_accessory;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([displayNames count] > 0)
|
if ([types count] > 0)
|
||||||
{
|
{
|
||||||
NSArray *extensions = [controller fileExtensionsFromType: [self fileType]];
|
NSArray *extensions = [controller fileExtensionsFromType: [self fileType]];
|
||||||
[savePanel setAllowedFileTypes: extensions];
|
[savePanel setAllowedFileTypes: extensions];
|
||||||
|
|
|
@ -56,6 +56,7 @@ static NSString *NSDOSExtensionsKey = @"NSDOSExtensions";
|
||||||
//static NSString *NSMacOSTypesKey = @"NSMacOSTypes";
|
//static NSString *NSMacOSTypesKey = @"NSMacOSTypes";
|
||||||
//static NSString *NSMIMETypesKey = @"NSMIMETypes";
|
//static NSString *NSMIMETypesKey = @"NSMIMETypes";
|
||||||
static NSString *NSDocumentClassKey = @"NSDocumentClass";
|
static NSString *NSDocumentClassKey = @"NSDocumentClass";
|
||||||
|
static NSString *NSExportableAsKey = @"NSExportableAs";
|
||||||
|
|
||||||
static NSString *CFBundleDocumentTypes = @"CFBundleDocumentTypes";
|
static NSString *CFBundleDocumentTypes = @"CFBundleDocumentTypes";
|
||||||
static NSString *CFBundleTypeExtensions = @"CFBundleTypeExtensions";
|
static NSString *CFBundleTypeExtensions = @"CFBundleTypeExtensions";
|
||||||
|
@ -196,19 +197,21 @@ TypeInfoForHumanReadableName (NSArray *types, NSString *typeName)
|
||||||
if (YES == [types isKindOfClass: [NSArray class]])
|
if (YES == [types isKindOfClass: [NSArray class]])
|
||||||
{
|
{
|
||||||
unsigned count = [types count];
|
unsigned count = [types count];
|
||||||
unsigned src;
|
unsigned i;
|
||||||
unsigned dst = 0;
|
unsigned nNames = 0;
|
||||||
|
unsigned nValid = 0;
|
||||||
NSString *names[count];
|
NSString *names[count];
|
||||||
NSDictionary *valid[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]])
|
if (YES == [d isKindOfClass: [NSDictionary class]])
|
||||||
{
|
{
|
||||||
NSString *name = [d objectForKey: NSDocumentClassKey];
|
NSString *name = [d objectForKey: NSDocumentClassKey];
|
||||||
|
|
||||||
|
valid[nValid++] = d;
|
||||||
/* Is this type handled by an NSDocument subclass?
|
/* Is this type handled by an NSDocument subclass?
|
||||||
*/
|
*/
|
||||||
if (YES == [name isKindOfClass: [NSString class]])
|
if (YES == [name isKindOfClass: [NSString class]])
|
||||||
|
@ -217,8 +220,7 @@ TypeInfoForHumanReadableName (NSArray *types, NSString *typeName)
|
||||||
|
|
||||||
if (YES == [c isSubclassOfClass: [NSDocument class]])
|
if (YES == [c isSubclassOfClass: [NSDocument class]])
|
||||||
{
|
{
|
||||||
names[dst] = name;
|
names[nNames++] = name;
|
||||||
valid[dst++] = d;
|
|
||||||
}
|
}
|
||||||
else if (c == 0)
|
else if (c == 0)
|
||||||
{
|
{
|
||||||
|
@ -234,13 +236,17 @@ TypeInfoForHumanReadableName (NSArray *types, NSString *typeName)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NSLog(@"Bad item at index %u in %@",
|
NSLog(@"Bad item at index %u in %@",
|
||||||
src, CFBundleDocumentTypes);
|
i, CFBundleDocumentTypes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (dst > 0)
|
if (nNames > 0)
|
||||||
{
|
{
|
||||||
classNames = [[NSArray alloc] initWithObjects: names count: dst];
|
classNames = [[NSArray alloc] initWithObjects: names
|
||||||
allTypes = [[NSArray alloc] initWithObjects: valid count: dst];
|
count: nNames];
|
||||||
|
}
|
||||||
|
if (nValid > 0)
|
||||||
|
{
|
||||||
|
allTypes = [[NSArray alloc] initWithObjects: valid count: nValid];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1346,7 +1352,7 @@ static BOOL _shouldClose = YES;
|
||||||
|
|
||||||
@implementation NSDocumentController (Private)
|
@implementation NSDocumentController (Private)
|
||||||
|
|
||||||
- (NSArray *) _editorAndViewerTypesForClass: (Class)documentClass
|
- (NSArray *) _readableTypesForClass: (Class)documentClass
|
||||||
{
|
{
|
||||||
int i, count = [_types count];
|
int i, count = [_types count];
|
||||||
NSMutableArray *types = [NSMutableArray arrayWithCapacity: count];
|
NSMutableArray *types = [NSMutableArray arrayWithCapacity: count];
|
||||||
|
@ -1382,7 +1388,7 @@ static BOOL _shouldClose = YES;
|
||||||
return types;
|
return types;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray *) _editorTypesForClass: (Class)documentClass
|
- (NSArray *) _writableTypesForClass: (Class)documentClass
|
||||||
{
|
{
|
||||||
int i, count = [_types count];
|
int i, count = [_types count];
|
||||||
NSMutableArray *types = [NSMutableArray arrayWithCapacity: count];
|
NSMutableArray *types = [NSMutableArray arrayWithCapacity: count];
|
||||||
|
@ -1393,6 +1399,7 @@ static BOOL _shouldClose = YES;
|
||||||
NSDictionary *typeInfo = [_types objectAtIndex: i];
|
NSDictionary *typeInfo = [_types objectAtIndex: i];
|
||||||
NSString *className = [typeInfo objectForKey: NSDocumentClassKey];
|
NSString *className = [typeInfo objectForKey: NSDocumentClassKey];
|
||||||
NSString *role = [typeInfo objectForKey: NSRoleKey];
|
NSString *role = [typeInfo objectForKey: NSRoleKey];
|
||||||
|
NSArray *exportableAs = [typeInfo objectForKey: NSExportableAsKey];
|
||||||
|
|
||||||
// if the standard one isn't filled... check the CF key.
|
// if the standard one isn't filled... check the CF key.
|
||||||
if (role == nil)
|
if (role == nil)
|
||||||
|
@ -1411,48 +1418,24 @@ static BOOL _shouldClose = YES;
|
||||||
}
|
}
|
||||||
[types addObject: name];
|
[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;
|
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 NSMapTable *autosavedDocuments = NULL;
|
||||||
static NSString *processName = nil;
|
static NSString *processName = nil;
|
||||||
|
|
||||||
|
|
|
@ -35,12 +35,8 @@
|
||||||
@class NSTimer;
|
@class NSTimer;
|
||||||
|
|
||||||
@interface NSDocumentController (Private)
|
@interface NSDocumentController (Private)
|
||||||
- (NSArray *)_editorAndViewerTypesForClass:(Class)documentClass;
|
- (NSArray *)_readableTypesForClass:(Class)documentClass;
|
||||||
- (NSArray *)_editorTypesForClass:(Class)fp12;
|
- (NSArray *)_writableTypesForClass:(Class)documentClass;
|
||||||
- (NSArray *)_exportableTypesForClass:(Class)documentClass;
|
|
||||||
- (NSString *)_nameForHumanReadableType: (NSString *)type;
|
|
||||||
- (NSArray *)_displayNamesForTypes: (NSArray *)types;
|
|
||||||
- (NSArray *)_displayNamesForClass: (Class)documentClass;
|
|
||||||
- (NSString *)_autosaveDirectory: (BOOL)create;
|
- (NSString *)_autosaveDirectory: (BOOL)create;
|
||||||
- (void)_autosaveDocuments: (NSTimer *)timer;
|
- (void)_autosaveDocuments: (NSTimer *)timer;
|
||||||
- (BOOL)_reopenAutosavedDocuments;
|
- (BOOL)_reopenAutosavedDocuments;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue