Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Import document between pages #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions NAPS2.Core/WinForms/FDesktop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ private IEnumerable<int> SelectedIndices
/// This keeps images from the same source together, even if multiple sources are providing images at the same time.
/// </summary>
/// <returns></returns>
public Action<ScannedImage> ReceiveScannedImage()
public Action<ScannedImage> ReceiveScannedImage(int atIndex=-1)
{
ScannedImage last = null;
return scannedImage =>
Expand All @@ -587,8 +587,8 @@ public Action<ScannedImage> 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)
{
Expand Down Expand Up @@ -989,10 +989,10 @@ private void Import()
}
}

private void ImportFiles(IEnumerable<string> files)
private void ImportFiles(IEnumerable<string> files, int atIndex=-1)
{
var op = operationFactory.Create<ImportOperation>();
if (op.Start(OrderFiles(files), ReceiveScannedImage()))
if (op.Start(OrderFiles(files), ReceiveScannedImage(atIndex)))
{
operationProgress.ShowProgress(op);
}
Expand Down Expand Up @@ -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)
Expand All @@ -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;
}
Expand Down Expand Up @@ -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<ListViewItem>().ToList();
var minY = items.Select(x => x.Bounds.Top).Min();
Expand Down