From 35a520f132870f513a0d0b162ff776e81b01b87d Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sat, 26 Mar 2022 16:42:11 +0100 Subject: [PATCH] ux: Disable various menu items when no provider is active --- .../source/content/views/view_data_processor.cpp | 14 ++++++-------- .../source/content/views/view_hex_editor.cpp | 12 ++++++------ .../source/content/views/view_pattern_editor.cpp | 14 ++++++-------- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/plugins/builtin/source/content/views/view_data_processor.cpp b/plugins/builtin/source/content/views/view_data_processor.cpp index 4680455f1..02c3fb546 100644 --- a/plugins/builtin/source/content/views/view_data_processor.cpp +++ b/plugins/builtin/source/content/views/view_data_processor.cpp @@ -53,10 +53,10 @@ namespace hex::plugin::builtin { }); ContentRegistry::Interface::addMenuItem("hex.builtin.menu.file", 3000, [&, this] { - if (ImGui::MenuItem("hex.builtin.view.data_processor.menu.file.load_processor"_lang)) { - fs::openFileBrowser("hex.builtin.view.data_processor.menu.file.load_processor"_lang, fs::DialogMode::Open, { - {"hex.builtin.view.data_processor.name"_lang, "hexnode"} - }, + bool providerValid = ImHexApi::Provider::isValid(); + + if (ImGui::MenuItem("hex.builtin.view.data_processor.menu.file.load_processor"_lang, nullptr, false, providerValid)) { + fs::openFileBrowser("hex.builtin.view.data_processor.menu.file.load_processor"_lang, fs::DialogMode::Open, { {"hex.builtin.view.data_processor.name"_lang, "hexnode"} }, [this](const std::fs::path &path) { fs::File file(path, fs::File::Mode::Read); if (file.isValid()) @@ -64,10 +64,8 @@ namespace hex::plugin::builtin { }); } - if (ImGui::MenuItem("hex.builtin.view.data_processor.menu.file.save_processor"_lang, nullptr, false, !this->m_nodes.empty())) { - fs::openFileBrowser("hex.builtin.view.data_processor.menu.file.save_processor"_lang, fs::DialogMode::Save, { - {"hex.builtin.view.data_processor.name"_lang, "hexnode"} - }, + if (ImGui::MenuItem("hex.builtin.view.data_processor.menu.file.save_processor"_lang, nullptr, false, !this->m_nodes.empty() && providerValid)) { + fs::openFileBrowser("hex.builtin.view.data_processor.menu.file.save_processor"_lang, fs::DialogMode::Save, { {"hex.builtin.view.data_processor.name"_lang, "hexnode"} }, [this](const std::fs::path &path) { fs::File file(path, fs::File::Mode::Create); if (file.isValid()) diff --git a/plugins/builtin/source/content/views/view_hex_editor.cpp b/plugins/builtin/source/content/views/view_hex_editor.cpp index d80100278..eaa8441d1 100644 --- a/plugins/builtin/source/content/views/view_hex_editor.cpp +++ b/plugins/builtin/source/content/views/view_hex_editor.cpp @@ -1120,7 +1120,7 @@ namespace hex::plugin::builtin { ProjectFile::store(); } - if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.file.load_encoding_file"_lang)) { + if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.file.load_encoding_file"_lang, nullptr, false, providerValid)) { std::vector paths; for (const auto &path : fs::getDefaultPaths(fs::ImHexPath::Encodings)) { std::error_code error; @@ -1131,9 +1131,7 @@ namespace hex::plugin::builtin { } } - View::showFileChooserPopup(paths, { - {"Thingy Table File", "tbl"} - }, + View::showFileChooserPopup(paths, { {"Thingy Table File", "tbl"} }, [this](const auto &path) { this->m_currEncodingFile = EncodingFile(EncodingFile::Type::Thingy, path); }); @@ -1307,13 +1305,15 @@ namespace hex::plugin::builtin { /* Search / Goto */ ContentRegistry::Interface::addMenuItem("hex.builtin.menu.file", 1400, [&, this] { - if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.file.search"_lang, "CTRL + F")) { + bool providerValid = ImHexApi::Provider::isValid(); + + if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.file.search"_lang, "CTRL + F", false, providerValid)) { this->getWindowOpenState() = true; this->m_searchRequested = true; ImGui::OpenPopupInWindow(View::toWindowName("hex.builtin.view.hex_editor.name").c_str(), "hex.builtin.view.hex_editor.menu.file.search"_lang); } - if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.file.goto"_lang, "CTRL + G")) { + if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.file.goto"_lang, "CTRL + G", false, providerValid)) { this->getWindowOpenState() = true; this->m_gotoRequested = true; ImGui::OpenPopupInWindow(View::toWindowName("hex.builtin.view.hex_editor.name").c_str(), "hex.builtin.view.hex_editor.menu.file.goto"_lang); diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index b4acfb536..66103ba49 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -193,7 +193,9 @@ namespace hex::plugin::builtin { }); ContentRegistry::Interface::addMenuItem("hex.builtin.menu.file", 2000, [&, this] { - if (ImGui::MenuItem("hex.builtin.view.pattern_editor.menu.file.load_pattern"_lang)) { + bool providerValid = ImHexApi::Provider::isValid(); + + if (ImGui::MenuItem("hex.builtin.view.pattern_editor.menu.file.load_pattern"_lang, nullptr, false, providerValid)) { std::vector paths; @@ -208,18 +210,14 @@ namespace hex::plugin::builtin { } } - View::showFileChooserPopup(paths, { - {"Pattern File", "hexpat"} - }, + View::showFileChooserPopup(paths, { {"Pattern File", "hexpat"} }, [this](const std::fs::path &path) { this->loadPatternFile(path); }); } - if (ImGui::MenuItem("hex.builtin.view.pattern_editor.menu.file.save_pattern"_lang)) { - fs::openFileBrowser("hex.builtin.view.pattern_editor.menu.file.save_pattern"_lang, fs::DialogMode::Save, { - {"Pattern", "hexpat"} - }, + if (ImGui::MenuItem("hex.builtin.view.pattern_editor.menu.file.save_pattern"_lang, nullptr, false, providerValid)) { + fs::openFileBrowser("hex.builtin.view.pattern_editor.menu.file.save_pattern"_lang, fs::DialogMode::Save, { {"Pattern", "hexpat"} }, [this](const auto &path) { fs::File file(path, fs::File::Mode::Create);