Merge branch 'dev' of git://github.com/thallard/FlaxEngine into thallard-dev

This commit is contained in:
Wojtek Figat
2021-08-07 15:29:01 +02:00
3 changed files with 66 additions and 7 deletions

View File

@@ -27,6 +27,22 @@ namespace FlaxEditor.Content.GUI
List, List,
} }
/// <summary>
/// The method sort for items.
/// </summary>
public enum SortType
{
/// <summary>
/// The classic alphabetic sort method (A-Z).
/// </summary>
AlphabeticOrder,
/// <summary>
/// The reverse alphabetic sort method (Z-A).
/// </summary>
AlphabeticReverse
}
/// <summary> /// <summary>
/// Main control for <see cref="ContentWindow"/> used to present collection of <see cref="ContentItem"/>. /// Main control for <see cref="ContentWindow"/> used to present collection of <see cref="ContentItem"/>.
/// </summary> /// </summary>
@@ -218,8 +234,9 @@ namespace FlaxEditor.Content.GUI
/// Shows the items collection in the view. /// Shows the items collection in the view.
/// </summary> /// </summary>
/// <param name="items">The items to show.</param> /// <param name="items">The items to show.</param>
/// <param name="sortType">The sort method for items.</param>
/// <param name="additive">If set to <c>true</c> items will be added to the current selection. Otherwise selection will be cleared before.</param> /// <param name="additive">If set to <c>true</c> items will be added to the current selection. Otherwise selection will be cleared before.</param>
public void ShowItems(List<ContentItem> items, bool additive = false) public void ShowItems(List<ContentItem> items, SortType sortType, bool additive = false)
{ {
if (items == null) if (items == null)
throw new ArgumentNullException(); throw new ArgumentNullException();
@@ -249,8 +266,23 @@ namespace FlaxEditor.Content.GUI
items[i].AddReference(this); items[i].AddReference(this);
} }
// Sort items // Sort items depending on sortMethod parameter
_children.Sort(); _children.Sort(((control, control1) =>
{
if (sortType == SortType.AlphabeticReverse)
{
if (control.CompareTo(control1) > 0)
{
return -1;
}
if (control.CompareTo(control1) == 0)
{
return 0;
}
return 1;
}
return control.CompareTo(control1);
}));
// Unload and perform UI layout // Unload and perform UI layout
IsLayoutLocked = wasLayoutLocked; IsLayoutLocked = wasLayoutLocked;

View File

@@ -230,7 +230,7 @@ namespace FlaxEditor.Windows
} }
_view.IsSearching = true; _view.IsSearching = true;
_view.ShowItems(items); _view.ShowItems(items, _sortType);
} }
private void UpdateItemsSearchFilter(ContentFolder folder, List<ContentItem> items, bool[] filters) private void UpdateItemsSearchFilter(ContentFolder folder, List<ContentItem> items, bool[] filters)

View File

@@ -39,6 +39,7 @@ namespace FlaxEditor.Windows
private TextBox _foldersSearchBox; private TextBox _foldersSearchBox;
private TextBox _itemsSearchBox; private TextBox _itemsSearchBox;
private ViewDropdown _viewDropdown; private ViewDropdown _viewDropdown;
private SortType _sortType;
private RootContentTreeNode _root; private RootContentTreeNode _root;
@@ -216,6 +217,20 @@ namespace FlaxEditor.Windows
} }
}; };
var sortBy = menu.AddChildMenu("Sort by");
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 = _sortType == (SortType)button.Tag;
}
};
return menu; return menu;
} }
@@ -230,6 +245,18 @@ namespace FlaxEditor.Windows
_viewDropdown.OnClicked(i); _viewDropdown.OnClicked(i);
} }
private void OnSortByButtonClicked(ContextMenuButton button)
{
switch ((SortType)button.Tag)
{
case SortType.AlphabeticOrder: _sortType = SortType.AlphabeticOrder;
break;
case SortType.AlphabeticReverse: _sortType = SortType.AlphabeticReverse;
break;
}
RefreshView(SelectedNode);
}
/// <summary> /// <summary>
/// Shows popup dialog with UI to rename content item. /// Shows popup dialog with UI to rename content item.
/// </summary> /// </summary>
@@ -701,12 +728,12 @@ namespace FlaxEditor.Windows
items.Add(node.Folder); items.Add(node.Folder);
} }
} }
_view.ShowItems(items); _view.ShowItems(items, _sortType);
} }
else else
{ {
// Show folder contents // Show folder contents
_view.ShowItems(target.Folder.Children); _view.ShowItems(target.Folder.Children, _sortType);
} }
} }