Fix events shortcuts from triggering when a dialog is opened (#6726)

This commit is contained in:
D8H
2024-06-30 17:31:00 +02:00
committed by GitHub
parent 6b3faa42bb
commit 4a283add00

View File

@@ -1869,303 +1869,305 @@ export class EventsSheetComponentWithoutHandle extends React.Component<
: projectScopedContainersAccessor;
return (
<ResponsiveWindowMeasurer>
{({ windowSize }) => (
<EventsSearcher
key={events.ptr}
ref={eventSearcher => (this._eventSearcher = eventSearcher)}
events={events}
globalObjectsContainer={globalObjectsContainer}
objectsContainer={objectsContainer}
selection={this.state.selection}
project={project}
>
{({
eventsSearchResultEvents,
searchFocusOffset,
searchInEvents,
replaceInEvents,
goToPreviousSearchResult,
goToNextSearchResult,
}) => (
<div
id="events-editor"
data-active={isActive ? 'true' : undefined}
className="gd-events-sheet"
style={styles.container}
onKeyDown={this._keyboardShortcuts.onKeyDown}
onKeyUp={this._keyboardShortcuts.onKeyUp}
onDragOver={this._keyboardShortcuts.onDragOver}
ref={this._containerDiv}
tabIndex={0}
>
{isFunctionOnlyCallingItself && (
<Line>
<Column expand>
<AlertMessage kind="warning">
<Trans>
This function calls itself (it is "recursive"). Ensure
this is expected and there is a proper condition to
stop it if necessary.
</Trans>
</AlertMessage>
</Column>
</Line>
)}
<EventsTree
ref={eventsTree => (this._eventsTree = eventsTree)}
key={events.ptr}
indentScale={preferences.values.eventsSheetIndentScale}
onScroll={this._ensureFocused}
events={events}
project={project}
scope={scope}
globalObjectsContainer={globalObjectsContainer}
objectsContainer={objectsContainer}
projectScopedContainersAccessor={
projectScopedContainersAccessor
}
selection={this.state.selection}
onInstructionClick={this.selectInstruction}
onInstructionDoubleClick={this.openInstructionEditor}
onInstructionContextMenu={this.openInstructionContextMenu}
onAddInstructionContextMenu={
this.openAddInstructionContextMenu
}
onAddNewInstruction={this.openInstructionEditor}
onPasteInstructions={this.pasteInstructionsInInstructionsList}
onMoveToInstruction={this.moveSelectionToInstruction}
onMoveToInstructionsList={
this.moveSelectionToInstructionsList
}
onParameterClick={this.openParameterEditor}
onVariableDeclarationClick={() => {
// Nothing to do.
}}
onVariableDeclarationDoubleClick={this.openVariablesEditor}
onEventClick={this.selectEvent}
onEventContextMenu={this.openEventContextMenu}
onAddNewEvent={(
eventType: string,
eventsList: gdEventsList
) => {
this.addNewEvent(eventType, {
eventsList,
indexInList: eventsList.getEventsCount(),
});
}}
onOpenExternalEvents={onOpenExternalEvents}
onOpenLayout={onOpenLayout}
searchResults={eventsSearchResultEvents}
searchFocusOffset={searchFocusOffset}
onEventMoved={this._onEventMoved}
onEndEditingEvent={this._onEndEditingStringEvent}
showObjectThumbnails={
preferences.values.eventsSheetShowObjectThumbnails
}
screenType={screenType}
windowSize={windowSize}
eventsSheetHeight={
this._containerDiv.current
? this._containerDiv.current.clientHeight
: 0
}
fontSize={preferences.values.eventsSheetZoomLevel}
preferences={preferences}
tutorials={tutorials}
/>
{this.state.showSearchPanel && (
<ErrorBoundary
componentTitle={<Trans>Search panel</Trans>}
scope="scene-events-search"
onClose={() => this._closeSearchPanel()}
>
<SearchPanel
ref={searchPanel => (this._searchPanel = searchPanel)}
onSearchInEvents={inputs =>
this._searchInEvents(searchInEvents, inputs)
}
onReplaceInEvents={inputs => {
this._replaceInEvents(replaceInEvents, inputs);
}}
resultsCount={
eventsSearchResultEvents
? eventsSearchResultEvents.length
: null
}
hasEventSelected={hasEventSelected(this.state.selection)}
onGoToPreviousSearchResult={() =>
this._ensureEventUnfolded(goToPreviousSearchResult)
}
onCloseSearchPanel={() => {
this._closeSearchPanel();
}}
onGoToNextSearchResult={() =>
this._ensureEventUnfolded(goToNextSearchResult)
}
searchFocusOffset={searchFocusOffset}
/>
</ErrorBoundary>
)}
<InlineParameterEditor
open={this.state.inlineEditing}
anchorEl={this.state.inlineEditingAnchorEl}
onRequestClose={() => {
this.closeParameterEditor(
/*shouldCancel=*/ preferences.values
.eventsSheetCancelInlineParameter === 'cancel'
);
}}
onApply={() => {
this.closeParameterEditor(/*shouldCancel=*/ false);
}}
project={project}
scope={scope}
globalObjectsContainer={globalObjectsContainer}
objectsContainer={objectsContainer}
projectScopedContainersAccessor={
editedParameterProjectScopedContainersAccessor
}
isCondition={this.state.editedParameter.isCondition}
instruction={this.state.editedParameter.instruction}
parameterIndex={this.state.editedParameter.parameterIndex}
onChange={value => {
const {
instruction,
parameterIndex,
} = this.state.editedParameter;
if (!instruction || !this.state.inlineEditing) {
// Unlikely to ever happen, but maybe a component could
// fire the "onChange" while the inline editor was just
// dismissed.
return;
}
instruction.setParameter(parameterIndex, value);
gd.VariableInstructionSwitcher.switchBetweenUnifiedInstructionIfNeeded(
project.getCurrentPlatform(),
editedParameterProjectScopedContainersAccessor.get(),
instruction
);
// Ask the component to re-render, so that the new parameter
// set for the instruction in the state
// is taken into account for the InlineParameterEditor.
this.forceUpdate();
if (this._searchPanel)
this._searchPanel.markSearchResultsDirty();
}}
resourceManagementProps={resourceManagementProps}
/>
<ContextMenu
ref={eventContextMenu =>
(this.eventContextMenu = eventContextMenu)
}
buildMenuTemplate={this._buildEventContextMenu}
/>
<ContextMenu
ref={instructionContextMenu =>
(this.instructionContextMenu = instructionContextMenu)
}
buildMenuTemplate={this._buildInstructionContextMenu}
/>
{this._renderInstructionEditorDialog()}
{this.state.analyzedEventsContextResult && (
<EventsContextAnalyzerDialog
onClose={this._closeEventsContextAnalyzer}
eventsContextResult={this.state.analyzedEventsContextResult}
/>
)}
{this.state.serializedEventsToExtract && (
<EventsFunctionExtractorDialog
<>
<ResponsiveWindowMeasurer>
{({ windowSize }) => (
<EventsSearcher
key={events.ptr}
ref={eventSearcher => (this._eventSearcher = eventSearcher)}
events={events}
globalObjectsContainer={globalObjectsContainer}
objectsContainer={objectsContainer}
selection={this.state.selection}
project={project}
>
{({
eventsSearchResultEvents,
searchFocusOffset,
searchInEvents,
replaceInEvents,
goToPreviousSearchResult,
goToNextSearchResult,
}) => (
<div
id="events-editor"
data-active={isActive ? 'true' : undefined}
className="gd-events-sheet"
style={styles.container}
onKeyDown={this._keyboardShortcuts.onKeyDown}
onKeyUp={this._keyboardShortcuts.onKeyUp}
onDragOver={this._keyboardShortcuts.onDragOver}
ref={this._containerDiv}
tabIndex={0}
>
{isFunctionOnlyCallingItself && (
<Line>
<Column expand>
<AlertMessage kind="warning">
<Trans>
This function calls itself (it is "recursive").
Ensure this is expected and there is a proper
condition to stop it if necessary.
</Trans>
</AlertMessage>
</Column>
</Line>
)}
<EventsTree
ref={eventsTree => (this._eventsTree = eventsTree)}
key={events.ptr}
indentScale={preferences.values.eventsSheetIndentScale}
onScroll={this._ensureFocused}
events={events}
project={project}
scope={scope}
globalObjectsContainer={globalObjectsContainer}
objectsContainer={objectsContainer}
onClose={() =>
this.setState({
serializedEventsToExtract: null,
})
}
serializedEvents={this.state.serializedEventsToExtract}
onCreate={(extensionName, eventsFunction) => {
onCreateEventsFunction(extensionName, eventsFunction);
this._replaceSelectionByEventsFunction(
extensionName,
eventsFunction
);
this.setState({
serializedEventsToExtract: null,
});
}}
/>
)}
{this.state.editedVariable && (
<LocalVariablesDialog
project={project}
projectScopedContainersAccessor={
editedParameterProjectScopedContainersAccessor
}
open
onCancel={() =>
this.setState({
editedVariable: null,
})
}
onApply={() => {
const eventContext = this.state.editedVariable
? this.state.editedVariable.eventContext
: null;
this.setState({
editedVariable: null,
});
if (this._eventsTree && eventContext) {
this._eventsTree.forceEventsUpdate(() => {
const positions = this._getChangedEventRows([
eventContext.event,
]);
this._saveChangesToHistory('ADD', {
positionsBeforeAction: positions,
positionAfterAction: positions,
});
});
}
}}
variablesContainer={
this.state.editedVariable.variablesContainer
}
initiallySelectedVariableName={
this.state.editedVariable.variableName
}
shouldCreateInitiallySelectedVariable={
this.state.editedVariable.shouldCreateVariable
}
/>
)}
{this.state.layoutVariablesDialogOpen && (
<GlobalAndSceneVariablesDialog
projectScopedContainersAccessor={
projectScopedContainersAccessor
}
open
onCancel={() => this.editLayoutVariables(false)}
onApply={() => this.editLayoutVariables(false)}
/>
)}
{this.state.textEditedEvent && (
<EventTextDialog
event={this.state.textEditedEvent}
onApply={() => {
this.closeEventTextDialog();
selection={this.state.selection}
onInstructionClick={this.selectInstruction}
onInstructionDoubleClick={this.openInstructionEditor}
onInstructionContextMenu={this.openInstructionContextMenu}
onAddInstructionContextMenu={
this.openAddInstructionContextMenu
}
onAddNewInstruction={this.openInstructionEditor}
onPasteInstructions={
this.pasteInstructionsInInstructionsList
}
onMoveToInstruction={this.moveSelectionToInstruction}
onMoveToInstructionsList={
this.moveSelectionToInstructionsList
}
onParameterClick={this.openParameterEditor}
onVariableDeclarationClick={() => {
// Nothing to do.
}}
onClose={this.closeEventTextDialog}
onVariableDeclarationDoubleClick={this.openVariablesEditor}
onEventClick={this.selectEvent}
onEventContextMenu={this.openEventContextMenu}
onAddNewEvent={(
eventType: string,
eventsList: gdEventsList
) => {
this.addNewEvent(eventType, {
eventsList,
indexInList: eventsList.getEventsCount(),
});
}}
onOpenExternalEvents={onOpenExternalEvents}
onOpenLayout={onOpenLayout}
searchResults={eventsSearchResultEvents}
searchFocusOffset={searchFocusOffset}
onEventMoved={this._onEventMoved}
onEndEditingEvent={this._onEndEditingStringEvent}
showObjectThumbnails={
preferences.values.eventsSheetShowObjectThumbnails
}
screenType={screenType}
windowSize={windowSize}
eventsSheetHeight={
this._containerDiv.current
? this._containerDiv.current.clientHeight
: 0
}
fontSize={preferences.values.eventsSheetZoomLevel}
preferences={preferences}
tutorials={tutorials}
/>
)}
</div>
)}
</EventsSearcher>
{this.state.showSearchPanel && (
<ErrorBoundary
componentTitle={<Trans>Search panel</Trans>}
scope="scene-events-search"
onClose={() => this._closeSearchPanel()}
>
<SearchPanel
ref={searchPanel => (this._searchPanel = searchPanel)}
onSearchInEvents={inputs =>
this._searchInEvents(searchInEvents, inputs)
}
onReplaceInEvents={inputs => {
this._replaceInEvents(replaceInEvents, inputs);
}}
resultsCount={
eventsSearchResultEvents
? eventsSearchResultEvents.length
: null
}
hasEventSelected={hasEventSelected(
this.state.selection
)}
onGoToPreviousSearchResult={() =>
this._ensureEventUnfolded(goToPreviousSearchResult)
}
onCloseSearchPanel={() => {
this._closeSearchPanel();
}}
onGoToNextSearchResult={() =>
this._ensureEventUnfolded(goToNextSearchResult)
}
searchFocusOffset={searchFocusOffset}
/>
</ErrorBoundary>
)}
<InlineParameterEditor
open={this.state.inlineEditing}
anchorEl={this.state.inlineEditingAnchorEl}
onRequestClose={() => {
this.closeParameterEditor(
/*shouldCancel=*/ preferences.values
.eventsSheetCancelInlineParameter === 'cancel'
);
}}
onApply={() => {
this.closeParameterEditor(/*shouldCancel=*/ false);
}}
project={project}
scope={scope}
globalObjectsContainer={globalObjectsContainer}
objectsContainer={objectsContainer}
projectScopedContainersAccessor={
editedParameterProjectScopedContainersAccessor
}
isCondition={this.state.editedParameter.isCondition}
instruction={this.state.editedParameter.instruction}
parameterIndex={this.state.editedParameter.parameterIndex}
onChange={value => {
const {
instruction,
parameterIndex,
} = this.state.editedParameter;
if (!instruction || !this.state.inlineEditing) {
// Unlikely to ever happen, but maybe a component could
// fire the "onChange" while the inline editor was just
// dismissed.
return;
}
instruction.setParameter(parameterIndex, value);
gd.VariableInstructionSwitcher.switchBetweenUnifiedInstructionIfNeeded(
project.getCurrentPlatform(),
editedParameterProjectScopedContainersAccessor.get(),
instruction
);
// Ask the component to re-render, so that the new parameter
// set for the instruction in the state
// is taken into account for the InlineParameterEditor.
this.forceUpdate();
if (this._searchPanel)
this._searchPanel.markSearchResultsDirty();
}}
resourceManagementProps={resourceManagementProps}
/>
<ContextMenu
ref={eventContextMenu =>
(this.eventContextMenu = eventContextMenu)
}
buildMenuTemplate={this._buildEventContextMenu}
/>
<ContextMenu
ref={instructionContextMenu =>
(this.instructionContextMenu = instructionContextMenu)
}
buildMenuTemplate={this._buildInstructionContextMenu}
/>
</div>
)}
</EventsSearcher>
)}
</ResponsiveWindowMeasurer>
{this._renderInstructionEditorDialog()}
{this.state.analyzedEventsContextResult && (
<EventsContextAnalyzerDialog
onClose={this._closeEventsContextAnalyzer}
eventsContextResult={this.state.analyzedEventsContextResult}
/>
)}
</ResponsiveWindowMeasurer>
{this.state.serializedEventsToExtract && (
<EventsFunctionExtractorDialog
project={project}
scope={scope}
globalObjectsContainer={globalObjectsContainer}
objectsContainer={objectsContainer}
onClose={() =>
this.setState({
serializedEventsToExtract: null,
})
}
serializedEvents={this.state.serializedEventsToExtract}
onCreate={(extensionName, eventsFunction) => {
onCreateEventsFunction(extensionName, eventsFunction);
this._replaceSelectionByEventsFunction(
extensionName,
eventsFunction
);
this.setState({
serializedEventsToExtract: null,
});
}}
/>
)}
{this.state.editedVariable && (
<LocalVariablesDialog
project={project}
projectScopedContainersAccessor={
editedParameterProjectScopedContainersAccessor
}
open
onCancel={() =>
this.setState({
editedVariable: null,
})
}
onApply={() => {
const eventContext = this.state.editedVariable
? this.state.editedVariable.eventContext
: null;
this.setState({
editedVariable: null,
});
if (this._eventsTree && eventContext) {
this._eventsTree.forceEventsUpdate(() => {
const positions = this._getChangedEventRows([
eventContext.event,
]);
this._saveChangesToHistory('ADD', {
positionsBeforeAction: positions,
positionAfterAction: positions,
});
});
}
}}
variablesContainer={this.state.editedVariable.variablesContainer}
initiallySelectedVariableName={
this.state.editedVariable.variableName
}
shouldCreateInitiallySelectedVariable={
this.state.editedVariable.shouldCreateVariable
}
/>
)}
{this.state.layoutVariablesDialogOpen && (
<GlobalAndSceneVariablesDialog
projectScopedContainersAccessor={projectScopedContainersAccessor}
open
onCancel={() => this.editLayoutVariables(false)}
onApply={() => this.editLayoutVariables(false)}
/>
)}
{this.state.textEditedEvent && (
<EventTextDialog
event={this.state.textEditedEvent}
onApply={() => {
this.closeEventTextDialog();
}}
onClose={this.closeEventTextDialog}
/>
)}
</>
);
}
}