dragData[] in LCB
-
- VIP Livecode Opensource Backer
- Posts: 858
- Joined: Wed Jun 24, 2009 1:17 pm
- Location: Plymouth, UK
- Contact:
dragData[] in LCB
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
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..."
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: dragData[] in LCB
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:
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.
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
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
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: dragData[] in LCB
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.
Now let us look forward to all the (new) foreign-handlers and their documentation (at least a listing with a one-liner info?).
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>"
shiftLock happens
-
- VIP Livecode Opensource Backer
- Posts: 858
- Joined: Wed Jun 24, 2009 1:17 pm
- Location: Plymouth, UK
- Contact:
Re: dragData[] in LCB
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
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..."
Re: dragData[] in LCB
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.
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
-
- VIP Livecode Opensource Backer
- Posts: 1005
- Joined: Sat Apr 08, 2006 3:06 pm
- Location: Overland Park, Kansas
- Contact:
Re: dragData[] in LCB
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.
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 - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
-
- VIP Livecode Opensource Backer
- Posts: 858
- Joined: Wed Jun 24, 2009 1:17 pm
- Location: Plymouth, UK
- Contact:
Re: dragData[] in LCB
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)
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..."