private void ResourcesListView_DragOver(object sender, DragEventArgs e) { e.Effect = DragDropEffects.None; if (!e.Data.GetDataPresent(DataFormats.FileDrop)) { return; } var paths = e.Data.GetData(DataFormats.FileDrop) as string[]; var point = ResourcesListView.PointToClient(new Point(e.X, e.Y)); var item = ResourcesListView.GetItemAt(point.X, point.Y); if (item != null) { var ipath = Walker.GetPath(item.Text); if (Resource.GetType(ipath) != ResourceType.Folder) { return; } foreach (var path in paths) { if (path == ipath) { return; } } } if ((e.KeyState & (8 + 32)) == (8 + 32) && e.AllowedEffect.HasFlag(DragDropEffects.Link)) { return;//e.Effect = DragDropEffects.Link; } else if ((e.KeyState & 32) == 32 && e.AllowedEffect.HasFlag(DragDropEffects.Link)) { return;//e.Effect = DragDropEffects.Link; } else if ((e.KeyState & 4) == 4 && e.AllowedEffect.HasFlag(DragDropEffects.Move)) { e.Effect = DragDropEffects.Move; } else if ((e.KeyState & 8) == 8 && e.AllowedEffect.HasFlag(DragDropEffects.Copy)) { e.Effect = DragDropEffects.Copy; } else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) { e.Effect = DragDropEffects.Move; } else { e.Effect = DragDropEffects.None; } }
private void ResourcesListView_DragDrop(object sender, DragEventArgs e) { var point = ResourcesListView.PointToClient(new Point(e.X, e.Y)); var item = ResourcesListView.GetItemAt(point.X, point.Y); string dest; if (item == null) { dest = Walker.CurrentPath; } else { dest = Walker.GetPath(item.Text); } if (e.Data.GetDataPresent(DataFormats.FileDrop)) { var paths = (string[])e.Data.GetData(DataFormats.FileDrop); bool convert = false; foreach (var path in paths) { if (Resource.PrimalFile(path)) { convert = true; break; } } if (convert) { var result = MessageBox.Show(this, "Would you like to create resources from them automatically?", "One or more of importing files are primal.", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result != DialogResult.Yes) { convert = false; } } foreach (var path in paths) { try { var fpath = Path.GetFullPath(path); if (Resource.PrimalFile(fpath) && convert) { Resource.Factory(dest, fpath); } else { var new_path = Path.Combine(dest, Path.GetFileName(fpath)); if (new_path == fpath) { continue; } if (e.Effect == DragDropEffects.Move) { if (File.Exists(fpath)) { File.Move(fpath, new_path); } if (Directory.Exists(fpath)) { Directory.Move(fpath, new_path); } } else if (e.Effect == DragDropEffects.Copy) { if (File.Exists(fpath)) { File.Copy(fpath, new_path); } if (Directory.Exists(fpath)) { DirectoryCopy(fpath, new_path, true); } } } } catch (Exception ex) { MessageBox.Show(this, ex.ToString(), "Error: Can not import item [" + path + "].", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } }