Merge branch 'dev' of git://github.com/thallard/FlaxEngine into thallard-dev
This commit is contained in:
@@ -27,6 +27,22 @@ namespace FlaxEditor.Content.GUI
|
||||
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>
|
||||
/// Main control for <see cref="ContentWindow"/> used to present collection of <see cref="ContentItem"/>.
|
||||
/// </summary>
|
||||
@@ -218,8 +234,9 @@ namespace FlaxEditor.Content.GUI
|
||||
/// Shows the items collection in the view.
|
||||
/// </summary>
|
||||
/// <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>
|
||||
public void ShowItems(List<ContentItem> items, bool additive = false)
|
||||
public void ShowItems(List<ContentItem> items, SortType sortType, bool additive = false)
|
||||
{
|
||||
if (items == null)
|
||||
throw new ArgumentNullException();
|
||||
@@ -249,9 +266,24 @@ namespace FlaxEditor.Content.GUI
|
||||
items[i].AddReference(this);
|
||||
}
|
||||
|
||||
// Sort items
|
||||
_children.Sort();
|
||||
|
||||
// Sort items depending on sortMethod parameter
|
||||
_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
|
||||
IsLayoutLocked = wasLayoutLocked;
|
||||
PerformLayout();
|
||||
|
||||
@@ -230,7 +230,7 @@ namespace FlaxEditor.Windows
|
||||
}
|
||||
|
||||
_view.IsSearching = true;
|
||||
_view.ShowItems(items);
|
||||
_view.ShowItems(items, _sortType);
|
||||
}
|
||||
|
||||
private void UpdateItemsSearchFilter(ContentFolder folder, List<ContentItem> items, bool[] filters)
|
||||
|
||||
@@ -39,6 +39,7 @@ namespace FlaxEditor.Windows
|
||||
private TextBox _foldersSearchBox;
|
||||
private TextBox _itemsSearchBox;
|
||||
private ViewDropdown _viewDropdown;
|
||||
private SortType _sortType;
|
||||
|
||||
private RootContentTreeNode _root;
|
||||
|
||||
@@ -215,6 +216,20 @@ namespace FlaxEditor.Windows
|
||||
filterButton.Checked = _viewDropdown.IsSelected(filterButton.Text);
|
||||
}
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -230,6 +245,18 @@ namespace FlaxEditor.Windows
|
||||
_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>
|
||||
/// Shows popup dialog with UI to rename content item.
|
||||
/// </summary>
|
||||
@@ -701,12 +728,12 @@ namespace FlaxEditor.Windows
|
||||
items.Add(node.Folder);
|
||||
}
|
||||
}
|
||||
_view.ShowItems(items);
|
||||
_view.ShowItems(items, _sortType);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Show folder contents
|
||||
_view.ShowItems(target.Folder.Children);
|
||||
_view.ShowItems(target.Folder.Children, _sortType);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user