From eb334fe00c65d16d00b398a33234575b3ff3992a Mon Sep 17 00:00:00 2001 From: Ray Date: Sat, 14 Nov 2020 15:58:10 +0000 Subject: [PATCH] Added: drag-drop file in folder support --- Windows/Forms/Tile/TTilePanel.cs | 78 ++++++++++++++++++++ Windows/Forms/Tile/TTilePanelLayout.cs | 98 ++++++++++++++------------ 2 files changed, 130 insertions(+), 46 deletions(-) diff --git a/Windows/Forms/Tile/TTilePanel.cs b/Windows/Forms/Tile/TTilePanel.cs index 00e144c..7b3e45a 100644 --- a/Windows/Forms/Tile/TTilePanel.cs +++ b/Windows/Forms/Tile/TTilePanel.cs @@ -24,6 +24,7 @@ namespace AppLauncher.Windows.Forms this.BackColor = Color.FromArgb(250, 250, 250); this.ContextMenuStrip = contextMenuStrip1; this.DoubleBuffered = true; + this.AllowDrop = true; label1.ForeColor = Color.FromArgb(99, 105, 119); 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) { this.modelInfo = model; diff --git a/Windows/Forms/Tile/TTilePanelLayout.cs b/Windows/Forms/Tile/TTilePanelLayout.cs index 53e62a8..98c9125 100644 --- a/Windows/Forms/Tile/TTilePanelLayout.cs +++ b/Windows/Forms/Tile/TTilePanelLayout.cs @@ -55,53 +55,8 @@ namespace AppLauncher.Windows.Forms protected override void OnDragDrop(DragEventArgs e) { string[] fileList = e.Data.GetData(DataFormats.FileDrop) as string[]; - 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); + this.DropFileList(fileList); } protected override void OnDragOver(DragEventArgs e) @@ -180,6 +135,57 @@ namespace AppLauncher.Windows.Forms 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 { get