Added file drag and drop support

This commit is contained in:
WerWolv
2020-11-17 13:58:50 +01:00
parent d05805595e
commit 6e21f703ab
8 changed files with 38 additions and 17 deletions

View File

@@ -49,6 +49,13 @@ namespace hex {
_this->m_memoryEditor.HighlightColor = 0x50C08080;
return false;
};
View::subscribeEvent(Events::FileDropped, [this](const void *userData) {
auto filePath = static_cast<const char*>(userData);
if (filePath != nullptr)
this->openFile(filePath);
});
}
ViewHexEditor::~ViewHexEditor() {
@@ -73,16 +80,20 @@ namespace hex {
this->m_fileBrowser.Display();
if (this->m_fileBrowser.HasSelected()) {
if (this->m_dataProvider != nullptr)
delete this->m_dataProvider;
this->m_dataProvider = new prv::FileProvider(this->m_fileBrowser.GetSelected().string());
View::postEvent(Events::DataChanged);
this->openFile(this->m_fileBrowser.GetSelected().string());
this->m_fileBrowser.ClearSelected();
}
}
void ViewHexEditor::openFile(std::string path) {
if (this->m_dataProvider != nullptr)
delete this->m_dataProvider;
this->m_dataProvider = new prv::FileProvider(path);
View::postEvent(Events::DataChanged);
}
void ViewHexEditor::copyBytes() {
size_t start = std::min(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd);
size_t end = std::max(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd);