Skip to content

Commit

Permalink
Factorize a bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
D8H committed Jan 21, 2025
1 parent 4840972 commit 847a6a3
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 41 deletions.
12 changes: 0 additions & 12 deletions newIDE/app/src/EventsSheet/ParameterFields/AnyVariableField.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,6 @@ export default React.forwardRef<ParameterFieldProps, ParameterFieldInterface>(
[projectScopedContainersAccessor]
);

const getVariableSourceFromVariableName = React.useCallback(
variableName =>
projectScopedContainersAccessor
.get()
.getVariablesContainersList()
.getVariablesContainerFromVariableNameExcludingParametersAndProperties(
variableName
)
.getSourceType(),
[projectScopedContainersAccessor]
);

const onVariableEditorApply = React.useCallback(
(selectedVariableName: string | null) => {
if (selectedVariableName && selectedVariableName.startsWith(value)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,6 @@ export default React.forwardRef<ParameterFieldProps, ParameterFieldInterface>(
[projectScopedContainersAccessor]
);

const getVariableSourceFromVariableName = React.useCallback(
variableName =>
projectScopedContainersAccessor
.get()
.getVariablesContainersList()
.getVariablesContainerFromVariableNameExcludingParameters(
variableName
)
.getSourceType(),
[projectScopedContainersAccessor]
);

const onVariableEditorApply = React.useCallback(
(selectedVariableName: string | null) => {
if (selectedVariableName && selectedVariableName.startsWith(value)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,6 @@ export default React.forwardRef<ParameterFieldProps, ParameterFieldInterface>(
[projectScopedContainersAccessor]
);

const getVariableSourceFromVariableName = React.useCallback(
variableName =>
projectScopedContainersAccessor
.get()
.getVariablesContainersList()
.getVariablesContainerFromVariableName(variableName)
.getSourceType(),
[projectScopedContainersAccessor]
);

const onVariableEditorApply = React.useCallback(
(selectedVariableName: string | null) => {
if (selectedVariableName && selectedVariableName.startsWith(value)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ export default React.forwardRef<ParameterFieldProps, ParameterFieldInterface>(
const variablesContainer = variablesContainers.find(
variablesContainer => variablesContainer.has(variableName)
);
return variablesContainer ? variablesContainer.getSourceType() : null;
return variablesContainer
? variablesContainer.getSourceType()
: gd.VariablesContainer.Unknown;
},
[variablesContainers]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ export default React.forwardRef<ParameterFieldProps, ParameterFieldInterface>(
const variablesContainer = variablesContainers.find(
variablesContainer => variablesContainer.has(variableName)
);
return variablesContainer ? variablesContainer.getSourceType() : null;
return variablesContainer
? variablesContainer.getSourceType()
: gd.VariablesContainer.Unknown;
},
[variablesContainers]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ export default React.forwardRef<ParameterFieldProps, ParameterFieldInterface>(
const variablesContainer = variablesContainers.find(
variablesContainer => variablesContainer.has(variableName)
);
return variablesContainer ? variablesContainer.getSourceType() : null;
return variablesContainer
? variablesContainer.getSourceType()
: gd.VariablesContainer.Unknown;
},
[variablesContainers]
);
Expand Down
13 changes: 9 additions & 4 deletions newIDE/app/src/EventsSheet/ParameterFields/VariableField.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ type Props = {
isObjectVariable: boolean,
variablesContainers: Array<gdVariablesContainer>,
getVariableSourceFromVariableName: (
variableRootName: string
) => VariablesContainer_SourceType | null,
variableRootName: string,
projectScopedContainers: gdProjectScopedContainers
) => VariablesContainer_SourceType,
enumerateVariables: () => Array<EnumeratedVariable>,
forceDeclaration?: boolean,
onOpenDialog: (VariableDialogOpeningProps => void) | null,
Expand Down Expand Up @@ -102,7 +103,8 @@ export const quicklyAnalyzeVariableName = (
name: string,
variablesContainers?: Array<gdVariablesContainer>,
getVariableSourceFromVariableName?: (
variableRootName: string
variableRootName: string,
projectScopedContainers: gdProjectScopedContainers
) => VariablesContainer_SourceType | null,
projectScopedContainersAccessor?: ProjectScopedContainersAccessor,
isObjectVariable: boolean = false
Expand Down Expand Up @@ -159,7 +161,10 @@ export const quicklyAnalyzeVariableName = (
name.length !== rootVariableName.length &&
getVariableSourceFromVariableName
) {
const variableSource = getVariableSourceFromVariableName(rootVariableName);
const variableSource = getVariableSourceFromVariableName(
rootVariableName,
projectScopedContainers
);

if (variableSource === gd.VariablesContainer.Parameters) {
return VariableNameQuickAnalyzeResults.PARAMETER_WITH_CHILD;
Expand Down

0 comments on commit 847a6a3

Please sign in to comment.