Ember
Loading...
Searching...
No Matches
XMLFileDropTarget.h
Go to the documentation of this file.
1#pragma once
2
3#include <functional>
4#include <wx/dnd.h>
5#include <wx/wx.h>
6
7namespace EmberForge {
8
16class XMLFileDropTarget : public wxFileDropTarget {
17 public:
18 using FileDropCallback = std::function<void(const wxString &filePath, bool loadInCurrentScene)>;
19
25 explicit XMLFileDropTarget(FileDropCallback callback) : m_callback(callback) {}
26
34 bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString &filenames) override {
35 // Only accept single files
36 if (filenames.GetCount() != 1) {
37 wxMessageBox("Please drop only one file at a time", "Multiple Files", wxOK | wxICON_INFORMATION);
38 return false;
39 }
40
41 wxString filePath = filenames[0];
42
43 // Check if it's an XML file
44 if (!filePath.Lower().EndsWith(".xml")) {
45 wxMessageBox("Only XML files are supported for drag and drop", "Invalid File Type", wxOK | wxICON_WARNING);
46 return false;
47 }
48
49 // Check if file exists
50 if (!wxFileExists(filePath)) {
51 wxMessageBox("The dropped file does not exist", "File Not Found", wxOK | wxICON_ERROR);
52 return false;
53 }
54
55 // Check if Ctrl key is pressed during drop
56 // Ctrl pressed = load in current scene, otherwise create new scene
57 bool ctrlPressed = wxGetKeyState(WXK_CONTROL);
58
59 // Call the callback with the file path and ctrl state
60 if (m_callback) {
61 m_callback(filePath, ctrlPressed);
62 return true;
63 }
64
65 return false;
66 }
67
68 private:
70};
71
72} // namespace EmberForge
bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString &filenames) override
Called when files are dropped.
std::function< void(const wxString &filePath, bool loadInCurrentScene)> FileDropCallback
XMLFileDropTarget(FileDropCallback callback)
Construct a new XMLFileDropTarget.