Skip to content

Commit

Permalink
Allow adding of tags when partial tag exists
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenwe committed May 3, 2020
1 parent 56cb1d3 commit 8b19191
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
8 changes: 4 additions & 4 deletions Assets/Scenes/MainScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ LightmapSettings:
m_TrainingDataDestination: TrainingData
m_LightProbeSampleCountMultiplier: 4
m_LightingDataAsset: {fileID: 0}
m_UseShadowmask: 0
m_UseShadowmask: 1
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2
Expand Down Expand Up @@ -5331,7 +5331,7 @@ PrefabInstance:
- target: {fileID: 2746333758154926288, guid: 7e33cda9a5d8c3e478c6888db2b484ea,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 0.000061035156
value: 0.000289917
objectReference: {fileID: 0}
- target: {fileID: 2746333758154926288, guid: 7e33cda9a5d8c3e478c6888db2b484ea,
type: 3}
Expand All @@ -5341,7 +5341,7 @@ PrefabInstance:
- target: {fileID: 2746333758174583497, guid: 7e33cda9a5d8c3e478c6888db2b484ea,
type: 3}
propertyPath: m_AnchoredPosition.y
value: -0.000030517578
value: 0.00025177002
objectReference: {fileID: 0}
- target: {fileID: 2746333758174583497, guid: 7e33cda9a5d8c3e478c6888db2b484ea,
type: 3}
Expand Down Expand Up @@ -5481,7 +5481,7 @@ PrefabInstance:
- target: {fileID: 2746333759616755060, guid: 7e33cda9a5d8c3e478c6888db2b484ea,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 0.000015258789
value: -0.00021362305
objectReference: {fileID: 0}
- target: {fileID: 2746333759616755060, guid: 7e33cda9a5d8c3e478c6888db2b484ea,
type: 3}
Expand Down
5 changes: 5 additions & 0 deletions Assets/Scripts/ViewModels/TagEditorModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ private void SelectionChanged()
private static bool IsValidEditorTag(string tag) => !tag.StartsWith("folder:") && !tag.StartsWith("collection:");
private static HashSet<string> Filter(IReadOnlyCollection<string> tags) => tags.Where(IsValidEditorTag).ToHashSet();

protected override bool IsValidTag(string tagText) =>
!string.IsNullOrWhiteSpace(tagText)
&& IsValidEditorTag(tagText)
&& Tags.Where(t => !t.IsPartial).All(tag => tag.Text != tagText);

private IEnumerable<string> Hashes => Mode == Current
? new[] {_detailMenu.Current.Value.FileHash}
: _detailMenu.Selection.Select(pi => pi.FileHash);
Expand Down
11 changes: 10 additions & 1 deletion Assets/Scripts/ViewModels/TagInputModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,13 @@ private void SuggestionChosen(SuggestionModel suggestion)
private bool AddTag(string tagText)
{
tagText = tagText?.Trim().ToLowerInvariant();
if (!string.IsNullOrEmpty(tagText) && Tags.All(tag => tag.Text != tagText))
if (IsValidTag(tagText))
{
tagText = OnAddingTag(tagText);

var sameTag = Tags.FirstOrDefault(t => t.Text == tagText);
if (sameTag != null) Tags.Remove(sameTag);

Tags.Add(new TagModel(tagText, RemoveTag));

return true;
Expand All @@ -71,6 +75,11 @@ private bool AddTag(string tagText)
return false;
}

protected virtual bool IsValidTag(string tagText)
{
return !string.IsNullOrEmpty(tagText) && Tags.All(tag => tag.Text != tagText);
}

protected virtual string OnAddingTag(string tagText) => tagText;

protected virtual bool CanPinCurrentInput()
Expand Down

0 comments on commit 8b19191

Please sign in to comment.