From da21340331d4ce838668335d196a7cdf27d85613 Mon Sep 17 00:00:00 2001 From: SweetId <2630750+SweetId@users.noreply.github.com> Date: Sat, 21 Oct 2023 10:22:44 -0400 Subject: [PATCH] path is now a vector of localized strings --- .../NazaraEditor/Core/Application/Action.hpp | 2 +- include/NazaraEditor/Core/UI/Window.hpp | 10 +++---- src/NazaraEditor/Core/UI/Window.cpp | 26 ++++++++----------- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/include/NazaraEditor/Core/Application/Action.hpp b/include/NazaraEditor/Core/Application/Action.hpp index af76f1c..a164268 100644 --- a/include/NazaraEditor/Core/Application/Action.hpp +++ b/include/NazaraEditor/Core/Application/Action.hpp @@ -19,7 +19,7 @@ namespace Nz { std::string className; Nz::LocalizedText description; - Nz::LocalizedText path; + std::vector path; std::string category; Nz::Shortcut shortcut; diff --git a/include/NazaraEditor/Core/UI/Window.hpp b/include/NazaraEditor/Core/UI/Window.hpp index 5145ea1..3dc7148 100644 --- a/include/NazaraEditor/Core/UI/Window.hpp +++ b/include/NazaraEditor/Core/UI/Window.hpp @@ -23,8 +23,8 @@ namespace Nz virtual void OnRenderImgui() override; - void AddMenuAction(const std::string& path, const std::string& shortcut, ActionCallback callback, const std::shared_ptr& icon = {}); - void AddMenuSeparator(const std::string& path); + void AddMenuAction(const std::vector& path, const std::string& shortcut, ActionCallback callback, const std::shared_ptr& icon = {}); + void AddMenuSeparator(const std::vector& path); EditorBaseApplication* GetApplication() { return m_application; } const EditorBaseApplication* GetApplication() const { return m_application; } @@ -46,7 +46,7 @@ namespace Nz struct MenuAction { - std::string label; + Nz::LocalizedText label; std::string shortcut; std::shared_ptr icon; ActionCallback callback; @@ -57,12 +57,12 @@ namespace Nz struct MenuList { - std::string label; + Nz::LocalizedText label; std::vector> entries; }; MenuList m_root; - MenuList& GetOrCreateMenuHierarchy(const std::vector& hierarchy); + MenuList& GetOrCreateMenuHierarchy(const std::vector& hierarchy); }; } \ No newline at end of file diff --git a/src/NazaraEditor/Core/UI/Window.cpp b/src/NazaraEditor/Core/UI/Window.cpp index dac3798..b507986 100644 --- a/src/NazaraEditor/Core/UI/Window.cpp +++ b/src/NazaraEditor/Core/UI/Window.cpp @@ -18,7 +18,7 @@ namespace Nz return; auto name = prop.className; - AddMenuAction(prop.path.ToString(), prop.shortcut.ToString(), [name]() { Nz::EditorBaseApplication::Instance()->GetActionStack().ExecuteAction(name); }, prop.icon); + AddMenuAction(prop.path, prop.shortcut.ToString(), [name]() { Nz::EditorBaseApplication::Instance()->GetActionStack().ExecuteAction(name); }, prop.icon); }); } @@ -45,25 +45,21 @@ namespace Nz } } - void EditorWindow::AddMenuAction(const std::string& path, const std::string& shortcut, ActionCallback callback, const std::shared_ptr& icon) + void EditorWindow::AddMenuAction(const std::vector& path, const std::string& shortcut, ActionCallback callback, const std::shared_ptr& icon) { - std::vector v; - Nz::SplitString(path, "|", [&](std::string_view str) { v.push_back(str); return true; }); + std::vector copy = path; + Nz::LocalizedText leaf = copy.back(); - std::string leaf = std::string(v.back()); + copy.pop_back(); // remove action name from hierarchy - v.pop_back(); // remove action name from hierarchy - - MenuList& parent = GetOrCreateMenuHierarchy(v); + MenuList& parent = GetOrCreateMenuHierarchy(copy); parent.entries.push_back(MenuAction{ leaf, shortcut, icon, callback}); } - void EditorWindow::AddMenuSeparator(const std::string& path) + void EditorWindow::AddMenuSeparator(const std::vector& path) { - std::vector v; - Nz::SplitString(path, "|", [&](std::string_view str) { v.push_back(str); return true; }); - MenuList& parent = GetOrCreateMenuHierarchy(v); + MenuList& parent = GetOrCreateMenuHierarchy(path); parent.entries.push_back(MenuSeparator{}); } @@ -109,9 +105,9 @@ namespace Nz visitor(menu); } - EditorWindow::MenuList& EditorWindow::GetOrCreateMenuHierarchy(const std::vector& hierarchy) + EditorWindow::MenuList& EditorWindow::GetOrCreateMenuHierarchy(const std::vector& hierarchy) { - auto getOrCreate_submenu = [](MenuList* menu, std::string_view v) -> MenuList* + auto getOrCreate_submenu = [](MenuList* menu, const Nz::LocalizedText& v) -> MenuList* { for (auto& e : menu->entries) { @@ -128,7 +124,7 @@ namespace Nz return ptr; } - menu->entries.push_back(MenuList{ std::string(v) }); + menu->entries.push_back(MenuList{ v }); return &std::get(menu->entries.back()); };