Skip to content

Commit d81a689

Browse files
authored
Allow to create variables from autocompletion in more cases (#8583)
Also, in the extension editor: - Focus and select new parameter names - Allow to add a new parameter from the variable autocompletion - Allow to add behaviors from the bottom of the instruction list
1 parent cacd28e commit d81a689

37 files changed

Lines changed: 1519 additions & 1114 deletions

newIDE/app/src/BehaviorsEditor/NewBehaviorDialog.js

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type Props = {|
4040
onChoose: (type: string, defaultName: string) => void,
4141
onWillInstallExtension: (extensionNames: Array<string>) => void,
4242
onExtensionInstalled: (extensionNames: Array<string>) => void,
43+
shouldShowCapabilityBehaviors: boolean,
4344
|};
4445

4546
export default function NewBehaviorDialog({
@@ -53,6 +54,7 @@ export default function NewBehaviorDialog({
5354
isChildObject,
5455
onWillInstallExtension,
5556
onExtensionInstalled,
57+
shouldShowCapabilityBehaviors,
5658
}: Props): null | React.Node {
5759
const [isInstalling, setIsInstalling] = React.useState(false);
5860
const authenticatedUser = React.useContext(AuthenticatedUserContext);
@@ -103,7 +105,7 @@ export default function NewBehaviorDialog({
103105
const allInstalledBehaviorMetadataList: Array<BehaviorShortHeader> = React.useMemo(
104106
() => {
105107
const platform = project.getCurrentPlatform();
106-
const behaviorMetadataList =
108+
let behaviorMetadataList =
107109
project && platform
108110
? enumerateBehaviorsMetadata(
109111
platform,
@@ -112,39 +114,48 @@ export default function NewBehaviorDialog({
112114
)
113115
: [];
114116

115-
return behaviorMetadataList
116-
.filter(behavior => !behavior.behaviorMetadata.isHidden())
117-
.map(behavior => ({
118-
type: behavior.type,
119-
fullName: behavior.fullName,
120-
description: behavior.description,
121-
previewIconUrl: behavior.previewIconUrl,
122-
objectType: behavior.objectType,
123-
category: behavior.category,
124-
allRequiredBehaviorTypes: getAllRequiredBehaviorTypes(
125-
behavior.behaviorMetadata
126-
),
127-
tags: behavior.tags,
128-
name: gd.PlatformExtension.getBehaviorNameFromFullBehaviorType(
129-
behavior.type
130-
),
131-
extensionName: gd.PlatformExtension.getExtensionFromFullBehaviorType(
132-
behavior.type
133-
),
117+
if (!shouldShowCapabilityBehaviors) {
118+
behaviorMetadataList = behaviorMetadataList.filter(
119+
behavior => !behavior.behaviorMetadata.isHidden()
120+
);
121+
}
122+
123+
return behaviorMetadataList.map(behavior => ({
124+
type: behavior.type,
125+
fullName: behavior.fullName,
126+
description: behavior.description,
127+
previewIconUrl: behavior.previewIconUrl,
128+
objectType: behavior.objectType,
129+
category: behavior.category,
130+
allRequiredBehaviorTypes: getAllRequiredBehaviorTypes(
131+
behavior.behaviorMetadata
132+
),
133+
tags: behavior.tags,
134+
name: gd.PlatformExtension.getBehaviorNameFromFullBehaviorType(
135+
behavior.type
136+
),
137+
extensionName: gd.PlatformExtension.getExtensionFromFullBehaviorType(
138+
behavior.type
139+
),
134140

135-
isInstalled: true,
136-
// The tier will be overridden with repository data.
137-
// Only the built-in and user extensions will keep this value.
138-
tier: 'installed',
139-
// Not relevant for `installed` extensions
140-
version: '',
141-
url: '',
142-
headerUrl: '',
143-
extensionNamespace: '',
144-
authorIds: [],
145-
}));
141+
isInstalled: true,
142+
// The tier will be overridden with repository data.
143+
// Only the built-in and user extensions will keep this value.
144+
tier: 'installed',
145+
// Not relevant for `installed` extensions
146+
version: '',
147+
url: '',
148+
headerUrl: '',
149+
extensionNamespace: '',
150+
authorIds: [],
151+
}));
146152
},
147-
[project, eventsFunctionsExtension, getAllRequiredBehaviorTypes]
153+
[
154+
project,
155+
eventsFunctionsExtension,
156+
shouldShowCapabilityBehaviors,
157+
getAllRequiredBehaviorTypes,
158+
]
148159
);
149160

150161
const installedBehaviorMetadataList: Array<BehaviorShortHeader> = React.useMemo(

newIDE/app/src/BehaviorsEditor/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@ export const useManageObjectBehaviors = ({
612612
eventsFunctionsExtension={eventsFunctionsExtension}
613613
onWillInstallExtension={onWillInstallExtension}
614614
onExtensionInstalled={onExtensionInstalled}
615+
shouldShowCapabilityBehaviors={false}
615616
/>
616617
);
617618

newIDE/app/src/EventsFunctionsExtensionEditor/EventsBasedBehaviorOrObjectEditor/EventsBasedBehaviorOrObjectPropertiesEditor.js

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,33 @@ const renderValueTypeIcon = (type: string, className: string): React.Node => {
9090
}
9191
};
9292

93+
export const fillBehaviorProperty = (
94+
projectScopedContainersAccessor: ProjectScopedContainersAccessor,
95+
eventsBasedBehavior: gdEventsBasedBehavior,
96+
property: gdNamedPropertyDescriptor,
97+
behaviorType: string
98+
) => {
99+
// Change the type of the required behavior.
100+
const extraInfo = property.getExtraInfo();
101+
if (extraInfo.size() === 0) {
102+
extraInfo.push_back(behaviorType);
103+
} else {
104+
extraInfo.set(0, behaviorType);
105+
}
106+
const behaviorMetadata = gd.MetadataProvider.getBehaviorMetadata(
107+
projectScopedContainersAccessor.getScope().project.getCurrentPlatform(),
108+
behaviorType
109+
);
110+
const projectScopedContainers = projectScopedContainersAccessor.get();
111+
const validatedNewName = getValidatedPropertyName(
112+
eventsBasedBehavior.getPropertyDescriptors(),
113+
projectScopedContainers,
114+
behaviorMetadata.getDefaultName()
115+
);
116+
property.setName(validatedNewName);
117+
property.setLabel(behaviorMetadata.getFullName());
118+
};
119+
93120
const setExtraInfoString = (
94121
property: gdNamedPropertyDescriptor,
95122
value: string
@@ -674,27 +701,15 @@ export const EventsBasedBehaviorPropertiesEditor: React.ComponentType<{
674701
: property.getExtraInfo().at(0)
675702
}
676703
onChange={(newValue: string) => {
677-
// Change the type of the required behavior.
678-
const extraInfo = property.getExtraInfo();
679-
if (extraInfo.size() === 0) {
680-
extraInfo.push_back(newValue);
681-
} else {
682-
extraInfo.set(0, newValue);
704+
if (!eventsBasedBehavior) {
705+
return;
683706
}
684-
const behaviorMetadata = gd.MetadataProvider.getBehaviorMetadata(
685-
project.getCurrentPlatform(),
707+
fillBehaviorProperty(
708+
projectScopedContainersAccessor,
709+
eventsBasedBehavior,
710+
property,
686711
newValue
687712
);
688-
const projectScopedContainers = projectScopedContainersAccessor.get();
689-
const validatedNewName = getValidatedPropertyName(
690-
properties,
691-
projectScopedContainers,
692-
behaviorMetadata.getDefaultName()
693-
);
694-
property.setName(validatedNewName);
695-
property.setLabel(
696-
behaviorMetadata.getFullName()
697-
);
698713
forceUpdate();
699714
onPropertiesUpdated();
700715
}}

0 commit comments

Comments
 (0)