ux: Disable various menu items when no provider is active

This commit is contained in:
WerWolv
2022-03-26 16:42:11 +01:00
parent 1c53d2c123
commit 35a520f132
3 changed files with 18 additions and 22 deletions

View File

@@ -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())

View File

@@ -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<std::fs::path> 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);

View File

@@ -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<std::fs::path> 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);