Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
donkeyProgramming committed Dec 20, 2024
1 parent 17b4e71 commit 6b041b7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
38 changes: 31 additions & 7 deletions Editors/KitbasherEditor/Core/SceneExplorer/MultiSelectTreeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,36 @@ public SelectionManager SelectionManager
set { SetValue(SelectionManagerProperty, value); }
}

public static readonly DependencyProperty EventHubProperty = DependencyProperty.Register(nameof(EventHub), typeof(IEventHub), typeof(MultiSelectTreeView), new FrameworkPropertyMetadata(AttemptRegistration));
public static readonly DependencyProperty SceneManagerProperty = DependencyProperty.Register(nameof(SceneManager), typeof(SceneManager), typeof(MultiSelectTreeView), new FrameworkPropertyMetadata(AttemptRegistration));
public static readonly DependencyProperty EventHubProperty = DependencyProperty.Register(nameof(EventHub), typeof(IEventHub), typeof(MultiSelectTreeView), new FrameworkPropertyMetadata(AttemptRegistrationEventHub));
public static readonly DependencyProperty SceneManagerProperty = DependencyProperty.Register(nameof(SceneManager), typeof(SceneManager), typeof(MultiSelectTreeView), new FrameworkPropertyMetadata(AttemptRegistrationSceneManager));
public static readonly DependencyProperty SelectionManagerProperty = DependencyProperty.Register(nameof(SelectionManager), typeof(SelectionManager), typeof(MultiSelectTreeView));

private static void AttemptRegistration(DependencyObject d, DependencyPropertyChangedEventArgs e)
private static void AttemptRegistrationSceneManager(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
(d as MultiSelectTreeView)?.Register();
}

private static void AttemptRegistrationEventHub(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var treeView = d as MultiSelectTreeView;
if (treeView == null)
return;

treeView.OnRegisterEventHub((IEventHub)e.OldValue, (IEventHub)e.NewValue);
}

public MultiSelectTreeView()
{
SelectedItemChanged += MyTreeView_SelectedItemChanged;
Focusable = true;
PreviewMouseDoubleClick += MultiSelectTreeView_PreviewMouseDoubleClick;
PreviewMouseRightButtonDown += MultiSelectTreeView_PreviewMouseRightButtonDown;
ItemsSource = _nodes;
Unloaded += MultiSelectTreeView_Unloaded;
}

private void MultiSelectTreeView_Unloaded(object sender, RoutedEventArgs e) => Dispose();

private void MultiSelectTreeView_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
var treeViewItem = ItemContainerGeneratorHelper.VisualUpwardSearch(e.OriginalSource as DependencyObject);
Expand All @@ -86,16 +98,27 @@ private void MultiSelectTreeView_PreviewMouseRightButtonDown(object sender, Mous
}
}

public void OnRegisterEventHub(IEventHub oldValue, IEventHub newValue)
{
if (newValue == null && oldValue != null)
oldValue.UnRegister(this);

if (newValue != null)
{
EventHub.Register<SelectionChangedEvent>(this, SelectionEventHandler);
EventHub.Register<SceneObjectAddedEvent>(this, x => RebuildTree());
EventHub.Register<SceneObjectRemovedEvent>(this, x => RebuildTree());
}

Register();
}


public void Register()
{
if (SceneManager == null || EventHub == null)
return;

EventHub.Register<SelectionChangedEvent>(this, SelectionEventHandler);
EventHub.Register<SceneObjectAddedEvent>(this, x => RebuildTree());
EventHub.Register<SceneObjectRemovedEvent>(this, x => RebuildTree());

RebuildTree();
}

Expand Down Expand Up @@ -299,6 +322,7 @@ public void Dispose()
SelectedItemChanged -= MyTreeView_SelectedItemChanged;
PreviewMouseDoubleClick -= MultiSelectTreeView_PreviewMouseDoubleClick;
PreviewMouseRightButtonDown -= MultiSelectTreeView_PreviewMouseRightButtonDown;
Unloaded -= MultiSelectTreeView_Unloaded;
}

private static bool IsCtrlPressed
Expand Down
2 changes: 1 addition & 1 deletion Shared/SharedCore/Services/VersionChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Shared.Core.Services
public class VersionChecker
{
private static readonly string GitHubLink = @"https://github.com/donkeyProgramming/TheAssetEditor/releases/latest";
public static string CurrentVersion { get => "0.56"; }
public static string CurrentVersion { get => "0.57"; }

public static void CheckVersion()
{
Expand Down

0 comments on commit 6b041b7

Please sign in to comment.