Added: drag-drop file in folder support

This commit is contained in:
Ray 2020-11-14 15:58:10 +00:00
parent fdf3ccbc1d
commit eb334fe00c
2 changed files with 130 additions and 46 deletions

View File

@ -24,6 +24,7 @@ namespace AppLauncher.Windows.Forms
this.BackColor = Color.FromArgb(250, 250, 250); this.BackColor = Color.FromArgb(250, 250, 250);
this.ContextMenuStrip = contextMenuStrip1; this.ContextMenuStrip = contextMenuStrip1;
this.DoubleBuffered = true; this.DoubleBuffered = true;
this.AllowDrop = true;
label1.ForeColor = Color.FromArgb(99, 105, 119); label1.ForeColor = Color.FromArgb(99, 105, 119);
label1.Font = new Font(this.Font.FontFamily, 8.25F); label1.Font = new Font(this.Font.FontFamily, 8.25F);
@ -76,6 +77,83 @@ namespace AppLauncher.Windows.Forms
} }
} }
protected override void OnDragDrop(DragEventArgs e)
{
string[] fileList = e.Data.GetData(DataFormats.FileDrop) as string[];
if (this.ModelInfo.IsGroup)
{
this.DropFileList(fileList);
this.LoadInfo(this.ModelInfo);
}
else
{
if (this.PanelContainer != null)
{
this.PanelContainer.DropFileList(fileList);
}
}
}
protected override void OnDragOver(DragEventArgs e)
{
base.OnDragDrop(e);
e.Effect = (e.Data.GetDataPresent(DataFormats.FileDrop)) ? DragDropEffects.Link : DragDropEffects.None;
}
public void DropFileList(string[] fileList)
{
if (fileList == null)
{
return;
}
if (fileList.Length <= 0)
{
return;
}
if (string.IsNullOrWhiteSpace(fileList[0]))
{
return;
}
TileModel model = new TileModel()
{
ProcessFilename = fileList[0],
Title = Path.GetFileName(fileList[0])
};
// exe
if (Path.GetExtension(fileList[0]).Equals(".exe", StringComparison.CurrentCultureIgnoreCase))
{
if (File.Exists(fileList[0]))
{
try
{
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(fileList[0]);
if (fvi != null)
{
model.Title = fvi.ProductName;
}
}
catch
{
// do nothing
}
}
if (string.IsNullOrWhiteSpace(model.Title))
{
model.Title = Path.GetFileNameWithoutExtension(fileList[0]);
}
}
this.ModelInfo.Items.Add(model);
}
public void LoadInfo(TileModel model) public void LoadInfo(TileModel model)
{ {
this.modelInfo = model; this.modelInfo = model;

View File

@ -55,53 +55,8 @@ namespace AppLauncher.Windows.Forms
protected override void OnDragDrop(DragEventArgs e) protected override void OnDragDrop(DragEventArgs e)
{ {
string[] fileList = e.Data.GetData(DataFormats.FileDrop) as string[]; string[] fileList = e.Data.GetData(DataFormats.FileDrop) as string[];
if (fileList == null)
{
return;
}
if (fileList.Length <= 0) this.DropFileList(fileList);
{
return;
}
if (string.IsNullOrWhiteSpace(fileList[0]))
{
return;
}
TileModel model = new TileModel()
{
ProcessFilename = fileList[0],
Title = Path.GetFileName(fileList[0])
};
// exe
if (Path.GetExtension(fileList[0]).Equals(".exe", StringComparison.CurrentCultureIgnoreCase))
{
if (File.Exists(fileList[0]))
{
try
{
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(fileList[0]);
if (fvi != null)
{
model.Title = fvi.ProductName;
}
}
catch
{
// do nothing
}
}
if (string.IsNullOrWhiteSpace(model.Title))
{
model.Title = Path.GetFileNameWithoutExtension(fileList[0]);
}
}
this.AddTile(model);
} }
protected override void OnDragOver(DragEventArgs e) protected override void OnDragOver(DragEventArgs e)
@ -180,6 +135,57 @@ namespace AppLauncher.Windows.Forms
public int ExpandedHeight => expandedHeight + this.Padding.Bottom; public int ExpandedHeight => expandedHeight + this.Padding.Bottom;
public void DropFileList(string[] fileList)
{
if (fileList == null)
{
return;
}
if (fileList.Length <= 0)
{
return;
}
if (string.IsNullOrWhiteSpace(fileList[0]))
{
return;
}
TileModel model = new TileModel()
{
ProcessFilename = fileList[0],
Title = Path.GetFileName(fileList[0])
};
// exe
if (Path.GetExtension(fileList[0]).Equals(".exe", StringComparison.CurrentCultureIgnoreCase))
{
if (File.Exists(fileList[0]))
{
try
{
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(fileList[0]);
if (fvi != null)
{
model.Title = fvi.ProductName;
}
}
catch
{
// do nothing
}
}
if (string.IsNullOrWhiteSpace(model.Title))
{
model.Title = Path.GetFileNameWithoutExtension(fileList[0]);
}
}
this.AddTile(model);
}
public TileGroupModel Model public TileGroupModel Model
{ {
get get