Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open asset in a new tab with MMB. #988

Merged
merged 2 commits into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions UndertaleModTool/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,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;
VladiStep marked this conversation as resolved.
Show resolved Hide resolved

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