Merge pull request #629 from LastFlux/master
Add file drop functionality
This commit is contained in:
commit
e3ac7bdae8
|
@ -32,6 +32,7 @@ using xe::ui::KeyEvent;
|
|||
using xe::ui::MenuItem;
|
||||
using xe::ui::MouseEvent;
|
||||
using xe::ui::UIEvent;
|
||||
using xe::ui::FileDropEvent;
|
||||
|
||||
const std::wstring kBaseTitle = L"xenia";
|
||||
|
||||
|
@ -81,6 +82,9 @@ bool EmulatorWindow::Initialize() {
|
|||
});
|
||||
loop_->on_quit.AddListener([this](UIEvent* e) { window_.reset(); });
|
||||
|
||||
window_->on_file_drop.AddListener(
|
||||
[this](FileDropEvent* e) { FileDrop(e->filename()); });
|
||||
|
||||
window_->on_key_down.AddListener([this](KeyEvent* e) {
|
||||
bool handled = true;
|
||||
switch (e->key_code()) {
|
||||
|
@ -257,6 +261,15 @@ bool EmulatorWindow::Initialize() {
|
|||
return true;
|
||||
}
|
||||
|
||||
void EmulatorWindow::FileDrop(wchar_t* filename) {
|
||||
std::wstring path = filename;
|
||||
auto result = emulator_->LaunchPath(path);
|
||||
if (XFAILED(result)) {
|
||||
// TODO: Display a message box.
|
||||
XELOGE("Failed to launch target: %.8X", result);
|
||||
}
|
||||
}
|
||||
|
||||
void EmulatorWindow::FileOpen() {
|
||||
std::wstring path;
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ class EmulatorWindow {
|
|||
|
||||
bool Initialize();
|
||||
|
||||
void FileDrop(wchar_t* filename);
|
||||
void FileOpen();
|
||||
void CheckHideCursor();
|
||||
void CpuTimeScalarReset();
|
||||
|
|
|
@ -26,6 +26,18 @@ class UIEvent {
|
|||
Window* target_ = nullptr;
|
||||
};
|
||||
|
||||
class FileDropEvent : public UIEvent {
|
||||
public:
|
||||
FileDropEvent(Window* target, wchar_t* filename)
|
||||
: UIEvent(target), filename_(filename) {}
|
||||
~FileDropEvent() override = default;
|
||||
|
||||
wchar_t* filename() const { return filename_; }
|
||||
|
||||
private:
|
||||
wchar_t* filename_ = nullptr;
|
||||
};
|
||||
|
||||
class KeyEvent : public UIEvent {
|
||||
public:
|
||||
KeyEvent(Window* target, int key_code, int repeat_count, bool prev_state)
|
||||
|
|
|
@ -213,6 +213,11 @@ void Window::OnPaint(UIEvent* e) {
|
|||
}
|
||||
}
|
||||
|
||||
void Window::OnFileDrop(FileDropEvent* e) {
|
||||
on_file_drop(e);
|
||||
ForEachListener([e](auto listener) { listener->OnFileDrop(e); });
|
||||
}
|
||||
|
||||
void Window::OnVisible(UIEvent* e) {
|
||||
ForEachListener([e](auto listener) { listener->OnVisible(e); });
|
||||
}
|
||||
|
|
|
@ -102,6 +102,7 @@ class Window {
|
|||
Delegate<UIEvent*> on_painting;
|
||||
Delegate<UIEvent*> on_paint;
|
||||
Delegate<UIEvent*> on_painted;
|
||||
Delegate<FileDropEvent*> on_file_drop;
|
||||
|
||||
Delegate<KeyEvent*> on_key_down;
|
||||
Delegate<KeyEvent*> on_key_up;
|
||||
|
@ -128,6 +129,7 @@ class Window {
|
|||
virtual void OnResize(UIEvent* e);
|
||||
virtual void OnLayout(UIEvent* e);
|
||||
virtual void OnPaint(UIEvent* e);
|
||||
virtual void OnFileDrop(FileDropEvent* e);
|
||||
|
||||
virtual void OnVisible(UIEvent* e);
|
||||
virtual void OnHidden(UIEvent* e);
|
||||
|
|
|
@ -31,6 +31,7 @@ class WindowListener {
|
|||
virtual void OnPainting(UIEvent* e) {}
|
||||
virtual void OnPaint(UIEvent* e) {}
|
||||
virtual void OnPainted(UIEvent* e) {}
|
||||
virtual void OnFileDrop(UIEvent* e) {}
|
||||
|
||||
virtual void OnVisible(UIEvent* e) {}
|
||||
virtual void OnHidden(UIEvent* e) {}
|
||||
|
|
|
@ -101,6 +101,8 @@ bool Win32Window::OnCreate() {
|
|||
|
||||
// Enable DWM elevation.
|
||||
EnableMMCSS();
|
||||
// Enable file dragging from external sources
|
||||
DragAcceptFiles(hwnd_, true);
|
||||
|
||||
ShowWindow(hwnd_, SW_SHOWNORMAL);
|
||||
UpdateWindow(hwnd_);
|
||||
|
@ -378,6 +380,21 @@ LRESULT Win32Window::WndProc(HWND hWnd, UINT message, WPARAM wParam,
|
|||
}
|
||||
|
||||
switch (message) {
|
||||
case WM_DROPFILES: {
|
||||
TCHAR lpszFile[MAX_PATH] = {0};
|
||||
UINT uFiles = 0;
|
||||
HDROP hDrop = (HDROP)wParam;
|
||||
// Get number of files dropped
|
||||
uFiles = DragQueryFile(hDrop, -1, NULL, NULL);
|
||||
|
||||
// Only getting first file dropped (other files ignored)
|
||||
if (DragQueryFile(hDrop, 0, lpszFile, MAX_PATH)) {
|
||||
auto e = FileDropEvent(this, lpszFile);
|
||||
OnFileDrop(&e);
|
||||
}
|
||||
|
||||
DragFinish(hDrop);
|
||||
} break;
|
||||
case WM_NCCREATE:
|
||||
break;
|
||||
case WM_CREATE:
|
||||
|
|
Loading…
Reference in New Issue