diff --git a/packages/project-editor/core/search.ts b/packages/project-editor/core/search.ts index a7a92c5f..475bcc67 100644 --- a/packages/project-editor/core/search.ts +++ b/packages/project-editor/core/search.ts @@ -489,7 +489,10 @@ export function* searchForReference( let identifierType: IdentifierType | undefined; let structType: ValueType | undefined; let enumType: ValueType | undefined; - if (object instanceof ProjectEditor.VariableClass) { + if ( + object instanceof ProjectEditor.VariableClass || + object instanceof ProjectEditor.UserPropertyClass + ) { let flow = getAncestorOfType(object, ProjectEditor.FlowClass.classInfo); if (flow) { identifierType = "local-variable"; diff --git a/packages/project-editor/flow/user-property.tsx b/packages/project-editor/flow/user-property.tsx index 2cd2cb36..483786f9 100644 --- a/packages/project-editor/flow/user-property.tsx +++ b/packages/project-editor/flow/user-property.tsx @@ -14,6 +14,7 @@ import { getParent, IEezObject, IMessage, + IOnSelectParams, MessageType, PropertyInfo, PropertyProps, @@ -251,8 +252,11 @@ function getReferencedFlow(object: IEezObject): Flow | undefined { return undefined; } -function getPropertyInfoForUserProperty(userProperty: UserProperty) { - return userProperty.assignable +function getPropertyInfoForUserProperty( + userProperty: UserProperty, + parent: IEezObject +) { + const propertyInfo = userProperty.assignable ? makeAssignableExpressionProperty( { name: userProperty.id, @@ -273,12 +277,31 @@ function getPropertyInfoForUserProperty(userProperty: UserProperty) { }, userProperty.type ); + + const onSelect = propertyInfo.onSelect!; + + propertyInfo.onSelect = async ( + object: IEezObject, + propertyInfo: PropertyInfo, + params?: IOnSelectParams + ) => { + (object as any)._eez_parent = parent; + + await onSelect(object, propertyInfo, params); + + delete (object as any)._eez_parent; + }; + + return propertyInfo; } function getUserPropertiesAsPropertyInfos( - userProperties: UserProperty[] + userProperties: UserProperty[], + parent: IEezObject ): PropertyInfo[] { - return userProperties.map(getPropertyInfoForUserProperty); + return userProperties.map(userProperty => + getPropertyInfoForUserProperty(userProperty, parent) + ); } function makeValueObjectForUserProperty( @@ -287,7 +310,7 @@ function makeValueObjectForUserProperty( ) { const valueObject = EezValueObject.create( userPropertyValues, - getPropertyInfoForUserProperty(userProperty), + getPropertyInfoForUserProperty(userProperty, userPropertyValues), userPropertyValues.values[userProperty.id] ); @@ -394,7 +417,10 @@ export const UserPropertyValuesProperty = observer( return []; } - return getUserPropertiesAsPropertyInfos(flow.userProperties); + return getUserPropertiesAsPropertyInfos( + flow.userProperties, + object + ); } render() { diff --git a/packages/project-editor/project-editor-create.tsx b/packages/project-editor/project-editor-create.tsx index ad9aecc3..0b1680f4 100644 --- a/packages/project-editor/project-editor-create.tsx +++ b/packages/project-editor/project-editor-create.tsx @@ -126,6 +126,7 @@ import { evalProperty } from "project-editor/flow/helper"; import { migrateLvglVersion } from "./lvgl/migrate"; import { FlowTabState } from "project-editor/flow/flow-tab-state"; import { Color } from "project-editor/features/style/theme"; +import { UserProperty } from "./flow/user-property"; export const conditionalStyleConditionProperty = makeExpressionProperty( { @@ -186,6 +187,7 @@ export async function createProjectEditor( OutputActionComponentClass: OutputActionComponent, CallActionActionComponentClass: CallActionActionComponent, VariableClass: Variable, + UserPropertyClass: UserProperty, GlyphClass: Glyph, ScpiCommandClass: ScpiCommand, ScpiSubsystemClass: ScpiSubsystem, diff --git a/packages/project-editor/project-editor-interface.tsx b/packages/project-editor/project-editor-interface.tsx index 008a2e4d..c1c6a7ce 100644 --- a/packages/project-editor/project-editor-interface.tsx +++ b/packages/project-editor/project-editor-interface.tsx @@ -103,6 +103,7 @@ import type { PropertyInfo } from "project-editor/core/object"; import type { migrateLvglVersion } from "project-editor/lvgl/migrate"; import type { FlowTabState } from "project-editor/flow/flow-tab-state"; import type { Color } from "project-editor/features/style/theme"; +import type { UserProperty } from "./flow/user-property"; export interface IProjectEditor { homeTabs?: Tabs; @@ -135,6 +136,7 @@ export interface IProjectEditor { OutputActionComponentClass: typeof OutputActionComponent; CallActionActionComponentClass: typeof CallActionActionComponent; VariableClass: typeof Variable; + UserPropertyClass: typeof UserProperty; GlyphClass: typeof Glyph; ScpiCommandClass: typeof ScpiCommand; ScpiSubsystemClass: typeof ScpiSubsystem; diff --git a/packages/project-editor/ui-components/PropertyGrid/Property.tsx b/packages/project-editor/ui-components/PropertyGrid/Property.tsx index 2ab2899f..dce091c1 100644 --- a/packages/project-editor/ui-components/PropertyGrid/Property.tsx +++ b/packages/project-editor/ui-components/PropertyGrid/Property.tsx @@ -449,6 +449,8 @@ export const Property = observer( if (newValue != oldValue) { this.context.undoManager.setCombineCommands(true); + console.log("Change unique value", oldValue, newValue); + runInAction(() => { replaceObjectReference( this.props.objects[0],