ファイル整理用ツールのWinFormサンプル実装
Revision | d9c818af7bc1577f2964a5cb57d2e8eb44741f96 (tree) |
---|---|
Time | 2018-12-27 13:05:40 |
Author | yoshy <yoshy@user...> |
Commiter | yoshy |
リファクタ - ドラッグ情報中のリストを配列に変更
@@ -54,20 +54,20 @@ namespace FolderCategorizer.Infra.Helper | ||
54 | 54 | return Path.GetFullPath(Path.Combine(dir, name)); |
55 | 55 | } |
56 | 56 | |
57 | - public static bool IsDstPathIncludedSrcPathList(string dstPath, List<string> srcPaths) | |
57 | + public static bool IsDstPathIncludedSrcPathList(string dstFolderPath, string[] srcFolderPaths) | |
58 | 58 | { |
59 | - foreach (string srcPath in srcPaths) | |
59 | + foreach (string srcFolderPath in srcFolderPaths) | |
60 | 60 | { |
61 | - string srcParent = Path.GetDirectoryName(srcPath); | |
61 | + string srcParent = Path.GetDirectoryName(srcFolderPath); | |
62 | 62 | |
63 | - if (dstPath.StartsWith(srcPath)) | |
63 | + if (dstFolderPath.StartsWith(srcFolderPath)) | |
64 | 64 | { |
65 | - string dstParent = Path.GetDirectoryName(dstPath); | |
65 | + string dstParent = Path.GetDirectoryName(dstFolderPath); | |
66 | 66 | |
67 | 67 | if (srcParent == dstParent) |
68 | 68 | { |
69 | - string srcName = Path.GetFileName(srcPath); | |
70 | - string dstName = Path.GetFileName(dstPath); | |
69 | + string srcName = Path.GetFileName(srcFolderPath); | |
70 | + string dstName = Path.GetFileName(dstFolderPath); | |
71 | 71 | |
72 | 72 | if (srcName == dstName) |
73 | 73 | { |
@@ -82,7 +82,7 @@ namespace FolderCategorizer.Infra.Helper | ||
82 | 82 | return true; |
83 | 83 | } |
84 | 84 | } |
85 | - else if (dstPath == srcParent) | |
85 | + else if (dstFolderPath == srcParent) | |
86 | 86 | { |
87 | 87 | return true; |
88 | 88 | // 対象フォルダがソースの親の場合はフルパスが自分になるのでNG |
@@ -85,51 +85,48 @@ namespace FolderCategorizer.Presentation.View | ||
85 | 85 | [Serializable] |
86 | 86 | public class DraggedFileListEntriesHolder |
87 | 87 | { |
88 | - public List<FileListEntry> DroppedEntries { get; set; } = null; | |
88 | + public FileListEntry[] DroppedEntries { get; set; } = null; | |
89 | 89 | |
90 | 90 | public string SrcRefreshPath { get; set; } = string.Empty; |
91 | 91 | |
92 | - public List<FileListEntry> SelectedFileListViewItems { get; set; } = null; | |
92 | + public FileListEntry[] SelectedListEntries { get; set; } = null; | |
93 | 93 | |
94 | - public TreeNodeStatus[] SelectedFolderTreeViewNodeStatuses { get; set; } = null; | |
94 | + public TreeNodeStatus[] SelectedNodeStatuses { get; set; } = null; | |
95 | 95 | |
96 | - public List<string> ProhibitedDropFolderTopPaths { get; set; } = null; | |
96 | + public string[] SrcFolderPaths { get; set; } = null; | |
97 | 97 | |
98 | 98 | //public ImageList DraggedImageList { get; set; } = null; |
99 | 99 | |
100 | 100 | public DraggedFileListEntriesHolder() |
101 | 101 | { |
102 | - DroppedEntries = new List<FileListEntry>(); | |
103 | - SelectedFileListViewItems = new List<FileListEntry>(); | |
104 | - SelectedFolderTreeViewNodeStatuses = new TreeNodeStatus[0]; | |
105 | - ProhibitedDropFolderTopPaths = new List<string>(); | |
102 | + DroppedEntries = new FileListEntry[0]; | |
103 | + SelectedListEntries = new FileListEntry[0]; | |
104 | + SelectedNodeStatuses = new TreeNodeStatus[0]; | |
105 | + SrcFolderPaths = new string[0]; | |
106 | 106 | } |
107 | 107 | |
108 | - public DraggedFileListEntriesHolder(List<ListViewItem> selectedItems, TreeNode[] selectedNodes, List<string> prohibitedFolders, string srcRefreshPath) | |
108 | + public DraggedFileListEntriesHolder(FileListEntry[] selectedListEntries, TreeNodeStatus[] selectedNodeStatuses, string[] prohibitedFolders, string srcRefreshPath) | |
109 | 109 | { |
110 | - SelectedFileListViewItems = FileListEntry.FromTagOf(selectedItems).ToList(); | |
111 | - SelectedFolderTreeViewNodeStatuses = TreeNodeStatus.FromTagOf(selectedNodes); | |
112 | - ProhibitedDropFolderTopPaths = prohibitedFolders; | |
110 | + SelectedListEntries = selectedListEntries; | |
111 | + SelectedNodeStatuses = selectedNodeStatuses; | |
112 | + SrcFolderPaths = prohibitedFolders; | |
113 | 113 | SrcRefreshPath = srcRefreshPath; |
114 | 114 | |
115 | - DroppedEntries = SelectedFileListViewItems; | |
115 | + DroppedEntries = SelectedListEntries; | |
116 | 116 | } |
117 | 117 | |
118 | - public DraggedFileListEntriesHolder(List<ListViewItem> selectedItems, TreeNode[] selectedNodes, TreeNode draggedNode) | |
118 | + public DraggedFileListEntriesHolder(FileListEntry[] selectedItems, TreeNodeStatus[] selectedNodes, TreeNode draggedNode) | |
119 | 119 | { |
120 | - SelectedFileListViewItems = FileListEntry.FromTagOf(selectedItems).ToList(); | |
121 | - SelectedFolderTreeViewNodeStatuses = TreeNodeStatus.FromTagOf(selectedNodes); | |
120 | + SelectedListEntries = selectedItems; | |
121 | + SelectedNodeStatuses = selectedNodes; | |
122 | 122 | |
123 | 123 | SrcRefreshPath = Path.GetDirectoryName(TreeNodeStatus.FromTagOf(draggedNode).RelativePath); |
124 | 124 | |
125 | - DroppedEntries = new List<FileListEntry>(); | |
126 | - ProhibitedDropFolderTopPaths = new List<string>(); | |
127 | - | |
128 | 125 | FileListEntry droppedEntry = new FileListEntry( |
129 | 126 | draggedNode.Name, Path.GetDirectoryName(TreeNodeStatus.FromTagOf(draggedNode).RelativePath), FileListEntry.EntryType.FOLDER); |
130 | 127 | |
131 | - DroppedEntries.Add(droppedEntry); | |
132 | - ProhibitedDropFolderTopPaths.Add(droppedEntry.RelativePath); | |
128 | + DroppedEntries = new FileListEntry[] { droppedEntry }; | |
129 | + SrcFolderPaths = new string[] { droppedEntry.RelativePath }; | |
133 | 130 | } |
134 | 131 | } |
135 | 132 |
@@ -186,7 +183,7 @@ namespace FolderCategorizer.Presentation.View | ||
186 | 183 | return ((TreeNodeStatus)node?.Tag); |
187 | 184 | } |
188 | 185 | |
189 | - public static TreeNodeStatus[] FromTagOf(params TreeNode[] nodes) | |
186 | + public static TreeNodeStatus[] ToArrayFromTagsOf(params TreeNode[] nodes) | |
190 | 187 | { |
191 | 188 | return FromTagOf(nodes.AsEnumerable()); |
192 | 189 | } |
@@ -394,18 +391,35 @@ namespace FolderCategorizer.Presentation.View | ||
394 | 391 | return (FileListEntry)item?.Tag; |
395 | 392 | } |
396 | 393 | |
397 | - public static FileListEntry[] FromTagOf(IEnumerable<ListViewItem> items) | |
394 | + public static List<FileListEntry> ToListFromTagsOf(IEnumerable items) | |
398 | 395 | { |
399 | - FileListEntry[] objs = new FileListEntry[items.Count()]; | |
400 | - | |
401 | - int i = 0; | |
396 | + List<FileListEntry> entries = new List<FileListEntry>(); | |
402 | 397 | |
403 | 398 | foreach (ListViewItem item in items) |
404 | 399 | { |
405 | - objs[i++] = FileListEntry.FromTagOf(item); | |
400 | + FileListEntry entry = FileListEntry.FromTagOf(item); | |
401 | + | |
402 | + switch (entry.Type) | |
403 | + { | |
404 | + case FileListEntry.EntryType.FOLDER: | |
405 | + case FileListEntry.EntryType.FILE: | |
406 | + break; | |
407 | + | |
408 | + default: | |
409 | + case FileListEntry.EntryType.INVALID: | |
410 | + case FileListEntry.EntryType.UPWARDS: | |
411 | + continue; | |
412 | + } | |
413 | + | |
414 | + entries.Add(entry); | |
406 | 415 | } |
407 | 416 | |
408 | - return objs; | |
417 | + return entries; | |
418 | + } | |
419 | + | |
420 | + public static FileListEntry[] ToArrayFromTagsOf(IEnumerable items) | |
421 | + { | |
422 | + return ToListFromTagsOf(items).ToArray(); ; | |
409 | 423 | } |
410 | 424 | |
411 | 425 | public static string ToTypeName(EntryType type) |
@@ -479,6 +493,21 @@ namespace FolderCategorizer.Presentation.View | ||
479 | 493 | public DateTime CreationTime { get; set; } |
480 | 494 | |
481 | 495 | public DateTime LastWriteTime { get; set; } |
496 | + | |
497 | + public bool IsFolder() | |
498 | + { | |
499 | + return Type == EntryType.FOLDER; | |
500 | + } | |
501 | + | |
502 | + public bool IsFile() | |
503 | + { | |
504 | + return Type == EntryType.FILE; | |
505 | + } | |
506 | + | |
507 | + public bool IsUpwards() | |
508 | + { | |
509 | + return Type == EntryType.UPWARDS; | |
510 | + } | |
482 | 511 | } |
483 | 512 | |
484 | 513 | private class FileListEntrySorter : IComparer |
@@ -3226,18 +3255,6 @@ namespace FolderCategorizer.Presentation.View | ||
3226 | 3255 | IGNORE_ALL_TARGET2_NOT_FOUND_ERROR = 3, |
3227 | 3256 | } |
3228 | 3257 | |
3229 | - private List<FileListEntry> CreateSelectedSrcEntries() | |
3230 | - { | |
3231 | - List<FileListEntry> entries = new List<FileListEntry>(); | |
3232 | - | |
3233 | - foreach (ListViewItem lvi in lvFileList.SelectedItems) | |
3234 | - { | |
3235 | - entries.Add(FileListEntry.FromTagOf(lvi)); | |
3236 | - } | |
3237 | - | |
3238 | - return entries; | |
3239 | - } | |
3240 | - | |
3241 | 3258 | private static bool CreateModifyMultiTargetFileList( |
3242 | 3259 | List<string> outTargetPaths, List<string> outTargetPathsForMsg1, List<string> outTargetPathsForMsg2, |
3243 | 3260 | AbstractFileSystemMultiTargetOperationRequest req) |
@@ -3581,37 +3598,16 @@ namespace FolderCategorizer.Presentation.View | ||
3581 | 3598 | |
3582 | 3599 | private void DoDragTreeView_TreeNode(ListView lv, TreeView tvSrcFolder1, TreeView tvSrcFolder2, TreeNode draggedItem) |
3583 | 3600 | { |
3584 | - List<ListViewItem> selectedItems = new List<ListViewItem>(lv.SelectedItems.Count); | |
3585 | - | |
3586 | - foreach (ListViewItem lvi in lvFileList.SelectedItems) | |
3587 | - { | |
3588 | - FileListEntry entry = FileListEntry.FromTagOf(lvi); | |
3589 | - | |
3590 | - switch (entry.Type) | |
3591 | - { | |
3592 | - case FileListEntry.EntryType.UPWARDS: | |
3593 | - case FileListEntry.EntryType.FOLDER: | |
3594 | - case FileListEntry.EntryType.FILE: | |
3595 | - break; | |
3596 | - | |
3597 | - default: | |
3598 | - case FileListEntry.EntryType.INVALID: | |
3599 | - continue; | |
3600 | - } | |
3601 | - | |
3602 | - selectedItems.Add(lvi); | |
3603 | - } | |
3601 | + FileListEntry[] entries = FileListEntry.ToArrayFromTagsOf(lvFileList.SelectedItems); | |
3604 | 3602 | |
3605 | 3603 | // ツリー上で、選択後にボタンを離さずファイルリストにドロップすると、 |
3606 | 3604 | // 選択ノードが切り替わらずにドラッグ動作が開始されるため、 |
3607 | 3605 | // ここで強制的にドラッグされたノードを選択状態にする |
3608 | 3606 | SelectTreeViewNode(TreeNodeStatus.FromTagOf(draggedItem).RelativePath); |
3609 | 3607 | |
3610 | - TreeNode[] selectedNodes = new TreeNode[] { tvSrcFolder1.SelectedNode, tvSrcFolder2.SelectedNode }; | |
3608 | + TreeNodeStatus[] statuses = TreeNodeStatus.ToArrayFromTagsOf(tvSrcFolder1.SelectedNode, tvSrcFolder2.SelectedNode); | |
3611 | 3609 | |
3612 | - DraggedFileListEntries = new DraggedFileListEntriesHolder(selectedItems, selectedNodes, draggedItem); | |
3613 | - | |
3614 | - lv.DoDragDrop(DraggedFileListEntries, DragDropEffects.Move | DragDropEffects.Copy); | |
3610 | + DraggedFileListEntries = new DraggedFileListEntriesHolder(entries, statuses, draggedItem); | |
3615 | 3611 | } |
3616 | 3612 | |
3617 | 3613 | private DragDropEffects DragEnterTreeView_DraggedFileListEntries(DraggedFileListEntriesHolder holder, TreeView tv, int keyState, DragDropEffects allowedEffect, Point p) |
@@ -3621,7 +3617,7 @@ namespace FolderCategorizer.Presentation.View | ||
3621 | 3617 | tv.Focus(); |
3622 | 3618 | |
3623 | 3619 | return DragOverCommon_DraggedFileListEntries_SwitchEffect(keyState, allowedEffect, |
3624 | - DragOverTreeView_DraggedFileListEntries_EmphasisDstItem(tv, p, holder.ProhibitedDropFolderTopPaths)); | |
3620 | + DragOverTreeView_DraggedFileListEntries_EmphasisDstItem(tv, p, holder.SrcFolderPaths)); | |
3625 | 3621 | } |
3626 | 3622 | |
3627 | 3623 | private void DragEnterTreeView_DraggedFileListEntries_EnterDragMode() |
@@ -3632,10 +3628,10 @@ namespace FolderCategorizer.Presentation.View | ||
3632 | 3628 | private DragDropEffects DragOverTreeView_DraggedFileListEntries(DraggedFileListEntriesHolder holder, TreeView tv, int keyState, DragDropEffects allowedEffect, Point p) |
3633 | 3629 | { |
3634 | 3630 | return DragOverCommon_DraggedFileListEntries_SwitchEffect(keyState, allowedEffect, |
3635 | - DragOverTreeView_DraggedFileListEntries_EmphasisDstItem(tv, p, holder.ProhibitedDropFolderTopPaths)); | |
3631 | + DragOverTreeView_DraggedFileListEntries_EmphasisDstItem(tv, p, holder.SrcFolderPaths)); | |
3636 | 3632 | } |
3637 | 3633 | |
3638 | - private static bool DragOverTreeView_DraggedFileListEntries_EmphasisDstItem(TreeView tv, Point p, List<string> srcPaths) | |
3634 | + private static bool DragOverTreeView_DraggedFileListEntries_EmphasisDstItem(TreeView tv, Point p, string[] srcFolderPaths) | |
3639 | 3635 | { |
3640 | 3636 | TreeNode dstNode = DragDropTreeView_GetNodeAt(tv, p); |
3641 | 3637 |
@@ -3648,7 +3644,7 @@ namespace FolderCategorizer.Presentation.View | ||
3648 | 3644 | |
3649 | 3645 | TreeNodeStatus dstStatus = TreeNodeStatus.FromTagOf(dstNode); |
3650 | 3646 | |
3651 | - if (PathHelper.IsDstPathIncludedSrcPathList(dstStatus.RelativePath, srcPaths)) | |
3647 | + if (PathHelper.IsDstPathIncludedSrcPathList(dstStatus.RelativePath, srcFolderPaths)) | |
3652 | 3648 | { |
3653 | 3649 | // invalid dst path |
3654 | 3650 | return false; |
@@ -3661,14 +3657,14 @@ namespace FolderCategorizer.Presentation.View | ||
3661 | 3657 | |
3662 | 3658 | private void DragLeaveTreeView_DraggedFileListEntries(DraggedFileListEntriesHolder holder) |
3663 | 3659 | { |
3664 | - DragLeaveCommon_DraggedFileListEntries_RestoreSelectedNodes(holder.SelectedFolderTreeViewNodeStatuses); | |
3660 | + DragLeaveCommon_DraggedFileListEntries_RestoreSelectedNodes(holder.SelectedNodeStatuses); | |
3665 | 3661 | |
3666 | 3662 | DragLeaveCommon_DraggedFileListEntries_LeaveDragMode(); |
3667 | 3663 | } |
3668 | 3664 | |
3669 | 3665 | private void DragDropTreeView_DraggedFileListEntries(DraggedFileListEntriesHolder holder, TreeView tv, Point p, DragDropEffects effect) |
3670 | 3666 | { |
3671 | - DragLeaveCommon_DraggedFileListEntries_RestoreSelectedNodes(holder.SelectedFolderTreeViewNodeStatuses); | |
3667 | + DragLeaveCommon_DraggedFileListEntries_RestoreSelectedNodes(holder.SelectedNodeStatuses); | |
3672 | 3668 | |
3673 | 3669 | DragLeaveCommon_DraggedFileListEntries_LeaveDragMode(); |
3674 | 3670 |
@@ -3706,39 +3702,12 @@ namespace FolderCategorizer.Presentation.View | ||
3706 | 3702 | |
3707 | 3703 | private void DoDragDropFileList_DraggedFileListEntries_CreateEntries(ListView lv, TreeView tvSrcFolder1, TreeView tvSrcFolder2) |
3708 | 3704 | { |
3709 | - List<ListViewItem> selectedItems = new List<ListViewItem>(lv.SelectedItems.Count); | |
3710 | - | |
3711 | - List<string> prohibitedFolders = new List<string>(); | |
3712 | - | |
3713 | - foreach (ListViewItem lvi in lvFileList.SelectedItems) | |
3714 | - { | |
3715 | - FileListEntry entry = FileListEntry.FromTagOf(lvi); | |
3716 | - | |
3717 | - switch (entry.Type) | |
3718 | - { | |
3719 | - case FileListEntry.EntryType.UPWARDS: | |
3720 | - continue; | |
3705 | + FileListEntry[] selectedListEntries = FileListEntry.ToArrayFromTagsOf(lvFileList.SelectedItems); | |
3706 | + string[] prohibitedFolders = selectedListEntries.Where(x => x.IsFolder()).Select(x => x.RelativePath).ToArray(); | |
3721 | 3707 | |
3722 | - case FileListEntry.EntryType.FOLDER: | |
3723 | - prohibitedFolders.Add(entry.RelativePath); | |
3724 | - break; | |
3708 | + TreeNodeStatus[] selectedNodeStatuses = TreeNodeStatus.ToArrayFromTagsOf(tvSrcFolder1.SelectedNode, tvSrcFolder2.SelectedNode); | |
3725 | 3709 | |
3726 | - case FileListEntry.EntryType.FILE: | |
3727 | - break; | |
3728 | - | |
3729 | - default: | |
3730 | - case FileListEntry.EntryType.INVALID: | |
3731 | - continue; | |
3732 | - } | |
3733 | - | |
3734 | - selectedItems.Add(lvi); | |
3735 | - } | |
3736 | - | |
3737 | - //ListViewHelper.DeselectAllItems(lv); | |
3738 | - | |
3739 | - TreeNode[] selectedNodes = new TreeNode[] { tvSrcFolder1.SelectedNode, tvSrcFolder2.SelectedNode }; | |
3740 | - | |
3741 | - DraggedFileListEntries = new DraggedFileListEntriesHolder(selectedItems, selectedNodes, prohibitedFolders, GetCurrentRelativePath()); | |
3710 | + DraggedFileListEntries = new DraggedFileListEntriesHolder(selectedListEntries, selectedNodeStatuses, prohibitedFolders, GetCurrentRelativePath()); | |
3742 | 3711 | } |
3743 | 3712 | |
3744 | 3713 | private DragDropEffects DragEnterFileList_DraggedFileListEntries(DraggedFileListEntriesHolder holder, int keyState, DragDropEffects allowedEffect, ListView lv, Point p) |
@@ -3747,8 +3716,7 @@ namespace FolderCategorizer.Presentation.View | ||
3747 | 3716 | |
3748 | 3717 | lv.Focus(); |
3749 | 3718 | |
3750 | - return DragOverFileList_DraggedFileListEntries_SwitchEffect(keyState, allowedEffect, | |
3751 | - DragOverFileList_DraggedFileListEntries_EmphasisDstItem(lv, p, holder.ProhibitedDropFolderTopPaths)); | |
3719 | + return DragOverFileList_DraggedFileListEntries(holder, keyState, allowedEffect, lv, p); | |
3752 | 3720 | } |
3753 | 3721 | |
3754 | 3722 | private void DragEnterFileList_DraggedFileListEntries_EnterDragMode() |
@@ -3758,13 +3726,19 @@ namespace FolderCategorizer.Presentation.View | ||
3758 | 3726 | DisableFileCategorizeBox(); |
3759 | 3727 | } |
3760 | 3728 | |
3729 | + private DragDropEffects DragOverFileList_DraggedFileListEntries_PreSwitchEffect(DragEventArgs e) | |
3730 | + { | |
3731 | + return DragOverCommon_DraggedFileListEntries_SwitchEffect(e.KeyState, e.AllowedEffect, | |
3732 | + DragDropFileList_GetItemAt(lvFileList, new Point(e.X, e.Y)) != null); | |
3733 | + } | |
3734 | + | |
3761 | 3735 | private DragDropEffects DragOverFileList_DraggedFileListEntries(DraggedFileListEntriesHolder holder, int keyState, DragDropEffects allowedEffect, ListView lv, Point p) |
3762 | 3736 | { |
3763 | - return DragOverFileList_DraggedFileListEntries_SwitchEffect(keyState, allowedEffect, | |
3764 | - DragOverFileList_DraggedFileListEntries_EmphasisDstItem(lv, p, holder.ProhibitedDropFolderTopPaths)); | |
3737 | + return DragOverCommon_DraggedFileListEntries_SwitchEffect(keyState, allowedEffect, | |
3738 | + DragOverFileList_DraggedFileListEntries_EmphasisDstItem(lv, p, holder.SrcFolderPaths)); | |
3765 | 3739 | } |
3766 | 3740 | |
3767 | - private static bool DragOverFileList_DraggedFileListEntries_EmphasisDstItem(ListView lv, Point p, List<string> srcPaths) | |
3741 | + private static bool DragOverFileList_DraggedFileListEntries_EmphasisDstItem(ListView lv, Point p, string[] srcFolderPaths) | |
3768 | 3742 | { |
3769 | 3743 | ListViewItem dstItem = DragDropFileList_GetItemAt(lv, p); |
3770 | 3744 |
@@ -3794,7 +3768,7 @@ namespace FolderCategorizer.Presentation.View | ||
3794 | 3768 | break; |
3795 | 3769 | } |
3796 | 3770 | |
3797 | - if (PathHelper.IsDstPathIncludedSrcPathList(dstEntry.RelativePath, srcPaths)) | |
3771 | + if (PathHelper.IsDstPathIncludedSrcPathList(dstEntry.RelativePath, srcFolderPaths)) | |
3798 | 3772 | { |
3799 | 3773 | // invalid dst path |
3800 | 3774 | return false; |
@@ -3805,14 +3779,9 @@ namespace FolderCategorizer.Presentation.View | ||
3805 | 3779 | return true; |
3806 | 3780 | } |
3807 | 3781 | |
3808 | - private static DragDropEffects DragOverFileList_DraggedFileListEntries_SwitchEffect(int keyState, DragDropEffects allowedEffect, bool isValidDropTarget) | |
3809 | - { | |
3810 | - return DragOverCommon_DraggedFileListEntries_SwitchEffect(keyState, allowedEffect, isValidDropTarget); | |
3811 | - } | |
3812 | - | |
3813 | 3782 | private void DragLeaveFileList_DraggedFileListEntries(DraggedFileListEntriesHolder holder) |
3814 | 3783 | { |
3815 | - DragLeaveFileList_DraggedFileListEntries_RestoreSelectedItems(holder.SelectedFileListViewItems); | |
3784 | + DragLeaveFileList_DraggedFileListEntries_RestoreSelectedItems(holder.SelectedListEntries); | |
3816 | 3785 | |
3817 | 3786 | DragLeaveCommon_DraggedFileListEntries_LeaveDragMode(); |
3818 | 3787 | } |
@@ -3844,9 +3813,9 @@ namespace FolderCategorizer.Presentation.View | ||
3844 | 3813 | |
3845 | 3814 | private void DragDropFileList_DraggedFileListEntries(DraggedFileListEntriesHolder holder, ListView lv, Point p, DragDropEffects effect) |
3846 | 3815 | { |
3847 | - List<FileListEntry> srcEntries = holder.DroppedEntries; | |
3816 | + FileListEntry[] srcEntries = holder.DroppedEntries; | |
3848 | 3817 | |
3849 | - DragLeaveFileList_DraggedFileListEntries_RestoreSelectedItems(holder.SelectedFileListViewItems); | |
3818 | + DragLeaveFileList_DraggedFileListEntries_RestoreSelectedItems(holder.SelectedListEntries); | |
3850 | 3819 | |
3851 | 3820 | DragLeaveCommon_DraggedFileListEntries_LeaveDragMode(); |
3852 | 3821 |
@@ -3921,7 +3890,7 @@ namespace FolderCategorizer.Presentation.View | ||
3921 | 3890 | } |
3922 | 3891 | |
3923 | 3892 | private FileSystemOperationResult DragDropCommon_DraggedFileListEntries( |
3924 | - string dstRelativePath, string srcRefreshPath, List<FileListEntry> srcEntries, DragDropEffects effect) | |
3893 | + string dstRelativePath, string srcRefreshPath, FileListEntry[] srcEntries, DragDropEffects effect) | |
3925 | 3894 | { |
3926 | 3895 | string srcTopPath1 = IsSrcFolder1Enabled ? txtSrcFolder1.Text : string.Empty; |
3927 | 3896 | string srcTopPath2 = IsSrcFolder2Enabled ? txtSrcFolder2.Text : string.Empty; |
@@ -3945,18 +3914,18 @@ namespace FolderCategorizer.Presentation.View | ||
3945 | 3914 | } |
3946 | 3915 | |
3947 | 3916 | private FileSystemOperationResult DragDropCommon_DraggedFileListEntries( |
3948 | - string dstFullPath1, string dstFullPath2, string srcTopPath1, string srcTopPath2, List<FileListEntry> srcEntries, | |
3917 | + string dstFullPath1, string dstFullPath2, string srcTopPath1, string srcTopPath2, FileListEntry[] srcEntries, | |
3949 | 3918 | string dstRefreshPath, string srcRefreshPath, DragDropEffects effect) |
3950 | 3919 | { |
3951 | 3920 | switch (DragDropCommon_SwitchEffect(effect)) |
3952 | 3921 | { |
3953 | 3922 | case DragDropEffects.Copy: |
3954 | 3923 | return DoFileSystemOperation(new FileSystemCopyOperationRequest( |
3955 | - this, dstFullPath1, dstFullPath2, srcTopPath1, srcTopPath2, srcEntries, dstRefreshPath, srcRefreshPath)); | |
3924 | + this, dstFullPath1, dstFullPath2, srcTopPath1, srcTopPath2, srcEntries.ToList(), dstRefreshPath, srcRefreshPath)); | |
3956 | 3925 | |
3957 | 3926 | case DragDropEffects.Move: |
3958 | 3927 | return DoFileSystemOperation(new FileSystemMoveOperationRequest( |
3959 | - this, dstFullPath1, dstFullPath2, srcTopPath1, srcTopPath2, srcEntries, dstRefreshPath, srcRefreshPath)); | |
3928 | + this, dstFullPath1, dstFullPath2, srcTopPath1, srcTopPath2, srcEntries.ToList(), dstRefreshPath, srcRefreshPath)); | |
3960 | 3929 | |
3961 | 3930 | default: |
3962 | 3931 | return new FileSystemOperationResult(null).Abort(); |
@@ -4250,7 +4219,7 @@ namespace FolderCategorizer.Presentation.View | ||
4250 | 4219 | return; |
4251 | 4220 | } |
4252 | 4221 | |
4253 | - List<FileListEntry> entries = CreateSelectedSrcEntries(); | |
4222 | + List<FileListEntry> entries = FileListEntry.ToListFromTagsOf(lvFileList.SelectedItems); | |
4254 | 4223 | |
4255 | 4224 | if (entries.Count == 0) |
4256 | 4225 | { |
@@ -4345,7 +4314,7 @@ namespace FolderCategorizer.Presentation.View | ||
4345 | 4314 | |
4346 | 4315 | private void btnCreateNewFolderAndMove_Click(object sender, EventArgs e) |
4347 | 4316 | { |
4348 | - List<FileListEntry> srcEntries = CreateSelectedSrcEntries(); | |
4317 | + List<FileListEntry> srcEntries = FileListEntry.ToListFromTagsOf(lvFileList.SelectedItems); | |
4349 | 4318 | |
4350 | 4319 | if (srcEntries.Count == 0) |
4351 | 4320 | { |
@@ -4471,7 +4440,7 @@ namespace FolderCategorizer.Presentation.View | ||
4471 | 4440 | |
4472 | 4441 | private void DeleteFileToolStripMenuItem_Click(object sender, EventArgs e) |
4473 | 4442 | { |
4474 | - List<FileListEntry> entries = CreateSelectedSrcEntries(); | |
4443 | + List<FileListEntry> entries = FileListEntry.ToListFromTagsOf(lvFileList.SelectedItems); | |
4475 | 4444 | |
4476 | 4445 | if (entries.Count == 0) |
4477 | 4446 | { |
@@ -4559,7 +4528,7 @@ namespace FolderCategorizer.Presentation.View | ||
4559 | 4528 | |
4560 | 4529 | private void OverwriteCreationTimeToolStripMenuItem_Click(object sender, EventArgs e) |
4561 | 4530 | { |
4562 | - List<FileListEntry> entries = CreateSelectedSrcEntries(); | |
4531 | + List<FileListEntry> entries = FileListEntry.ToListFromTagsOf(lvFileList.SelectedItems); | |
4563 | 4532 | |
4564 | 4533 | if (entries.Count == 0) |
4565 | 4534 | { |
@@ -4575,7 +4544,7 @@ namespace FolderCategorizer.Presentation.View | ||
4575 | 4544 | |
4576 | 4545 | private void OverwriteLastWriteTimeToolStripMenuItem_Click(object sender, EventArgs e) |
4577 | 4546 | { |
4578 | - List<FileListEntry> entries = CreateSelectedSrcEntries(); | |
4547 | + List<FileListEntry> entries = FileListEntry.ToListFromTagsOf(lvFileList.SelectedItems); | |
4579 | 4548 | |
4580 | 4549 | if (entries.Count == 0) |
4581 | 4550 | { |
@@ -4591,7 +4560,7 @@ namespace FolderCategorizer.Presentation.View | ||
4591 | 4560 | |
4592 | 4561 | private void ExchangeCreationAndLastWriteTimeToolStripMenuItem_Click(object sender, EventArgs e) |
4593 | 4562 | { |
4594 | - List<FileListEntry> entries = CreateSelectedSrcEntries(); | |
4563 | + List<FileListEntry> entries = FileListEntry.ToListFromTagsOf(lvFileList.SelectedItems); | |
4595 | 4564 | |
4596 | 4565 | if (entries.Count == 0) |
4597 | 4566 | { |
@@ -4609,7 +4578,7 @@ namespace FolderCategorizer.Presentation.View | ||
4609 | 4578 | { |
4610 | 4579 | List<FileListEntry> entries = new List<FileListEntry>(); |
4611 | 4580 | |
4612 | - entries.AddRange(CreateSelectedSrcEntries().Where((x) => x.Type == FileListEntry.EntryType.FOLDER)); | |
4581 | + entries.AddRange(FileListEntry.ToListFromTagsOf(lvFileList.SelectedItems).Where((x) => x.Type == FileListEntry.EntryType.FOLDER)); | |
4613 | 4582 | |
4614 | 4583 | if (entries.Count == 0) |
4615 | 4584 | { |
@@ -4736,7 +4705,7 @@ namespace FolderCategorizer.Presentation.View | ||
4736 | 4705 | |
4737 | 4706 | private void lvFileList_ItemDrag(object sender, ItemDragEventArgs e) |
4738 | 4707 | { |
4739 | - Logger.Info("lvFileList_ItemDrag"); | |
4708 | + //Logger.Info("lvFileList_ItemDrag"); | |
4740 | 4709 | |
4741 | 4710 | if (e.Button == MouseButtons.Left) |
4742 | 4711 | { |
@@ -4744,6 +4713,7 @@ namespace FolderCategorizer.Presentation.View | ||
4744 | 4713 | |
4745 | 4714 | DataObjectEx data = new DataObjectEx(); |
4746 | 4715 | data.SetData(DataFormats.Serializable, true, DraggedFileListEntries); |
4716 | + | |
4747 | 4717 | DragDropEffects res = ShellUtils.DragSource.DoDragDrop( |
4748 | 4718 | data, lvFileList, DragDropEffects.Copy | DragDropEffects.Move, PointToClient(MousePosition)); |
4749 | 4719 |
@@ -4753,45 +4723,47 @@ namespace FolderCategorizer.Presentation.View | ||
4753 | 4723 | |
4754 | 4724 | private void lvFileList_DragEnter(object sender, DragEventArgs e) |
4755 | 4725 | { |
4756 | - Logger.Info("lvFileList_DragEnter"); | |
4726 | + //Logger.Info("lvFileList_DragEnter"); | |
4757 | 4727 | |
4758 | - e.Effect = DragDropEffects.None; | |
4728 | + bool isDataSerializable = e.Data.GetDataPresent(DataFormats.Serializable); | |
4759 | 4729 | |
4760 | - DragDropEffects effect = DragOverFileList_DraggedFileListEntries_SwitchEffect(e.KeyState, e.AllowedEffect, | |
4761 | - DragDropFileList_GetItemAt(lvFileList, new Point(e.X, e.Y)) != null); | |
4730 | + DragDropEffects effect = isDataSerializable ? DragOverFileList_DraggedFileListEntries_PreSwitchEffect(e) : DragDropEffects.None; | |
4762 | 4731 | |
4763 | 4732 | dropHelperFileListView.DragEnter(lvFileList.PointToClient(new Point(e.X, e.Y)), effect, e.Data); |
4764 | 4733 | |
4765 | - if (e.Data.GetDataPresent(DataFormats.Serializable)) | |
4734 | + if (isDataSerializable) | |
4766 | 4735 | { |
4767 | 4736 | e.Effect = DragEnterFileList_DraggedFileListEntries( |
4768 | 4737 | (DraggedFileListEntriesHolder)e.Data.GetData(DataFormats.Serializable), |
4769 | 4738 | e.KeyState, e.AllowedEffect, lvFileList, new Point(e.X, e.Y)); |
4770 | - } | |
4739 | + } | |
4740 | + | |
4741 | + e.Effect = effect; | |
4771 | 4742 | } |
4772 | 4743 | |
4773 | 4744 | private void lvFileList_DragOver(object sender, DragEventArgs e) |
4774 | 4745 | { |
4775 | - Logger.Info("lvFileList_DragOver"); | |
4746 | + //Logger.Info("lvFileList_DragOver"); | |
4776 | 4747 | |
4777 | - e.Effect = DragDropEffects.None; | |
4748 | + bool isDataSerializable = e.Data.GetDataPresent(DataFormats.Serializable); | |
4778 | 4749 | |
4779 | - DragDropEffects effect = DragOverFileList_DraggedFileListEntries_SwitchEffect(e.KeyState, e.AllowedEffect, | |
4780 | - DragDropFileList_GetItemAt(lvFileList, new Point(e.X, e.Y)) != null); | |
4750 | + DragDropEffects effect = isDataSerializable ? DragOverFileList_DraggedFileListEntries_PreSwitchEffect(e) : DragDropEffects.None; | |
4781 | 4751 | |
4782 | 4752 | dropHelperFileListView.DragOver(lvFileList.PointToClient(new Point(e.X, e.Y)), effect); |
4783 | 4753 | |
4784 | - if (e.Data.GetDataPresent(DataFormats.Serializable)) | |
4754 | + if (isDataSerializable) | |
4785 | 4755 | { |
4786 | - e.Effect = DragOverFileList_DraggedFileListEntries( | |
4756 | + effect = DragOverFileList_DraggedFileListEntries( | |
4787 | 4757 | (DraggedFileListEntriesHolder)e.Data.GetData(DataFormats.Serializable, true), |
4788 | 4758 | e.KeyState, e.AllowedEffect, lvFileList, new Point(e.X, e.Y)); |
4789 | 4759 | } |
4760 | + | |
4761 | + e.Effect = effect; | |
4790 | 4762 | } |
4791 | 4763 | |
4792 | 4764 | private void lvFileList_DragLeave(object sender, EventArgs e) |
4793 | 4765 | { |
4794 | - Logger.Info("lvFileList_DragLeave"); | |
4766 | + //Logger.Info("lvFileList_DragLeave"); | |
4795 | 4767 | |
4796 | 4768 | dropHelperFileListView.DragLeave(); |
4797 | 4769 |
@@ -4800,7 +4772,7 @@ namespace FolderCategorizer.Presentation.View | ||
4800 | 4772 | |
4801 | 4773 | private void lvFileList_DragDrop(object sender, DragEventArgs e) |
4802 | 4774 | { |
4803 | - Logger.Info("lvFileList_DragDrop"); | |
4775 | + //Logger.Info("lvFileList_DragDrop"); | |
4804 | 4776 | |
4805 | 4777 | dropHelperFileListView.Drop(PointToClient(MousePosition), e.Effect, e.Data); |
4806 | 4778 |