From 8821f75e6b35aef06fa068dcbb910df4146d0c2c Mon Sep 17 00:00:00 2001 From: WerWolv Date: Tue, 17 Oct 2023 10:22:56 +0200 Subject: [PATCH] impr: Display friendly disk name as the tab title of the disk provider --- .../content/providers/disk_provider.hpp | 1 + .../content/providers/disk_provider.cpp | 23 +++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/plugins/builtin/include/content/providers/disk_provider.hpp b/plugins/builtin/include/content/providers/disk_provider.hpp index 398941df3..3a29db41f 100644 --- a/plugins/builtin/include/content/providers/disk_provider.hpp +++ b/plugins/builtin/include/content/providers/disk_provider.hpp @@ -64,6 +64,7 @@ namespace hex::plugin::builtin { std::set m_availableDrives; std::fs::path m_path; + std::string m_friendlyName; #if defined(OS_WINDOWS) HANDLE m_diskHandle = INVALID_HANDLE_VALUE; diff --git a/plugins/builtin/source/content/providers/disk_provider.cpp b/plugins/builtin/source/content/providers/disk_provider.cpp index 1fbb437b6..e3a97b194 100644 --- a/plugins/builtin/source/content/providers/disk_provider.cpp +++ b/plugins/builtin/source/content/providers/disk_provider.cpp @@ -342,12 +342,15 @@ namespace hex::plugin::builtin { } std::string DiskProvider::getName() const { - return wolv::util::toUTF8String(this->m_path); + if (this->m_friendlyName.empty()) + return wolv::util::toUTF8String(this->m_path); + else + return this->m_friendlyName; } std::vector DiskProvider::getDataDescription() const { return { - { "hex.builtin.provider.disk.selected_disk"_lang, wolv::util::toUTF8String(this->m_path) }, + { "hex.builtin.provider.disk.selected_disk"_lang, wolv::util::toUTF8String(this->m_path) }, { "hex.builtin.provider.disk.disk_size"_lang, hex::toByteString(this->m_diskSize) }, { "hex.builtin.provider.disk.sector_size"_lang, hex::toByteString(this->m_sectorSize) } }; @@ -435,8 +438,10 @@ namespace hex::plugin::builtin { ImGui::PushID(1); for (const auto &[path, friendlyName] : this->m_availableDrives) { - if (ImGui::Selectable(friendlyName.c_str(), this->m_path == path)) + if (ImGui::Selectable(friendlyName.c_str(), this->m_path == path)) { this->m_path = path; + this->m_friendlyName = friendlyName; + } ImGui::InfoTooltip(path.c_str()); } @@ -454,8 +459,10 @@ namespace hex::plugin::builtin { #else - if (ImGui::InputText("hex.builtin.provider.disk.selected_disk"_lang, this->m_pathBuffer.data(), this->m_pathBuffer.size(), ImGuiInputTextFlags_CallbackResize, ImGui::UpdateStringSizeCallback, &this->m_pathBuffer)) + if (ImGui::InputText("hex.builtin.provider.disk.selected_disk"_lang, this->m_pathBuffer.data(), this->m_pathBuffer.size(), ImGuiInputTextFlags_CallbackResize, ImGui::UpdateStringSizeCallback, &this->m_pathBuffer)) { this->m_path = this->m_pathBuffer; + this->m_friendlyName = this->m_pathBuffer; + } #endif @@ -465,6 +472,8 @@ namespace hex::plugin::builtin { nlohmann::json DiskProvider::storeSettings(nlohmann::json settings) const { settings["path"] = wolv::util::toUTF8String(this->m_path); + settings["friendly_name"] = this->m_friendlyName; + return Provider::storeSettings(settings); } @@ -472,6 +481,10 @@ namespace hex::plugin::builtin { Provider::loadSettings(settings); auto path = settings.at("path").get(); + + if (settings.contains("friendly_name")) + this->m_friendlyName = settings.at("friendly_name").get(); + this->setPath(std::u8string(path.begin(), path.end())); this->reloadDrives(); } @@ -490,6 +503,8 @@ namespace hex::plugin::builtin { return wolv::util::toUTF8String(this->m_path); else if (category == "sector_size") return this->m_sectorSize; + else if (category == "friendly_name") + return this->m_friendlyName; else return Provider::queryInformation(category, argument); }