From d95cd24b76d1cc18223ca4ca8b06b5fc7071411c Mon Sep 17 00:00:00 2001 From: thallard Date: Thu, 5 Aug 2021 22:24:01 +0200 Subject: [PATCH 1/7] Added functionality to order items by name --- Source/Editor/Content/GUI/ContentView.cs | 24 +++++++++++++++++-- Source/Editor/Windows/ContentWindow.Search.cs | 2 +- Source/Editor/Windows/ContentWindow.cs | 17 +++++++++++-- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/Source/Editor/Content/GUI/ContentView.cs b/Source/Editor/Content/GUI/ContentView.cs index 6cfdea210..3eeb18f51 100644 --- a/Source/Editor/Content/GUI/ContentView.cs +++ b/Source/Editor/Content/GUI/ContentView.cs @@ -219,8 +219,9 @@ namespace FlaxEditor.Content.GUI /// /// The items to show. /// If set to true items will be added to the current selection. Otherwise selection will be cleared before. - public void ShowItems(List items, bool additive = false) + public void ShowItems(List items, string sortMethod, bool additive = false) { + Console.WriteLine("GROS CON"); if (items == null) throw new ArgumentNullException(); @@ -250,7 +251,26 @@ namespace FlaxEditor.Content.GUI } // Sort items - _children.Sort(); + ContentItem oui = (ContentItem) _children[0]; + Console.WriteLine("Ici " + oui); + _children.Sort(((control, control1) => + { + if (sortMethod == "Alphabetic Reverse") + { + if (((ContentItem)control).CompareTo((ContentItem)control1) > 0) + return -1; + if (((ContentItem)control).CompareTo((ContentItem)control1) == 0) + return 0; + + + return 1; + } + + return (((ContentItem)control).CompareTo((ContentItem)control1)); + + })); + + // Unload and perform UI layout IsLayoutLocked = wasLayoutLocked; diff --git a/Source/Editor/Windows/ContentWindow.Search.cs b/Source/Editor/Windows/ContentWindow.Search.cs index e8ef60e23..b89bfff89 100644 --- a/Source/Editor/Windows/ContentWindow.Search.cs +++ b/Source/Editor/Windows/ContentWindow.Search.cs @@ -230,7 +230,7 @@ namespace FlaxEditor.Windows } _view.IsSearching = true; - _view.ShowItems(items); + _view.ShowItems(items, Editor.Windows.ContentWin._sortBy); } private void UpdateItemsSearchFilter(ContentFolder folder, List items, bool[] filters) diff --git a/Source/Editor/Windows/ContentWindow.cs b/Source/Editor/Windows/ContentWindow.cs index 8a4db3789..a9ce2a367 100644 --- a/Source/Editor/Windows/ContentWindow.cs +++ b/Source/Editor/Windows/ContentWindow.cs @@ -39,6 +39,7 @@ namespace FlaxEditor.Windows private TextBox _foldersSearchBox; private TextBox _itemsSearchBox; private ViewDropdown _viewDropdown; + private string _sortBy; private RootContentTreeNode _root; @@ -215,6 +216,11 @@ namespace FlaxEditor.Windows filterButton.Checked = _viewDropdown.IsSelected(filterButton.Text); } }; + + var sortBy = menu.AddChildMenu("Sort by"); + sortBy.ContextMenu.AddButton("Alphabetic Order", OnSortByButtonClicked); + sortBy.ContextMenu.AddButton("Alphabetic Reverse", OnSortByButtonClicked); + sortBy.ContextMenu.AddButton("Last Modified", OnSortByButtonClicked); return menu; } @@ -230,6 +236,13 @@ namespace FlaxEditor.Windows _viewDropdown.OnClicked(i); } + private void OnSortByButtonClicked(ContextMenuButton button) + { + Editor.Windows.ContentWin._sortBy = button.Text; + RefreshView(SelectedNode); + Console.WriteLine(Editor.Windows.ContentWin._sortBy); + } + /// /// Shows popup dialog with UI to rename content item. /// @@ -701,12 +714,12 @@ namespace FlaxEditor.Windows items.Add(node.Folder); } } - _view.ShowItems(items); + _view.ShowItems(items, Editor.Windows.ContentWin._sortBy); } else { // Show folder contents - _view.ShowItems(target.Folder.Children); + _view.ShowItems(target.Folder.Children, Editor.Windows.ContentWin._sortBy); } } From 1426b4ca4987cfdd949fc2c6c570ce4d350ad979 Mon Sep 17 00:00:00 2001 From: thallard Date: Thu, 5 Aug 2021 23:05:27 +0200 Subject: [PATCH 2/7] Removed useless debug logs --- Source/Editor/Content/GUI/ContentView.cs | 26 ++++++++++-------------- Source/Editor/Windows/ContentWindow.cs | 4 +--- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/Source/Editor/Content/GUI/ContentView.cs b/Source/Editor/Content/GUI/ContentView.cs index 3eeb18f51..32b5dc6c3 100644 --- a/Source/Editor/Content/GUI/ContentView.cs +++ b/Source/Editor/Content/GUI/ContentView.cs @@ -218,10 +218,10 @@ namespace FlaxEditor.Content.GUI /// Shows the items collection in the view. /// /// 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) { - Console.WriteLine("GROS CON"); if (items == null) throw new ArgumentNullException(); @@ -250,28 +250,24 @@ namespace FlaxEditor.Content.GUI items[i].AddReference(this); } - // Sort items - ContentItem oui = (ContentItem) _children[0]; - Console.WriteLine("Ici " + oui); + // Sort items depending on sortMethod parameter _children.Sort(((control, control1) => { if (sortMethod == "Alphabetic Reverse") { - if (((ContentItem)control).CompareTo((ContentItem)control1) > 0) - return -1; - if (((ContentItem)control).CompareTo((ContentItem)control1) == 0) - return 0; - - + if (control.CompareTo(control1) > 0) + { + return -1; + } + if (control.CompareTo(control1) == 0) + { + return 0; + } return 1; } - - return (((ContentItem)control).CompareTo((ContentItem)control1)); - + return control.CompareTo(control1); })); - - // Unload and perform UI layout IsLayoutLocked = wasLayoutLocked; PerformLayout(); diff --git a/Source/Editor/Windows/ContentWindow.cs b/Source/Editor/Windows/ContentWindow.cs index a9ce2a367..8ad9f6256 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; + private string _sortBy = "Alphabetic Order"; private RootContentTreeNode _root; @@ -220,7 +220,6 @@ namespace FlaxEditor.Windows var sortBy = menu.AddChildMenu("Sort by"); sortBy.ContextMenu.AddButton("Alphabetic Order", OnSortByButtonClicked); sortBy.ContextMenu.AddButton("Alphabetic Reverse", OnSortByButtonClicked); - sortBy.ContextMenu.AddButton("Last Modified", OnSortByButtonClicked); return menu; } @@ -240,7 +239,6 @@ namespace FlaxEditor.Windows { Editor.Windows.ContentWin._sortBy = button.Text; RefreshView(SelectedNode); - Console.WriteLine(Editor.Windows.ContentWin._sortBy); } /// From e8b867430f095aa41d7fb752e61a6c5c6892c852 Mon Sep 17 00:00:00 2001 From: thallard Date: Thu, 5 Aug 2021 23:38:08 +0200 Subject: [PATCH 3/7] 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); } From 78d668c599764d9dfe8a1a10d2b4492e9aa562fd Mon Sep 17 00:00:00 2001 From: thallard Date: Fri, 6 Aug 2021 00:07:44 +0200 Subject: [PATCH 4/7] Change enum and variable name --- Source/Editor/Content/GUI/ContentView.cs | 8 ++++---- Source/Editor/Windows/ContentWindow.Search.cs | 2 +- Source/Editor/Windows/ContentWindow.cs | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Source/Editor/Content/GUI/ContentView.cs b/Source/Editor/Content/GUI/ContentView.cs index 0401e14a6..23d81421d 100644 --- a/Source/Editor/Content/GUI/ContentView.cs +++ b/Source/Editor/Content/GUI/ContentView.cs @@ -30,7 +30,7 @@ namespace FlaxEditor.Content.GUI /// /// The method sort for items. /// - public enum MethodSort + public enum SortType { /// /// The classic alphabetic sort method (A-Z). @@ -234,9 +234,9 @@ namespace FlaxEditor.Content.GUI /// Shows the items collection in the view. /// /// The items to show. - /// The sort method for items. + /// 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, MethodSort sortMethod, bool additive = false) + public void ShowItems(List items, SortType sortType, bool additive = false) { if (items == null) throw new ArgumentNullException(); @@ -269,7 +269,7 @@ namespace FlaxEditor.Content.GUI // Sort items depending on sortMethod parameter _children.Sort(((control, control1) => { - if (sortMethod == MethodSort.AlphabeticReverse) + if (sortType == SortType.AlphabeticReverse) { if (control.CompareTo(control1) > 0) { diff --git a/Source/Editor/Windows/ContentWindow.Search.cs b/Source/Editor/Windows/ContentWindow.Search.cs index b89bfff89..d8c304c23 100644 --- a/Source/Editor/Windows/ContentWindow.Search.cs +++ b/Source/Editor/Windows/ContentWindow.Search.cs @@ -230,7 +230,7 @@ namespace FlaxEditor.Windows } _view.IsSearching = true; - _view.ShowItems(items, Editor.Windows.ContentWin._sortBy); + _view.ShowItems(items, Editor.Windows.ContentWin._sortType); } private void UpdateItemsSearchFilter(ContentFolder folder, List items, bool[] filters) diff --git a/Source/Editor/Windows/ContentWindow.cs b/Source/Editor/Windows/ContentWindow.cs index 9985393ef..332e9331f 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 MethodSort _sortBy; + private SortType _sortType; private RootContentTreeNode _root; @@ -239,9 +239,9 @@ namespace FlaxEditor.Windows { switch (button.Text) { - case "Alphabetic Order": Editor.Windows.ContentWin._sortBy = MethodSort.AlphabeticOrder; + case "Alphabetic Order": Editor.Windows.ContentWin._sortType = SortType.AlphabeticOrder; break; - case "Alphabetic Reverse": Editor.Windows.ContentWin._sortBy = MethodSort.AlphabeticReverse; + case "Alphabetic Reverse": Editor.Windows.ContentWin._sortType = SortType.AlphabeticReverse; break; } RefreshView(SelectedNode); @@ -718,12 +718,12 @@ namespace FlaxEditor.Windows items.Add(node.Folder); } } - _view.ShowItems(items, Editor.Windows.ContentWin._sortBy); + _view.ShowItems(items, Editor.Windows.ContentWin._sortType); } else { // Show folder contents - _view.ShowItems(target.Folder.Children, Editor.Windows.ContentWin._sortBy); + _view.ShowItems(target.Folder.Children, Editor.Windows.ContentWin._sortType); } } From 5e2b4adff30052192fe18be5329801ecc35daf6a Mon Sep 17 00:00:00 2001 From: thallard Date: Fri, 6 Aug 2021 00:21:27 +0200 Subject: [PATCH 5/7] Removed useless static path thanks to @jb-perrier --- Source/Editor/Windows/ContentWindow.Search.cs | 2 +- Source/Editor/Windows/ContentWindow.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/Editor/Windows/ContentWindow.Search.cs b/Source/Editor/Windows/ContentWindow.Search.cs index d8c304c23..4800705ce 100644 --- a/Source/Editor/Windows/ContentWindow.Search.cs +++ b/Source/Editor/Windows/ContentWindow.Search.cs @@ -230,7 +230,7 @@ namespace FlaxEditor.Windows } _view.IsSearching = true; - _view.ShowItems(items, Editor.Windows.ContentWin._sortType); + _view.ShowItems(items, _sortType); } private void UpdateItemsSearchFilter(ContentFolder folder, List items, bool[] filters) diff --git a/Source/Editor/Windows/ContentWindow.cs b/Source/Editor/Windows/ContentWindow.cs index 332e9331f..3b9c47c13 100644 --- a/Source/Editor/Windows/ContentWindow.cs +++ b/Source/Editor/Windows/ContentWindow.cs @@ -239,9 +239,9 @@ namespace FlaxEditor.Windows { switch (button.Text) { - case "Alphabetic Order": Editor.Windows.ContentWin._sortType = SortType.AlphabeticOrder; + case "Alphabetic Order": _sortType = SortType.AlphabeticOrder; break; - case "Alphabetic Reverse": Editor.Windows.ContentWin._sortType = SortType.AlphabeticReverse; + case "Alphabetic Reverse": _sortType = SortType.AlphabeticReverse; break; } RefreshView(SelectedNode); @@ -718,12 +718,12 @@ namespace FlaxEditor.Windows items.Add(node.Folder); } } - _view.ShowItems(items, Editor.Windows.ContentWin._sortType); + _view.ShowItems(items, _sortType); } else { // Show folder contents - _view.ShowItems(target.Folder.Children, Editor.Windows.ContentWin._sortType); + _view.ShowItems(target.Folder.Children, _sortType); } } From baee3a60a65f703f09ea2439e4b5bff82eee22cb Mon Sep 17 00:00:00 2001 From: thallard Date: Fri, 6 Aug 2021 11:47:50 +0200 Subject: [PATCH 6/7] Added tick when a button is selected --- Source/Editor/Windows/ContentWindow.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Source/Editor/Windows/ContentWindow.cs b/Source/Editor/Windows/ContentWindow.cs index 3b9c47c13..2140aac53 100644 --- a/Source/Editor/Windows/ContentWindow.cs +++ b/Source/Editor/Windows/ContentWindow.cs @@ -40,6 +40,7 @@ namespace FlaxEditor.Windows private TextBox _itemsSearchBox; private ViewDropdown _viewDropdown; private SortType _sortType; + private string _buttonNameChecked = "Alphabetic Order"; private RootContentTreeNode _root; @@ -218,8 +219,18 @@ namespace FlaxEditor.Windows }; var sortBy = menu.AddChildMenu("Sort by"); - sortBy.ContextMenu.AddButton("Alphabetic Order", OnSortByButtonClicked); - sortBy.ContextMenu.AddButton("Alphabetic Reverse", OnSortByButtonClicked); + sortBy.ContextMenu.AddButton("Alphabetic Order", OnSortByButtonClicked).Tag = SortType.AlphabeticOrder; + sortBy.ContextMenu.AddButton("Alphabetic Reverse", OnSortByButtonClicked).Tag = SortType.AlphabeticReverse; + sortBy.ContextMenu.VisibleChanged += control => + { + if (!control.Visible) + return; + foreach (var item in ((ContextMenu)control).Items) + { + if (item is ContextMenuButton button) + button.Checked = _buttonNameChecked == button.Text; + } + }; return menu; } @@ -237,6 +248,7 @@ namespace FlaxEditor.Windows private void OnSortByButtonClicked(ContextMenuButton button) { + _buttonNameChecked = button.Text; switch (button.Text) { case "Alphabetic Order": _sortType = SortType.AlphabeticOrder; From 3bc489a7b51df937e94147a5f7897b09722d14bb Mon Sep 17 00:00:00 2001 From: thallard Date: Fri, 6 Aug 2021 15:50:30 +0200 Subject: [PATCH 7/7] Replace string variable check by an enum --- Source/Editor/Windows/ContentWindow.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Source/Editor/Windows/ContentWindow.cs b/Source/Editor/Windows/ContentWindow.cs index 2140aac53..04a82087c 100644 --- a/Source/Editor/Windows/ContentWindow.cs +++ b/Source/Editor/Windows/ContentWindow.cs @@ -40,7 +40,6 @@ namespace FlaxEditor.Windows private TextBox _itemsSearchBox; private ViewDropdown _viewDropdown; private SortType _sortType; - private string _buttonNameChecked = "Alphabetic Order"; private RootContentTreeNode _root; @@ -228,7 +227,7 @@ namespace FlaxEditor.Windows foreach (var item in ((ContextMenu)control).Items) { if (item is ContextMenuButton button) - button.Checked = _buttonNameChecked == button.Text; + button.Checked = _sortType == (SortType)button.Tag; } }; @@ -248,12 +247,11 @@ namespace FlaxEditor.Windows private void OnSortByButtonClicked(ContextMenuButton button) { - _buttonNameChecked = button.Text; - switch (button.Text) + switch ((SortType)button.Tag) { - case "Alphabetic Order": _sortType = SortType.AlphabeticOrder; + case SortType.AlphabeticOrder: _sortType = SortType.AlphabeticOrder; break; - case "Alphabetic Reverse": _sortType = SortType.AlphabeticReverse; + case SortType.AlphabeticReverse: _sortType = SortType.AlphabeticReverse; break; } RefreshView(SelectedNode);