mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 05:27:41 -05:00
feature: User now can add custom directories (#444)
* feat: user directories * ux: show setting categories in order they were created * feat: add descriptable setting categories
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
#include <hex/api/localization.hpp>
|
||||
|
||||
#include <imgui.h>
|
||||
#include <hex/ui/imgui_imhex_extensions.h>
|
||||
#include <fonts/codicons_font.h>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
@@ -219,6 +221,50 @@ namespace hex::plugin::builtin {
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
static const std::string dirsSetting { "hex.builtin.setting.folders" };
|
||||
|
||||
ContentRegistry::Settings::addCategoryDescrition(dirsSetting, "hex.builtin.setting.folders.description");
|
||||
|
||||
ContentRegistry::Settings::add(dirsSetting, dirsSetting, std::vector<std::string> {}, [](auto name, nlohmann::json &setting) {
|
||||
static std::vector<std::string> folders = setting;
|
||||
static int currentItemIndex = 0;
|
||||
|
||||
if (!ImGui::BeginListBox("", ImVec2(-38, -FLT_MIN))) {
|
||||
return false;
|
||||
} else {
|
||||
for (size_t n = 0; n < folders.size(); n++) {
|
||||
const bool isSelected = (currentItemIndex == n);
|
||||
if (ImGui::Selectable(folders.at(n).c_str(), isSelected)) { currentItemIndex = n; }
|
||||
if (isSelected) { ImGui::SetItemDefaultFocus(); }
|
||||
}
|
||||
ImGui::EndListBox();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::BeginGroup();
|
||||
|
||||
if (ImGui::IconButton(ICON_VS_NEW_FOLDER, ImGui::GetCustomColorVec4(ImGuiCustomCol_DescButton), ImVec2(30, 30))) {
|
||||
hex::openFileBrowser("Select include folder", hex::DialogMode::Folder, {}, [&](fs::path path) {
|
||||
auto pathStr = path.string();
|
||||
|
||||
if (std::find(folders.begin(), folders.end(), pathStr) == folders.end()) {
|
||||
folders.emplace_back(pathStr);
|
||||
ContentRegistry::Settings::write(dirsSetting, dirsSetting, folders);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (ImGui::IconButton(ICON_VS_REMOVE_CLOSE, ImGui::GetCustomColorVec4(ImGuiCustomCol_DescButton), ImVec2(30, 30))) {
|
||||
if (!folders.empty()) {
|
||||
folders.erase(std::next(folders.begin(), currentItemIndex));
|
||||
ContentRegistry::Settings::write(dirsSetting, dirsSetting, folders);
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::EndGroup();
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,13 +30,29 @@ namespace hex::plugin::builtin {
|
||||
|
||||
if (ImGui::BeginPopupModal(View::toWindowName("hex.builtin.view.settings.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoResize)) {
|
||||
if (ImGui::BeginTabBar("settings")) {
|
||||
for (auto &[category, entries] : ContentRegistry::Settings::getEntries()) {
|
||||
auto &entries = ContentRegistry::Settings::getEntries();
|
||||
|
||||
std::vector<std::decay_t<decltype(entries)>::const_iterator> sortedCategories;
|
||||
|
||||
for (auto it = entries.cbegin(); it != entries.cend(); it++) {
|
||||
sortedCategories.emplace_back(std::move(it));
|
||||
}
|
||||
|
||||
std::sort(sortedCategories.begin(), sortedCategories.end(), [](auto &item0, auto &item1) {
|
||||
return item0->first.slot < item1->first.slot;
|
||||
});
|
||||
|
||||
const auto &descriptions = ContentRegistry::Settings::getCategoryDescriptions();
|
||||
|
||||
for (auto &it : sortedCategories) {
|
||||
auto &[category, entries] = *it;
|
||||
if (ImGui::BeginTabItem(LangEntry(category))) {
|
||||
ImGui::TextUnformatted(LangEntry(category));
|
||||
const std::string &categoryDesc = descriptions.count(category) ? descriptions.at(category) : category.name;
|
||||
ImGui::TextUnformatted(LangEntry(categoryDesc));
|
||||
ImGui::Separator();
|
||||
|
||||
for (auto &[name, callback] : entries) {
|
||||
if (callback(LangEntry(name), ContentRegistry::Settings::getSettingsData()[category][name]))
|
||||
if (callback(LangEntry(name), ContentRegistry::Settings::getSettingsData()[category.name][name]))
|
||||
EventManager::post<EventSettingsChanged>();
|
||||
}
|
||||
|
||||
@@ -51,4 +67,4 @@ namespace hex::plugin::builtin {
|
||||
this->getWindowOpenState() = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -674,6 +674,8 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.setting.hex_editor.grey_zeros", "Grey out zeros" },
|
||||
{ "hex.builtin.setting.hex_editor.uppercase_hex", "Upper case Hex characters" },
|
||||
{ "hex.builtin.setting.hex_editor.extra_info", "Display extra information" },
|
||||
{ "hex.builtin.setting.folders", "Folders" },
|
||||
{ "hex.builtin.setting.folders.description", "Specify additional search paths for patterns, scripts, rules and more" },
|
||||
|
||||
{ "hex.builtin.provider.file.path", "File path" },
|
||||
{ "hex.builtin.provider.file.size", "Size" },
|
||||
|
||||
Reference in New Issue
Block a user