Skip to content

Commit 9a6c6cc

Browse files
committed
add drag n drop support into Input File textbox (drag file or folder from explorer)
1 parent 162f144 commit 9a6c6cc

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

MainWindow.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
Title="PointCloudConverter" Height="640" Width="907" Background="#FF252222" Closing="Window_Closing" Loaded="Window_Loaded">
99
<Grid Margin="0,0,2,0">
1010
<Button x:Name="btnBrowseInput" Content="..." HorizontalAlignment="Left" Margin="636,48,0,0" VerticalAlignment="Top" Width="32" Height="23" Click="btnBrowseInput_Click" ToolTip="Browse for input file"/>
11-
<TextBox x:Name="txtInputFile" HorizontalAlignment="Left" Height="23" Margin="20,48,0,0" VerticalAlignment="Top" Width="611"/>
11+
<TextBox x:Name="txtInputFile" HorizontalAlignment="Left" AllowDrop="True" Height="23" Margin="20,48,0,0" VerticalAlignment="Top" Width="611" PreviewDrop="txtInputFile_Drop" PreviewDragOver="txtInputFile_DragEnter"/>
1212
<Label x:Name="label" Content="Input file or folder:&#xD;&#xA;" HorizontalAlignment="Left" Margin="20,22,0,0" VerticalAlignment="Top" Foreground="{DynamicResource MainText}" Height="26"/>
1313
<Button x:Name="btnConvert" Content="Convert" HorizontalAlignment="Left" Margin="516,441,0,0" VerticalAlignment="Top" Width="371" Height="58" Click="btnConvert_Click"/>
1414
<Button x:Name="btnBrowseOutput" Content="..." HorizontalAlignment="Left" Margin="636,114,0,0" VerticalAlignment="Top" Width="32" Height="23" Click="btnBrowseOutput_Click" ToolTip="Browse for output file"/>
@@ -29,7 +29,7 @@
2929
<StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" Orientation="Horizontal"/>
3030
<StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" Orientation="Horizontal">
3131
<CheckBox x:Name="chkUseScale" Content="Scale:" HorizontalAlignment="Left" VerticalAlignment="Top" Foreground="{DynamicResource MainText}" ToolTip="Scale XYZ values (You need meters inside Unity)"/>
32-
<TextBox x:Name="txtScale" HorizontalAlignment="Left" Margin="0" TextWrapping="Wrap" VerticalAlignment="Top" Width="40" Text="0.1"/>
32+
<TextBox x:Name="txtScale" HorizontalAlignment="Left" Margin="0" TextWrapping="Wrap" VerticalAlignment="Top" Width="40" Text="0.1" />
3333
</StackPanel>
3434
<CheckBox x:Name="chkSwapYZ" Content="Swap Y and Z" HorizontalAlignment="Left" VerticalAlignment="Top" Foreground="{DynamicResource MainText}" IsChecked="True" ToolTip="Swaps Z and Y values, since unity Y is up"/>
3535
<CheckBox x:Name="chkInvertX" Content="Invert X" HorizontalAlignment="Left" VerticalAlignment="Top" Foreground="{DynamicResource MainText}" ToolTip="Inverts X value (x=-x)"/>

MainWindow.xaml.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,5 +637,31 @@ private void chkImportRGB_Unchecked(object sender, RoutedEventArgs e)
637637
Properties.Settings.Default.importIntensity = true;
638638
Properties.Settings.Default.Save();
639639
}
640+
641+
private void txtInputFile_DragEnter(object sender, DragEventArgs e)
642+
{
643+
if (e.Data.GetDataPresent(DataFormats.FileDrop))
644+
{
645+
e.Effects = DragDropEffects.Copy;
646+
}
647+
else
648+
{
649+
e.Effects = DragDropEffects.None;
650+
}
651+
e.Handled = true;
652+
}
653+
654+
private void txtInputFile_Drop(object sender, DragEventArgs e)
655+
{
656+
if (e.Data.GetDataPresent(DataFormats.FileDrop))
657+
{
658+
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
659+
if (files.Length > 0)
660+
{
661+
txtInputFile.Text = files[0];
662+
}
663+
}
664+
}
665+
640666
} // class
641667
} // namespace

0 commit comments

Comments
 (0)