From b9034d6c32e84bd5b032de7234430c120bd213fe Mon Sep 17 00:00:00 2001 From: bruxo Date: Tue, 21 May 2019 09:51:07 -0300 Subject: [PATCH] [Feature] Import document between pages Import document using drag&drop between pages Ticket #592, item 1 --- NAPS2.Core/WinForms/FDesktop.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/NAPS2.Core/WinForms/FDesktop.cs b/NAPS2.Core/WinForms/FDesktop.cs index e0a36fd6f3..0d5a098800 100644 --- a/NAPS2.Core/WinForms/FDesktop.cs +++ b/NAPS2.Core/WinForms/FDesktop.cs @@ -578,7 +578,7 @@ private IEnumerable SelectedIndices /// This keeps images from the same source together, even if multiple sources are providing images at the same time. /// /// - public Action ReceiveScannedImage() + public Action ReceiveScannedImage(int atIndex=-1) { ScannedImage last = null; return scannedImage => @@ -587,8 +587,8 @@ public Action ReceiveScannedImage() { lock (imageList) { - // Default to the end of the list - int index = imageList.Images.Count; + // Default to the end of the list or at index + int index = atIndex >= 0 ? atIndex : imageList.Images.Count; // Use the index after the last image from the same source (if it exists) if (last != null) { @@ -989,10 +989,10 @@ private void Import() } } - private void ImportFiles(IEnumerable files) + private void ImportFiles(IEnumerable files, int atIndex=-1) { var op = operationFactory.Create(); - if (op.Start(OrderFiles(files), ReceiveScannedImage())) + if (op.Start(OrderFiles(files), ReceiveScannedImage(atIndex))) { operationProgress.ShowProgress(op); } @@ -1971,7 +1971,7 @@ private void thumbnailList1_DragEnter(object sender, DragEventArgs e) } else if (e.Data.GetDataPresent(DataFormats.FileDrop)) { - e.Effect = DragDropEffects.Copy; + e.Effect = DragDropEffects.Move; } } catch (Exception ex) @@ -1998,7 +1998,8 @@ private void thumbnailList1_DragDrop(object sender, DragEventArgs e) else if (e.Data.GetDataPresent(DataFormats.FileDrop)) { var data = (string[])e.Data.GetData(DataFormats.FileDrop); - ImportFiles(data); + var atIndex = GetDragIndex(e); + ImportFiles(data, atIndex); } thumbnailList1.InsertionMark.Index = -1; } @@ -2044,7 +2045,7 @@ private int GetDragIndex(DragEventArgs e) { Point cp = thumbnailList1.PointToClient(new Point(e.X, e.Y)); ListViewItem dragToItem = thumbnailList1.GetItemAt(cp.X, cp.Y); - if (dragToItem == null) + if (dragToItem == null && thumbnailList1.Items.Count > 0) { var items = thumbnailList1.Items.Cast().ToList(); var minY = items.Select(x => x.Bounds.Top).Min();