Skip to content

Commit cfd0318

Browse files
committed
fix user property bugs: not opening expression builder and auto update after rename
1 parent b6480d9 commit cfd0318

File tree

5 files changed

+42
-7
lines changed

5 files changed

+42
-7
lines changed

packages/project-editor/core/search.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,10 @@ export function* searchForReference(
489489
let identifierType: IdentifierType | undefined;
490490
let structType: ValueType | undefined;
491491
let enumType: ValueType | undefined;
492-
if (object instanceof ProjectEditor.VariableClass) {
492+
if (
493+
object instanceof ProjectEditor.VariableClass ||
494+
object instanceof ProjectEditor.UserPropertyClass
495+
) {
493496
let flow = getAncestorOfType(object, ProjectEditor.FlowClass.classInfo);
494497
if (flow) {
495498
identifierType = "local-variable";

packages/project-editor/flow/user-property.tsx

+32-6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
getParent,
1515
IEezObject,
1616
IMessage,
17+
IOnSelectParams,
1718
MessageType,
1819
PropertyInfo,
1920
PropertyProps,
@@ -251,8 +252,11 @@ function getReferencedFlow(object: IEezObject): Flow | undefined {
251252
return undefined;
252253
}
253254

254-
function getPropertyInfoForUserProperty(userProperty: UserProperty) {
255-
return userProperty.assignable
255+
function getPropertyInfoForUserProperty(
256+
userProperty: UserProperty,
257+
parent: IEezObject
258+
) {
259+
const propertyInfo = userProperty.assignable
256260
? makeAssignableExpressionProperty(
257261
{
258262
name: userProperty.id,
@@ -273,12 +277,31 @@ function getPropertyInfoForUserProperty(userProperty: UserProperty) {
273277
},
274278
userProperty.type
275279
);
280+
281+
const onSelect = propertyInfo.onSelect!;
282+
283+
propertyInfo.onSelect = async (
284+
object: IEezObject,
285+
propertyInfo: PropertyInfo,
286+
params?: IOnSelectParams
287+
) => {
288+
(object as any)._eez_parent = parent;
289+
290+
await onSelect(object, propertyInfo, params);
291+
292+
delete (object as any)._eez_parent;
293+
};
294+
295+
return propertyInfo;
276296
}
277297

278298
function getUserPropertiesAsPropertyInfos(
279-
userProperties: UserProperty[]
299+
userProperties: UserProperty[],
300+
parent: IEezObject
280301
): PropertyInfo[] {
281-
return userProperties.map(getPropertyInfoForUserProperty);
302+
return userProperties.map(userProperty =>
303+
getPropertyInfoForUserProperty(userProperty, parent)
304+
);
282305
}
283306

284307
function makeValueObjectForUserProperty(
@@ -287,7 +310,7 @@ function makeValueObjectForUserProperty(
287310
) {
288311
const valueObject = EezValueObject.create(
289312
userPropertyValues,
290-
getPropertyInfoForUserProperty(userProperty),
313+
getPropertyInfoForUserProperty(userProperty, userPropertyValues),
291314
userPropertyValues.values[userProperty.id]
292315
);
293316

@@ -394,7 +417,10 @@ export const UserPropertyValuesProperty = observer(
394417
return [];
395418
}
396419

397-
return getUserPropertiesAsPropertyInfos(flow.userProperties);
420+
return getUserPropertiesAsPropertyInfos(
421+
flow.userProperties,
422+
object
423+
);
398424
}
399425

400426
render() {

packages/project-editor/project-editor-create.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ import { evalProperty } from "project-editor/flow/helper";
126126
import { migrateLvglVersion } from "./lvgl/migrate";
127127
import { FlowTabState } from "project-editor/flow/flow-tab-state";
128128
import { Color } from "project-editor/features/style/theme";
129+
import { UserProperty } from "./flow/user-property";
129130

130131
export const conditionalStyleConditionProperty = makeExpressionProperty(
131132
{
@@ -186,6 +187,7 @@ export async function createProjectEditor(
186187
OutputActionComponentClass: OutputActionComponent,
187188
CallActionActionComponentClass: CallActionActionComponent,
188189
VariableClass: Variable,
190+
UserPropertyClass: UserProperty,
189191
GlyphClass: Glyph,
190192
ScpiCommandClass: ScpiCommand,
191193
ScpiSubsystemClass: ScpiSubsystem,

packages/project-editor/project-editor-interface.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ import type { PropertyInfo } from "project-editor/core/object";
103103
import type { migrateLvglVersion } from "project-editor/lvgl/migrate";
104104
import type { FlowTabState } from "project-editor/flow/flow-tab-state";
105105
import type { Color } from "project-editor/features/style/theme";
106+
import type { UserProperty } from "./flow/user-property";
106107

107108
export interface IProjectEditor {
108109
homeTabs?: Tabs;
@@ -135,6 +136,7 @@ export interface IProjectEditor {
135136
OutputActionComponentClass: typeof OutputActionComponent;
136137
CallActionActionComponentClass: typeof CallActionActionComponent;
137138
VariableClass: typeof Variable;
139+
UserPropertyClass: typeof UserProperty;
138140
GlyphClass: typeof Glyph;
139141
ScpiCommandClass: typeof ScpiCommand;
140142
ScpiSubsystemClass: typeof ScpiSubsystem;

packages/project-editor/ui-components/PropertyGrid/Property.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,8 @@ export const Property = observer(
449449
if (newValue != oldValue) {
450450
this.context.undoManager.setCombineCommands(true);
451451

452+
console.log("Change unique value", oldValue, newValue);
453+
452454
runInAction(() => {
453455
replaceObjectReference(
454456
this.props.objects[0],

0 commit comments

Comments
 (0)