1
0
mirror of synced 2024-11-30 02:14:30 +01:00
ImHex/plugins/builtin/source/content/main_menu_items.cpp
WerWolv 1991afb87b
sys: Get rid of SharedData struct and cleanup code structure (#411)
* sys: Initial refactoring of the SharedData class

* sys/pattern: More refactoring, make every provider have its own patterns

* sys: Finished up refactoring. No more SharedData!

* sys: Fixed compile on Unix

* tests: Fixed unit tests

* sys: Moved view and lang files

* pattern: Added assignment operator support to for loops

* tests: Fixed compile issue
2022-02-01 18:09:40 +01:00

59 lines
2.2 KiB
C++

#include <hex/api/content_registry.hpp>
#include <imgui.h>
#include <implot.h>
#include <hex/ui/view.hpp>
namespace hex::plugin::builtin {
static bool g_demoWindowOpen = false;
void registerMainMenuEntries() {
ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.file", 1000);
ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.edit", 2000);
ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.view", 3000);
ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.layout", 4000);
ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.help", 5000);
ContentRegistry::Interface::addMenuItem("hex.builtin.menu.view", 1000, [] {
for (auto &[name, view] : ContentRegistry::Views::getEntries()) {
if (view->hasViewMenuItemEntry())
ImGui::MenuItem(LangEntry(view->getUnlocalizedName()), "", &view->getWindowOpenState());
}
});
#if defined(DEBUG)
ContentRegistry::Interface::addMenuItem("hex.builtin.menu.view", 2000, [] {
ImGui::MenuItem("hex.builtin.menu.view.demo"_lang, "", &g_demoWindowOpen);
});
#endif
ContentRegistry::Interface::addMenuItem("hex.builtin.menu.layout", 1000, [] {
for (auto &[layoutName, func] : ContentRegistry::Interface::getLayouts()) {
if (ImGui::MenuItem(LangEntry(layoutName), "", false, ImHexApi::Provider::isValid())) {
auto dock = ImHexApi::System::getMainDockSpaceId();
for (auto &[viewName, view] : ContentRegistry::Views::getEntries()) {
view->getWindowOpenState() = false;
}
ImGui::DockBuilderRemoveNode(dock);
ImGui::DockBuilderAddNode(dock);
func(dock);
ImGui::DockBuilderFinish(dock);
}
}
});
(void)EventManager::subscribe<EventFrameEnd>([] {
if (g_demoWindowOpen) {
ImGui::ShowDemoWindow(&g_demoWindowOpen);
ImPlot::ShowDemoWindow(&g_demoWindowOpen);
}
});
}
}