Skip to content

Commit

Permalink
일괄처리기에 drb 파일 드래그 드롭 시 바로 열리도록 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
daramkun committed Jul 1, 2024
1 parent 402ce19 commit 0401021
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion DaramRenamer.Windows/BatchWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
</StackPanel>
</Grid>

<TreeView Grid.Row="1" x:Name="TreeViewCommands" Margin="0,0,0,8">
<TreeView Grid.Row="1" x:Name="TreeViewCommands" Margin="0,0,0,8"
AllowDrop="True" DragEnter="TreeViewCommands_DragEnter" Drop="TreeViewCommands_Drop">
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="True" />
Expand Down
28 changes: 28 additions & 0 deletions DaramRenamer.Windows/BatchWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,32 @@ private void BatchSave_Click(object sender, RoutedEventArgs e)
rootNode.Serialize(writer);
writer.Flush();
}

private void TreeViewCommands_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effects = DragDropEffects.None;
}

private void TreeViewCommands_Drop(object sender, DragEventArgs e)
{
if (!e.Data.GetDataPresent(DataFormats.FileDrop))
return;

var fileObject = e.Data.GetData(DataFormats.FileDrop);
if (fileObject is string file)
{
using Stream stream = new FileStream(file, FileMode.Open);
using TextReader reader = new StreamReader(stream, Encoding.UTF8, false, -1, true);

rootNode.Deserializer(reader);
}
else if (fileObject is string[] files)
{
using Stream stream = new FileStream(files[0], FileMode.Open);
using TextReader reader = new StreamReader(stream, Encoding.UTF8, false, -1, true);

rootNode.Deserializer(reader);
}
}
}

0 comments on commit 0401021

Please sign in to comment.