context menus, document refactoring, fixes

This commit is contained in:
2025-10-26 00:10:44 -04:00
parent 87c2db2a77
commit fe9366f9ef
62 changed files with 2138 additions and 793 deletions

View File

@@ -2,22 +2,21 @@
#include <ranges>
using namespace anm2ed::document_manager;
using namespace anm2ed::clipboard;
using namespace anm2ed::manager;
using namespace anm2ed::settings;
using namespace anm2ed::resources;
using namespace anm2ed::types;
namespace anm2ed::events
{
void Events::update(DocumentManager& manager, Settings& settings, Resources& resources)
void Events::update(Manager& manager, Settings& settings, Resources& resources, Clipboard& clipboard)
{
auto& document = *manager.get();
auto& anm2 = document.anm2;
auto& selection = document.selectedEvents;
if (document.is_just_changed(change::EVENTS)) unusedEventIDs = anm2.events_unused();
storage.user_data_set(&selection);
auto& unused = document.unusedEventIDs;
auto& hovered = document.hoveredEvent;
auto& multiSelect = document.eventMultiSelect;
if (ImGui::Begin("Events", &settings.windowIsEvents))
{
@@ -26,17 +25,16 @@ namespace anm2ed::events
if (ImGui::BeginChild("##Events Child", childSize, true))
{
storage.begin(anm2.content.events.size());
multiSelect.start(anm2.content.events.size());
for (auto& [id, event] : anm2.content.events)
{
auto isSelected = selection.contains(id);
ImGui::PushID(id);
ImGui::SetNextItemSelectionUserData(id);
if (imgui::selectable_input_text(event.name, std::format("###Document #{} Event #{}", manager.selected, id),
event.name, isSelected, 0, &isRenamed))
if (isRenamed) document.change(change::EVENTS);
event.name, multiSelect.contains(id), 0, &isRenamed))
if (ImGui::IsItemHovered()) hovered = id;
if (isRenamed) document.change(change::EVENTS);
if (ImGui::BeginItemTooltip())
{
ImGui::PushFont(resources.fonts[font::BOLD].get(), font::SIZE);
@@ -47,34 +45,67 @@ namespace anm2ed::events
ImGui::PopID();
}
storage.end();
multiSelect.finish();
auto copy = [&]()
{
if (!multiSelect.empty())
{
std::string clipboardText{};
for (auto& id : multiSelect)
clipboardText += anm2.content.events[id].to_string(id);
clipboard.set(clipboardText);
}
else if (hovered > -1)
clipboard.set(anm2.content.events[hovered].to_string(hovered));
};
auto paste = [&](merge::Type type)
{
auto clipboardText = clipboard.get();
document.events_deserialize(clipboardText, type);
};
if (imgui::shortcut(settings.shortcutCopy, shortcut::FOCUSED)) copy();
if (imgui::shortcut(settings.shortcutPaste, shortcut::FOCUSED)) paste(merge::APPEND);
if (ImGui::BeginPopupContextWindow("##Context Menu", ImGuiPopupFlags_MouseButtonRight))
{
ImGui::BeginDisabled();
ImGui::MenuItem("Cut", settings.shortcutCut.c_str());
ImGui::EndDisabled();
ImGui::BeginDisabled(multiSelect.empty() && hovered == -1);
if (ImGui::MenuItem("Copy", settings.shortcutCopy.c_str())) copy();
ImGui::EndDisabled();
ImGui::BeginDisabled(clipboard.is_empty());
{
if (ImGui::BeginMenu("Paste"))
{
if (ImGui::MenuItem("Append", settings.shortcutPaste.c_str())) paste(merge::APPEND);
if (ImGui::MenuItem("Replace")) paste(merge::REPLACE);
ImGui::EndMenu();
}
}
ImGui::EndDisabled();
ImGui::EndPopup();
}
}
ImGui::EndChild();
auto widgetSize = imgui::widget_size_with_row_get(2);
imgui::shortcut(settings.shortcutAdd);
if (ImGui::Button("Add", widgetSize))
{
int id{};
anm2.event_add(id);
selection = {id};
document.change(change::EVENTS);
}
if (ImGui::Button("Add", widgetSize)) document.event_add();
imgui::set_item_tooltip_shortcut("Add an event.", settings.shortcutAdd);
ImGui::SameLine();
imgui::shortcut(settings.shortcutRemove);
ImGui::BeginDisabled(unusedEventIDs.empty());
{
if (ImGui::Button("Remove Unused", widgetSize))
{
for (auto& id : unusedEventIDs)
anm2.content.events.erase(id);
document.change(change::EVENTS);
unusedEventIDs.clear();
}
}
ImGui::BeginDisabled(unused.empty());
if (ImGui::Button("Remove Unused", widgetSize)) document.events_remove_unused();
ImGui::EndDisabled();
imgui::set_item_tooltip_shortcut("Remove unused events (i.e., ones not used by any trigger in any animation.)",
settings.shortcutRemove);