2020-11-10 14:26:38 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-05-27 18:42:07 +00:00
|
|
|
#include <hex/api/content_registry.hpp>
|
|
|
|
|
2022-02-01 17:09:40 +00:00
|
|
|
#include <hex/ui/view.hpp>
|
2022-05-27 18:42:07 +00:00
|
|
|
#include <hex/helpers/concepts.hpp>
|
2021-12-07 21:47:41 +00:00
|
|
|
#include <hex/helpers/encoding_file.hpp>
|
2020-11-10 14:26:38 +00:00
|
|
|
|
2022-09-18 14:22:08 +00:00
|
|
|
#include <content/helpers/provider_extra_data.hpp>
|
2022-11-08 20:43:22 +00:00
|
|
|
#include <ui/hex_editor.hpp>
|
2021-12-07 21:47:41 +00:00
|
|
|
|
|
|
|
namespace hex::plugin::builtin {
|
2020-11-10 14:26:38 +00:00
|
|
|
|
|
|
|
class ViewHexEditor : public View {
|
|
|
|
public:
|
2021-04-20 19:46:48 +00:00
|
|
|
ViewHexEditor();
|
2022-11-06 23:04:47 +00:00
|
|
|
~ViewHexEditor() override;
|
2020-11-10 14:26:38 +00:00
|
|
|
|
2020-12-22 17:10:01 +00:00
|
|
|
void drawContent() override;
|
2020-11-10 14:26:38 +00:00
|
|
|
|
2022-05-27 18:42:07 +00:00
|
|
|
class Popup {
|
|
|
|
public:
|
|
|
|
virtual ~Popup() = default;
|
|
|
|
virtual void draw(ViewHexEditor *editor) = 0;
|
|
|
|
};
|
2020-11-15 23:07:42 +00:00
|
|
|
|
2022-05-27 18:42:07 +00:00
|
|
|
[[nodiscard]] bool isAnyPopupOpen() const {
|
|
|
|
return this->m_currPopup != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<std::derived_from<Popup> T>
|
|
|
|
[[nodiscard]] bool isPopupOpen() const {
|
|
|
|
return dynamic_cast<T*>(this->m_currPopup.get()) != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<std::derived_from<Popup> T, typename ... Args>
|
|
|
|
void openPopup(Args && ...args) {
|
|
|
|
this->m_currPopup = std::make_unique<T>(std::forward<Args>(args)...);
|
|
|
|
this->m_shouldOpenPopup = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void closePopup() {
|
|
|
|
this->m_currPopup.reset();
|
|
|
|
}
|
|
|
|
|
2022-11-06 11:19:12 +00:00
|
|
|
bool isSelectionValid() {
|
2022-11-06 23:04:47 +00:00
|
|
|
return this->m_hexEditor.isSelectionValid();
|
2022-11-06 11:19:12 +00:00
|
|
|
}
|
2022-05-27 18:42:07 +00:00
|
|
|
|
2022-11-06 11:19:12 +00:00
|
|
|
Region getSelection() {
|
2022-11-06 23:04:47 +00:00
|
|
|
return this->m_hexEditor.getSelection();
|
2022-11-06 11:19:12 +00:00
|
|
|
}
|
2022-05-27 18:42:07 +00:00
|
|
|
|
2022-11-06 11:19:12 +00:00
|
|
|
void setSelection(const Region ®ion) {
|
2022-11-06 23:04:47 +00:00
|
|
|
this->m_hexEditor.setSelection(region);
|
2022-11-06 11:19:12 +00:00
|
|
|
}
|
2022-05-27 18:42:07 +00:00
|
|
|
|
2022-11-06 11:19:12 +00:00
|
|
|
void setSelection(u128 start, u128 end) {
|
2022-11-06 23:04:47 +00:00
|
|
|
this->m_hexEditor.setSelection(start, end);
|
2022-11-06 11:19:12 +00:00
|
|
|
}
|
2022-05-27 18:42:07 +00:00
|
|
|
|
2022-11-06 11:19:12 +00:00
|
|
|
void jumpToSelection() {
|
2022-11-06 23:04:47 +00:00
|
|
|
this->m_hexEditor.jumpToSelection();
|
2022-11-06 11:19:12 +00:00
|
|
|
}
|
2022-05-27 18:42:07 +00:00
|
|
|
|
2022-11-06 11:19:12 +00:00
|
|
|
private:
|
|
|
|
void drawPopup();
|
2022-05-27 18:42:07 +00:00
|
|
|
|
2022-11-06 11:19:12 +00:00
|
|
|
void registerShortcuts();
|
|
|
|
void registerEvents();
|
|
|
|
void registerMenuItems();
|
2022-05-27 18:42:07 +00:00
|
|
|
|
2022-11-08 20:43:22 +00:00
|
|
|
ui::HexEditor m_hexEditor;
|
2022-05-27 18:42:07 +00:00
|
|
|
|
|
|
|
bool m_shouldOpenPopup = false;
|
|
|
|
std::unique_ptr<Popup> m_currPopup;
|
2020-11-10 14:26:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|