private void _tree_DragDrop(object sender, DragEventArgs e) { bool needRebuild = false; if (e.Data.GetDataPresent(typeof(ExternalCommand))) { ExternalCommand command = (ExternalCommand)e.Data.GetData(typeof(ExternalCommand)); if (e.Effect == DragDropEffects.Move) { if (_nodeWhereToDrop != null) { Command newInstance = command.Clone().Instance; InsertCommandIntoTree((TreeNodeData)_nodeWhereToDrop.Tag, newInstance); needRebuild = true; } } } if (e.Data.GetDataPresent(typeof(TreeNodeData))) { TreeNodeData data = (TreeNodeData)e.Data.GetData(typeof(TreeNodeData)); if (e.Effect == DragDropEffects.Move || e.Effect == DragDropEffects.Copy) { if (_nodeWhereToDrop != null) { Command cmd = data.Command; if (e.Effect == DragDropEffects.Copy) { cmd = data.Command.Copy(); } ExternalCommand command = new ExternalCommand(cmd); TreeNodeData dataWhereToDrop = (TreeNodeData)_nodeWhereToDrop.Tag; if (data.Node.HasNested(dataWhereToDrop.Node)) { return; } bool commandMoved = InsertCommandIntoTree(dataWhereToDrop, command.Instance); needRebuild = commandMoved; if (commandMoved && e.Effect == DragDropEffects.Move) { data.Node.Remove(); } } } } if (e.Data.GetDataPresent("FileDrop")) { if (e.Effect == DragDropEffects.Move) { if (_nodeWhereToDrop != null) { string[] fileNames = (string[])e.Data.GetData("FileDrop"); GinMetaData metadata = GinMetaData.GetInstance(); bool applyToAllCommands = false; ExternalCommand selectedCommand = null; int lastIndex = -1; for (int i = 0; i < fileNames.Length; i++) { string fileName = fileNames[i]; ExternalCommand[] commands = metadata.GetAssumedCommands(fileName); if (commands.Length == 0) { return; } if (commands.Length == 1) { InsertCommandIntoTree((TreeNodeData)_nodeWhereToDrop.Tag, commands[0].Instance); needRebuild = true; return; } if (commands.Length > 1) { ChooseDroppedCommandForm form = new ChooseDroppedCommandForm(); form.InitDroppedCommands(commands); if (form.ShowDialog() == DialogResult.OK) { InsertCommandIntoTree((TreeNodeData)_nodeWhereToDrop.Tag, form.SelectedExternalCommand.Instance); needRebuild = true; applyToAllCommands = form.ApplyToAllCommands; if (applyToAllCommands) { selectedCommand = form.SelectedExternalCommand; lastIndex = i; break; } } } } if (applyToAllCommands) { for (int i = lastIndex + 1; i < fileNames.Length; i++) { string fileName = fileNames[i]; InsertCommandIntoTree((TreeNodeData)_nodeWhereToDrop.Tag, selectedCommand.Instance); needRebuild = true; } } } } } if (needRebuild) { ((TreeNodeData)_rootNode.Nodes[0].Tag).Node.Rebuild(true); } }