August 26, 2016 at 7:03 am #3463
Does mx2 support dropping of files on the app window?
If so, how?
if not, how?August 26, 2016 at 12:34 pm #3471
I know (and found in module source) that SDL has an event SDL_DropEvent but not sure if this is implemented/used in MX2 (its defined so I imagine that can be catched).
tested using the SDL example, just adding in Select..End Select
Print “Event dropfile”
looking at the event.monkey2 source it seems that SDL_DROP is not implemented (or maybe I’ve looked in the wrong place! – there are only key, windows and mouse events)
it seems to worksAugust 26, 2016 at 1:48 pm #3479
Looks like you need to hack Mojo to support dragging items onto the application window.
Rough “proof of concept” example:
Add the following field, property and method to to the AppInstance class:Monkey12345678910111213[crayon-5b73d201dcb6d981691220 inline="true" ]PrivateField _draggedFileName:StringPublicProperty DraggedFileName:String()Return _draggedFileNameEndMethod ClearDraggedFileName:Void()_draggedFileName = NullEnd
Add the following function call to the bottom of the AppInstance class constructor, just before the End statement:Monkey123456789[crayon-5b73d201dcb71646609376 inline="true" ]Method New()...SDL_EventState(SDL_DROPFILE, SDL_ENABLE)End
Add the following to the Select statement in the DispatchEvent method:Monkey1234567891011121314151617[crayon-5b73d201dcb75916790013 inline="true" ]Method DispatchEvent( event:SDL_Event Ptr )Select event->type...Case SDL_DROPFILELocal devent:=Cast<SDL_DropEvent Ptr>( event )_draggedFileName = String.FromCString(devent->file)Print _draggedFileNameSDL_free(devent->file)EndEnd
Compile the mojo module. Test it out with the following example.
sdl2DragTest.monkey2:Monkey1234567891011121314151617181920212223242526272829[crayon-5b73d201dcb7a970864416 inline="true" ]#Import "<std>"#Import "<mojo>"Using std..Using mojo..Class MyWindow Extends WindowMethod New()Super.New("Window",640, 480)EndMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender()If App.DraggedFileNamecanvas.DrawText(App.DraggedFileName, Width/2, Height/2, .5, .5)Elsecanvas.DrawText("Drag something onto the window...", Width/2, Height/2, .5, .5)EndifEndEndFunction Main()New AppInstanceNew MyWindowApp.Run()End
As I said, that’s just a proof of concept that works for me (on Windows).
To make DropEvent behave like the other Mojo event types requires extra work… Something for another time…August 26, 2016 at 8:30 pm #3488
Looks nice and easy, will have a hack at this today.August 8, 2018 at 1:55 pm #15266
Does drag and drop work for both windows and icons? Please create a drag and drop banana how to use it in new releases it could be emmensly useful to have sometimes 🤔August 9, 2018 at 11:59 am #15268
It’s easy. Write in your widow constructorMonkey123App.FileDropped+=Lambda( path: String )Print pathEnd
Works fine on Windows, don’t know about osx.August 9, 2018 at 12:55 pm #15269
it works in macos the same ☺️, also with folders and multiple files is confirmed.
How about dropping files onto the actual app icon instead of the app window?
In windows this would mean reading the parameters of the exe file right? What about macOS?August 9, 2018 at 1:08 pm #15270
Ted2go is supporting drag-into-exe. You can test it on win and mac.
The codeMonkey12345678910App.Idle+=Lambda()' open docs from argsLocal args:=AppArgs()For Local i:=1 Until args.LengthLocal arg:=args[i]arg=arg.Replace( "\","/" )MainWindow.OnFileDropped( arg )NextEndAugust 9, 2018 at 1:49 pm #15271
I get the error “identifier “MainWindow” Not found?August 9, 2018 at 2:04 pm #15272
Replace MainWindow.OnFileDropped( arg ) with your code .August 9, 2018 at 2:22 pm #15273
oh gotcha I thought was some clever mechanism to chain parameter/icon input to the window drag and drop input.
for macos you need to edit info.plist to allow dragging to an icon on the desktop or onto the dock
info.plist needs the added line:
Add/Modify public.data mime type
I can be misstaken as this is all new to me, but am exploring it now. Is this why you can’t drag files onto Monkey2 in the macos dock (or desk) maybe.
You must be logged in to reply to this topic.