Re: IKImageBrowserView Dragging outside
Re: IKImageBrowserView Dragging outside
- Subject: Re: IKImageBrowserView Dragging outside
- From: "email@hidden" <email@hidden>
- Date: Sun, 25 Oct 2009 11:41:55 +0000
On 24 Oct 2009, at 16:36, TFS - Tobias Jordan wrote:
Thanks again Thomas and Jonathan. What you've written, Thomas, is
indeed working as it should however I can't use it for my project
since I am creating special folder structures when copying the
files, e.g. Adobe Photoshop Files -> 2008-10-20 -> MyPSFile.psd.
Isn't there a way to get the folder dropped to and then do the copy
operation myself? I am having an NSTableView that does pretty much
the same thing, look:
- (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet
*)rowIndexes toPasteboard:(NSPasteboard *)pboard
{
if (NSNotFound != [rowIndexes firstIndex])
{
[array setSelectionIndexes:rowIndexes];
[pboard declareTypes:[self types] owner:self];
[pboard setPropertyList:[NSArray
arrayWithObject:@"ESPFilePromiseType"]
forType:NSFilesPromisePboardType];
}
return YES;
}
- (NSArray *)tableView:(NSTableView *)tv
namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination
forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes
{
[self restoreManagedObjects:[array selectedObjects]
withDestinationFolder:[dropDestination path]];
return nil;
}
Since the method 'tableView:namesOfPromisedFilesDroppedAtDestination:
…' doesn't exist I am currently out of luck.
That might prove to be the case.
Others think the same: http://www.cocoabuilder.com/archive/message/cocoa/2009/7/29/241852
An approach might be to use an NSTableView instance as a drag source
proxy.
When your IKImageBrowserView instance gets a drag request pass it on
to the tableview which can deliver on the promise.
You would have to keep the datasources synchronised of course.
Either that or populate the tableview with just the items to be
dragged when the IKImageBrowserView
drag begins.
Just an idea. Might be tricky to pull off in practice.
Regards
Jonathan Mitchell
Developer
http://www.mugginsoft.com
Tobias.
On Oct 23, 2009, at 10:24 PM, email@hidden wrote:
Tobias
Not sure if this will help.
In the example GoodThing is a core data subclass which stores the
image as NSData.
As such it implements the IKImageBrowserItem informal protocol
methods
-imageRepresentation, -imageRepresentationType (==
IKImageBrowserNSDataRepresentationType) and - imageUID;
/*
write images to paste board
need for dragging of non path represented images
*/
- (NSUInteger) imageBrowser:(IKImageBrowserView *) aBrowser
writeItemsAtIndexes:(NSIndexSet *) itemIndexes toPasteboard:
(NSPasteboard *)pasteboard
{
NSInteger index;
NSInteger itemsWritten = 0;
for (index = [itemIndexes lastIndex]; index != NSNotFound; index
= [itemIndexes indexLessThanIndex:index])
{
// get image data.
GoodThing *goodThing = [imageBrowser itemAtIndex:index];
NSData *imageData = goodThing.imageRepresentation;
// get a tiff representation and write to pasteboard
NSImage *image = [[NSImage alloc] initWithData:imageData];
if (image) {
NSData *tiffData = [image TIFFRepresentation]; // may raise an
exception
if (tiffData) {
// prepare the pasteboard
if (itemsWritten == 0) {
[pasteboard declareTypes:[NSArray
arrayWithObject:NSTIFFPboardType] owner:nil];
}
// write to the pasteboard
[pasteboard setData:tiffData forType:NSTIFFPboardType];
itemsWritten++;
}
}
}
return itemsWritten;
}
Regards
Jonathan Mitchell
Developer
http://www.mugginsoft.com
On Oct 23, 2009, at 11:44 PM, Thomas Goossens wrote:
On Oct 23, 2009, at 9:15 PM, TFS - Tobias Jordan wrote:
Thanks for that, Thomas. The Problem I'm having is that the
IKImageBrowserView is just representing previews. So it's a file
preview and there's a path behind the preview to be copied when
dragging out.
With the standard settings of the view, I'll get the preview image
copied to the location instead of the file behind the image.
That's why I have to implement everything on my own, I know this
sounds confusing. ;-)
ok that makes sense.
I dunno know what to declare in the pasteboard when it is about
NSIndexSets. And what to do next after implementing
writeItemsAtIndexes:toPasteboard:…?
Thanks so much for your help, I really appreciate it.
This is not something specific to the IKImageBrowserView here so
the pasteboard programming guide should help: http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/PasteboardGuide106/Introduction/Introduction.html
Typically you will have to do something like this:
- (NSUInteger) imageBrowser:(IKImageBrowserView *) aBrowser
writeItemsAtIndexes:(NSIndexSet *) itemIndexes toPasteboard:
(NSPasteboard *)pasteboard
{
NSUinteger index;
//instantiate an array to store paths
filesArray = [NSMutableArray array];
//for each index...
for(index = [itemIndexes firstIndex]; index != NSNotFound; index =
[itemIndexes indexGreaterThanIndex:index]){
//...get the path you want to add to the pasteboard
id myDatasourceItem = [_myDatasourceArray objectAtIndex:index];
NSString *path = [myDatasourceItem myLargeImageFilePath];
//add it to your array
[filesArray addObject:path];
}
//declare the pasteboard will contain paths
[pasteboard declareTypes:[NSArray
arrayWithObjects:NSFilenamesPboardType,nil] owner:self];
//set the paths
[pasteboard setPropertyList:filesArray
forType:NSFilenamesPboardType];
//return the number of items added to the pasteboard
return [filesArray count];
}
-- Thomas
On Oct 23, 2009, at 6:49 PM, Thomas Goossens wrote:
Hi Jordan,
imageBrowser:writeItemsAtIndexes:toPasteboard: is indeed the way
to go.
Implement this method in your datasource and just fill the
pasteboard with the info you want (Images, paths, urls, data...)
for the indexes passed in arguments.
Also if you feed the imageBrowser with paths or urls
(IKImageBrowserPathRepresentationType,
IKImageBrowserNSURLRepresentationType...) , you don't have to do
anything, the pasteboard is filled automatically (i.e you don't
need to implement imageBrowser:writeItemsAtIndexes:toPasteboard:).
-- Thomas
On Oct 22, 2009, at 2:30 PM, TFS - Tobias Jordan wrote:
Hi all,
I've been wondering on how to implement dragging out of the view
in the IKImageBrowserView. I am pretty sure this is where I have
to start: -imageBrowser:writeItemsAtIndexes:toPasteboard: but I
don't have a clue what to do next. It's not a real File Promise,
I just need the folder (in most cases the Desktop) dragged to
and the indexes that have been dragged.
The class seems to be quite different to the NSTableView in
which I am using '-tableView:writeRowsWithIndexes:toPasteboard'
and '-
tableView:namesOfPromisedFilesDroppedAtDestination:forDraggedRowsWithIndexes
:'.
What's the method I am missing?
Best regards & thanks.
Tobias Jordan.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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