/// <summary> /// Checking if the source item can be dropped into the target item /// </summary> /// <param name="sourceItem"></param> /// <param name="targetItem"></param> /// <returns></returns> private bool CheckDropTarget(MRecipeBaseNode sourceItem, MRecipeBaseNode targetItem) { return( sourceItem.GetType() == targetItem.GetType() || sourceItem.Parent?.GetType() == targetItem.GetType() ); }
/// <summary> /// Insert source item into target /// </summary> /// <param name="sourceItem"></param> /// <param name="targetItem"></param> private void CopyItem(MRecipeBaseNode sourceItem, MRecipeBaseNode targetItem, bool deleteSource = true) { if ( (sourceItem.GetType() == targetItem.GetType()) && targetItem.Parent != null && sourceItem.Parent != null ) { if (targetItem.Parent is MRecipePlate) { var data = (sourceItem as MRecipeDevice); var targetParent = (targetItem.Parent as MRecipePlate); var sourceParent = (sourceItem.Parent as MRecipePlate); int targetIndex = targetParent.Devices.IndexOf(targetItem as MRecipeDevice); // remove data from source and insert data into target if (deleteSource) { sourceParent.Devices.Remove(data); } targetParent.Devices.Insert(targetIndex, data); // update source's parent sourceItem.Parent = targetItem.Parent; lock (_undoRedoHelper) _undoRedoHelper.SaveState(); } else if (sourceItem.Parent is MRecipeDevice) { var data = (sourceItem as MRecipeDeviceLayer); var targetParent = (targetItem.Parent as MRecipeDevice); var sourceParent = (sourceItem.Parent as MRecipeDevice); int targetIndex = targetParent.Layers.IndexOf(targetItem as MRecipeDeviceLayer); // remove data from source and insert data into target if (deleteSource) { sourceParent.Layers.Remove(data); } targetParent.Layers.Insert(targetIndex, data); // update source's parent sourceItem.Parent = targetItem.Parent; lock (_undoRedoHelper) _undoRedoHelper.SaveState(); } else if (sourceItem is MRecipePlate) { var data = (sourceItem as MRecipePlate); var targetParent = (targetItem.Parent as MRecipe); var sourceParent = (sourceItem.Parent as MRecipe); int targetIndex = targetParent.Plates.IndexOf(targetItem as MRecipePlate); // remove data from source and insert data into target if (deleteSource) { sourceParent.Plates.Remove(data); } targetParent.Plates.Insert(targetIndex, data); // update source's parent sourceItem.Parent = targetItem.Parent; lock (_undoRedoHelper) _undoRedoHelper.SaveState(); } //var response = MessageBox.Show( // $"Would you like to move {sourceItem.Tag} into position" + + "", "", MessageBoxButton.YesNo //); } else if ( (sourceItem.Parent?.GetType() == targetItem.GetType()) ) { if (targetItem is MRecipePlate) { var data = (sourceItem as MRecipeDevice); var targetParent = (targetItem as MRecipePlate); var sourceParent = (sourceItem.Parent as MRecipePlate); // remove data from source and add data to target if (deleteSource) { sourceParent.Devices.Remove(data); } targetParent.Devices.Add(data); // update source's parent sourceItem.Parent = targetParent; lock (_undoRedoHelper) _undoRedoHelper.SaveState(); } else if (targetItem is MRecipeDevice) { var data = (sourceItem as MRecipeDeviceLayer); var targetParent = (targetItem as MRecipeDevice); var sourceParent = (sourceItem.Parent as MRecipeDevice); // remove data from source and add data to target if (deleteSource) { sourceParent.Layers.Remove(data); } targetParent.Layers.Add(data); // update source's parent sourceItem.Parent = targetParent; lock (_undoRedoHelper) _undoRedoHelper.SaveState(); } } }