Share the Add action of events and shaders

This commit is contained in:
shweet committed 2026-11-22 19:11:47 -05:00
1 parent 69cb240a8d
commit f6325a794b
3 files changed
+27 -33

No files matched your search

+2 -17
View File
@@ -236,23 +236,8 @@ void events_update(Panel& panel)
actions.add( actions.add(
ACTION_RENAME, [selection]() { return selection.size() == 1; }, ACTION_RENAME, [selection]() { return selection.size() == 1; },
[&state, selection]() { state.newId = *selection.begin(); }); [&state, selection]() { state.newId = *selection.begin(); });
actions.add( named_item_add_action_add(actions, panel, SelectionKind::EVENTS, &Content::events, EDIT_ADD_EVENT,
ACTION_ADD, {}, TEXT_NEW_EVENT, TOOLTIP_ADD_EVENT);
[&panel]() {
auto& state = panel.state;
command_push(panel, [&state](Document& document) {
int id = 0;
document.edit_apply(EDIT_ADD_EVENT, [&](Model& model) {
auto& events = model.content.events;
id = item_next_id_get(events);
events.push_back({.id = id, .name = localize.get(TEXT_NEW_EVENT)});
});
document.selected_ids_set(SelectionKind::EVENTS, {id});
document.focused_id_set(SelectionKind::EVENTS, id);
state.newId = id;
});
},
TOOLTIP_ADD_EVENT);
content_remove_action_add(actions, panel, ElementType::EVENT_ELEMENT, SelectionKind::EVENTS); content_remove_action_add(actions, panel, ElementType::EVENT_ELEMENT, SelectionKind::EVENTS);
items_clipboard_actions_add<Event>(actions, panel, SelectionKind::EVENTS, EDIT_PASTE_EVENTS, items_clipboard_actions_add<Event>(actions, panel, SelectionKind::EVENTS, EDIT_PASTE_EVENTS,
TOAST_DESERIALIZE_EVENTS_FAILED, &Content::events); TOAST_DESERIALIZE_EVENTS_FAILED, &Content::events);
+23
View File
@@ -227,6 +227,29 @@ void items_paste(const Panel& panel, SelectionKind kind, StringType edit, String
}); });
} }
// An Add action making a named item (an event or a shader), selected and ready to rename.
template <class Item>
void named_item_add_action_add(Actions& actions, Panel& panel, SelectionKind kind, ContentList<Item> list,
StringType edit, StringType name, StringType tooltip)
{
actions.add(
ACTION_ADD, {},
[&panel, kind, list, edit, name]() {
command_push(panel, [&state = panel.state, kind, list, edit, name](Document& document) {
int id = 0;
document.edit_apply(edit, [&](Model& model) {
auto& items = model.content.*list;
id = item_next_id_get(items);
items.push_back({.id = id, .name = localize.get(name)});
});
document.selected_ids_set(kind, {id});
document.focused_id_set(kind, id);
state.newId = id;
});
},
tooltip);
}
// Copy and paste for a content list, after a separator. // Copy and paste for a content list, after a separator.
template <class Item> template <class Item>
void items_clipboard_actions_add(Actions& actions, Panel& panel, SelectionKind kind, StringType pasteEdit, void items_clipboard_actions_add(Actions& actions, Panel& panel, SelectionKind kind, StringType pasteEdit,
+2 -16
View File
@@ -307,22 +307,8 @@ void shaders_update(Panel& panel, ShadersPanel& shaders)
}; };
Actions actions = {}; Actions actions = {};
actions.add( named_item_add_action_add(actions, panel, SelectionKind::SHADERS, &Content::shaders, EDIT_ADD_SHADER,
ACTION_ADD, {}, TEXT_NEW_SHADER, TOOLTIP_ADD_SHADER);
[&]() {
command_push(panel, [&state](Document& document) {
int id = 0;
document.edit_apply(EDIT_ADD_SHADER, [&](Model& model) {
auto& shaders = model.content.shaders;
id = item_next_id_get(shaders);
shaders.push_back({.id = id, .name = localize.get(TEXT_NEW_SHADER)});
});
document.selected_ids_set(SelectionKind::SHADERS, {id});
document.focused_id_set(SelectionKind::SHADERS, id);
state.newId = id;
});
},
TOOLTIP_ADD_SHADER);
content_remove_action_add(actions, panel, ElementType::SHADER, SelectionKind::SHADERS); content_remove_action_add(actions, panel, ElementType::SHADER, SelectionKind::SHADERS);
actions.add( actions.add(
ACTION_RELOAD, [selection]() { return !selection.empty(); }, ACTION_RELOAD, [selection]() { return !selection.empty(); },