Skip to content

Commit

Permalink
Merge pull request #988 from VladiStep/mmbAssets
Browse files Browse the repository at this point in the history
Open asset in a new tab with MMB.
  • Loading branch information
Grossley authored Jun 20, 2022
2 parents 4c403c1 + 586c946 commit 16fd4f5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
9 changes: 6 additions & 3 deletions UndertaleModTool/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,12 @@
</Button>
<TextBox Grid.Column="1" Name="SearchBox" ToolTip="Search" TextChanged="SearchBox_TextChanged"/>
</Grid>
<TreeView Grid.Column="0" Grid.Row="1" Margin="5" DataContext="{Binding Data}" SelectedItemChanged="TreeView_SelectedItemChanged" MouseDoubleClick="MainTree_MouseDoubleClick" KeyUp="MainTree_KeyUp" AllowDrop="True" Name="MainTree" KeyDown="MainTree_KeyDown" PreviewMouseRightButtonDown="MainTree_PreviewMouseRightButtonDown"
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode="Recycling">
<TreeView Grid.Column="0" Grid.Row="1" Name="MainTree" Margin="5" DataContext="{Binding Data}" AllowDrop="True"
SelectedItemChanged="TreeView_SelectedItemChanged"
MouseDoubleClick="MainTree_MouseDoubleClick" PreviewMouseRightButtonDown="MainTree_PreviewMouseRightButtonDown" MouseDown="MainTree_MouseDown"
KeyUp="MainTree_KeyUp" KeyDown="MainTree_KeyDown"
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode="Recycling">
<TreeView.Resources>
<ContextMenu x:Key="AddMenu">
<MenuItem Header="Add" Click="MenuItem_Add_Click"/>
Expand Down
27 changes: 26 additions & 1 deletion UndertaleModTool/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,7 @@ private void TreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEv
{
if (e.NewValue is TreeViewItem)
{
string item = (e.NewValue as TreeViewItem)?.Header?.ToString();
string item = (e.NewValue as TreeViewItem).Header?.ToString();

if (item == "Data")
{
Expand Down Expand Up @@ -1567,7 +1567,32 @@ private void MainTree_MouseDoubleClick(object sender, MouseButtonEventArgs e)

OpenInTab(Highlighted);
}
private void MainTree_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ButtonState == MouseButtonState.Pressed && e.ChangedButton == System.Windows.Input.MouseButton.Middle)
{
// Gets the clicked visual element by the mouse position (relative to "MainTree").
// This is used instead of "VisualTreeHelper.HitTest()" because that ignores the visibility of elements,
// which led to "ghost" hits on empty space.
DependencyObject obj = MainTree.InputHitTest(e.GetPosition(MainTree)) as DependencyObject;
if (obj is not TextBlock)
return;

TreeViewItem item = GetNearestParent<TreeViewItem>(obj);
if (item is null)
return;

item.IsSelected = true;

if (item.DataContext is not UndertaleResource)
return;

if (Highlighted is UndertaleRoom room && Selected is not UndertaleRoom)
UndertaleRoomEditor.CheckAndRearrangeLayers(room);

OpenInTab(Highlighted, true);
}
}
private void MainTree_KeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return)
Expand Down

0 comments on commit 16fd4f5

Please sign in to comment.