diff --git a/Source/Editor/Modules/ContentFindingModule.cs b/Source/Editor/Modules/ContentFindingModule.cs index c2a547bde..647daef2b 100644 --- a/Source/Editor/Modules/ContentFindingModule.cs +++ b/Source/Editor/Modules/ContentFindingModule.cs @@ -45,12 +45,13 @@ namespace FlaxEditor.Modules /// public class ContentFindingModule : EditorModule { - private List _quickActions = new List(); + private List _quickActions; + private ContentFinder _finder; /// /// The content finding context menu. /// - public ContentFinder Finder { get; private set; } + public ContentFinder Finder => _finder ?? (_finder = new ContentFinder()); /// /// Initializes a new instance of the class. @@ -61,22 +62,20 @@ namespace FlaxEditor.Modules { } - /// - public override void OnInit() - { - base.OnInit(); - - Finder = new ContentFinder(); - } - /// public override void OnExit() { - _quickActions.Clear(); - _quickActions = null; + if (_quickActions != null) + { + _quickActions.Clear(); + _quickActions = null; + } - Finder?.Dispose(); - Finder = null; + if (_finder != null) + { + _finder.Dispose(); + _finder = null; + } base.OnExit(); } @@ -87,8 +86,9 @@ namespace FlaxEditor.Modules /// The target control to show finder over it. public void ShowFinder(Control control) { - var position = (control.Size - new Vector2(Finder.Width, 300.0f)) * 0.5f; - Finder.Show(control, position); + var finder = Finder; + var position = (control.Size - new Vector2(finder.Width, 300.0f)) * 0.5f; + finder.Show(control, position); } /// @@ -98,6 +98,8 @@ namespace FlaxEditor.Modules /// The actual action callback. public void AddQuickAction(string name, Action action) { + if (_quickActions == null) + _quickActions = new List(); _quickActions.Add(new QuickAction { Name = name, @@ -112,6 +114,8 @@ namespace FlaxEditor.Modules /// True when it succeed, false if there is no Quick Action with this name. public bool RemoveQuickAction(string name) { + if (_quickActions == null) + return false; foreach (var action in _quickActions) { if (action.Name.Equals(name)) @@ -120,7 +124,6 @@ namespace FlaxEditor.Modules return true; } } - return false; } @@ -183,13 +186,14 @@ namespace FlaxEditor.Modules Profiler.EndEvent(); } + if (_quickActions != null) { Profiler.BeginEvent("QuickActions"); - _quickActions.ForEach(action => + foreach (var action in _quickActions) { if (nameRegex.Match(action.Name).Success && typeRegex.Match("Quick Action").Success) matches.Add(new SearchResult { Name = action.Name, Type = "Quick Action", Item = action }); - }); + } Profiler.EndEvent(); }