diff --git a/lib/libimhex/include/hex/providers/provider.hpp b/lib/libimhex/include/hex/providers/provider.hpp index 79a59fe09..a1586093e 100644 --- a/lib/libimhex/include/hex/providers/provider.hpp +++ b/lib/libimhex/include/hex/providers/provider.hpp @@ -17,23 +17,67 @@ #include namespace hex::prv { + /** + * @brief Interface for providers that need to draw a config interface when being created + */ + class IProviderLoadInterface { + public: + virtual ~IProviderLoadInterface() = default; + virtual bool drawLoadInterface() = 0; + }; /** - * @brief Represent the data source for a tab in the UI + * @brief Interface for providers that want to provide a custom sidebar interface */ - class Provider { + class IProviderSidebarInterface { public: - struct Description { - std::string name; - std::string value; - }; + virtual ~IProviderSidebarInterface() = default; + virtual void drawSidebarInterface() = 0; + }; + /** + * @brief Interface for providers that need to show a file picker dialog when being created + */ + class IProviderFilePicker { + public: + virtual ~IProviderFilePicker() = default; + virtual bool handleFilePicker() = 0; + }; + + /** + * @brief Interface for providers that want to display custom menu items in the provider context menu + */ + class IProviderMenuItems { + public: struct MenuEntry { std::string name; const char *icon; std::function callback; }; + virtual ~IProviderMenuItems() = default; + virtual std::vector getMenuEntries() = 0; + }; + + /** + * @brief Interface for providers that want to show some extra information in the information view + */ + class IProviderDataDescription { + public: + struct Description { + std::string name; + std::string value; + }; + + virtual ~IProviderDataDescription() = default; + [[nodiscard]] virtual std::vector getDataDescription() const = 0; + }; + + /** + * @brief Represent the data source for a tab in the UI + */ + class Provider { + public: constexpr static u64 MaxPageSize = 0xFFFF'FFFF'FFFF'FFFF; Provider(); @@ -191,7 +235,6 @@ namespace hex::prv { [[nodiscard]] virtual u64 getSize() const; [[nodiscard]] virtual std::optional getPageOfAddress(u64 address) const; - [[nodiscard]] virtual std::vector getDataDescription() const; [[nodiscard]] virtual std::variant queryInformation(const std::string &category, const std::string &argument); virtual void undo(); @@ -200,16 +243,6 @@ namespace hex::prv { [[nodiscard]] virtual bool canUndo() const; [[nodiscard]] virtual bool canRedo() const; - [[nodiscard]] virtual bool hasFilePicker() const; - virtual bool handleFilePicker(); - - virtual std::vector getMenuEntries() { return { }; } - - [[nodiscard]] virtual bool hasLoadInterface() const; - [[nodiscard]] virtual bool hasInterface() const; - virtual bool drawLoadInterface(); - virtual void drawInterface(); - [[nodiscard]] u32 getID() const; void setID(u32 id); @@ -250,12 +283,11 @@ namespace hex::prv { bool m_dirty = false; /** - * @brief Control whetever to skip provider initialization - * initialization may be asking the user for information related to the provider, + * @brief Control if provider initialization should be skipped. + * Initialization may be asking the user for information related to the provider, * e.g. a process ID for the process memory provider * this is used mainly when restoring a provider with already known initialization information * for example when loading a project or loading a provider from the "recent" lsit - * */ bool m_skipLoadInterface = false; diff --git a/lib/libimhex/source/providers/provider.cpp b/lib/libimhex/source/providers/provider.cpp index 779c6437f..381ba357a 100644 --- a/lib/libimhex/source/providers/provider.cpp +++ b/lib/libimhex/source/providers/provider.cpp @@ -230,10 +230,6 @@ namespace hex::prv { return page; } - std::vector Provider::getDataDescription() const { - return { }; - } - void Provider::undo() { m_undoRedoStack.undo(); } @@ -250,29 +246,6 @@ namespace hex::prv { return m_undoRedoStack.canRedo(); } - bool Provider::hasFilePicker() const { - return false; - } - - bool Provider::handleFilePicker() { - return false; - } - - bool Provider::hasLoadInterface() const { - return false; - } - - bool Provider::hasInterface() const { - return false; - } - - bool Provider::drawLoadInterface() { - return true; - } - - void Provider::drawInterface() { - } - nlohmann::json Provider::storeSettings(nlohmann::json settings) const { settings["displayName"] = this->getName(); settings["type"] = this->getTypeName(); diff --git a/plugins/builtin/include/content/providers/disk_provider.hpp b/plugins/builtin/include/content/providers/disk_provider.hpp index a08956f03..4fd32fd53 100644 --- a/plugins/builtin/include/content/providers/disk_provider.hpp +++ b/plugins/builtin/include/content/providers/disk_provider.hpp @@ -9,7 +9,9 @@ namespace hex::plugin::builtin { - class DiskProvider : public hex::prv::Provider { + class DiskProvider : public prv::Provider, + public prv::IProviderDataDescription, + public prv::IProviderLoadInterface { public: DiskProvider() = default; ~DiskProvider() override = default; @@ -32,7 +34,6 @@ namespace hex::plugin::builtin { [[nodiscard]] std::string getName() const override; [[nodiscard]] std::vector getDataDescription() const override; - [[nodiscard]] bool hasLoadInterface() const override { return true; } bool drawLoadInterface() override; void loadSettings(const nlohmann::json &settings) override; diff --git a/plugins/builtin/include/content/providers/file_provider.hpp b/plugins/builtin/include/content/providers/file_provider.hpp index b837a0555..e224e2ab5 100644 --- a/plugins/builtin/include/content/providers/file_provider.hpp +++ b/plugins/builtin/include/content/providers/file_provider.hpp @@ -9,7 +9,10 @@ namespace hex::plugin::builtin { - class FileProvider : public hex::prv::Provider { + class FileProvider : public prv::Provider, + public prv::IProviderDataDescription, + public prv::IProviderFilePicker, + public prv::IProviderMenuItems { public: FileProvider() = default; ~FileProvider() override = default; @@ -31,12 +34,10 @@ namespace hex::plugin::builtin { void saveAs(const std::fs::path &path) override; [[nodiscard]] std::string getName() const override; - [[nodiscard]] std::vector getDataDescription() const override; std::variant queryInformation(const std::string &category, const std::string &argument) override; - [[nodiscard]] bool hasFilePicker() const override { return true; } + [[nodiscard]] std::vector getDataDescription() const override; [[nodiscard]] bool handleFilePicker() override; - std::vector getMenuEntries() override; void setPath(const std::fs::path &path); diff --git a/plugins/builtin/include/content/providers/gdb_provider.hpp b/plugins/builtin/include/content/providers/gdb_provider.hpp index 7c4ed4372..437485cea 100644 --- a/plugins/builtin/include/content/providers/gdb_provider.hpp +++ b/plugins/builtin/include/content/providers/gdb_provider.hpp @@ -12,7 +12,9 @@ namespace hex::plugin::builtin { - class GDBProvider : public hex::prv::CachedProvider { + class GDBProvider : public prv::CachedProvider, + public prv::IProviderDataDescription, + public prv::IProviderLoadInterface { public: GDBProvider(); ~GDBProvider() override = default; @@ -37,7 +39,6 @@ namespace hex::plugin::builtin { [[nodiscard]] bool isConnected() const; - [[nodiscard]] bool hasLoadInterface() const override { return true; } bool drawLoadInterface() override; void loadSettings(const nlohmann::json &settings) override; diff --git a/plugins/builtin/include/content/providers/intel_hex_provider.hpp b/plugins/builtin/include/content/providers/intel_hex_provider.hpp index 36bf6f9e7..6e61f0de5 100644 --- a/plugins/builtin/include/content/providers/intel_hex_provider.hpp +++ b/plugins/builtin/include/content/providers/intel_hex_provider.hpp @@ -6,7 +6,9 @@ namespace hex::plugin::builtin { - class IntelHexProvider : public hex::prv::Provider { + class IntelHexProvider : public hex::prv::Provider, + public hex::prv::IProviderDataDescription, + public hex::prv::IProviderFilePicker { public: IntelHexProvider() = default; ~IntelHexProvider() override = default; @@ -36,7 +38,6 @@ namespace hex::plugin::builtin { return "hex.builtin.provider.intel_hex"; } - [[nodiscard]] bool hasFilePicker() const override { return true; } [[nodiscard]] bool handleFilePicker() override; std::pair getRegionValidity(u64 address) const override; diff --git a/plugins/builtin/include/content/providers/memory_file_provider.hpp b/plugins/builtin/include/content/providers/memory_file_provider.hpp index 23f97a86a..cdf40e2c2 100644 --- a/plugins/builtin/include/content/providers/memory_file_provider.hpp +++ b/plugins/builtin/include/content/providers/memory_file_provider.hpp @@ -4,7 +4,8 @@ namespace hex::plugin::builtin { - class MemoryFileProvider : public hex::prv::Provider { + class MemoryFileProvider : public hex::prv::Provider, + public prv::IProviderMenuItems { public: explicit MemoryFileProvider() = default; ~MemoryFileProvider() override = default; @@ -28,7 +29,6 @@ namespace hex::plugin::builtin { void save() override; [[nodiscard]] std::string getName() const override; - [[nodiscard]] std::vector getDataDescription() const override { return { }; } std::vector getMenuEntries() override; diff --git a/plugins/builtin/include/content/providers/null_provider.hpp b/plugins/builtin/include/content/providers/null_provider.hpp index 450f6f637..4c84acaa8 100644 --- a/plugins/builtin/include/content/providers/null_provider.hpp +++ b/plugins/builtin/include/content/providers/null_provider.hpp @@ -42,7 +42,6 @@ namespace hex::plugin::builtin { [[nodiscard]] u64 getActualSize() const override { return 0x00; } [[nodiscard]] std::string getName() const override { return "ImHex"; } - [[nodiscard]] std::vector getDataDescription() const override { return { }; } void loadSettings(const nlohmann::json &settings) override { std::ignore = settings; } [[nodiscard]] nlohmann::json storeSettings(nlohmann::json settings) const override { return settings; } diff --git a/plugins/builtin/include/content/providers/process_memory_provider.hpp b/plugins/builtin/include/content/providers/process_memory_provider.hpp index de60b166f..edc255a72 100644 --- a/plugins/builtin/include/content/providers/process_memory_provider.hpp +++ b/plugins/builtin/include/content/providers/process_memory_provider.hpp @@ -23,7 +23,10 @@ namespace hex::plugin::builtin { - class ProcessMemoryProvider : public hex::prv::Provider { + class ProcessMemoryProvider : public prv::Provider, + public prv::IProviderDataDescription, + public prv::IProviderLoadInterface, + public prv::IProviderSidebarInterface { public: ProcessMemoryProvider() = default; ~ProcessMemoryProvider() override = default; @@ -58,10 +61,8 @@ namespace hex::plugin::builtin { [[nodiscard]] bool open() override; void close() override; - [[nodiscard]] bool hasLoadInterface() const override { return true; } - [[nodiscard]] bool hasInterface() const override { return true; } bool drawLoadInterface() override; - void drawInterface() override; + void drawSidebarInterface() override; void loadSettings(const nlohmann::json &) override {} [[nodiscard]] nlohmann::json storeSettings(nlohmann::json) const override { return { }; } diff --git a/plugins/builtin/include/content/providers/udp_provider.hpp b/plugins/builtin/include/content/providers/udp_provider.hpp index 2071bf8ac..23964e97c 100644 --- a/plugins/builtin/include/content/providers/udp_provider.hpp +++ b/plugins/builtin/include/content/providers/udp_provider.hpp @@ -8,7 +8,9 @@ namespace hex::plugin::builtin { - class UDPProvider : public hex::prv::Provider { + class UDPProvider : public hex::prv::Provider, + public hex::prv::IProviderSidebarInterface, + public hex::prv::IProviderLoadInterface { public: UDPProvider() = default; ~UDPProvider() override = default; @@ -24,11 +26,8 @@ namespace hex::plugin::builtin { [[nodiscard]] u64 getActualSize() const override; - - [[nodiscard]] bool hasLoadInterface() const override { return true; } [[nodiscard]] bool drawLoadInterface() override; - bool hasInterface() const override { return true; } - void drawInterface() override; + void drawSidebarInterface() override; [[nodiscard]] bool open() override; void close() override; diff --git a/plugins/builtin/include/content/providers/view_provider.hpp b/plugins/builtin/include/content/providers/view_provider.hpp index 6f278da04..31303cf7f 100644 --- a/plugins/builtin/include/content/providers/view_provider.hpp +++ b/plugins/builtin/include/content/providers/view_provider.hpp @@ -4,7 +4,9 @@ namespace hex::plugin::builtin { - class ViewProvider : public hex::prv::Provider { + class ViewProvider : public prv::Provider, + public prv::IProviderDataDescription, + public prv::IProviderMenuItems { public: ViewProvider() = default; ~ViewProvider() override = default; @@ -48,7 +50,7 @@ namespace hex::plugin::builtin { void setBaseAddress(u64 address) override { std::ignore = address; } - void setProvider(u64 startAddress, size_t size, hex::prv::Provider *provider); + void setProvider(u64 startAddress, size_t size, Provider *provider); void setName(const std::string &name); [[nodiscard]] std::pair getRegionValidity(u64 address) const override; diff --git a/plugins/builtin/source/content/data_information_sections.cpp b/plugins/builtin/source/content/data_information_sections.cpp index f9795e195..bf7390eb8 100644 --- a/plugins/builtin/source/content/data_information_sections.cpp +++ b/plugins/builtin/source/content/data_information_sections.cpp @@ -40,13 +40,15 @@ namespace hex::plugin::builtin { ImGui::TableNextRow(); - for (auto &[name, value] : m_provider->getDataDescription()) { - ImGui::TableNextColumn(); - ImGuiExt::TextFormatted("{}", name); - ImGui::TableNextColumn(); - ImGui::PushID(name.c_str()); - ImGuiExt::TextFormattedWrappedSelectable("{}", value); - ImGui::PopID(); + if (auto *dataDescriptionProvider = dynamic_cast(m_provider); dataDescriptionProvider != nullptr) { + for (auto &[name, value] : dataDescriptionProvider->getDataDescription()) { + ImGui::TableNextColumn(); + ImGuiExt::TextFormatted("{}", name); + ImGui::TableNextColumn(); + ImGui::PushID(name.c_str()); + ImGuiExt::TextFormattedWrappedSelectable("{}", value); + ImGui::PopID(); + } } ImGui::TableNextColumn(); diff --git a/plugins/builtin/source/content/events.cpp b/plugins/builtin/source/content/events.cpp index 3519ef01d..a7e98ea16 100644 --- a/plugins/builtin/source/content/events.cpp +++ b/plugins/builtin/source/content/events.cpp @@ -198,8 +198,8 @@ namespace hex::plugin::builtin { if (provider->shouldSkipLoadInterface()) return; - if (provider->hasFilePicker()) { - if (!provider->handleFilePicker()) { + if (auto *filePickerProvider = dynamic_cast(provider); filePickerProvider != nullptr) { + if (!filePickerProvider->handleFilePicker()) { TaskManager::doLater([provider] { ImHexApi::Provider::remove(provider); }); return; } @@ -213,7 +213,7 @@ namespace hex::plugin::builtin { } }); } - else if (!provider->hasLoadInterface()) { + else if (dynamic_cast(provider) == nullptr) { TaskManager::createBlockingTask("hex.builtin.provider.opening", TaskManager::NoProgress, [provider]() { if (!provider->open() || !provider->isAvailable()) { ui::ToastError::open(hex::format("hex.builtin.provider.error.open"_lang, provider->getErrorMessage())); diff --git a/plugins/builtin/source/content/providers/file_provider.cpp b/plugins/builtin/source/content/providers/file_provider.cpp index e2dde4fa4..77ab30ba7 100644 --- a/plugins/builtin/source/content/providers/file_provider.cpp +++ b/plugins/builtin/source/content/providers/file_provider.cpp @@ -178,7 +178,7 @@ namespace hex::plugin::builtin { } std::vector FileProvider::getMenuEntries() { - FileProvider::MenuEntry loadMenuItem; + MenuEntry loadMenuItem; if (m_loadedIntoMemory) loadMenuItem = { "hex.builtin.provider.file.menu.direct_access"_lang, ICON_VS_ARROW_SWAP, [this] { this->convertToDirectAccess(); } }; diff --git a/plugins/builtin/source/content/providers/process_memory_provider.cpp b/plugins/builtin/source/content/providers/process_memory_provider.cpp index 91290e112..7aaeffd32 100644 --- a/plugins/builtin/source/content/providers/process_memory_provider.cpp +++ b/plugins/builtin/source/content/providers/process_memory_provider.cpp @@ -282,7 +282,7 @@ namespace hex::plugin::builtin { return m_selectedProcess != nullptr; } - void ProcessMemoryProvider::drawInterface() { + void ProcessMemoryProvider::drawSidebarInterface() { ImGuiExt::Header("hex.builtin.provider.process_memory.memory_regions"_lang, true); auto availableX = ImGui::GetContentRegionAvail().x; diff --git a/plugins/builtin/source/content/providers/udp_provider.cpp b/plugins/builtin/source/content/providers/udp_provider.cpp index 631ff9428..907929bbe 100644 --- a/plugins/builtin/source/content/providers/udp_provider.cpp +++ b/plugins/builtin/source/content/providers/udp_provider.cpp @@ -68,7 +68,7 @@ namespace hex::plugin::builtin { /* Not supported */ } - void UDPProvider::drawInterface() { + void UDPProvider::drawSidebarInterface() { std::scoped_lock lock(m_mutex); if (ImGui::BeginTable("##Messages", 2, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg, ImGui::GetContentRegionAvail())) { diff --git a/plugins/builtin/source/content/providers/view_provider.cpp b/plugins/builtin/source/content/providers/view_provider.cpp index 2a6c49edb..8cf8ed7e9 100644 --- a/plugins/builtin/source/content/providers/view_provider.cpp +++ b/plugins/builtin/source/content/providers/view_provider.cpp @@ -124,11 +124,16 @@ namespace hex::plugin::builtin { else return hex::format("{} View", m_provider->getName()); } + [[nodiscard]] std::vector ViewProvider::getDataDescription() const { if (m_provider == nullptr) return { }; - return m_provider->getDataDescription(); + if (auto *dataDescriptionProvider = dynamic_cast(m_provider); dataDescriptionProvider != nullptr) { + return dataDescriptionProvider->getDataDescription(); + } + + return {}; } void ViewProvider::loadSettings(const nlohmann::json &settings) { @@ -181,7 +186,7 @@ namespace hex::plugin::builtin { return { Region::Invalid(), false }; } - std::vector ViewProvider::getMenuEntries() { + std::vector ViewProvider::getMenuEntries() { return { MenuEntry { Lang("hex.builtin.provider.rename"), ICON_VS_TAG, [this] { this->renameFile(); } } }; diff --git a/plugins/builtin/source/content/report_generators.cpp b/plugins/builtin/source/content/report_generators.cpp index 69e627abf..286b38074 100644 --- a/plugins/builtin/source/content/report_generators.cpp +++ b/plugins/builtin/source/content/report_generators.cpp @@ -15,12 +15,18 @@ namespace hex::plugin::builtin { ContentRegistry::Reports::addReportProvider([](const prv::Provider *provider) -> std::string { std::string result; - result += "## Data description\n\n"; - result += "| Type | Value |\n"; - result += "| ---- | ----- |\n"; + if (auto *dataDescriptionProvider = dynamic_cast(provider); dataDescriptionProvider != nullptr) { + auto descriptions = dataDescriptionProvider->getDataDescription(); + if (!descriptions.empty()) { + result += "## Data description\n\n"; + result += "| Type | Value |\n"; + result += "| ---- | ----- |\n"; + + for (const auto &[type, value] : dataDescriptionProvider->getDataDescription()) + result += hex::format("| {} | {} |\n", type, value); + } + } - for (const auto &[type, value] : provider->getDataDescription()) - result += hex::format("| {} | {} |\n", type, value); return result; }); diff --git a/plugins/builtin/source/content/ui_items.cpp b/plugins/builtin/source/content/ui_items.cpp index 6e3b61749..3582d2f0e 100644 --- a/plugins/builtin/source/content/ui_items.cpp +++ b/plugins/builtin/source/content/ui_items.cpp @@ -353,9 +353,11 @@ namespace hex::plugin::builtin { } static void drawProviderContextMenu(prv::Provider *provider) { - for (const auto &menuEntry : provider->getMenuEntries()) { - if (ImGui::MenuItemEx(menuEntry.name.c_str(), menuEntry.icon)) { - menuEntry.callback(); + if (auto *menuItemProvider = dynamic_cast(provider); menuItemProvider != nullptr) { + for (const auto &menuEntry : menuItemProvider->getMenuEntries()) { + if (ImGui::MenuItemEx(menuEntry.name.c_str(), menuEntry.icon)) { + menuEntry.callback(); + } } } } @@ -366,28 +368,30 @@ namespace hex::plugin::builtin { ImGuiExt::TextFormatted("{}", provider->getName().c_str()); - const auto &description = provider->getDataDescription(); - if (!description.empty()) { - ImGui::Separator(); - if (ImGui::GetIO().KeyShift && !description.empty()) { + if (auto *dataDescriptionProvider = dynamic_cast(provider); dataDescriptionProvider != nullptr) { + const auto &description = dataDescriptionProvider->getDataDescription(); + if (!description.empty()) { + ImGui::Separator(); + if (ImGui::GetIO().KeyShift && !description.empty()) { - if (ImGui::BeginTable("information", 2, ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_RowBg | ImGuiTableFlags_NoKeepColumnsVisible, ImVec2(400_scaled, 0))) { - ImGui::TableSetupColumn("type"); - ImGui::TableSetupColumn("value", ImGuiTableColumnFlags_WidthStretch); + if (ImGui::BeginTable("information", 2, ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_RowBg | ImGuiTableFlags_NoKeepColumnsVisible, ImVec2(400_scaled, 0))) { + ImGui::TableSetupColumn("type"); + ImGui::TableSetupColumn("value", ImGuiTableColumnFlags_WidthStretch); - ImGui::TableNextRow(); + ImGui::TableNextRow(); - for (auto &[name, value] : description) { - ImGui::TableNextColumn(); - ImGuiExt::TextFormatted("{}", name); - ImGui::TableNextColumn(); - ImGuiExt::TextFormattedWrapped("{}", value); + for (auto &[name, value] : description) { + ImGui::TableNextColumn(); + ImGuiExt::TextFormatted("{}", name); + ImGui::TableNextColumn(); + ImGuiExt::TextFormattedWrapped("{}", value); + } + + ImGui::EndTable(); } - - ImGui::EndTable(); + } else { + ImGuiExt::TextFormattedDisabled("hex.builtin.provider.tooltip.show_more"_lang); } - } else { - ImGuiExt::TextFormattedDisabled("hex.builtin.provider.tooltip.show_more"_lang); } } @@ -423,10 +427,14 @@ namespace hex::plugin::builtin { }); EventFrameBegin::subscribe([] { - if (rightClickedProvider != nullptr && !rightClickedProvider->getMenuEntries().empty()) { - if (ImGui::BeginPopup("ProviderMenu")) { - drawProviderContextMenu(rightClickedProvider); - ImGui::EndPopup(); + if (rightClickedProvider != nullptr) { + if (auto *menuItemProvider = dynamic_cast(rightClickedProvider); menuItemProvider != nullptr) { + if (!menuItemProvider->getMenuEntries().empty()) { + if (ImGui::BeginPopup("ProviderMenu")) { + drawProviderContextMenu(rightClickedProvider); + ImGui::EndPopup(); + } + } } } }); diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index 3c52afdfd..03af78877 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -1453,7 +1453,7 @@ namespace hex::plugin::builtin { bool foundCorrectType = false; - auto mimeType = magic::getMIMEType(provider, 0, 100_KiB, true); + auto mimeType = magic::getMIMEType(provider, 0, 4_KiB, true); runtime.addPragma("MIME", [&mimeType, &foundCorrectType](const pl::PatternLanguage &runtime, const std::string &value) { std::ignore = runtime; diff --git a/plugins/builtin/source/content/views/view_provider_settings.cpp b/plugins/builtin/source/content/views/view_provider_settings.cpp index ea4665987..504addb12 100644 --- a/plugins/builtin/source/content/views/view_provider_settings.cpp +++ b/plugins/builtin/source/content/views/view_provider_settings.cpp @@ -10,20 +10,20 @@ namespace hex::plugin::builtin { ViewProviderSettings::ViewProviderSettings() : View::Modal("hex.builtin.view.provider_settings.name") { EventProviderCreated::subscribe(this, [this](const hex::prv::Provider *provider) { - if (provider->hasLoadInterface() && !provider->shouldSkipLoadInterface()) + if (dynamic_cast(provider) != nullptr && !provider->shouldSkipLoadInterface()) this->getWindowOpenState() = true; }); ContentRegistry::Interface::addSidebarItem(ICON_VS_SERVER_PROCESS, [] { auto provider = hex::ImHexApi::Provider::get(); - if (provider != nullptr) - provider->drawInterface(); + if (auto *sidebarInterfaceProvider = dynamic_cast(provider); sidebarInterfaceProvider != nullptr) + sidebarInterfaceProvider->drawSidebarInterface(); }, [] { auto provider = hex::ImHexApi::Provider::get(); - return provider != nullptr && provider->hasInterface() && provider->isAvailable(); + return provider != nullptr && dynamic_cast(provider) != nullptr && provider->isAvailable(); }); } @@ -33,8 +33,8 @@ namespace hex::plugin::builtin { void ViewProviderSettings::drawContent() { auto provider = hex::ImHexApi::Provider::get(); - if (provider != nullptr) { - bool settingsValid = provider->drawLoadInterface(); + if (auto *loadInterfaceProvider = dynamic_cast(provider); loadInterfaceProvider != nullptr) { + bool settingsValid = loadInterfaceProvider->drawLoadInterface(); ImGui::NewLine(); ImGui::Separator(); diff --git a/plugins/remote/include/content/providers/ssh_provider.hpp b/plugins/remote/include/content/providers/ssh_provider.hpp index 29fd53115..ba3b79c75 100644 --- a/plugins/remote/include/content/providers/ssh_provider.hpp +++ b/plugins/remote/include/content/providers/ssh_provider.hpp @@ -5,7 +5,8 @@ namespace hex::plugin::remote { - class SSHProvider : public hex::prv::CachedProvider { + class SSHProvider : public prv::CachedProvider, + public prv::IProviderLoadInterface { public: bool isAvailable() const override { return m_remoteFile.isOpen(); } bool isReadable() const override { return isAvailable(); } @@ -25,7 +26,6 @@ namespace hex::plugin::remote { std::string getName() const override; bool drawLoadInterface() override; - bool hasLoadInterface() const override { return true; } void loadSettings(const nlohmann::json &settings) override; nlohmann::json storeSettings(nlohmann::json settings) const override;