mirror of
https://github.com/ShareX/ShareX.git
synced 2024-07-15 19:36:38 +12:00
Support drag n drop file from task thumbnail
This commit is contained in:
parent
7c1ae3488c
commit
7f817082c3
4
ShareX/Controls/TaskPanel.Designer.cs
generated
4
ShareX/Controls/TaskPanel.Designer.cs
generated
|
@ -54,7 +54,6 @@ private void InitializeComponent()
|
||||||
this.pThumbnail.Radius = 5F;
|
this.pThumbnail.Radius = 5F;
|
||||||
this.pThumbnail.Size = new System.Drawing.Size(256, 256);
|
this.pThumbnail.Size = new System.Drawing.Size(256, 256);
|
||||||
this.pThumbnail.TabIndex = 0;
|
this.pThumbnail.TabIndex = 0;
|
||||||
this.pThumbnail.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PbThumbnail_MouseDown);
|
|
||||||
//
|
//
|
||||||
// pbProgress
|
// pbProgress
|
||||||
//
|
//
|
||||||
|
@ -78,7 +77,10 @@ private void InitializeComponent()
|
||||||
this.pbThumbnail.Size = new System.Drawing.Size(246, 246);
|
this.pbThumbnail.Size = new System.Drawing.Size(246, 246);
|
||||||
this.pbThumbnail.TabIndex = 2;
|
this.pbThumbnail.TabIndex = 2;
|
||||||
this.pbThumbnail.TabStop = false;
|
this.pbThumbnail.TabStop = false;
|
||||||
|
this.pbThumbnail.QueryContinueDrag += new System.Windows.Forms.QueryContinueDragEventHandler(this.PbThumbnail_QueryContinueDrag);
|
||||||
this.pbThumbnail.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PbThumbnail_MouseDown);
|
this.pbThumbnail.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PbThumbnail_MouseDown);
|
||||||
|
this.pbThumbnail.MouseMove += new System.Windows.Forms.MouseEventHandler(this.PbThumbnail_MouseMove);
|
||||||
|
this.pbThumbnail.MouseUp += new System.Windows.Forms.MouseEventHandler(this.PbThumbnail_MouseUp);
|
||||||
//
|
//
|
||||||
// lblFilename
|
// lblFilename
|
||||||
//
|
//
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
using ShareX.HelpersLib;
|
using ShareX.HelpersLib;
|
||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.IO;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace ShareX
|
namespace ShareX
|
||||||
|
@ -91,6 +92,8 @@ public bool ProgressVisible
|
||||||
public Size ThumbnailSize { get; private set; }
|
public Size ThumbnailSize { get; private set; }
|
||||||
public string ThumbnailSourceFilePath { get; private set; }
|
public string ThumbnailSourceFilePath { get; private set; }
|
||||||
|
|
||||||
|
private Rectangle dragBoxFromMouseDown;
|
||||||
|
|
||||||
public new event MouseEventHandler MouseDown
|
public new event MouseEventHandler MouseDown
|
||||||
{
|
{
|
||||||
add
|
add
|
||||||
|
@ -149,7 +152,7 @@ public void ChangeThumbnailSize(Size size)
|
||||||
|
|
||||||
public void UpdateFilename()
|
public void UpdateFilename()
|
||||||
{
|
{
|
||||||
Filename = Task.Info.FileName;
|
Filename = Task.Info?.FileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateThumbnail()
|
public void UpdateThumbnail()
|
||||||
|
@ -201,9 +204,12 @@ public void UpdateThumbnail()
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateProgress()
|
public void UpdateProgress()
|
||||||
|
{
|
||||||
|
if (Task.Info != null)
|
||||||
{
|
{
|
||||||
Progress = (int)Task.Info.Progress.Percentage;
|
Progress = (int)Task.Info.Progress.Percentage;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void ClearThumbnail()
|
public void ClearThumbnail()
|
||||||
{
|
{
|
||||||
|
@ -220,6 +226,17 @@ public void ClearThumbnail()
|
||||||
|
|
||||||
private void PbThumbnail_MouseDown(object sender, MouseEventArgs e)
|
private void PbThumbnail_MouseDown(object sender, MouseEventArgs e)
|
||||||
{
|
{
|
||||||
|
if (e.Button == MouseButtons.Left)
|
||||||
|
{
|
||||||
|
Size dragSize = SystemInformation.DragSize;
|
||||||
|
dragBoxFromMouseDown = new Rectangle(new Point(e.X - (dragSize.Width / 2), e.Y - (dragSize.Height / 2)), dragSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PbThumbnail_MouseUp(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
dragBoxFromMouseDown = Rectangle.Empty;
|
||||||
|
|
||||||
if (e.Button == MouseButtons.Left && !string.IsNullOrEmpty(ThumbnailSourceFilePath))
|
if (e.Button == MouseButtons.Left && !string.IsNullOrEmpty(ThumbnailSourceFilePath))
|
||||||
{
|
{
|
||||||
pbThumbnail.Enabled = false;
|
pbThumbnail.Enabled = false;
|
||||||
|
@ -227,5 +244,29 @@ private void PbThumbnail_MouseDown(object sender, MouseEventArgs e)
|
||||||
pbThumbnail.Enabled = true;
|
pbThumbnail.Enabled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void PbThumbnail_MouseMove(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Button == MouseButtons.Left && dragBoxFromMouseDown != Rectangle.Empty && !dragBoxFromMouseDown.Contains(e.X, e.Y) &&
|
||||||
|
Task.Info != null && !string.IsNullOrEmpty(Task.Info.FilePath) && File.Exists(Task.Info.FilePath))
|
||||||
|
{
|
||||||
|
IDataObject dataObject = new DataObject(DataFormats.FileDrop, new string[] { Task.Info.FilePath });
|
||||||
|
|
||||||
|
if (dataObject != null)
|
||||||
|
{
|
||||||
|
Program.MainForm.AllowDrop = false;
|
||||||
|
|
||||||
|
DoDragDrop(dataObject, DragDropEffects.Copy | DragDropEffects.Move);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PbThumbnail_QueryContinueDrag(object sender, QueryContinueDragEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Action != DragAction.Continue)
|
||||||
|
{
|
||||||
|
Program.MainForm.AllowDrop = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue