Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions Editor/DataVisualizer/DataVisualizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1653,7 +1653,7 @@ is ScriptableObject selectedObject
_searchField.value = string.Empty;
}

evt.PreventDefault();
evt.PreventDefaultCompat();
evt.StopPropagation();
}

Expand All @@ -1662,7 +1662,7 @@ is ScriptableObject selectedObject
case KeyCode.Escape:
{
CloseActivePopover();
evt.PreventDefault();
evt.PreventDefaultCompat();
evt.StopPropagation();
break;
}
Expand All @@ -1675,7 +1675,7 @@ is ScriptableObject selectedObject
if (highlightChanged)
{
UpdateSearchResultHighlight();
evt.PreventDefault();
evt.PreventDefaultCompat();
evt.StopPropagation();
}
}
Expand Down Expand Up @@ -2713,7 +2713,7 @@ private void HandleGlobalKeyDown(KeyDownEvent evt)
case KeyCode.Escape:
{
CloseActivePopover();
evt.PreventDefault();
evt.PreventDefaultCompat();
evt.StopPropagation();
return;
}
Expand Down Expand Up @@ -2760,7 +2760,7 @@ private void HandleGlobalKeyDown(KeyDownEvent evt)

if (evt.keyCode == KeyCode.DownArrow || evt.keyCode == KeyCode.UpArrow)
{
evt.PreventDefault();
evt.PreventDefaultCompat();
evt.StopPropagation();
return;
}
Expand All @@ -2783,7 +2783,7 @@ private void HandleGlobalKeyDown(KeyDownEvent evt)

if (navigationHandled)
{
evt.PreventDefault();
evt.PreventDefaultCompat();
evt.StopPropagation();
}

Expand All @@ -2804,7 +2804,7 @@ private void HandleGlobalKeyDown(KeyDownEvent evt)

if (navigationHandled)
{
evt.PreventDefault();
evt.PreventDefaultCompat();
evt.StopPropagation();
}

Expand All @@ -2826,7 +2826,7 @@ private void HandlePopoverKeyDown(KeyDownEvent evt)
case KeyCode.Escape:
{
CloseActivePopover();
evt.PreventDefault();
evt.PreventDefaultCompat();
evt.StopPropagation();
return;
}
Expand Down Expand Up @@ -4241,7 +4241,7 @@ private void HandleTypePopoverKeyDown(KeyDownEvent evt)
_typePopoverHighlightIndex
];
HandleEnterOnPopoverItem(selectedElement);
evt.PreventDefault();
evt.PreventDefaultCompat();
evt.StopPropagation();
}

Expand All @@ -4250,7 +4250,7 @@ private void HandleTypePopoverKeyDown(KeyDownEvent evt)
case KeyCode.Escape:
{
CloseActivePopover();
evt.PreventDefault();
evt.PreventDefaultCompat();
evt.StopPropagation();
break;
}
Expand All @@ -4263,7 +4263,7 @@ private void HandleTypePopoverKeyDown(KeyDownEvent evt)
if (highlightChanged)
{
UpdateTypePopoverHighlight();
evt.PreventDefault();
evt.PreventDefaultCompat();
evt.StopPropagation();
}
}
Expand Down Expand Up @@ -5887,7 +5887,7 @@ private void BuildObjectRow(ScriptableObject dataObject, int index)

VisualElement objectItemRow = new()
{
name = $"object-item-row-{dataObject.GetInstanceID()}",
name = $"object-item-row-{dataObject.GetObjectIdString()}",
};
objectItemRow.AddToClassList(ObjectItemClass);
objectItemRow.AddToClassList(StyleConstants.ClickableClass);
Expand Down Expand Up @@ -6526,7 +6526,7 @@ private void HandleNewLabelInputKeyDown(KeyDownEvent evt)
if (evt.keyCode is KeyCode.Return or KeyCode.KeypadEnter)
{
AddLabelToSelectedAsset();
evt.PreventDefault();
evt.PreventDefaultCompat();
evt.StopPropagation();
}
return;
Expand Down Expand Up @@ -6581,14 +6581,14 @@ is string selectedSuggestion
CloseActivePopover();
}

