Soorya
Soorya

Reputation: 39

Datasource method for reordering in IKImageBrowserView, not being called

- (BOOL) imageBrowser:(IKImageBrowserView *) aBrowser moveItemsAtIndexes: (NSIndexSet *)indexes toIndex:(NSUInteger)destinationIndex;

This datasource method for reordering in IKImageBrowserView is not being called. Nib connections have been made correctly. setAllowsReorderdering is set YES.

But it isn't working yet.

- (void)imageBrowser:(IKImageBrowserView *)aBrowser removeItemsAtIndexes:(NSIndexSet *)indexes

At the same time, the above method for deleting items is correctly called and works perfectly. Why not for reordering ?

When I drag the item to reorder, the following drag and drop code is being called. There are actually 2 IKImageBrowserViews here.

- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{           
NSPoint draggingLocation = [self convertPoint:[sender draggingLocation] fromView:nil];
NSRect contentRect  = [[_indexContentBrowserView enclosingScrollView] frame];
BOOL isForContent   = (contentRect.origin.x < draggingLocation.x) && (draggingLocation.x < contentRect.origin.x + contentRect.size.width);

if (isForContent)
{
    if ([sender draggingSource] == _indexContentBrowserView)
    {
        return NSDragOperationMove;
    }
    else
    {
        NSPasteboard *pb = [sender draggingPasteboard]; 
        NSString * type = [pb availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]];

        if(type != nil)
        {
            return NSDragOperationEvery;
        }           
    }
}
else
{
    if ([sender draggingSource] == _indexListBrowserView)
    {
        return NSDragOperationMove;
    }
    else
    {
        NSPasteboard *pb = [sender draggingPasteboard]; 
        NSString * type = [pb availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]];

        if(type != nil)
        {
            return NSDragOperationEvery;
        }           
    }
}

return NSDragOperationNone;



}

Upvotes: 2

Views: 705

Answers (2)

Soorya
Soorya

Reputation: 39

- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
{
    [super prepareForDragOperation:sender];

    if(nil == [sender draggingSource])
        return YES;

    BOOL success = NO;

    if (_galleryMultiImageFileBrowserView != [sender draggingSource])
    {
        //Code for checking the duplication of files
    }
    else
    {
        success = YES;
    }
    return success;
    //I had returned NO here which was the reason for the problem.
}

I found out the problem. It was my mistake. The above code is the corrected one. Earlier, when the [sender draggingSource] was the IKImageBrowserView, it returned NO. That was the reason why the moveItemsAtIndexes: method was not being called.

@Dov: Thank you Dov for giving your precious time. Thanks a lot. @Joaquin: Thank you very much.

Upvotes: 1

Dov
Dov

Reputation: 16186

Based on your comments, your problem seems to be that you've overridden the built-in drag/drop functionality, and so you no longer get reordering "for free". I would recommend calling the super implementation at the beginning of your override, like so:

[super draggingEntered:sender];

That might not work for you, but if not, I'm not sure what would. You say you do need the drag/drop code - two questions along those lines: first, what do you hope to achieve? Second, is overriding draggingEntered: the best/only way to achieve this?

Upvotes: 0

Related Questions