Problem Displaying a Sheet During Drag-and-Drop
Problem Displaying a Sheet During Drag-and-Drop
- Subject: Problem Displaying a Sheet During Drag-and-Drop
- From: David Emme <email@hidden>
- Date: Tue, 22 May 2007 16:09:44 -0700
I have a single-document app, based on Core Data, which is a database/
catalog of images (slides and prints). I am adding support for
cataloging image files (jpegs, etc).
As a convenience, I have implemented drag-and-drop so that the user
can drop one or several jpeg files onto my window, and I will create
a new "record" (Core Data entity) for each file dropped. This is all
working.
Now I want to drop a sheet during performDragOperation: processing,
to allow the user to set defaults for certain image attributes (where
image was taken, etc); these defaults will be set into each of the
several newly-created "records". However, I am unable to figure out
how to drop the sheet during drag-and-drop processing. Depending on
what I've tried, I either hang my app, requiring a Force Quit, or I
get an error message and the drag operation is canceled. The error
message is:
2007-05-22 15:51:02.996 ImageLib[26826] *** Assertion failure in -
[NSApplication
_commonBeginModalSessionForWindow:relativeToWindow:modalDelegate:didEndS
elector:contextInfo:], AppKit.subproj/NSApplication.m:3057
2007-05-22 15:51:02.997 ImageLib[26826] *** Canceling drag because
exception 'NSInternalInconsistencyException' (reason 'Modal session
requires modal window') was raised during a dragging session
My code looks like the following (extraneous details removed):
-(BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
NSManagedObjectContext *moc = [self managedObjectContext];
NSString *aPath = nil;
NSEnumerator *en = [imageFilePathsToImport objectEnumerator];
// Custom initialization here
[self constructModelImageForDnD]; // SHOULD DROP THE SHEET TO GET
USER DEFAULTS
if (!modelImage) return NO; // user canceled
while (aPath = [en nextObject]) {
EImage * newImage = [NSEntityDescription
insertNewObjectForEntityForName:@"Image" inManagedObjectContext:moc];
[[self document]initializeImage:newImage from:modelImage];
[[NSAppDelegate imageFileImporter] importImageFile:aPath
toImage:newImage];
}
[self removeModelImageForDnD];
return YES;
}
- (void)constructModelImageForDnD {
if (!dndSheet) {
[NSBundle loadNibNamed:@"DragNDropSheet" owner:self];
}
// Display the sheet; allow user to specify image attribute defaults.
// [NSApp runModalForWindow:[self window]];
// HERE'S THE PROBLEM SHEET
[NSApp beginSheet:dndSheet modalForWindow:[self window]
modalDelegate:self didEndSelector:nil contextInfo:NULL];
}
There are "Continue" and "Cancel" IBAction buttons on the sheet. If
"Continue" is clicked, image attribute values will be taken from the
sheet and used in Core Data entity construction via the "modelImage"
entity. "Cancel" will abort the whole drag operation.
As the code in constructModelImageForDnD stands above, I get the
indicated error message and the drag operation is canceled. I've
tried various combinations with the [NSApp runModalForWindow...
included, but then the app just hangs. Specifying "modalDelegate:nil"
instead of "modalDelegate:self" (I saw that somewhere(?)) also gives
me the same error message.
How can I successfully drop a sheet during the drag-and-drop operation?
TIA,
-Dave
--
FAILURE IS NOT AN OPTION!
It comes bundled with the software.
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden