private static bool MoveItem(IntPtr sourceItems, IntPtr destinationFolder) { if (!IsCustomDialog) { return(false); } var destinationObject = Marshal.GetObjectForIUnknown(destinationFolder); var sourceObject = Marshal.GetObjectForIUnknown(sourceItems); var sourceItemsCollection = ShellObjectCollection.FromDataObject((System.Runtime.InteropServices.ComTypes.IDataObject)sourceObject).Select(c => c.ParsingName).ToArray(); var destinationLocation = ShellObjectFactory.Create((IShellItem)destinationObject).ParsingName; SyncContext.Post((o) => { var tempWindow = new Shell.FileOperations.FileOperation(sourceItemsCollection, destinationLocation, OperationType.Move); var currentDialog = System.Windows.Application.Current.MainWindow.OwnedWindows.OfType <FileOperationDialog>().SingleOrDefault(); if (currentDialog == null) { currentDialog = new FileOperationDialog(); tempWindow.ParentContents = currentDialog; currentDialog.Owner = System.Windows.Application.Current.MainWindow; tempWindow.Visibility = Visibility.Collapsed; currentDialog.Contents.Add(tempWindow); } else { tempWindow.ParentContents = currentDialog; tempWindow.Visibility = Visibility.Collapsed; currentDialog.Contents.Add(tempWindow); } }, null); return(true); }
public static void ShowDeleteDialog(string[] sourceItemsCollection, Window win, bool isMoveToRB) { var confirmationDialog = new FODeleteDialog(); if (sourceItemsCollection.Count() == 1) { ShellObject item = ShellObject.FromParsingName(sourceItemsCollection[0]); item.Thumbnail.CurrentSize = new Size(96, 96); confirmationDialog.MessageCaption = string.Format("{0} {1}", win.FindResource("btnDeleteCP"), win.FindResource((item.IsLink ? "txtShortcut" : item.IsFolder ? "txtAccusativeFolder" : "txtFile")) as string); var itemTypeName = win.FindResource((item.IsLink ? "txtShortcut" : item.IsFolder ? "txtAccusativeFolder" : "txtFile")) as string; confirmationDialog.MessageIcon = item.Thumbnail.BitmapSource; confirmationDialog.MessageText = isMoveToRB ? string.Format((string)win.FindResource("txtConfirmDeleteObject"), itemTypeName, win.FindResource("txtRecycleBin")) : string.Format((string)win.FindResource("txtConfirmRemoveObject"), itemTypeName); confirmationDialog.FileInfo = item.Name + "\n"; if (item.IsFolder) { confirmationDialog.FileInfo += string.Format("{0}: {1} ", win.FindResource("btnODateCCP") as string, item.Properties.GetProperty("System.DateCreated").ValueAsObject); } else if (item.IsLink) { var targetPath = item.Properties.GetProperty("System.Link.TargetParsingPath").ValueAsObject as string; confirmationDialog.FileInfo += string.Format("{0}: {1}\n({2}) ", win.FindResource("txtLocation") as string, Path.GetFileNameWithoutExtension(targetPath), Path.GetDirectoryName(targetPath)); } else // file { var fileInfo = string.Format("{0}: {1}\n", win.FindResource("txtType"), item.Properties.System.ItemTypeText.ValueAsObject); if (item.Properties.System.ItemAuthors.Value != null) { fileInfo += string.Format("{0}: {1}\n", win.FindResource("btnAuthorCP"), string.Join(";", item.Properties.System.ItemAuthors.Value)); } string[] sizes = { "B", "KB", "MB", "GB" }; var len = (ulong)item.Properties.System.Size.ValueAsObject; int order = 0; while (len >= 1000 && order + 1 < sizes.Length) // using SI system, not IEC { order++; len = len / 1000; } // Adjust the format string to your preferences. For example "{0:0.#}{1}" would // show a single decimal place, and no space. string result = String.Format("{0:0.##} {1}", len, sizes[order]); fileInfo += string.Format("{0}: {1}\n", win.FindResource("txtFileSize"), result); fileInfo += string.Format("{0}: {1}\n", win.FindResource("btnODateModCP") as string, item.Properties.GetProperty("System.DateModified").ValueAsObject); confirmationDialog.FileInfo += fileInfo; } } else { confirmationDialog.MessageCaption = win.FindResource("txtDeleteSeveralItems") as string; confirmationDialog.MessageText = isMoveToRB ? string.Format((string)win.FindResource("txtConfirmDeleteObjects"), sourceItemsCollection.Count()) : string.Format((string)win.FindResource("txtConfirmRemoveObjects"), sourceItemsCollection.Count()); } confirmationDialog.Owner = win; if (confirmationDialog.ShowDialog() == true) { var tempWindow = new Shell.FileOperations.FileOperation(sourceItemsCollection, String.Empty, OperationType.Delete, isMoveToRB); var currentDialog = win.OwnedWindows.OfType <FileOperationDialog>().SingleOrDefault(); if (currentDialog == null) { currentDialog = new FileOperationDialog(); tempWindow.ParentContents = currentDialog; currentDialog.Owner = win; tempWindow.Visibility = Visibility.Collapsed; currentDialog.Contents.Add(tempWindow); } else { tempWindow.ParentContents = currentDialog; tempWindow.Visibility = Visibility.Collapsed; currentDialog.Contents.Add(tempWindow); } } }