diff --git a/src/MicroStationTagExplorer/MainWindow.xaml b/src/MicroStationTagExplorer/MainWindow.xaml index 0219859..0efbb17 100644 --- a/src/MicroStationTagExplorer/MainWindow.xaml +++ b/src/MicroStationTagExplorer/MainWindow.xaml @@ -8,7 +8,8 @@ Title="MicroStation Tag Explorer" Height="650" Width="1000" WindowStartupLocation="CenterScreen" WindowState="Normal" UseLayoutRounding="True" TextOptions.TextFormattingMode="Display" SnapsToDevicePixels="True" - PreviewKeyDown="Window_PreviewKeyDown"> + PreviewKeyDown="Window_PreviewKeyDown" + AllowDrop="True" Drop="Window_Drop" DragEnter="Window_DragEnter"> diff --git a/src/MicroStationTagExplorer/MainWindow.xaml.cs b/src/MicroStationTagExplorer/MainWindow.xaml.cs index b16063c..20cfec0 100644 --- a/src/MicroStationTagExplorer/MainWindow.xaml.cs +++ b/src/MicroStationTagExplorer/MainWindow.xaml.cs @@ -201,6 +201,65 @@ namespace MicroStationTagExplorer } } + private void Window_Drop(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(DataFormats.FileDrop)) + { + var data = e.Data.GetData(DataFormats.FileDrop); + if (data != null && data is string[]) + { + IList files = null; + if (DataGridFiles.DataContext != null) + { + files = DataGridFiles.DataContext as IList; + } + else + { + files = new ObservableCollection(); + DataGridFiles.DataContext = files; + } + + var droppedFiles = data as string[]; + foreach (var droppedFile in droppedFiles) + { + System.IO.FileAttributes attributes = System.IO.File.GetAttributes(droppedFile); + if (attributes.HasFlag(System.IO.FileAttributes.Directory)) + { + var allFiles = System.IO.Directory.EnumerateFiles(droppedFile, "*.*", System.IO.SearchOption.AllDirectories) + .Where(s => s.EndsWith(".dwg") || s.EndsWith(".dgn")); ; + foreach (var allFile in allFiles) + { + var file = new File() + { + Path = allFile + }; + files.Add(file); + } + } + else + { + if (droppedFile.EndsWith(".dwg") || droppedFile.EndsWith(".dgn")) + { + var file = new File() + { + Path = droppedFile + }; + files.Add(file); + } + } + } + } + } + } + + private void Window_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(DataFormats.FileDrop)) + { + e.Effects = DragDropEffects.All; + } + } + private void FileAddFiles_Click(object sender, RoutedEventArgs e) { AddFiles();