evt.PreventDefault();
evt.PreventDefaultCompat();
evt.StopPropagation();
break;
}
case KeyCode.Escape:
{
CloseActivePopover();
evt.PreventDefault();
evt.PreventDefaultCompat();
evt.StopPropagation();
break;
}
Expand All @@ -6601,7 +6601,7 @@ is string selectedSuggestion
if (highlightChanged)
{
UpdateLabelSuggestionHighlight();
evt.PreventDefault();
evt.PreventDefaultCompat();
evt.StopPropagation();
}
}
Expand Down
23 changes: 23 additions & 0 deletions Editor/DataVisualizer/Extensions/EventExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace WallstopStudios.DataVisualizer.Editor.Extensions
{
using UnityEngine.UIElements;

internal static class EventExtensions
{
/// <summary>
/// Prevents the event's default action on Unity versions where
/// <see cref="EventBase.PreventDefault"/> is supported. On Unity 2023.2+ that method
/// is obsolete, so this is a no-op there: every caller pairs it with
/// <see cref="EventBase.StopPropagation"/>, which consumes the event — the sanctioned
/// replacement for the KeyDownEvents handled here. FocusController.IgnoreEvent (the
/// other suggested replacement) only affects pointer/navigation events, so it is
/// intentionally not used.
/// </summary>
internal static void PreventDefaultCompat(this EventBase evt)
{
#if !UNITY_2023_2_OR_NEWER
evt.PreventDefault();
#endif
}
}
}
3 changes: 3 additions & 0 deletions Editor/DataVisualizer/Extensions/EventExtensions.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions Editor/DataVisualizer/Extensions/ObjectIdExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace WallstopStudios.DataVisualizer.Editor.Extensions
{
using System.Globalization;
using UnityEngine;

/// <summary>
/// Helpers for deriving identifier strings from Unity objects. Public because the
/// package's editor test assembly cannot access internals of the editor assembly:
/// InternalsVisibleTo is not honored for this assembly pair in Unity's compilation
/// (verified — the internal type is reported CS0122 from the test assembly even with
/// a correct friend attribute compiled into the editor assembly).
/// </summary>
public static class ObjectIdExtensions
{
/// <summary>
/// Returns a per-session unique identifier string for the object, suitable for
/// building unique UI element names. NOT stable across editor sessions or domain
/// reloads; do not persist.
/// </summary>
public static string GetObjectIdString(this Object obj)
{
#if UNITY_6000_4_OR_NEWER
return EntityId.ToULong(obj.GetEntityId()).ToString(CultureInfo.InvariantCulture);
#else
return obj.GetInstanceID().ToString(CultureInfo.InvariantCulture);
#endif
}
}
}
3 changes: 3 additions & 0 deletions Editor/DataVisualizer/Extensions/ObjectIdExtensions.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 2 additions & 64 deletions Editor/DataVisualizer/UI/HorizontalToggle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,72 +5,10 @@ namespace WallstopStudios.DataVisualizer.Editor.UI
using UnityEngine.UIElements;
using UnityEngine.UIElements.Experimental;

