[Mono-osx] Outline view drag and drop

Arakun hugo.forss at gmail.com
Sun Sep 11 06:49:36 EDT 2011


Hello,

I'm trying to add drag and drop to an outline view so that you can rearrange
its nodes. The OutlineViewWriteItemstoPasteboard is causing me a lot of
headache though. I'm handed an array containing the object(s) being dragged,
however I there's no way of extracting the objects other than in the form of
an IntPtr. The proper way would be to use NSKeyedArchiver to add the objects
to the pasteboard but the nodes I'm using are just wrappers for
non-NSObjects (plus it would just move the problem to the
ValidateDrop/AcceptDrop methods). Since all of the drag and drop is done
within the same view it seems a lot easier to just store a reference to the
item being dragged in a variable.

One of the big problems with the IntPtr is that I can see no way of finding
out the type of the object. Each layer of my tree structure uses a different
subclass of NSTreeNode. Back when I was trying to use the NSTreeController
and Cocoa Bindings the nodes would get wrapped up in another layer of
NSTreeNode objects. Then I could simply do something like this:

IntPtr ptr = items.ValueAt(0); /// where items is the NSArray/
NSTreeNode node = new NSTreeNode(ptr);
NSTreeNode myNode = node.RepresentedObject;
Type t = myNode.GetType();

if (t == typeof(MyTreeNode))
{
	MyTreeNode typecastNode = (MyTreeNode)myNode;
	// Do something
}

Since then I've changed into using the NSOutlineViewDataSource protocol
instead. I'm not sure whether I'm supposed to ever be using "new
NSTreeNode(IntPtr)". Using it on one of my subclasses seems to convert the
original object into just an NSTreeNode which messes up the code since I can
no longer call my own custom methods. This is where I'm stuck – I need to
figure out exactly what object I'm dealing with and its type.

Regards,
— Hugo

--
View this message in context: http://mono.1490590.n4.nabble.com/Outline-view-drag-and-drop-tp3804994p3804994.html
Sent from the Mono - OSX mailing list archive at Nabble.com.


More information about the Mono-osx mailing list