dragData[] in LCB

Moderators: LCMark, LCfraser

Post Reply
dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 828
Joined: Wed Jun 24, 2009 1:17 pm
Location: Plymouth, UK
Contact:

dragData[] in LCB

Post by dave.kilroy » Tue Jul 26, 2016 9:34 pm

Hi, in dictionary of LC8.1.0(dp2) in the LiveCodeBuilder section I can see entries for ondragEnter and ondragDrop - but nothing for dragData[]. Does anyone know if this is just a documentation error or has dragData[] not been included in LCB yet?

FYI, what I would like to do is to drag 'n drop a file onto a widget and from there read the contents of the file ...

Thanks

Dave
"...this is not the code you are looking for..."

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1521
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: dragData[] in LCB

Post by [-hh] » Fri Oct 07, 2016 9:35 pm

Hi Dave,

presumably the dragData is not available in LCB, also not the dragAction.

I found a "weak work-around" without using LCS handlers and LCS properties (dragAction, dragEnter, ...). By defining a property:

Code: Select all

private variable mDragFile as String

property dragFile   get mDragFile   set setDragFile
-- PI adds an answer file dialog to the text input box:
metadata dragFile.editor is "com.livecode.pi.file" 

private handler setDragFile(in pString as String)
    put pString into mDragFile
    ...
end handler
Then I can drag a file icon to the property's entry in the property inspector to have the filename accessible in the widget.

But now, how to read the file from LCB if it's not an imagefile?
(I opened an own thread for that question).

Hermann

** Edit. To have it even more comfortable, thanks tothe property inspector, use as editor '.file' instead of '.string', as now above.
Last edited by [-hh] on Mon Oct 10, 2016 3:43 pm, edited 1 time in total.
shiftLock happens

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1521
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: dragData[] in LCB

Post by [-hh] » Sat Oct 08, 2016 12:31 am

And below is the answer, stolen from Peter's treasure chest.

If I now drag a text file's icon/filePath to the property's field in the property inspector then I have the content of that file in the variable mText.

Code: Select all

use com.livecode.foreign
--
private variable mText as String
--
private handler setDragFile(in pString as String) returns nothing
	put pString into mDragFile
	put decodeText_utf8(the contents of file mDragFile) into mText
end handler
--
private handler decodeText_utf8(in pData as Data) returns String
	variable tString as String
	unsafe
		MCStringDecode(pData, 4 /* UTF-8 */, false, tString)
	end unsafe
	return tString
end handler
--
private handler encodeText_utf8(in pString as String) returns Data
	variable tEncoded as Data
	unsafe
		MCStringEncode(pString, 4 /* UTF-8 */, false, tEncoded)
	end unsafe
	return tEncoded
end handler
-- 
foreign handler MCStringEncode(in Source as String, in Encoding as CInt, in IsExternalRep as CBool, out Encoded as Data) returns CBool binds to "<builtin>"
foreign handler MCStringDecode(in Encoded as Data, in Encoding as CInt, in IsExternalRep as CBool, out Result as String) returns CBool binds to "<builtin>"
Now let us look forward to all the (new) foreign-handlers and their documentation (at least a listing with a one-liner info?).
shiftLock happens

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 828
Joined: Wed Jun 24, 2009 1:17 pm
Location: Plymouth, UK
Contact:

Re: dragData[] in LCB

Post by dave.kilroy » Sun Oct 09, 2016 3:15 pm

Hi Hermann

Yes that is roughly what I did back in August - I put a widget inside a group and used the LCS dragenter and dragdrop commands to get the filesource (path) and from that get the .txt or .json file's contents

Trevor at his Widgets session at the conference (that we were both at) suggested I use this method to populate the source of the image-displaying widget we were playing with at the session - and dragging and dropping an image file onto the widget worked nicely...

However I'm afraid I've somehow lost the stack I was experimenting on so can't be 100% sure that's how I did it :(

Thank you for thinking of me - I've not had a chance to do more LCB stuff since then but am itching to do so :)

Kind regards

Dave
"...this is not the code you are looking for..."

peter-b
Posts: 182
Joined: Thu Nov 20, 2014 2:14 pm
Location: LiveCode Ltd.

Re: dragData[] in LCB

Post by peter-b » Mon Oct 10, 2016 9:01 am

You can find a list of all LiveCode's "foundation" library functions that can be accessed like that by looking at the libfoundation header file. You should be able to define a LCB foreign handler in the same way as above for any function labelled "MC_DLLEXPORT".

In the long run all of these built-in capabilities will be accessible by "proper" LCB syntax and no messing around with foreign handler definitions will be required.
LiveCode Open Source Team — @PeterTBBrett — peter.brett@livecode.com

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 841
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: dragData[] in LCB

Post by trevordevore » Mon Oct 10, 2016 3:06 pm

Dave,

IIRC, the drag/drop was handled in LCS and then you just set a property of the widget. That is the easiest way to handle drag/drop with widgets.
Trevor DeVore
ScreenSteps - http://www.screensteps.com

Levure Application Framework: https://github.com/trevordevore/levure
LiveCode Resources for Developers: http://livecode.bluemangolearning.com

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 828
Joined: Wed Jun 24, 2009 1:17 pm
Location: Plymouth, UK
Contact:

Re: dragData[] in LCB

Post by dave.kilroy » Tue Oct 11, 2016 12:29 pm

Thanks Trevor, yep using LCS to change a property in the widget is exactly what I did - once you told me I should do it :)

I think actually on the second day of the conference Fraser told me the same thing (but the penny didn't drop until I heard it the second time)
"...this is not the code you are looking for..."

Post Reply

Return to “LiveCode Builder”