1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 11:38:21 +02:00

Add support for file drag drop

This commit is contained in:
disarray2077 2022-01-07 12:51:57 -03:00
parent 73376d2f75
commit 6d2803dbb1
7 changed files with 94 additions and 18 deletions

View file

@ -48,6 +48,7 @@ namespace Beefy
ShowMinimized = 0x0200'0000, ShowMinimized = 0x0200'0000,
ShowMaximized = 0x0400'0000, ShowMaximized = 0x0400'0000,
AllowFullscreen = 0x0800'0000, AllowFullscreen = 0x0800'0000,
AcceptFiles = 0x1000'0000
}; };
[AllowDuplicates] [AllowDuplicates]
@ -128,6 +129,7 @@ namespace Beefy
delegate void NativeMouseWheelDelegate(void* window, int32 x, int32 y, float deltaX, float deltaY); delegate void NativeMouseWheelDelegate(void* window, int32 x, int32 y, float deltaX, float deltaY);
delegate void NativeMouseLeaveDelegate(void* window); delegate void NativeMouseLeaveDelegate(void* window);
delegate void NativeMenuItemSelectedDelegate(void* window, void* menu); delegate void NativeMenuItemSelectedDelegate(void* window, void* menu);
delegate void NativeDragDropFileDelegate(void* window, char8* filePath);
public void* mNativeWindow; public void* mNativeWindow;
public bool mNativeWindowClosed; public bool mNativeWindowClosed;
@ -178,6 +180,7 @@ namespace Beefy
static NativeMouseWheelDelegate sNativeMouseWheelDelegate ~ delete _; static NativeMouseWheelDelegate sNativeMouseWheelDelegate ~ delete _;
static NativeMouseLeaveDelegate sNativeMouseLeaveDelegate ~ delete _; static NativeMouseLeaveDelegate sNativeMouseLeaveDelegate ~ delete _;
static NativeMenuItemSelectedDelegate sNativeMenuItemSelectedDelegate ~ delete _; static NativeMenuItemSelectedDelegate sNativeMenuItemSelectedDelegate ~ delete _;
static NativeDragDropFileDelegate sNativeDragDropFileDelegate ~ delete _;
[CallingConvention(.Stdcall), CLink] [CallingConvention(.Stdcall), CLink]
static extern void* BFApp_CreateWindow(void* parent, char8* title, int32 x, int32 y, int32 width, int32 height, int32 windowFlags); static extern void* BFApp_CreateWindow(void* parent, char8* title, int32 x, int32 y, int32 width, int32 height, int32 windowFlags);
@ -190,7 +193,7 @@ namespace Beefy
void* gotFocusDelegate, void* lostFocusDelegate, void* gotFocusDelegate, void* lostFocusDelegate,
void* keyCharDelegate, void* keyDownDelegate, void* keyUpDelegate, void* hitTestDelegate, void* keyCharDelegate, void* keyDownDelegate, void* keyUpDelegate, void* hitTestDelegate,
void* mouseMoveDelegate, void* mouseProxyMoveDelegate, void* mouseDownDelegate, void* mouseUpDelegate, void* mouseWheelDelegate, void* mouseLeaveDelegate, void* mouseMoveDelegate, void* mouseProxyMoveDelegate, void* mouseDownDelegate, void* mouseUpDelegate, void* mouseWheelDelegate, void* mouseLeaveDelegate,
void* menuItemSelectedDelegate); void* menuItemSelectedDelegate, void* dragDropFileDelegate);
[CallingConvention(.Stdcall), CLink] [CallingConvention(.Stdcall), CLink]
static extern void BFWindow_SetTitle(void* window, char8* title); static extern void BFWindow_SetTitle(void* window, char8* title);
@ -299,6 +302,7 @@ namespace Beefy
static void Static_NativeMouseWheelDelegate(void* window, int32 mouseX, int32 mouseY, float deltaX, float deltaY) { GetBFWindow(window).MouseWheel(mouseX, mouseY, deltaX, deltaY); } static void Static_NativeMouseWheelDelegate(void* window, int32 mouseX, int32 mouseY, float deltaX, float deltaY) { GetBFWindow(window).MouseWheel(mouseX, mouseY, deltaX, deltaY); }
static void Static_NativeMouseLeaveDelegate(void* window) { GetBFWindow(window).MouseLeave(); } static void Static_NativeMouseLeaveDelegate(void* window) { GetBFWindow(window).MouseLeave(); }
static void Static_NativeMenuItemSelectedDelegate(void* window, void* item) { GetBFWindow(window).NativeMenuItemSelected(item); } static void Static_NativeMenuItemSelectedDelegate(void* window, void* item) { GetBFWindow(window).NativeMenuItemSelected(item); }
static void Static_NativeDragDropFileDelegate(void* window, char8* filePath) { GetBFWindow(window).DragDropFile(StringView(filePath)); }
#endif #endif
public this() public this()
@ -351,12 +355,13 @@ namespace Beefy
sNativeMouseWheelDelegate = new => Static_NativeMouseWheelDelegate; sNativeMouseWheelDelegate = new => Static_NativeMouseWheelDelegate;
sNativeMouseLeaveDelegate = new => Static_NativeMouseLeaveDelegate; sNativeMouseLeaveDelegate = new => Static_NativeMouseLeaveDelegate;
sNativeMenuItemSelectedDelegate = new => Static_NativeMenuItemSelectedDelegate; sNativeMenuItemSelectedDelegate = new => Static_NativeMenuItemSelectedDelegate;
sNativeDragDropFileDelegate = new => Static_NativeDragDropFileDelegate;
} }
BFWindow_SetCallbacks(mNativeWindow, sNativeMovedDelegate.GetFuncPtr(), sNativeCloseQueryDelegate.GetFuncPtr(), sNativeClosedDelegate.GetFuncPtr(), sNativeGotFocusDelegate.GetFuncPtr(), sNativeLostFocusDelegate.GetFuncPtr(), BFWindow_SetCallbacks(mNativeWindow, sNativeMovedDelegate.GetFuncPtr(), sNativeCloseQueryDelegate.GetFuncPtr(), sNativeClosedDelegate.GetFuncPtr(), sNativeGotFocusDelegate.GetFuncPtr(), sNativeLostFocusDelegate.GetFuncPtr(),
sNativeKeyCharDelegate.GetFuncPtr(), sNativeKeyDownDelegate.GetFuncPtr(), sNativeKeyUpDelegate.GetFuncPtr(), sNativeHitTestDelegate.GetFuncPtr(), sNativeKeyCharDelegate.GetFuncPtr(), sNativeKeyDownDelegate.GetFuncPtr(), sNativeKeyUpDelegate.GetFuncPtr(), sNativeHitTestDelegate.GetFuncPtr(),
sNativeMouseMoveDelegate.GetFuncPtr(), sNativeMouseProxyMoveDelegate.GetFuncPtr(), sNativeMouseDownDelegate.GetFuncPtr(), sNativeMouseUpDelegate.GetFuncPtr(), sNativeMouseWheelDelegate.GetFuncPtr(), sNativeMouseLeaveDelegate.GetFuncPtr(), sNativeMouseMoveDelegate.GetFuncPtr(), sNativeMouseProxyMoveDelegate.GetFuncPtr(), sNativeMouseDownDelegate.GetFuncPtr(), sNativeMouseUpDelegate.GetFuncPtr(), sNativeMouseWheelDelegate.GetFuncPtr(), sNativeMouseLeaveDelegate.GetFuncPtr(),
sNativeMenuItemSelectedDelegate.GetFuncPtr()); sNativeMenuItemSelectedDelegate.GetFuncPtr(), sNativeDragDropFileDelegate.GetFuncPtr());
BFApp.sApp.mWindows.Add(this); BFApp.sApp.mWindows.Add(this);
mDefaultDrawLayer = new DrawLayer(this); mDefaultDrawLayer = new DrawLayer(this);
@ -575,6 +580,10 @@ namespace Beefy
MenuItemSelected(aSysMenu); MenuItemSelected(aSysMenu);
} }
public virtual void DragDropFile(StringView filePath)
{
}
public virtual SysBitmap LoadSysBitmap(String path) public virtual SysBitmap LoadSysBitmap(String path)
{ {
return null; return null;

View file

@ -17,6 +17,7 @@ namespace Beefy.widgets
public delegate void MouseWheelHandler(MouseEvent mouseEvent); public delegate void MouseWheelHandler(MouseEvent mouseEvent);
public delegate void KeyDownHandler(KeyDownEvent keyboardEvent); public delegate void KeyDownHandler(KeyDownEvent keyboardEvent);
//public delegate void CloseTemporaryHandler(WidgetWindow window); //public delegate void CloseTemporaryHandler(WidgetWindow window);
public delegate void DragDropFileHandler(StringView filePath);
public class WidgetWindow : BFWindow public class WidgetWindow : BFWindow
{ {
@ -31,6 +32,7 @@ namespace Beefy.widgets
public Event<MenuItemSelectedHandler> mOnMenuItemSelected ~ _.Dispose(); public Event<MenuItemSelectedHandler> mOnMenuItemSelected ~ _.Dispose();
public Event<KeyDownHandler> mOnWindowKeyDown ~ _.Dispose(); public Event<KeyDownHandler> mOnWindowKeyDown ~ _.Dispose();
public Event<delegate HitTestResult(int32, int32)> mOnHitTest ~ _.Dispose(); public Event<delegate HitTestResult(int32, int32)> mOnHitTest ~ _.Dispose();
public Event<DragDropFileHandler> mOnDragDropFile ~ _.Dispose();
public static Event<MouseLeftWindowHandler> sOnMouseLeftWindow ~ _.Dispose(); public static Event<MouseLeftWindowHandler> sOnMouseLeftWindow ~ _.Dispose();
public static Event<WindowLostFocusHandler> sOnWindowLostFocus ~ _.Dispose(); public static Event<WindowLostFocusHandler> sOnWindowLostFocus ~ _.Dispose();
@ -812,6 +814,12 @@ namespace Beefy.widgets
base.MenuItemSelected(sysMenu); base.MenuItemSelected(sysMenu);
} }
public override void DragDropFile(StringView filePath)
{
mOnDragDropFile(filePath);
base.DragDropFile(filePath);
}
public void TransferMouse(WidgetWindow newMouseWindow) public void TransferMouse(WidgetWindow newMouseWindow)
{ {
if (mWindowFlags.HasFlag(.FakeFocus)) if (mWindowFlags.HasFlag(.FakeFocus))

View file

@ -154,6 +154,7 @@ BFWindow::BFWindow()
mMouseWheelFunc = NULL; mMouseWheelFunc = NULL;
mMouseLeaveFunc = NULL; mMouseLeaveFunc = NULL;
mMenuItemSelectedFunc = NULL; mMenuItemSelectedFunc = NULL;
mDragDropFileFunc = NULL;
mHitTestFunc = NULL; mHitTestFunc = NULL;
mFlags = 0; mFlags = 0;

View file

@ -23,6 +23,7 @@ typedef void (*BFWindow_MouseUp)(BFWindow* window, int x, int y, int btn);
typedef void (*BFWindow_MouseWheel)(BFWindow* window, int x, int y, float deltaX, float deltaY); typedef void (*BFWindow_MouseWheel)(BFWindow* window, int x, int y, float deltaX, float deltaY);
typedef void (*BFWindow_MouseLeave)(BFWindow* window); typedef void (*BFWindow_MouseLeave)(BFWindow* window);
typedef void (*BFWindow_MenuItemSelectedFunc)(BFWindow* window, BFMenu* menu); typedef void (*BFWindow_MenuItemSelectedFunc)(BFWindow* window, BFMenu* menu);
typedef void (*BFWindow_DragDropFileFunc)(BFWindow* window, const char* filePath);
enum enum
{ {
@ -53,7 +54,8 @@ enum
BFWINDOW_FAKEFOCUS = 0x1000000, BFWINDOW_FAKEFOCUS = 0x1000000,
BFWINDOW_SHOWMINIMIZED = 0x2000000, BFWINDOW_SHOWMINIMIZED = 0x2000000,
BFWINDOW_SHOWMAXIMIZED = 0x4000000, BFWINDOW_SHOWMAXIMIZED = 0x4000000,
BFWINDOW_ALLOW_FULLSCREEN = 0x8000000 BFWINDOW_ALLOW_FULLSCREEN = 0x8000000,
BFWINDOW_ACCEPTFILES = 0x10000000
}; };
@ -121,6 +123,7 @@ public:
BFWindow_MouseWheel mMouseWheelFunc; BFWindow_MouseWheel mMouseWheelFunc;
BFWindow_MouseLeave mMouseLeaveFunc; BFWindow_MouseLeave mMouseLeaveFunc;
BFWindow_MenuItemSelectedFunc mMenuItemSelectedFunc; BFWindow_MenuItemSelectedFunc mMenuItemSelectedFunc;
BFWindow_DragDropFileFunc mDragDropFileFunc;
public: public:
BFWindow(); BFWindow();

View file

@ -283,7 +283,7 @@ BF_EXPORT void BF_CALLTYPE BFWindow_SetCallbacks(BFWindow* window, BFWindow_Move
BFWindow_KeyCharFunc keyCharFunc, BFWindow_KeyDownFunc keyDownFunc, BFWindow_KeyUpFunc keyUpFunc, BFWindow_HitTestFunc hitTestFunc, BFWindow_KeyCharFunc keyCharFunc, BFWindow_KeyDownFunc keyDownFunc, BFWindow_KeyUpFunc keyUpFunc, BFWindow_HitTestFunc hitTestFunc,
BFWindow_MouseMove mouseMoveFunc, BFWindow_MouseProxyMove mouseProxyMoveFunc, BFWindow_MouseMove mouseMoveFunc, BFWindow_MouseProxyMove mouseProxyMoveFunc,
BFWindow_MouseDown mouseDownFunc, BFWindow_MouseUp mouseUpFunc, BFWindow_MouseWheel mouseWheelFunc, BFWindow_MouseLeave mouseLeaveFunc, BFWindow_MouseDown mouseDownFunc, BFWindow_MouseUp mouseUpFunc, BFWindow_MouseWheel mouseWheelFunc, BFWindow_MouseLeave mouseLeaveFunc,
BFWindow_MenuItemSelectedFunc menuItemSelectedFunc) BFWindow_MenuItemSelectedFunc menuItemSelectedFunc, BFWindow_DragDropFileFunc dragDropFileFunc)
{ {
window->mMovedFunc = movedFunc; window->mMovedFunc = movedFunc;
window->mCloseQueryFunc = closeQueryFunc; window->mCloseQueryFunc = closeQueryFunc;
@ -301,6 +301,7 @@ BF_EXPORT void BF_CALLTYPE BFWindow_SetCallbacks(BFWindow* window, BFWindow_Move
window->mMouseWheelFunc = mouseWheelFunc; window->mMouseWheelFunc = mouseWheelFunc;
window->mMouseLeaveFunc = mouseLeaveFunc; window->mMouseLeaveFunc = mouseLeaveFunc;
window->mMenuItemSelectedFunc = menuItemSelectedFunc; window->mMenuItemSelectedFunc = menuItemSelectedFunc;
window->mDragDropFileFunc = dragDropFileFunc;
} }
BF_EXPORT void* BFWindow_GetNativeUnderlying(BFWindow* window) BF_EXPORT void* BFWindow_GetNativeUnderlying(BFWindow* window)

View file

@ -163,6 +163,9 @@ WinBFWindow::WinBFWindow(BFWindow* parent, const StringImpl& title, int x, int y
aWindowFlags |= WS_MAXIMIZEBOX; aWindowFlags |= WS_MAXIMIZEBOX;
if ((windowFlags & BFWINDOW_TOPMOST) && (parent == NULL)) if ((windowFlags & BFWINDOW_TOPMOST) && (parent == NULL))
windowFlagsEx |= WS_EX_TOPMOST; windowFlagsEx |= WS_EX_TOPMOST;
if ((windowFlags & BFWINDOW_ACCEPTFILES))
windowFlagsEx |= WS_EX_ACCEPTFILES;
if (windowFlags & BFWINDOW_CLIENT_SIZED) if (windowFlags & BFWINDOW_CLIENT_SIZED)
{ {
RECT rect = {0, 0, width, height}; RECT rect = {0, 0, width, height};
@ -1123,6 +1126,18 @@ LRESULT WinBFWindow::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
case WM_INPUTLANGCHANGE: case WM_INPUTLANGCHANGE:
mKeyLayoutHasAltGr = (KeyboardLayoutHasAltGr((HKL)lParam) == TRUE); mKeyLayoutHasAltGr = (KeyboardLayoutHasAltGr((HKL)lParam) == TRUE);
break; break;
case WM_DROPFILES:
{
HDROP hDropInfo = (HDROP)wParam;
char sItem[MAX_PATH];
for(int i = 0; DragQueryFileA(hDropInfo, i, (LPSTR)sItem, sizeof(sItem)); i++)
mDragDropFileFunc(this, sItem);
DragFinish(hDropInfo);
}
break;
} }
app->mInMsgProc = false; app->mInMsgProc = false;

View file

@ -846,6 +846,17 @@ namespace IDE
public void DoOpenFile() public void DoOpenFile()
{ {
#if !CLI #if !CLI
if (mDeferredOpenFileName != null)
{
for (let filePath in mDeferredOpenFileName.Split('|'))
{
AddRecentFile(.OpenedFile, filePath);
ShowSourceFile(scope String()..Reference(filePath));
}
DeleteAndNullify!(mDeferredOpenFileName);
return;
}
String fullDir = scope .(); String fullDir = scope .();
let sourceViewPanel = GetActiveSourceViewPanel(); let sourceViewPanel = GetActiveSourceViewPanel();
if (sourceViewPanel != null) if (sourceViewPanel != null)
@ -7093,6 +7104,11 @@ namespace IDE
public override void UnhandledCommandLine(String key, String value) public override void UnhandledCommandLine(String key, String value)
{ {
if (File.Exists(key))
{
DragDropFile(key);
return;
}
Fail(StackStringFormat!("Unhandled command line param: {0}", key)); Fail(StackStringFormat!("Unhandled command line param: {0}", key));
} }
@ -7238,13 +7254,7 @@ namespace IDE
else else
mWorkspace.mDir = fullDir; mWorkspace.mDir = fullDir;
case "-file": case "-file":
String.NewOrSet!(mDeferredOpenFileName, value); DragDropFile(value);
if (mDeferredOpenFileName.EndsWith(".bfdbg", .OrdinalIgnoreCase))
mDeferredOpen = .DebugSession;
else if (mDeferredOpenFileName.EndsWith(".dmp", .OrdinalIgnoreCase))
mDeferredOpen = .CrashDump;
else
mDeferredOpen = .File;
default: default:
return false; return false;
} }
@ -7252,6 +7262,34 @@ namespace IDE
} }
} }
public void DragDropFile(StringView filePath)
{
let prevDeferredOpen = mDeferredOpen;
if (filePath.EndsWith(".bfdbg", .OrdinalIgnoreCase))
mDeferredOpen = .DebugSession;
else if (filePath.EndsWith(".dmp", .OrdinalIgnoreCase))
mDeferredOpen = .CrashDump;
else
mDeferredOpen = .File;
if (prevDeferredOpen == .File && mDeferredOpen == .File)
{
if (String.IsNullOrEmpty(mDeferredOpenFileName))
String.NewOrSet!(mDeferredOpenFileName, filePath);
else
mDeferredOpenFileName.AppendF("|{}", filePath);
}
else if (prevDeferredOpen != .None && prevDeferredOpen != .File && mDeferredOpen == .File)
{
// Do nothing
}
else
{
String.NewOrSet!(mDeferredOpenFileName, filePath);
}
}
class Board : Widget class Board : Widget
{ {
public override void Draw(Graphics g) public override void Draw(Graphics g)
@ -11498,7 +11536,7 @@ namespace IDE
// //
{ {
BFWindow.Flags flags = .Border | .ThickFrame | .Resizable | .SysMenu | BFWindow.Flags flags = .Border | .ThickFrame | .Resizable | .SysMenu |
.Caption | .Minimize | .Maximize | .QuitOnClose | .Menu | .PopupPosition; .Caption | .Minimize | .Maximize | .QuitOnClose | .Menu | .PopupPosition | .AcceptFiles;
if (mRunningTestScript) if (mRunningTestScript)
flags |= .NoActivate; flags |= .NoActivate;
@ -11528,6 +11566,7 @@ namespace IDE
mMainWindow.mOnMouseUp.Add(new => MouseUp); mMainWindow.mOnMouseUp.Add(new => MouseUp);
mMainWindow.mOnWindowKeyDown.Add(new => SysKeyDown); mMainWindow.mOnWindowKeyDown.Add(new => SysKeyDown);
mMainWindow.mOnWindowCloseQuery.Add(new => AllowClose); mMainWindow.mOnWindowCloseQuery.Add(new => AllowClose);
mMainWindow.mOnDragDropFile.Add(new => DragDropFile);
CreateMenu(); CreateMenu();
UpdateRecentDisplayedFilesMenuItems(); UpdateRecentDisplayedFilesMenuItems();
if (mRecentlyDisplayedFiles.Count > 0) if (mRecentlyDisplayedFiles.Count > 0)