mirror of
https://github.com/gnustep/apps-gorm.git
synced 2025-04-22 22:20:44 +00:00
* GormCore/GNUmakefile: Add GormDocumentWindow.[h,m].
* GormCore/GormResourceManager.m: Add code to handle image/sound/header files. * GormCore/GormDocument.[h,m]: Add -viewWithTag: method. * GormCore/GormClassEditor.m: Remove dragging destination code for resources. * GormCore/GormResourceEditor.m: Ditto. * GormCore/GormObjectEditor.m: Ditto. (addObject:): Change the editor to the GormObjectEditor. * GormCore/GormDocument.m: Register the window for dragged types. Implement -viewWithTag:. * GormCore/GormDocumentWindow.[h,m]: New subclass of NSWindow which handles drag and drop to GormResourceManager. * GormCore/GormDocument.gorm: Set the main document window to a GormDocumentWindow class. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@24129 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
d72994d445
commit
8b6d518d07
11 changed files with 307 additions and 261 deletions
18
ChangeLog
18
ChangeLog
|
@ -1,3 +1,21 @@
|
|||
2006-11-18 Matt Rice <ratmice@yahoo.com>
|
||||
|
||||
* GormCore/GNUmakefile: Add GormDocumentWindow.[h,m].
|
||||
* GormCore/GormResourceManager.m: Add code to handle
|
||||
image/sound/header files.
|
||||
* GormCore/GormDocument.[h,m]: Add -viewWithTag: method.
|
||||
* GormCore/GormClassEditor.m: Remove dragging destination code
|
||||
for resources.
|
||||
* GormCore/GormResourceEditor.m: Ditto.
|
||||
* GormCore/GormObjectEditor.m: Ditto.
|
||||
(addObject:): Change the editor to the GormObjectEditor.
|
||||
* GormCore/GormDocument.m: Register the window for dragged types.
|
||||
Implement -viewWithTag:.
|
||||
* GormCore/GormDocumentWindow.[h,m]: New subclass of NSWindow which
|
||||
handles drag and drop to GormResourceManager.
|
||||
* GormCore/GormDocument.gorm: Set the main document window to a
|
||||
GormDocumentWindow class.
|
||||
|
||||
2006-11-15 Nicola Pero <nicola.pero@meta-innovation.com>
|
||||
|
||||
* Documentation/Examples/Controller/GNUmakefile: Do not set
|
||||
|
|
Binary file not shown.
|
@ -48,6 +48,7 @@ GormCore_HEADER_FILES = \
|
|||
GormCustomView.h \
|
||||
GormDocument.h \
|
||||
GormDocumentController.h \
|
||||
GormDocumentWindow.h \
|
||||
GormFilePrefsManager.h \
|
||||
GormFilesOwner.h \
|
||||
GormFontViewController.h \
|
||||
|
@ -105,6 +106,7 @@ GormCore_OBJC_FILES = \
|
|||
GormCustomView.m \
|
||||
GormDocument.m \
|
||||
GormDocumentController.m \
|
||||
GormDocumentWindow.m \
|
||||
GormFilePrefsManager.m \
|
||||
GormFilesOwner.m \
|
||||
GormFontViewController.m \
|
||||
|
|
|
@ -180,10 +180,6 @@ NSImage *browserImage = nil;
|
|||
|
||||
// switch...
|
||||
[self switchViewToDefault];
|
||||
|
||||
// register for types...
|
||||
[IBResourceManager registerForAllPboardTypes: self
|
||||
inDocument: document];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -729,105 +725,6 @@ NSImage *browserImage = nil;
|
|||
// no image.
|
||||
}
|
||||
|
||||
- (unsigned) draggingEntered: (id<NSDraggingInfo>)sender
|
||||
{
|
||||
NSPasteboard *pb = [sender draggingPasteboard];
|
||||
NSArray *pbTypes = [pb types];
|
||||
unsigned int oper = NSDragOperationNone;
|
||||
NSString *ext = nil;
|
||||
|
||||
// Get the resource manager first, if nil don't bother calling the rest...
|
||||
if([pbTypes containsObject: NSFilenamesPboardType] == YES)
|
||||
{
|
||||
NSArray *types = [self fileTypes];
|
||||
NSArray *data = [pb propertyListForType: NSFilenamesPboardType];
|
||||
NSString *fileName = nil;
|
||||
NSEnumerator *en = [data objectEnumerator];
|
||||
|
||||
while((fileName = [en nextObject]) != nil)
|
||||
{
|
||||
ext = [fileName pathExtension];
|
||||
if([types containsObject: ext])
|
||||
{
|
||||
oper = NSDragOperationCopy;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
oper = NSDragOperationNone;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(oper == NSDragOperationNone)
|
||||
{
|
||||
[(GormDocument *)document changeToTopLevelEditorAcceptingTypes: pbTypes
|
||||
andFileType: ext];
|
||||
}
|
||||
|
||||
return oper;
|
||||
}
|
||||
|
||||
- (unsigned) draggingUpdate: (id<NSDraggingInfo>)sender
|
||||
{
|
||||
return [self draggingEntered: sender];
|
||||
}
|
||||
|
||||
- (BOOL) performDragOperation: (id<NSDraggingInfo>)sender
|
||||
{
|
||||
NSPasteboard *pb = [sender draggingPasteboard];
|
||||
NSArray *types = [pb types];
|
||||
|
||||
if ([types containsObject: NSFilenamesPboardType])
|
||||
{
|
||||
NSArray *data;
|
||||
NSEnumerator *en = nil;
|
||||
NSString *fileName = nil;
|
||||
|
||||
data = [pb propertyListForType: NSFilenamesPboardType];
|
||||
if(data != nil)
|
||||
{
|
||||
en = [data objectEnumerator];
|
||||
while((fileName = [en nextObject]) != nil)
|
||||
{
|
||||
NS_DURING
|
||||
{
|
||||
if(![classManager parseHeader: fileName])
|
||||
{
|
||||
NSString *file = [fileName lastPathComponent];
|
||||
NSString *message = [NSString stringWithFormat:
|
||||
_(@"Unable to parse class in %@"),file];
|
||||
NSRunAlertPanel(_(@"Problem parsing class"),
|
||||
message,
|
||||
nil, nil, nil);
|
||||
}
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
NSString *message = [localException reason];
|
||||
NSRunAlertPanel(_(@"Problem parsing class"),
|
||||
message,
|
||||
nil, nil, nil);
|
||||
}
|
||||
NS_ENDHANDLER;
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL) prepareForDragOperation: (id<NSDraggingInfo>)sender
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
// IBEditor protocol
|
||||
|
||||
- (BOOL) acceptsTypeFromArray: (NSArray*)types
|
||||
|
|
|
@ -191,6 +191,12 @@
|
|||
*/
|
||||
- (void) changeToViewWithTag: (int)tag;
|
||||
|
||||
/**
|
||||
* returns the view using the specified tag.
|
||||
* They are 0=objects, 1=images, 2=sounds, 3=classes, 4=file prefs.
|
||||
*/
|
||||
- (NSView *)viewWithTag:(int)tag;
|
||||
|
||||
/**
|
||||
* Returns all pasteboard types registered for with the IBResourceManager.
|
||||
*/
|
||||
|
|
|
@ -333,7 +333,10 @@ static NSImage *fileImage = nil;
|
|||
|
||||
// get the window and cache it...
|
||||
window = [self _docWindow];
|
||||
|
||||
[IBResourceManager registerForAllPboardTypes:window
|
||||
inDocument:self];
|
||||
[window setDocument:self];
|
||||
|
||||
// set up the toolbar...
|
||||
toolbar = [(NSToolbar *)[NSToolbar alloc] initWithIdentifier: @"GormToolbar"];
|
||||
[toolbar setAllowsUserCustomization: NO];
|
||||
|
@ -924,6 +927,25 @@ static NSImage *fileImage = nil;
|
|||
}
|
||||
}
|
||||
|
||||
- (NSView *) viewWithTag:(int)tag
|
||||
{
|
||||
switch (tag)
|
||||
{
|
||||
case 0: // objects
|
||||
return objectsView;
|
||||
case 1: // images
|
||||
return imagesView;
|
||||
case 2: // sounds
|
||||
return soundsView;
|
||||
case 3: // classes
|
||||
return classesView;
|
||||
case 4: // file prefs
|
||||
return filePrefsView;
|
||||
default:
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void) changeToTopLevelEditorAcceptingTypes: (NSArray *)types
|
||||
andFileType: (NSString *)fileType
|
||||
{
|
||||
|
@ -1727,6 +1749,8 @@ static NSImage *fileImage = nil;
|
|||
Class cls = [aNotification object];
|
||||
id mgr = [(IBResourceManager *)[cls alloc] initWithDocument: self];
|
||||
[resourceManagers addObject: mgr];
|
||||
[IBResourceManager registerForAllPboardTypes:window
|
||||
inDocument:self];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
14
GormCore/GormDocumentWindow.h
Normal file
14
GormCore/GormDocumentWindow.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#ifndef __INCLUDED_GormDocumentWindow_h
|
||||
#include <AppKit/NSWindow.h>
|
||||
#include <GormLib/IBResourceManager.h>
|
||||
|
||||
@interface GormDocumentWindow : NSWindow
|
||||
{
|
||||
id _document;
|
||||
IBResourceManager *dragMgr;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#define __INCLUDED_GormDocumentWindow_h
|
||||
#endif
|
76
GormCore/GormDocumentWindow.m
Normal file
76
GormCore/GormDocumentWindow.m
Normal file
|
@ -0,0 +1,76 @@
|
|||
#include "GormDocumentWindow.h"
|
||||
#include "GormPrivate.h"
|
||||
|
||||
#include <GormLib/IBResourceManager.h>
|
||||
#include <AppKit/NSDragging.h>
|
||||
#include <AppKit/NSPasteboard.h>
|
||||
|
||||
@implementation GormDocumentWindow
|
||||
- (void) setDocument:(id)document
|
||||
{
|
||||
_document = document;
|
||||
}
|
||||
|
||||
|
||||
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender;
|
||||
{
|
||||
NSPasteboard *pb = [sender draggingPasteboard];
|
||||
unsigned int mask = [sender draggingSourceOperationMask];
|
||||
unsigned int oper = NSDragOperationNone;
|
||||
dragMgr = [_document resourceManagerForPasteboard:pb];
|
||||
|
||||
if (dragMgr)
|
||||
{
|
||||
if (mask & NSDragOperationCopy)
|
||||
{
|
||||
oper = NSDragOperationCopy;
|
||||
}
|
||||
else if (mask & NSDragOperationLink)
|
||||
{
|
||||
oper = NSDragOperationLink;
|
||||
}
|
||||
else if (mask & NSDragOperationMove)
|
||||
{
|
||||
oper = NSDragOperationMove;
|
||||
}
|
||||
else if (mask & NSDragOperationGeneric)
|
||||
{
|
||||
oper = NSDragOperationGeneric;
|
||||
}
|
||||
else if (mask & NSDragOperationPrivate)
|
||||
{
|
||||
oper = NSDragOperationPrivate;
|
||||
}
|
||||
}
|
||||
|
||||
return oper;
|
||||
}
|
||||
|
||||
- (void)draggingExited:(id <NSDraggingInfo>)sender;
|
||||
{
|
||||
dragMgr = nil;
|
||||
}
|
||||
|
||||
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender;
|
||||
{
|
||||
return !(dragMgr == nil);
|
||||
}
|
||||
|
||||
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender;
|
||||
{
|
||||
[dragMgr addResourcesFromPasteboard:[sender draggingPasteboard]];
|
||||
return !(dragMgr == nil);
|
||||
}
|
||||
|
||||
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender;
|
||||
{
|
||||
dragMgr = nil;
|
||||
}
|
||||
|
||||
- (void)draggingEnded: (id <NSDraggingInfo>)sender;
|
||||
{
|
||||
dragMgr = nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -227,38 +227,15 @@ static NSMapTable *docMap = 0;
|
|||
- (unsigned) draggingEntered: (id<NSDraggingInfo>)sender
|
||||
{
|
||||
NSArray *pbTypes = nil;
|
||||
NSString *type = nil;
|
||||
NSArray *mgrTypes = nil;
|
||||
|
||||
// Get the resource manager first, if nil don't bother calling the rest...
|
||||
dragPb = [sender draggingPasteboard];
|
||||
pbTypes = [dragPb types];
|
||||
resourceManager = [(GormDocument *)document resourceManagerForPasteboard: dragPb];
|
||||
|
||||
if(resourceManager != nil)
|
||||
{
|
||||
mgrTypes = [resourceManager resourcePasteboardTypes];
|
||||
type = [mgrTypes firstObjectCommonWithArray: pbTypes];
|
||||
}
|
||||
|
||||
if (type != nil)
|
||||
{
|
||||
dragType = type;
|
||||
}
|
||||
else if ([pbTypes containsObject: GormLinkPboardType] == YES)
|
||||
|
||||
if ([pbTypes containsObject: GormLinkPboardType] == YES)
|
||||
{
|
||||
dragType = GormLinkPboardType;
|
||||
}
|
||||
else if ([pbTypes containsObject: NSFilenamesPboardType] == YES)
|
||||
{
|
||||
NSArray *data = [dragPb propertyListForType: NSFilenamesPboardType];
|
||||
NSString *fileName = [data objectAtIndex: 0];
|
||||
NSString *ext = [fileName pathExtension];
|
||||
|
||||
[(GormDocument *)document changeToTopLevelEditorAcceptingTypes: pbTypes
|
||||
andFileType: ext];
|
||||
dragType = nil;
|
||||
}
|
||||
else
|
||||
{
|
||||
dragType = nil;
|
||||
|
@ -269,11 +246,7 @@ static NSMapTable *docMap = 0;
|
|||
|
||||
- (unsigned) draggingUpdated: (id<NSDraggingInfo>)sender
|
||||
{
|
||||
if ([[resourceManager resourcePasteboardTypes] containsObject: dragType])
|
||||
{
|
||||
return NSDragOperationCopy;
|
||||
}
|
||||
else if (dragType == GormLinkPboardType)
|
||||
if (dragType == GormLinkPboardType)
|
||||
{
|
||||
NSPoint loc = [sender draggingLocation];
|
||||
int r, c;
|
||||
|
@ -322,11 +295,6 @@ static NSMapTable *docMap = 0;
|
|||
NSDebugLog(@"Recieved notification");
|
||||
[self setCellSize: defaultCellSize()];
|
||||
}
|
||||
else if([name isEqual: IBResourceManagerRegistryDidChangeNotification])
|
||||
{
|
||||
[IBResourceManager registerForAllPboardTypes: self
|
||||
inDocument: document];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -350,10 +318,8 @@ static NSMapTable *docMap = 0;
|
|||
NSButtonCell *proto;
|
||||
|
||||
document = aDocument;
|
||||
|
||||
[IBResourceManager registerForAllPboardTypes: self
|
||||
inDocument: document];
|
||||
|
||||
|
||||
[self registerForDraggedTypes:[NSArray arrayWithObject:GormLinkPboardType]];
|
||||
[self setAutosizesCells: NO];
|
||||
[self setCellSize: defaultCellSize()];
|
||||
[self setIntercellSpacing: NSMakeSize(8,8)];
|
||||
|
@ -470,12 +436,7 @@ static NSMapTable *docMap = 0;
|
|||
|
||||
- (BOOL) performDragOperation: (id<NSDraggingInfo>)sender
|
||||
{
|
||||
if ([[resourceManager resourcePasteboardTypes] containsObject: dragType])
|
||||
{
|
||||
[resourceManager addResourcesFromPasteboard: dragPb];
|
||||
return YES;
|
||||
}
|
||||
else if (dragType == GormLinkPboardType)
|
||||
if (dragType == GormLinkPboardType)
|
||||
{
|
||||
NSPoint loc = [sender draggingLocation];
|
||||
int r, c;
|
||||
|
@ -512,14 +473,7 @@ static NSMapTable *docMap = 0;
|
|||
/*
|
||||
* Tell the source that we will accept the drop if we can.
|
||||
*/
|
||||
if ([[resourceManager resourcePasteboardTypes] containsObject: dragType])
|
||||
{
|
||||
/*
|
||||
* We can accept objects dropped anywhere.
|
||||
*/
|
||||
return YES;
|
||||
}
|
||||
else if (dragType == GormLinkPboardType)
|
||||
if (dragType == GormLinkPboardType)
|
||||
{
|
||||
NSPoint loc = [sender draggingLocation];
|
||||
int r, c;
|
||||
|
@ -570,6 +524,15 @@ static NSMapTable *docMap = 0;
|
|||
[mgr setClassInspector];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) addObject:(id)anObject
|
||||
{
|
||||
[super addObject:anObject];
|
||||
/* we need to do this for palettes which can drop top level objects */
|
||||
[(GormDocument *)document changeToViewWithTag:0];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
|
|
@ -32,9 +32,6 @@
|
|||
|
||||
@implementation GormResourceEditor
|
||||
|
||||
// for the resource editors
|
||||
static int handled_mask= NSDragOperationCopy | NSDragOperationGeneric | NSDragOperationPrivate;
|
||||
|
||||
- (BOOL) acceptsTypeFromArray: (NSArray*)types
|
||||
{
|
||||
return [types containsObject: NSFilenamesPboardType];
|
||||
|
@ -57,101 +54,6 @@ static int handled_mask= NSDragOperationCopy | NSDragOperationGeneric | NSDragOp
|
|||
{
|
||||
}
|
||||
|
||||
- (unsigned int) draggingEntered: (id<NSDraggingInfo>)sender
|
||||
{
|
||||
NSPasteboard *pb = [sender draggingPasteboard];
|
||||
NSArray *pbTypes = [pb types];
|
||||
unsigned int mask = [sender draggingSourceOperationMask];
|
||||
unsigned int oper = NSDragOperationNone;
|
||||
NSString *ext = nil;
|
||||
|
||||
if ((mask & handled_mask) && [pbTypes containsObject: NSFilenamesPboardType])
|
||||
{
|
||||
NSArray *data;
|
||||
NSEnumerator *en;
|
||||
NSString *fileName;
|
||||
NSArray *types = [self fileTypes];
|
||||
|
||||
data = [pb propertyListForType: NSFilenamesPboardType];
|
||||
if (!data)
|
||||
{
|
||||
data = [NSUnarchiver unarchiveObjectWithData: [pb dataForType: NSFilenamesPboardType]];
|
||||
}
|
||||
|
||||
en = [data objectEnumerator];
|
||||
while((fileName = (NSString *)[en nextObject]) != nil)
|
||||
{
|
||||
ext = [fileName pathExtension];
|
||||
if([types containsObject: ext] == YES)
|
||||
{
|
||||
oper = NSDragOperationCopy;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
oper = NSDragOperationNone;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(oper == NSDragOperationNone)
|
||||
{
|
||||
[(GormDocument *)document changeToTopLevelEditorAcceptingTypes: pbTypes
|
||||
andFileType: ext];
|
||||
}
|
||||
|
||||
return oper;
|
||||
}
|
||||
|
||||
- (unsigned int) draggingUpdated: (id<NSDraggingInfo>)sender
|
||||
{
|
||||
return [self draggingEntered: sender];
|
||||
}
|
||||
|
||||
- (BOOL) performDragOperation: (id<NSDraggingInfo>)sender
|
||||
{
|
||||
NSPasteboard *pb = [sender draggingPasteboard];
|
||||
NSArray *types = [pb types];
|
||||
unsigned int mask = [sender draggingSourceOperationMask];
|
||||
|
||||
NSDebugLLog(@"dragndrop",@"performDrag %x %@",mask,types);
|
||||
|
||||
if (!(mask & handled_mask))
|
||||
return NO;
|
||||
|
||||
if ([types containsObject: NSFilenamesPboardType])
|
||||
{
|
||||
NSArray *data;
|
||||
int i,c;
|
||||
|
||||
data = [pb propertyListForType: NSFilenamesPboardType];
|
||||
if (!data)
|
||||
data = [NSUnarchiver unarchiveObjectWithData: [pb dataForType: NSFilenamesPboardType]];
|
||||
|
||||
c=[data count];
|
||||
for (i=0;i<c;i++)
|
||||
{
|
||||
NSString *fileName = [data objectAtIndex: i];
|
||||
id placeHolder = [self placeHolderWithPath: fileName];
|
||||
|
||||
NSLog(@"====> %@", fileName);
|
||||
if (placeHolder)
|
||||
{
|
||||
NSLog(@"here %@", fileName);
|
||||
[self addObject: placeHolder];
|
||||
}
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL) prepareForDragOperation: (id<NSDraggingInfo>)sender
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (unsigned int) draggingSourceOperationMaskForLocal: (BOOL)flag
|
||||
{
|
||||
return NSDragOperationCopy;
|
||||
|
@ -188,7 +90,7 @@ static int handled_mask= NSDragOperationCopy | NSDragOperationGeneric | NSDragOp
|
|||
}
|
||||
|
||||
/*
|
||||
* Initialisation - register to receive DnD with our own types.
|
||||
* Initialisation
|
||||
*/
|
||||
- (id) initWithObject: (id)anObject inDocument: (id<IBDocuments>)aDocument
|
||||
{
|
||||
|
@ -196,10 +98,6 @@ static int handled_mask= NSDragOperationCopy | NSDragOperationGeneric | NSDragOp
|
|||
{
|
||||
NSButtonCell *proto;
|
||||
|
||||
// register for all types.
|
||||
[IBResourceManager registerForAllPboardTypes: self
|
||||
inDocument: aDocument];
|
||||
|
||||
[self setAutosizesCells: NO];
|
||||
[self setCellSize: NSMakeSize(72,72)];
|
||||
[self setIntercellSpacing: NSMakeSize(8,8)];
|
||||
|
|
|
@ -23,14 +23,162 @@
|
|||
*/
|
||||
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSArchiver.h>
|
||||
#include <AppKit/NSSound.h>
|
||||
#include <AppKit/NSImage.h>
|
||||
#include <AppKit/NSPasteboard.h>
|
||||
#include <InterfaceBuilder/IBPalette.h>
|
||||
|
||||
#include "GormSound.h"
|
||||
#include "GormImage.h"
|
||||
#include "GormClassManager.h"
|
||||
#include "GormResourceManager.h"
|
||||
#include "GormGenericEditor.h"
|
||||
#include "GormDocument.h"
|
||||
#include "GormObjectEditor.h"
|
||||
|
||||
@implementation GormResourceManager
|
||||
|
||||
- (NSArray *) resourcePasteboardTypes
|
||||
{
|
||||
return [NSArray arrayWithObjects: IBWindowPboardType, IBViewPboardType, nil];
|
||||
return [NSArray arrayWithObjects: IBWindowPboardType, IBViewPboardType,
|
||||
NSFilenamesPboardType, GormLinkPboardType,
|
||||
nil];
|
||||
}
|
||||
|
||||
- (BOOL) acceptsResourcesFromPasteboard:(NSPasteboard *)pb
|
||||
{
|
||||
NSArray *types = [pb types];
|
||||
NSArray *acceptedTypes = [self resourcePasteboardTypes];
|
||||
BOOL flag = YES;
|
||||
int i;
|
||||
int c = [types count];
|
||||
|
||||
if (c == 0) return NO;
|
||||
|
||||
flag = ([acceptedTypes firstObjectCommonWithArray:types] != nil);
|
||||
|
||||
for (i = 0; flag && i < c; i++)
|
||||
{
|
||||
id type = [types objectAtIndex:i];
|
||||
|
||||
if ([type isEqual:NSFilenamesPboardType])
|
||||
{
|
||||
NSArray *files = [pb propertyListForType:type];
|
||||
NSArray *acceptedFiles = [self resourceFileTypes];
|
||||
int j, d;
|
||||
|
||||
if (!files)
|
||||
{
|
||||
files = [NSUnarchiver unarchiveObjectWithData:
|
||||
[pb dataForType: NSFilenamesPboardType]];
|
||||
}
|
||||
for (j = 0, d = [files count]; j < d; j++)
|
||||
{
|
||||
NSString *ext = [[files objectAtIndex:j] pathExtension];
|
||||
flag = [acceptedFiles containsObject:ext];
|
||||
}
|
||||
}
|
||||
else if ([type isEqual:GormLinkPboardType])
|
||||
{
|
||||
[(GormDocument *)document changeToViewWithTag:0];
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
- (void) addResourcesFromPasteboard:(NSPasteboard *)pb
|
||||
{
|
||||
NSArray *types = [pb types];
|
||||
NSArray *soundTypes = [NSSound soundUnfilteredFileTypes];
|
||||
NSArray *imageTypes = [NSImage imageFileTypes];
|
||||
int i;
|
||||
int c = [types count];
|
||||
BOOL found = NO;
|
||||
|
||||
for (i = 0; i < c; i++)
|
||||
{
|
||||
id type = [types objectAtIndex:i];
|
||||
|
||||
if ([type isEqual:NSFilenamesPboardType])
|
||||
{
|
||||
int j, d;
|
||||
NSArray *files = [pb propertyListForType:type];
|
||||
found = YES;
|
||||
if (!files)
|
||||
{
|
||||
files = [NSUnarchiver unarchiveObjectWithData:
|
||||
[pb dataForType: NSFilenamesPboardType]];
|
||||
}
|
||||
|
||||
for (j = 0, d = [files count]; j < d; j++)
|
||||
{
|
||||
NSString *file = [files objectAtIndex:j];
|
||||
NSString *ext = [file pathExtension];
|
||||
if ([ext isEqual:@"h"])
|
||||
{
|
||||
GormDocument *doc = document;
|
||||
GormClassManager *classManager = [doc classManager];
|
||||
NS_DURING
|
||||
{
|
||||
if (![classManager parseHeader: file])
|
||||
{
|
||||
NSString *file = [file lastPathComponent];
|
||||
NSString *message;
|
||||
|
||||
message = [NSString stringWithFormat:
|
||||
_(@"Unable to parse class in %@"), file];
|
||||
|
||||
NSRunAlertPanel(_(@"Problem parsing class"),
|
||||
message,
|
||||
nil, nil, nil);
|
||||
}
|
||||
|
||||
[doc changeToViewWithTag:3];
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
NSString *message = [localException reason];
|
||||
NSRunAlertPanel(_(@"Problem parsing class"),
|
||||
message,
|
||||
nil, nil, nil);
|
||||
}
|
||||
NS_ENDHANDLER;
|
||||
}
|
||||
else if ([imageTypes containsObject:ext])
|
||||
{
|
||||
GormDocument *doc = document;
|
||||
[(GormGenericEditor *)[doc viewWithTag:1]
|
||||
addObject:[GormImage imageForPath:file]];
|
||||
[doc changeToViewWithTag:1];
|
||||
}
|
||||
else if ([soundTypes containsObject:ext])
|
||||
{
|
||||
GormDocument *doc = document;
|
||||
[(GormGenericEditor *)[doc viewWithTag:2]
|
||||
addObject:[GormSound soundForPath:file]];
|
||||
[doc changeToViewWithTag:2];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
[super addResourcesFromPasteboard:pb];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSArray *) resourceFileTypes
|
||||
{
|
||||
NSArray *types = [NSSound soundUnfilteredFileTypes];
|
||||
|
||||
types = [types arrayByAddingObjectsFromArray:[NSImage imageFileTypes]];
|
||||
|
||||
types = [types arrayByAddingObject:@"h"];
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in a new issue