Fix the event height after adding local variables (#6590)

- Also fix local variable dialog cancel.
- Don't show in changelog
This commit is contained in:
D8H
2024-05-24 16:39:11 +02:00
committed by GitHub
parent 0fd25c381a
commit 4886cf4fd3
2 changed files with 70 additions and 16 deletions

View File

@@ -114,7 +114,7 @@ import {
} from '../MainFrame/ResourcesWatcher';
import { insertInVariablesContainer } from '../Utils/VariablesUtils';
import { ProjectScopedContainersAccessor } from '../InstructionOrExpression/EventsScope.flow';
import VariablesEditorDialog from '../VariablesList/VariablesEditorDialog';
import LocalVariablesDialog from '../VariablesList/LocalVariablesDialog';
const gd: libGDevelop = global.gd;
@@ -2102,9 +2102,8 @@ export class EventsSheetComponentWithoutHandle extends React.Component<
/>
)}
{this.state.editedVariable && (
<VariablesEditorDialog
<LocalVariablesDialog
project={project}
title={<Trans>Local variables</Trans>}
open
onCancel={() =>
this.setState({
@@ -2112,23 +2111,27 @@ export class EventsSheetComponentWithoutHandle extends React.Component<
})
}
onApply={() => {
const eventContext = this.state.editedVariable
? this.state.editedVariable.eventContext
: null;
this.setState({
editedVariable: null,
});
if (this._eventsTree)
this._eventsTree.forceEventsUpdate();
if (this._eventsTree && eventContext) {
this._eventsTree.forceEventsUpdate(() => {
const positions = this._getChangedEventRows([
eventContext.event,
]);
this._saveChangesToHistory('ADD', {
positionsBeforeAction: positions,
positionAfterAction: positions,
});
});
}
}}
tabs={[
{
id: 'local-variables',
label: '',
variablesContainer: this.state.editedVariable
.variablesContainer,
onComputeAllVariableNames: () => [],
},
]}
helpPagePath={'/all-features/variables/local-variables'}
preventRefactoringToDeleteInstructions
variablesContainer={
this.state.editedVariable.variablesContainer
}
initiallySelectedVariableName={
this.state.editedVariable.variableName
}

View File

@@ -0,0 +1,51 @@
// @flow
import * as React from 'react';
import { Trans } from '@lingui/macro';
import VariablesEditorDialog from './VariablesEditorDialog';
type Props = {|
open: boolean,
project: gdProject,
variablesContainer: gdVariablesContainer,
onApply: (selectedVariableName: string | null) => void,
onCancel: () => void,
initiallySelectedVariableName: string,
|};
const LocalVariablesDialog = ({
project,
variablesContainer,
open,
onCancel,
onApply,
initiallySelectedVariableName,
}: Props) => {
const tabs = React.useMemo(
() => [
{
id: 'local-variables',
label: '',
variablesContainer,
onComputeAllVariableNames: () => [],
},
],
[variablesContainer]
);
return (
<VariablesEditorDialog
project={project}
open={open}
onCancel={onCancel}
onApply={onApply}
title={<Trans>Local variables</Trans>}
tabs={tabs}
helpPagePath={'/all-features/variables/local-variables'}
preventRefactoringToDeleteInstructions
id="local-variables-dialog"
initiallySelectedVariableName={initiallySelectedVariableName}
/>
);
};
export default LocalVariablesDialog;