This repository has been archived by the owner on Aug 24, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
775 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
Editor/EditorAddons/Drawers/Select/SetupStrategies/DropdownCollection.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
...or/EditorAddons/Drawers/Select/SetupStrategies/DropdownCollection/DictionaryCollection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Better.Attributes.EditorAddons.Drawers.Utilities; | ||
using Better.Extensions.Runtime; | ||
|
||
namespace Better.Attributes.EditorAddons.Drawers.Select.SetupStrategies.DropdownCollection | ||
{ | ||
public class DictionaryCollection : IDataCollection | ||
{ | ||
private readonly IDictionary _dictionary; | ||
private readonly bool _showDefault; | ||
private readonly bool _showUniqueKey; | ||
|
||
public DictionaryCollection(IDictionary dictionary, bool showDefault, bool showUniqueKey) | ||
{ | ||
_dictionary = dictionary; | ||
_showDefault = showDefault; | ||
_showUniqueKey = showUniqueKey; | ||
} | ||
|
||
public string FindName(object obj) | ||
{ | ||
if (obj == null) | ||
{ | ||
return SelectUtility.Null; | ||
} | ||
|
||
foreach (DictionaryEntry en in _dictionary) | ||
{ | ||
if (en.Value.Equals(obj)) | ||
{ | ||
return en.Key as string; | ||
} | ||
} | ||
|
||
return obj.ToString(); | ||
} | ||
|
||
public List<object> GetValues() | ||
{ | ||
Type type = null; | ||
foreach (DictionaryEntry entry in _dictionary) | ||
{ | ||
type = entry.Value.GetType(); | ||
break; | ||
} | ||
|
||
if (type == null) return new List<object>(); | ||
var defaultElement = type.GetDefault(); | ||
var objects = _dictionary.Values.Cast<object>(); | ||
|
||
if (_showUniqueKey) | ||
{ | ||
|
||
} | ||
|
||
if (_showDefault) | ||
{ | ||
if (!objects.Contains(defaultElement, EqualityComparer<object>.Default)) | ||
{ | ||
objects = objects.Prepend(defaultElement); | ||
} | ||
} | ||
|
||
return objects.ToList(); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...itorAddons/Drawers/Select/SetupStrategies/DropdownCollection/DictionaryCollection.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
Editor/EditorAddons/Drawers/Select/SetupStrategies/DropdownCollection/IDataCollection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Better.Attributes.EditorAddons.Drawers.Select.SetupStrategies.DropdownCollection | ||
{ | ||
public interface IDataCollection | ||
{ | ||
public string FindName(object obj); | ||
public List<object> GetValues(); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...or/EditorAddons/Drawers/Select/SetupStrategies/DropdownCollection/IDataCollection.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
102 changes: 102 additions & 0 deletions
102
Editor/EditorAddons/Drawers/Select/SetupStrategies/DropdownCollection/ListCollection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.CompilerServices; | ||
using Better.Attributes.EditorAddons.Drawers.Utilities; | ||
using Better.Extensions.Runtime; | ||
|
||
namespace Better.Attributes.EditorAddons.Drawers.Select.SetupStrategies.DropdownCollection | ||
{ | ||
public class ListCollection : IDataCollection | ||
{ | ||
private readonly IList _list; | ||
private readonly bool _showDefault; | ||
private readonly bool _showUniqueKey; | ||
|
||
public ListCollection(IList list, bool showDefault, bool showUniqueKey) | ||
{ | ||
_list = list; | ||
_showDefault = showDefault; | ||
_showUniqueKey = showUniqueKey; | ||
} | ||
|
||
public string FindName(object obj) | ||
{ | ||
if (obj == null) | ||
{ | ||
return SelectUtility.Null; | ||
} | ||
|
||
if (_list[_list.Count - 1] is ITuple) | ||
{ | ||
foreach (ITuple item in _list) | ||
{ | ||
if (item != null && item[1].Equals(obj)) | ||
{ | ||
return item[0].ToString(); | ||
} | ||
} | ||
} | ||
|
||
return obj.ToString(); | ||
} | ||
|
||
private class KeyTupleComparer : IEqualityComparer<ITuple> | ||
{ | ||
public bool Equals(ITuple x, ITuple y) | ||
{ | ||
if (ReferenceEquals(x, y)) return true; | ||
if (ReferenceEquals(x, null)) return false; | ||
if (ReferenceEquals(y, null)) return false; | ||
if (x.GetType() != y.GetType()) return false; | ||
return Equals(x[0], y[0]); | ||
} | ||
|
||
public int GetHashCode(ITuple obj) | ||
{ | ||
return obj.Length; | ||
} | ||
} | ||
|
||
public List<object> GetValues() | ||
{ | ||
var last = _list[_list.Count - 1]; | ||
var type = last.GetType(); | ||
object defaultElement; | ||
IEnumerable<object> objects; | ||
if (last is ITuple lastTuple) | ||
{ | ||
var tupleLength = lastTuple.Length - 1; | ||
defaultElement = lastTuple[tupleLength].GetType().GetDefault(); | ||
if (_showUniqueKey) | ||
{ | ||
objects = _list.Cast<ITuple>().Distinct(new KeyTupleComparer()).Select(tuple => tuple[tupleLength]); | ||
} | ||
else | ||
{ | ||
objects = _list.Cast<ITuple>().Select(tuple => tuple[tupleLength]); | ||
} | ||
} | ||
else | ||
{ | ||
defaultElement = type.GetDefault(); | ||
objects = _list.Cast<object>(); | ||
|
||
if (_showUniqueKey) | ||
{ | ||
objects = objects.Distinct(EqualityComparer<object>.Default); | ||
} | ||
} | ||
|
||
if (_showDefault) | ||
{ | ||
if (!objects.Contains(defaultElement, EqualityComparer<object>.Default)) | ||
{ | ||
objects = objects.Prepend(defaultElement); | ||
} | ||
} | ||
|
||
return objects.ToList(); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Editor/EditorAddons/Drawers/Select/SetupStrategies/DropdownCollection/ListCollection.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
Editor/EditorAddons/Drawers/Select/SetupStrategies/DropdownCollection/NoneCollection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Better.Attributes.EditorAddons.Drawers.Select.SetupStrategies.DropdownCollection | ||
{ | ||
public class NoneCollection : IDataCollection | ||
{ | ||
private const string None = "Selector not found"; | ||
|
||
public string FindName(object obj) | ||
{ | ||
return None; | ||
} | ||
|
||
public List<object> GetValues() | ||
{ | ||
return new List<object>(); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Editor/EditorAddons/Drawers/Select/SetupStrategies/DropdownCollection/NoneCollection.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.