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:
Lukas Cone
2022-02-18 22:34:54 +01:00
committed by GitHub
parent 60a717365c
commit 26f998ecb6
6 changed files with 164 additions and 20 deletions

View File

@@ -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;
});
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -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" },