diff --git a/include/window.hpp b/include/window.hpp index 6e8613be2..7b47e51a4 100644 --- a/include/window.hpp +++ b/include/window.hpp @@ -34,6 +34,7 @@ namespace hex { void frameEnd(); void drawWelcomeScreen(); + void resetLayout(); void initGLFW(); void initImGui(); @@ -45,6 +46,7 @@ namespace hex { float m_globalScale = 1.0f, m_fontScale = 1.0f; bool m_fpsVisible = false; bool m_demoWindowOpen = false; + bool m_layoutConfigured = false; static inline std::tuple s_currShortcut = { -1, -1 }; diff --git a/plugins/builtin/source/lang/en_US.cpp b/plugins/builtin/source/lang/en_US.cpp index 47e1aee26..a82e7a0b0 100644 --- a/plugins/builtin/source/lang/en_US.cpp +++ b/plugins/builtin/source/lang/en_US.cpp @@ -120,8 +120,8 @@ namespace hex::plugin::builtin { { "hex.view.hashes.poly", "Polynomial" }, { "hex.view.hashes.result", "Result" }, - { "hex.view.help.title", "Help" }, - { "hex.view.help.about.title", "About" }, + { "hex.view.help.name", "Help" }, + { "hex.view.help.about.name", "About" }, { "hex.view.help.about.translator", "Translated by WerWolv" }, { "hex.view.help.about.source", "Source code available on GitHub:" }, { "hex.view.help.about.donations", "Donations" }, @@ -130,7 +130,7 @@ namespace hex::plugin::builtin { { "hex.view.help.pattern_cheat_sheet", "Pattern Language Cheat Sheet"}, { "hex.view.help.calc_cheat_sheet", "Calculator Cheat Sheet" }, - { "hex.view.hexeditor.title", "Hex editor" }, + { "hex.view.hexeditor.name", "Hex editor" }, { "hex.view.hexeditor.save_changes", "Save Changes" }, { "hex.view.hexeditor.open_file", "Open File" }, { "hex.view.hexeditor.open_project", "Open Project" }, @@ -194,7 +194,7 @@ namespace hex::plugin::builtin { { "hex.view.hexeditor.menu.edit.bookmark", "Create bookmark" }, { "hex.view.hexeditor.menu.edit.set_base", "Set base address" }, - { "hex.view.information.title", "Data Information" }, + { "hex.view.information.name", "Data Information" }, { "hex.view.information.analyze", "Analyze current page" }, { "hex.view.information.region", "analyzed region" }, { "hex.view.information.description", "Description:" }, @@ -207,13 +207,13 @@ namespace hex::plugin::builtin { { "hex.view.information.highest_entropy", "Highest entropy block" }, { "hex.view.information.encrypted", "This data is most likely encrypted or compressed!" }, - { "hex.view.patches.title", "Patches" }, + { "hex.view.patches.name", "Patches" }, { "hex.view.patches.offset", "Offset" }, { "hex.view.patches.orig", "Original value" }, { "hex.view.patches.patch", "Patched value"}, { "hex.view.patches.remove", "Remove patch" }, - { "hex.view.pattern.title", "Pattern editor" }, + { "hex.view.pattern.name", "Pattern editor" }, { "hex.view.pattern.accept_pattern", "Accept pattern" }, { "hex.view.pattern.accept_pattern.desc", "One or more patterns compatible with this data type has been found" }, { "hex.view.pattern.accept_pattern.patterns", "Patterns" }, @@ -223,7 +223,7 @@ namespace hex::plugin::builtin { { "hex.view.pattern.compiling", "[%c] Compiling..." }, { "hex.view.pattern.auto", "Auto compile" }, - { "hex.view.pattern_data.title", "Pattern Data" }, + { "hex.view.pattern_data.name", "Pattern Data" }, { "hex.view.pattern_data.name", "Name" }, { "hex.view.pattern_data.color", "Color" }, { "hex.view.pattern_data.offset", "Offset" }, @@ -231,9 +231,9 @@ namespace hex::plugin::builtin { { "hex.view.pattern_data.type", "Type" }, { "hex.view.pattern_data.value", "Value" }, - { "hex.view.settings.title", "Settings" }, + { "hex.view.settings.name", "Settings" }, - { "hex.view.strings.title", "Strings" }, + { "hex.view.strings.name", "Strings" }, { "hex.view.strings.copy", "Copy string" }, { "hex.view.strings.demangle", "Demangle" }, { "hex.view.strings.min_length", "Minimum length" }, @@ -245,7 +245,7 @@ namespace hex::plugin::builtin { { "hex.view.strings.demangle.title", "Demangled name" }, { "hex.view.strings.demangle.copy", "Copy" }, - { "hex.view.tools.title", "Tools" }, + { "hex.view.tools.name", "Tools" }, /* Builtin plugin features */ diff --git a/plugins/libimhex/include/hex/views/view.hpp b/plugins/libimhex/include/hex/views/view.hpp index 78f8c8c80..8f65e2e6e 100644 --- a/plugins/libimhex/include/hex/views/view.hpp +++ b/plugins/libimhex/include/hex/views/view.hpp @@ -57,7 +57,7 @@ namespace hex { private: std::string m_viewName; - bool m_windowOpen = false; + bool m_windowOpen = this->hasViewMenuItemEntry(); }; } \ No newline at end of file diff --git a/source/views/view_help.cpp b/source/views/view_help.cpp index 5c10dd016..04702dc77 100644 --- a/source/views/view_help.cpp +++ b/source/views/view_help.cpp @@ -4,7 +4,7 @@ namespace hex { - ViewHelp::ViewHelp() : View("hex.view.help.about.title"_lang) { + ViewHelp::ViewHelp() : View("hex.view.help.about.name"_lang) { } ViewHelp::~ViewHelp() { @@ -29,7 +29,7 @@ namespace hex { void ViewHelp::drawAboutPopup() { - if (ImGui::BeginPopupModal("hex.view.help.about.title"_lang, &this->m_aboutWindowOpen, ImGuiWindowFlags_AlwaysAutoResize)) { + if (ImGui::BeginPopupModal("hex.view.help.about.name"_lang, &this->m_aboutWindowOpen, ImGuiWindowFlags_AlwaysAutoResize)) { ImGui::Text("ImHex Hex Editor v%s by WerWolv -", IMHEX_VERSION); #if defined(GIT_BRANCH) && defined(GIT_COMMIT_HASH) ImGui::SameLine(); @@ -313,8 +313,8 @@ namespace hex { void ViewHelp::drawMenu() { if (ImGui::BeginMenu("hex.menu.help"_lang)) { - if (ImGui::MenuItem("hex.view.help.about.title"_lang, "")) { - View::doLater([] { ImGui::OpenPopup("hex.view.help.about.title"_lang); }); + if (ImGui::MenuItem("hex.view.help.about.name"_lang, "")) { + View::doLater([] { ImGui::OpenPopup("hex.view.help.about.name"_lang); }); this->m_aboutWindowOpen = true; this->getWindowOpenState() = true; } diff --git a/source/views/view_hexeditor.cpp b/source/views/view_hexeditor.cpp index 8573574b0..988373b21 100644 --- a/source/views/view_hexeditor.cpp +++ b/source/views/view_hexeditor.cpp @@ -17,7 +17,7 @@ namespace hex { ViewHexEditor::ViewHexEditor(std::vector &patternData) - : View("hex.view.hexeditor.title"_lang), m_patternData(patternData) { + : View("hex.view.hexeditor.name"_lang), m_patternData(patternData) { this->m_searchStringBuffer.resize(0xFFF, 0x00); this->m_searchHexBuffer.resize(0xFFF, 0x00); @@ -197,10 +197,10 @@ namespace hex { size_t dataSize = (provider == nullptr || !provider->isReadable()) ? 0x00 : provider->getSize(); - this->m_memoryEditor.DrawWindow("hex.view.hexeditor.title"_lang, &this->getWindowOpenState(), this, dataSize, dataSize == 0 ? 0x00 : provider->getBaseAddress()); + this->m_memoryEditor.DrawWindow("hex.view.hexeditor.name"_lang, &this->getWindowOpenState(), this, dataSize, dataSize == 0 ? 0x00 : provider->getBaseAddress()); if (dataSize != 0x00) { - if (ImGui::Begin("hex.view.hexeditor.title"_lang)) { + if (ImGui::Begin("hex.view.hexeditor.name"_lang)) { if (ImGui::IsMouseReleased(ImGuiMouseButton_Right) && ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows)) ImGui::OpenPopup("hex.menu.edit"_lang); diff --git a/source/views/view_information.cpp b/source/views/view_information.cpp index beefa955e..d738ef016 100644 --- a/source/views/view_information.cpp +++ b/source/views/view_information.cpp @@ -13,7 +13,7 @@ namespace hex { - ViewInformation::ViewInformation() : View("hex.view.information.title"_lang) { + ViewInformation::ViewInformation() : View("hex.view.information.name"_lang) { View::subscribeEvent(Events::DataChanged, [this](auto) { this->m_dataValid = false; this->m_highestBlockEntropy = 0; @@ -45,7 +45,7 @@ namespace hex { } void ViewInformation::drawContent() { - if (ImGui::Begin("hex.view.information.title"_lang, &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) { + if (ImGui::Begin("hex.view.information.name"_lang, &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) { ImGui::BeginChild("##scrolling", ImVec2(0, 0), false, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoNav); auto provider = SharedData::currentProvider; diff --git a/source/views/view_patches.cpp b/source/views/view_patches.cpp index e5a265f07..dccc9e69a 100644 --- a/source/views/view_patches.cpp +++ b/source/views/view_patches.cpp @@ -11,7 +11,7 @@ using namespace std::literals::string_literals; namespace hex { - ViewPatches::ViewPatches() : View("hex.view.patches.title"_lang) { + ViewPatches::ViewPatches() : View("hex.view.patches.name"_lang) { View::subscribeEvent(Events::ProjectFileStore, [](auto) { auto provider = SharedData::currentProvider; if (provider != nullptr) @@ -31,7 +31,7 @@ namespace hex { } void ViewPatches::drawContent() { - if (ImGui::Begin("hex.view.patches.title"_lang, &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) { + if (ImGui::Begin("hex.view.patches.name"_lang, &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) { auto provider = SharedData::currentProvider; if (provider != nullptr && provider->isReadable()) { diff --git a/source/views/view_pattern.cpp b/source/views/view_pattern.cpp index 68d5c72c9..69af337bc 100644 --- a/source/views/view_pattern.cpp +++ b/source/views/view_pattern.cpp @@ -76,7 +76,7 @@ namespace hex { } - ViewPattern::ViewPattern(std::vector &patternData) : View("hex.view.pattern.title"_lang), m_patternData(patternData) { + ViewPattern::ViewPattern(std::vector &patternData) : View("hex.view.pattern.name"_lang), m_patternData(patternData) { this->m_patternLanguageRuntime = new lang::PatternLanguage(); this->m_textEditor.SetLanguageDefinition(PatternLanguage()); @@ -215,14 +215,14 @@ namespace hex { } void ViewPattern::drawContent() { - if (ImGui::Begin("hex.view.pattern.title"_lang, &this->getWindowOpenState(), ImGuiWindowFlags_None | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) { + if (ImGui::Begin("hex.view.pattern.name"_lang, &this->getWindowOpenState(), ImGuiWindowFlags_None | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) { auto provider = SharedData::currentProvider; if (provider != nullptr && provider->isAvailable()) { auto textEditorSize = ImGui::GetContentRegionAvail(); textEditorSize.y *= 4.0/5.0; textEditorSize.y -= ImGui::GetTextLineHeightWithSpacing(); - this->m_textEditor.Render("hex.view.pattern.title"_lang, textEditorSize, true); + this->m_textEditor.Render("hex.view.pattern.name"_lang, textEditorSize, true); auto consoleSize = ImGui::GetContentRegionAvail(); consoleSize.y -= ImGui::GetTextLineHeightWithSpacing(); diff --git a/source/views/view_pattern_data.cpp b/source/views/view_pattern_data.cpp index 039983e23..dc8d52081 100644 --- a/source/views/view_pattern_data.cpp +++ b/source/views/view_pattern_data.cpp @@ -6,7 +6,7 @@ namespace hex { ViewPatternData::ViewPatternData(std::vector &patternData) - : View("hex.view.pattern_data.title"_lang), m_patternData(patternData) { + : View("hex.view.pattern_data.name"_lang), m_patternData(patternData) { this->subscribeEvent(Events::PatternChanged, [this](auto data) { this->m_sortedPatternData.clear(); @@ -49,7 +49,7 @@ namespace hex { } void ViewPatternData::drawContent() { - if (ImGui::Begin("hex.view.pattern_data.title"_lang, &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) { + if (ImGui::Begin("hex.view.pattern_data.name"_lang, &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) { auto provider = SharedData::currentProvider; if (provider != nullptr && provider->isReadable()) { diff --git a/source/views/view_settings.cpp b/source/views/view_settings.cpp index 2a5ba9a22..91b0c4154 100644 --- a/source/views/view_settings.cpp +++ b/source/views/view_settings.cpp @@ -4,10 +4,10 @@ namespace hex { - ViewSettings::ViewSettings() : View("hex.view.settings.title"_lang) { + ViewSettings::ViewSettings() : View("hex.view.settings.name"_lang) { View::subscribeEvent(Events::OpenWindow, [this](auto name) { - if (std::any_cast(name) == std::string("hex.view.settings.title")) { - View::doLater([]{ ImGui::OpenPopup("hex.view.settings.title"_lang); }); + if (std::any_cast(name) == std::string("hex.view.settings.name")) { + View::doLater([]{ ImGui::OpenPopup("hex.view.settings.name"_lang); }); this->getWindowOpenState() = true; } }); @@ -21,7 +21,7 @@ namespace hex { ImGui::SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(FLT_MAX, FLT_MAX)); - if (ImGui::BeginPopupModal("hex.view.settings.title"_lang, &this->getWindowOpenState(), ImGuiWindowFlags_AlwaysAutoResize)) { + if (ImGui::BeginPopupModal("hex.view.settings.name"_lang, &this->getWindowOpenState(), ImGuiWindowFlags_AlwaysAutoResize)) { for (auto &[category, entries] : ContentRegistry::Settings::getEntries()) { ImGui::TextUnformatted(LangEntry(category)); ImGui::Separator(); @@ -39,8 +39,8 @@ namespace hex { void ViewSettings::drawMenu() { if (ImGui::BeginMenu("hex.menu.help"_lang)) { - if (ImGui::MenuItem("hex.view.settings.title"_lang)) { - View::doLater([]{ ImGui::OpenPopup("hex.view.settings.title"_lang); }); + if (ImGui::MenuItem("hex.view.settings.name"_lang)) { + View::doLater([]{ ImGui::OpenPopup("hex.view.settings.name"_lang); }); this->getWindowOpenState() = true; } ImGui::EndMenu(); diff --git a/source/views/view_strings.cpp b/source/views/view_strings.cpp index 3a80cdff3..f79c4bae1 100644 --- a/source/views/view_strings.cpp +++ b/source/views/view_strings.cpp @@ -11,7 +11,7 @@ using namespace std::literals::string_literals; namespace hex { - ViewStrings::ViewStrings() : View("hex.view.strings.title"_lang) { + ViewStrings::ViewStrings() : View("hex.view.strings.name"_lang) { View::subscribeEvent(Events::DataChanged, [this](auto){ this->m_foundStrings.clear(); }); @@ -37,7 +37,7 @@ namespace hex { if (ImGui::MenuItem("hex.view.strings.demangle"_lang)) { this->m_demangledName = llvm::demangle(this->m_selectedString); if (!this->m_demangledName.empty()) - View::doLater([]{ ImGui::OpenPopup("hex.view.strings.demangle.title"_lang); }); + View::doLater([]{ ImGui::OpenPopup("hex.view.strings.demangle.name"_lang); }); } ImGui::EndPopup(); } diff --git a/source/views/view_tools.cpp b/source/views/view_tools.cpp index df8afd985..b81f8dbfb 100644 --- a/source/views/view_tools.cpp +++ b/source/views/view_tools.cpp @@ -4,12 +4,12 @@ namespace hex { - ViewTools::ViewTools() : View("hex.view.tools.title"_lang) { } + ViewTools::ViewTools() : View("hex.view.tools.name"_lang) { } ViewTools::~ViewTools() { } void ViewTools::drawContent() { - if (ImGui::Begin("hex.view.tools.title"_lang, &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) { + if (ImGui::Begin("hex.view.tools.name"_lang, &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) { for (const auto& [name, function] : ContentRegistry::Tools::getEntries()) { if (ImGui::CollapsingHeader(LangEntry(name))) { function(); diff --git a/source/window.cpp b/source/window.cpp index c2beee10f..994867933 100644 --- a/source/window.cpp +++ b/source/window.cpp @@ -305,11 +305,7 @@ namespace hex { Window::s_currShortcut = { -1, -1 }; } - bool anyViewOpen = false; - for (auto &view : ContentRegistry::Views::getEntries()) - anyViewOpen = anyViewOpen || (view->getWindowOpenState() && view->isAvailable()); - - if (!anyViewOpen && SharedData::currentProvider == nullptr) { + if (SharedData::currentProvider == nullptr) { char title[256]; ImFormatString(title, IM_ARRAYSIZE(title), "%s/DockSpace_%08X", ImGui::GetCurrentWindow()->Name, ImGui::GetID("MainDock")); if (ImGui::Begin(title)) { @@ -321,6 +317,12 @@ namespace hex { ImGui::PopStyleVar(); } ImGui::End(); + } else if (!this->m_layoutConfigured) { + this->m_layoutConfigured = true; + if (ContentRegistry::Settings::read("hex.builtin.setting.imhex", "hex.builtin.setting.imhex.launched", 0) == 0) { + ContentRegistry::Settings::write("hex.builtin.setting.imhex", "hex.builtin.setting.imhex.launched", 1); + this->resetLayout(); + } } } @@ -429,7 +431,6 @@ namespace hex { } } - ImGui::EndTable(); } ImGui::SameLine(); @@ -469,6 +470,29 @@ namespace hex { } } + void Window::resetLayout() { + auto dockId = ImGui::GetID("MainDock"); + + ImGui::DockBuilderRemoveNode(dockId); + ImGui::DockBuilderAddNode(dockId, ImGuiDockNodeFlags_DockSpace); + ImGui::DockBuilderSetNodeSize(dockId, ImGui::GetWindowSize()); + + ImGuiID mainWindowId, splitWindowId, hexEditorId, utilitiesId, inspectorId, patternDataId; + + ImGui::DockBuilderSplitNode(dockId, ImGuiDir_Left, 0.8, &mainWindowId, &utilitiesId); + ImGui::DockBuilderSplitNode(mainWindowId, ImGuiDir_Down, 0.3, &patternDataId, &splitWindowId); + ImGui::DockBuilderSplitNode(splitWindowId, ImGuiDir_Right, 0.3, &inspectorId, &hexEditorId); + + for (auto &view : ContentRegistry::Views::getEntries()) + + ImGui::DockBuilderDockWindow(view->getName().data(), utilitiesId); + ImGui::DockBuilderDockWindow("hex.view.hexeditor.name"_lang, hexEditorId); + ImGui::DockBuilderDockWindow("hex.view.data_inspector.name"_lang, inspectorId); + ImGui::DockBuilderDockWindow("hex.view.pattern_data.name"_lang, patternDataId); + + ImGui::DockBuilderFinish(dockId); + } + void Window::initGLFW() { glfwSetErrorCallback([](int error, const char* desc) { fprintf(stderr, "Glfw Error %d: %s\n", error, desc);