From aa08125e43ad592fa07a8b66ac22d7853d7ff5bf Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Thu, 17 Oct 2019 07:35:27 +1100 Subject: [PATCH] fix directory drag drop --- .../Views/ProgramSetting.xaml.cs | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/Plugins/Wox.Plugin.Program/Views/ProgramSetting.xaml.cs b/Plugins/Wox.Plugin.Program/Views/ProgramSetting.xaml.cs index 51f277062d..9950adf3c0 100644 --- a/Plugins/Wox.Plugin.Program/Views/ProgramSetting.xaml.cs +++ b/Plugins/Wox.Plugin.Program/Views/ProgramSetting.xaml.cs @@ -116,22 +116,34 @@ namespace Wox.Plugin.Program.Views private void programSourceView_Drop(object sender, DragEventArgs e) { - string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); + var directories = (string[])e.Data.GetData(DataFormats.FileDrop); - if (files != null && files.Length > 0) + var directoriesToAdd = new List(); + + if (directories != null && directories.Length > 0) { - foreach (string s in files) + foreach (string directory in directories) { - if (Directory.Exists(s)) + if (Directory.Exists(directory) && !ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == directory)) { - _settings.ProgramSources.Add(new Settings.ProgramSource + var source = new ProgramSource { - Location = s - }); + Location = directory, + UniqueIdentifier = directory + }; - ReIndexing(); + directoriesToAdd.Add(source); } } + + if (directoriesToAdd.Count() > 0) + { + directoriesToAdd.ForEach(x => _settings.ProgramSources.Add(x)); + directoriesToAdd.ForEach(x => ProgramSettingDisplayList.Add(x)); + + programSourceView.Items.Refresh(); + ReIndexing(); + } } }