From e8b867430f095aa41d7fb752e61a6c5c6892c852 Mon Sep 17 00:00:00 2001 From: thallard Date: Thu, 5 Aug 2021 23:38:08 +0200 Subject: [PATCH] Remplace string variable by enum --- Source/Editor/Content/GUI/ContentView.cs | 20 ++++++++++++++++++-- Source/Editor/Windows/ContentWindow.cs | 10 ++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Source/Editor/Content/GUI/ContentView.cs b/Source/Editor/Content/GUI/ContentView.cs index 32b5dc6c3..0401e14a6 100644 --- a/Source/Editor/Content/GUI/ContentView.cs +++ b/Source/Editor/Content/GUI/ContentView.cs @@ -27,6 +27,22 @@ namespace FlaxEditor.Content.GUI List, } + /// + /// The method sort for items. + /// + public enum MethodSort + { + /// + /// The classic alphabetic sort method (A-Z). + /// + AlphabeticOrder, + + /// + /// The reverse alphabetic sort method (Z-A). + /// + AlphabeticReverse + } + /// /// Main control for used to present collection of . /// @@ -220,7 +236,7 @@ namespace FlaxEditor.Content.GUI /// The items to show. /// The sort method for items. /// If set to true items will be added to the current selection. Otherwise selection will be cleared before. - public void ShowItems(List items, string sortMethod, bool additive = false) + public void ShowItems(List items, MethodSort sortMethod, bool additive = false) { if (items == null) throw new ArgumentNullException(); @@ -253,7 +269,7 @@ namespace FlaxEditor.Content.GUI // Sort items depending on sortMethod parameter _children.Sort(((control, control1) => { - if (sortMethod == "Alphabetic Reverse") + if (sortMethod == MethodSort.AlphabeticReverse) { if (control.CompareTo(control1) > 0) { diff --git a/Source/Editor/Windows/ContentWindow.cs b/Source/Editor/Windows/ContentWindow.cs index 8ad9f6256..9985393ef 100644 --- a/Source/Editor/Windows/ContentWindow.cs +++ b/Source/Editor/Windows/ContentWindow.cs @@ -39,7 +39,7 @@ namespace FlaxEditor.Windows private TextBox _foldersSearchBox; private TextBox _itemsSearchBox; private ViewDropdown _viewDropdown; - private string _sortBy = "Alphabetic Order"; + private MethodSort _sortBy; private RootContentTreeNode _root; @@ -237,7 +237,13 @@ namespace FlaxEditor.Windows private void OnSortByButtonClicked(ContextMenuButton button) { - Editor.Windows.ContentWin._sortBy = button.Text; + switch (button.Text) + { + case "Alphabetic Order": Editor.Windows.ContentWin._sortBy = MethodSort.AlphabeticOrder; + break; + case "Alphabetic Reverse": Editor.Windows.ContentWin._sortBy = MethodSort.AlphabeticReverse; + break; + } RefreshView(SelectedNode); }