Add drag and drop from history window

Drag and drop of entries in history list view copies file to drop location.

Closes #1550
This commit is contained in:
campbeb 2017-10-20 18:46:23 -04:00
parent cc6df4560c
commit 0b94f69b0e
2 changed files with 20 additions and 0 deletions

View file

@ -99,6 +99,7 @@ private void InitializeComponent()
this.lvHistory.Name = "lvHistory";
this.lvHistory.UseCompatibleStateImageBehavior = false;
this.lvHistory.View = System.Windows.Forms.View.Details;
this.lvHistory.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.lvHistory_ItemDrag);
this.lvHistory.ItemSelectionChanged += new System.Windows.Forms.ListViewItemSelectionChangedEventHandler(this.lvHistory_ItemSelectionChanged);
this.lvHistory.KeyDown += new System.Windows.Forms.KeyEventHandler(this.lvHistory_KeyDown);
this.lvHistory.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.lvHistory_MouseDoubleClick);

View file

@ -27,6 +27,7 @@
using ShareX.HistoryLib.Properties;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
@ -395,6 +396,24 @@ private void lvHistory_KeyDown(object sender, KeyEventArgs e)
e.Handled = true;
}
private void lvHistory_ItemDrag(object sender, ItemDragEventArgs e)
{
List<string> selection = new List<string>();
foreach (ListViewItem item in lvHistory.SelectedItems)
{
HistoryItem hi = (HistoryItem)item.Tag;
if (File.Exists(hi.Filepath))
selection.Add(hi.Filepath);
}
if (selection.Count == 0)
return;
DataObject data = new DataObject(DataFormats.FileDrop, selection.ToArray());
DoDragDrop(data, DragDropEffects.Copy);
}
private void txtFilenameFilter_TextChanged(object sender, EventArgs e)
{
cbFilenameFilter.Checked = txtFilenameFilter.TextLength > 0;