impr: Better sorting of hex cell visualizers
This commit is contained in:
parent
98395afe9d
commit
da11c47693
@ -723,9 +723,9 @@ namespace hex {
|
||||
|
||||
namespace impl {
|
||||
|
||||
void addDataVisualizer(const std::string &unlocalizedName, DataVisualizer *visualizer);
|
||||
void addDataVisualizer(std::shared_ptr<DataVisualizer> &&visualizer);
|
||||
|
||||
std::map<std::string, DataVisualizer*> &getVisualizers();
|
||||
std::vector<std::shared_ptr<DataVisualizer>> &getVisualizers();
|
||||
|
||||
}
|
||||
|
||||
@ -737,10 +737,16 @@ namespace hex {
|
||||
*/
|
||||
template<std::derived_from<DataVisualizer> T, typename... Args>
|
||||
void addDataVisualizer(Args &&...args) {
|
||||
auto visualizer = new T(std::forward<Args>(args)...);
|
||||
return impl::addDataVisualizer(visualizer->getUnlocalizedName(), visualizer);
|
||||
return impl::addDataVisualizer(std::make_shared<T>(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets a data visualizer by its unlocalized nameb
|
||||
* @param unlocalizedName Unlocalized name of the data visualizer
|
||||
* @return The data visualizer, or nullptr if it doesn't exist
|
||||
*/
|
||||
std::shared_ptr<DataVisualizer> getVisualizerByName(const std::string &unlocalizedName);
|
||||
|
||||
}
|
||||
|
||||
/* Hash Registry. Allows adding new hashes to the Hash view */
|
||||
|
@ -754,19 +754,28 @@ namespace hex {
|
||||
|
||||
namespace impl {
|
||||
|
||||
void addDataVisualizer(const std::string &unlocalizedName, DataVisualizer *visualizer) {
|
||||
getVisualizers().insert({ unlocalizedName, visualizer });
|
||||
void addDataVisualizer(std::shared_ptr<DataVisualizer> &&visualizer) {
|
||||
getVisualizers().emplace_back(std::move(visualizer));
|
||||
|
||||
}
|
||||
|
||||
std::map<std::string, DataVisualizer*> &getVisualizers() {
|
||||
static std::map<std::string, DataVisualizer*> visualizers;
|
||||
std::vector<std::shared_ptr<DataVisualizer>> &getVisualizers() {
|
||||
static std::vector<std::shared_ptr<DataVisualizer>> visualizers;
|
||||
|
||||
return visualizers;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::shared_ptr<DataVisualizer> getVisualizerByName(const std::string &unlocalizedName) {
|
||||
for (const auto &visualizer : impl::getVisualizers()) {
|
||||
if (visualizer->getUnlocalizedName() == unlocalizedName)
|
||||
return visualizer;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -364,6 +364,7 @@ namespace hex::init {
|
||||
ContentRegistry::DataFormatter::impl::getEntries().clear();
|
||||
ContentRegistry::FileHandler::impl::getEntries().clear();
|
||||
ContentRegistry::Hashes::impl::getHashes().clear();
|
||||
ContentRegistry::HexEditor::impl::getVisualizers().clear();
|
||||
|
||||
ContentRegistry::BackgroundServices::impl::stopServices();
|
||||
ContentRegistry::BackgroundServices::impl::getServices().clear();
|
||||
@ -374,12 +375,6 @@ namespace hex::init {
|
||||
|
||||
ThemeManager::reset();
|
||||
|
||||
{
|
||||
auto &visualizers = ContentRegistry::HexEditor::impl::getVisualizers();
|
||||
for (auto &[name, visualizer] : visualizers)
|
||||
delete visualizer;
|
||||
visualizers.clear();
|
||||
}
|
||||
|
||||
ProjectFile::getHandlers().clear();
|
||||
ProjectFile::getProviderHandlers().clear();
|
||||
|
@ -192,7 +192,7 @@ namespace hex::plugin::builtin::ui {
|
||||
float m_scrollPosition = 0;
|
||||
|
||||
u16 m_bytesPerRow = 16;
|
||||
ContentRegistry::HexEditor::DataVisualizer *m_currDataVisualizer;
|
||||
std::shared_ptr<ContentRegistry::HexEditor::DataVisualizer> m_currDataVisualizer;
|
||||
char m_unknownDataCharacter = '?';
|
||||
|
||||
bool m_shouldJumpToSelection = false;
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include <ui/hex_editor.hpp>
|
||||
|
||||
#include <hex/api/imhex_api.hpp>
|
||||
#include <hex/api/content_registry.hpp>
|
||||
#include <hex/api/localization.hpp>
|
||||
|
||||
@ -71,7 +70,7 @@ namespace hex::plugin::builtin::ui {
|
||||
/* Hex Editor */
|
||||
|
||||
HexEditor::HexEditor(prv::Provider *provider) : m_provider(provider) {
|
||||
this->m_currDataVisualizer = ContentRegistry::HexEditor::impl::getVisualizers()["hex.builtin.visualizer.hexadecimal.8bit"];
|
||||
this->m_currDataVisualizer = ContentRegistry::HexEditor::getVisualizerByName("hex.builtin.visualizer.hexadecimal.8bit");
|
||||
|
||||
EventManager::subscribe<EventSettingsChanged>(this, [this] {
|
||||
{
|
||||
@ -802,8 +801,8 @@ namespace hex::plugin::builtin::ui {
|
||||
ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x);
|
||||
if (ImGui::BeginCombo("##visualizer", LangEntry(this->m_currDataVisualizer->getUnlocalizedName()))) {
|
||||
|
||||
for (const auto &[unlocalizedName, visualizer] : visualizers) {
|
||||
if (ImGui::Selectable(LangEntry(unlocalizedName))) {
|
||||
for (const auto &visualizer : visualizers) {
|
||||
if (ImGui::Selectable(LangEntry(visualizer->getUnlocalizedName()))) {
|
||||
this->m_currDataVisualizer = visualizer;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user