This commit is contained in:
Wiesław Šoltés 2018-06-15 17:02:31 +02:00
Родитель cb436d0505
Коммит d2c73ae328
2 изменённых файлов: 61 добавлений и 1 удалений

Просмотреть файл

@ -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">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>

Просмотреть файл

@ -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<File> files = null;
if (DataGridFiles.DataContext != null)
{
files = DataGridFiles.DataContext as IList<File>;
}
else
{
files = new ObservableCollection<File>();
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();