Share the Add action of events and shaders
This commit is contained in:
1 parent
69cb240a8d
commit
f6325a794b
3 files changed
+27
-33
No files matched your search
+2
-17
@@ -236,23 +236,8 @@ void events_update(Panel& panel)
|
||||
actions.add(
|
||||
ACTION_RENAME, [selection]() { return selection.size() == 1; },
|
||||
[&state, selection]() { state.newId = *selection.begin(); });
|
||||
actions.add(
|
||||
ACTION_ADD, {},
|
||||
[&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);
|
||||
named_item_add_action_add(actions, panel, SelectionKind::EVENTS, &Content::events, EDIT_ADD_EVENT,
|
||||
TEXT_NEW_EVENT, TOOLTIP_ADD_EVENT);
|
||||
content_remove_action_add(actions, panel, ElementType::EVENT_ELEMENT, SelectionKind::EVENTS);
|
||||
items_clipboard_actions_add<Event>(actions, panel, SelectionKind::EVENTS, EDIT_PASTE_EVENTS,
|
||||
TOAST_DESERIALIZE_EVENTS_FAILED, &Content::events);
|
||||
|
||||
@@ -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.
|
||||
template <class Item>
|
||||
void items_clipboard_actions_add(Actions& actions, Panel& panel, SelectionKind kind, StringType pasteEdit,
|
||||
|
||||
+2
-16
@@ -307,22 +307,8 @@ void shaders_update(Panel& panel, ShadersPanel& shaders)
|
||||
};
|
||||
|
||||
Actions actions = {};
|
||||
actions.add(
|
||||
ACTION_ADD, {},
|
||||
[&]() {
|
||||
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);
|
||||
named_item_add_action_add(actions, panel, SelectionKind::SHADERS, &Content::shaders, EDIT_ADD_SHADER,
|
||||
TEXT_NEW_SHADER, TOOLTIP_ADD_SHADER);
|
||||
content_remove_action_add(actions, panel, ElementType::SHADER, SelectionKind::SHADERS);
|
||||
actions.add(
|
||||
ACTION_RELOAD, [selection]() { return !selection.empty(); },
|
||||
|
||||
Reference in new issue
Block a user