/// <summary> /// Paste the Copied or Cut Items /// </summary> /// <param name="containerControl">The UI control which paste is done on (DataGrid/TreeView/ListView)</param> /// <param name="propertiesToSet">List of properties PropertyName-Value to set in reflection to they paste item</param> public static void PasteItems(IClipboardOperations containerControl, List <Tuple <string, object> > propertiesToSet = null, int currentIndex = -1, Context context = null) { bool IsValidActionPlatform = true; ((Control)containerControl).Dispatcher.Invoke(() => { try { if (CopiedorCutItems.Count > 0) { Reporter.ToStatus(eStatusMsgKey.PasteProcess, null, string.Format("Performing paste operation for {0} items...", CopiedorCutItems.Count)); if (CutSourceList != null) { //CUT //first remove from cut source foreach (RepositoryItemBase item in CopiedorCutItems) { //clear from source CutSourceList.Remove(item); if (currentIndex > 0) { currentIndex--; } //set needed properties if any SetProperties(item, propertiesToSet); if (!containerControl.GetSourceItemsAsIList().Contains(item))//Not cut & paste on same grid { //set unique name GingerCoreNET.GeneralLib.General.SetUniqueNameToRepoItem(containerControl.GetSourceItemsAsList(), item); } //check action platform before copy if (!ActionsFactory.IsValidActionPlatformForActivity(item, context)) { IsValidActionPlatform = false; continue; } //paste on target and select containerControl.SetSelectedIndex(AddItemAfterCurrent(containerControl, item, currentIndex)); //Trigger event for changing sub classes fields containerControl.OnPasteItemEvent(PasteItemEventArgs.ePasteType.PasteCutedItem, item); } //clear so will be past only once CutSourceList = null; CopiedorCutItems.Clear(); } else { //COPY //paste on target foreach (RepositoryItemBase item in CopiedorCutItems) { RepositoryItemBase copiedItem = item.CreateCopy(); //set unique name GingerCoreNET.GeneralLib.General.SetUniqueNameToRepoItem(containerControl.GetSourceItemsAsList(), copiedItem, "_Copy"); //set needed properties if any SetProperties(copiedItem, propertiesToSet); //check action platform before copy if (!ActionsFactory.IsValidActionPlatformForActivity(copiedItem, context)) { IsValidActionPlatform = false; continue; } //add and select containerControl.SetSelectedIndex(AddItemAfterCurrent(containerControl, copiedItem, currentIndex)); //Trigger event for changing sub classes fields containerControl.OnPasteItemEvent(PasteItemEventArgs.ePasteType.PasteCopiedItem, copiedItem); } } } else { Reporter.ToStatus(eStatusMsgKey.PasteProcess, null, "No items found to paste"); } if (!IsValidActionPlatform) { Reporter.ToUser(eUserMsgKey.MissingTargetApplication, "Unable to copy actions with different platform."); } } catch (Exception ex) { Reporter.ToUser(eUserMsgKey.StaticWarnMessage, "Operation Failed, make sure the copied/cut items type and destination type is matching." + System.Environment.NewLine + System.Environment.NewLine + "Error: " + ex.Message); //CutSourceList = null; //CopiedorCutItems.Clear(); } finally { Reporter.HideStatusMessage(); } }); }