//respond to an item dropped in my treeview protected override void OnDragDrop(DragEventArgs e) { base.OnDragDrop(e); TmTreeNode destinationTreeNode = NodeAtEvent(e); TmNode destinationNode = null; if (destinationTreeNode != null) destinationNode = destinationTreeNode.TmNode; // TmNodeList drop if (e.Data.GetDataPresent("TmNodeList", false)) { List<TmNode> nodes = e.Data.GetData("TmNodeList") as List<TmNode>; if (nodes != null && nodes.Count() > 0) { foreach (TmNode node in nodes) { if (e.Effect == DragDropEffects.Move) MoveNode(destinationNode, node); if (e.Effect == DragDropEffects.Copy) CopyNode(destinationNode, node); } if (e.Effect != DragDropEffects.None) { //SelectNode(destinationTreeNode); destinationTreeNode.Expand(); return; } } } // TmNode drop if (e.Data.GetDataPresent("TmNode", false)) { // e.Effect == none for illeagal drops. TmNode oldNode = e.Data.GetData("TmNode") as TmNode; Debug.Assert(oldNode != null, "Could not reserialize node from clipboard"); if (oldNode != null) { if (e.Effect == DragDropEffects.Move) MoveNode(destinationNode, oldNode); if (e.Effect == DragDropEffects.Copy) CopyNode(destinationNode, oldNode); if (e.Effect != DragDropEffects.None) { //SelectNode(destinationTreeNode); destinationTreeNode.Expand(); return; } } } // FileDrop if (e.Data.GetDataPresent(DataFormats.FileDrop)) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); TmTreeNode newTreeNode = null; foreach (string file in files) { //FIXME - determine if this is a Theme or a ThemeList //currently assuming it is a theme. TmNode newNode = new ThemeNode(Path.GetFileNameWithoutExtension(file), file); try { // May need to load to query arc objects which could throw any number of exceptions. newNode.Reload(); } catch (Exception ex) { MessageBox.Show("Unable to load the theme properties" + ex); } if (destinationNode == null) newTreeNode = Add(newNode); else destinationNode.Add(newNode); } if (newTreeNode != null) SelectNode(newTreeNode); else { SelectNode(destinationTreeNode); destinationTreeNode.Expand(); } return; } // Text Drop if (e.Data.GetDataPresent(DataFormats.Text)) { string txt = (string)e.Data.GetData(DataFormats.Text); TmNode newNode = new CategoryNode(txt); if (destinationNode == null) SelectNode(Add(newNode)); else { destinationNode.Add(newNode); SelectNode(destinationTreeNode); destinationTreeNode.Expand(); } } }
private void PasteAsFiles() { TmNode currentNode = GetCurrentTmNode(); StringCollection files = Clipboard.GetFileDropList(); foreach (string file in files) { string basename = Path.GetFileNameWithoutExtension(file); //assume this file is a valid theme //FIXME - determine valid theme or themelist; reject otherwise. TmNode newNode = new ThemeNode(basename, file); try { // May need to load to query arc objects which could throw any number of exceptions. newNode.Reload(); } catch (Exception ex) { MessageBox.Show("Unable to load the theme properties" + ex); } if (currentNode == null) Add(newNode); else currentNode.Add(newNode); } }