Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract events into new group #1254

Merged
merged 5 commits into from Oct 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 39 additions & 0 deletions newIDE/app/src/EventsSheet/index.js
Expand Up @@ -750,6 +750,17 @@ export default class EventsSheet extends React.Component<Props, State> {
eventsList.delete();
};

moveEventsIntoNewGroup = () => {
const eventsList = new gd.EventsList();

getSelectedEvents(this.state.selection).forEach(event =>
eventsList.insertEvent(event, eventsList.getEventsCount())
);

this._replaceSelectionByGroupOfEvents(eventsList);
eventsList.delete();
};

_replaceSelectionByEventsFunction = (
extensionName: string,
eventsFunction: gdEventsFunction
Expand Down Expand Up @@ -777,6 +788,30 @@ export default class EventsSheet extends React.Component<Props, State> {
this.deleteSelection({ deleteInstructions: false });
};

_replaceSelectionByGroupOfEvents = (eventsList: gdEventsList) => {
const contexts = getSelectedEventContexts(this.state.selection);
if (!contexts.length) return;

const newEvents = this.addNewEvent(
'BuiltinCommonInstructions::Group',
contexts[0]
);
if (!newEvents.length) {
console.error('A new event should have been created');
return;
}

const groupEvent = gd.asGroupEvent(newEvents[0]);

groupEvent.setName('Grouped events');
groupEvent.setFolded(true);
groupEvent
.getSubEvents()
.insertEvents(eventsList, 0, eventsList.getEventsCount(), 0);

this.deleteSelection({ deleteInstructions: false });
};

_ensureEventUnfolded = (cb: () => ?gdBaseEvent) => {
const event = cb();
if (event && this._eventsTree) {
Expand Down Expand Up @@ -1093,6 +1128,10 @@ export default class EventsSheet extends React.Component<Props, State> {
label: 'Extract Events to a Function',
click: () => this.extractEventsToFunction(),
},
{
label: 'Move Events into a Group',
click: () => this.moveEventsIntoNewGroup(),
},
{
label: 'Analyze Objects Used in this Event',
click: this._openEventsContextAnalyzer,
Expand Down