// Instantiated only from C# (never from UXML), so the deprecated UxmlFactory/UxmlTraits
// pair is intentionally omitted.
public sealed class HorizontalToggle : VisualElement
{
public new class UxmlFactory : UxmlFactory<HorizontalToggle, UxmlTraits> { }

public new class UxmlTraits : VisualElement.UxmlTraits
{
private readonly UxmlStringAttributeDescription _leftText = new()
{
name = "left-text",
defaultValue = "Left",
};

private readonly UxmlStringAttributeDescription _rightText = new()
{
name = "right-text",
defaultValue = "Right",
};

private readonly UxmlColorAttributeDescription _selectedBackgroundColor = new()
{
name = "selected-background-color",
defaultValue = new Color(0.1f, 0.5f, 0.8f),
};

private readonly UxmlColorAttributeDescription _unselectedBackgroundColor = new()
{
name = "unselected-background-color",
defaultValue = new Color(0.2f, 0.2f, 0.2f),
};

private readonly UxmlColorAttributeDescription _selectedTextColor = new()
{
name = "selected-text-color",
defaultValue = Color.white,
};

private readonly UxmlColorAttributeDescription _unselectedTextColor = new()
{
name = "unselected-text-color",
defaultValue = new Color(0.7f, 0.7f, 0.7f),
};

private readonly UxmlColorAttributeDescription _indicatorColor = new()
{
name = "indicator-color",
defaultValue = new Color(0.15f, 0.65f, 0.95f),
};

public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
{
base.Init(ve, bag, cc);
HorizontalToggle ate = ve as HorizontalToggle;

ate.LeftText = _leftText.GetValueFromBag(bag, cc);
ate.RightText = _rightText.GetValueFromBag(bag, cc);
ate.SelectedBackgroundColor = _selectedBackgroundColor.GetValueFromBag(bag, cc);
ate.UnselectedBackgroundColor = _unselectedBackgroundColor.GetValueFromBag(bag, cc);
ate.SelectedTextColor = _selectedTextColor.GetValueFromBag(bag, cc);
ate.UnselectedTextColor = _unselectedTextColor.GetValueFromBag(bag, cc);
ate.IndicatorColor = _indicatorColor.GetValueFromBag(bag, cc);

ate.Clear();
ate.Initialize();
}
}

public static readonly string ussClassName = "horizontal-toggle";
public static readonly string containerUssClassName = ussClassName + "__container";
public static readonly string labelContainerUssClassName =
Expand Down
9 changes: 9 additions & 0 deletions PLAN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Plan

Active work items. Completed/obsolete items are removed after each session; history lives in `progress/`.

## Active

- [ ] PR [#13](https://github.com/wallstop/DataVisualizer/pull/13) (branch `dev/wallstop/bug-fixes`) — Unity 6000.x compile-cleanliness. Open and green; awaiting merge (merge to `main` publishes 0.0.35 to npm).
- Issue #12 — CS0619: `Object.GetInstanceID()` → `EntityId` behind `UNITY_6000_4_OR_NEWER`; first EditMode tests; version bump to 0.0.35. Tracking: `progress/session-001-issue-12-entityid-fix.md`.
- CS0618 deprecations — remove dead `UxmlTraits`/`UxmlFactory` from `HorizontalToggle`; gate `EventBase.PreventDefault()` behind `UNITY_2023_2_OR_NEWER` via `EventExtensions.PreventDefaultCompat`. Tracking: `progress/session-002-uxml-preventdefault-deprecations.md`.
7 changes: 7 additions & 0 deletions PLAN.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Tests.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Tests/Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions Tests/Editor/ObjectIdExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
namespace WallstopStudios.DataVisualizer.Tests.Editor
{
using NUnit.Framework;
using UnityEngine;
using WallstopStudios.DataVisualizer.Editor.Extensions;

public sealed class ObjectIdExtensionsTests
{
[Test]
public void GetObjectIdStringIsNonEmptyStableAndUnique()
{
ScriptableObject first = ScriptableObject.CreateInstance<ScriptableObject>();
ScriptableObject second = ScriptableObject.CreateInstance<ScriptableObject>();
try
{
string firstId = first.GetObjectIdString();
string secondId = second.GetObjectIdString();

Assert.That(firstId, Is.Not.Null.And.Not.Empty);
Assert.That(secondId, Is.Not.Null.And.Not.Empty);
Assert.AreEqual(
firstId,
first.GetObjectIdString(),
"The id must be stable across repeated calls on the same object."
);
Assert.AreNotEqual(
firstId,
secondId,
"Distinct objects must produce distinct ids."
);
#if UNITY_6000_4_OR_NEWER
Assert.IsTrue(
ulong.TryParse(firstId, out _),
"The EntityId branch must produce a numeric (ulong) id string."
);
#else
Assert.IsTrue(
int.TryParse(firstId, out _),
"The legacy InstanceID branch must produce a numeric (int) id string."
);
Comment thread
Copilot marked this conversation as resolved.
#endif
}
finally
{
Object.DestroyImmediate(first);
Object.DestroyImmediate(second);
}
}
}
}
3 changes: 3 additions & 0 deletions Tests/Editor/ObjectIdExtensionsTests.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions Tests/Editor/WallstopStudios.DataVisualizer.Tests.Editor.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "WallstopStudios.DataVisualizer.Tests.Editor",
"rootNamespace": "WallstopStudios.DataVisualizer.Tests.Editor",
"references": [
"UnityEditor.TestRunner",
"UnityEngine.TestRunner",
"WallstopStudios.DataVisualizer.Editor"
],
"includePlatforms": ["Editor"],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": ["nunit.framework.dll"],
"autoReferenced": false,
"defineConstraints": ["UNITY_INCLUDE_TESTS"],
"versionDefines": [],
"noEngineReferences": false
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading