Click, Pause, Click Again to Edit a Line in a Field?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Livecode Opensource Backer
- Posts: 107
- Joined: Fri Nov 10, 2006 8:58 pm
- Contact:
Click, Pause, Click Again to Edit a Line in a Field?
In a field with listBehavior = true, I'm trying to figure out how to make the field's lines behave the way items in Windows Explorer or Mac's Finder do: If I click a line, pause, and click again, the text in that line becomes editable and is selected.
Something Completely Different: The way this forum's search throws out words it deems too common makes trying to search for previous posts approximately impossible for me. Maybe I just don't understand how to search, but I kind of doubt it.
Something Completely Different: The way this forum's search throws out words it deems too common makes trying to search for previous posts approximately impossible for me. Maybe I just don't understand how to search, but I kind of doubt it.
Re: Click, Pause, Click Again to Edit a Line in a Field?
On the first click, set a flag to TRUE and do a send in time.. if the second click is before that handler runs, cancel the queued message and proceed with your editing.. if the click is fast, cancel the queued message in the mouseDoubleUp message.. The following code should get you started (just off the top of my head and not run through Rev/LC)
Code: Select all
local sAllowEditingFlag = "FALSE" -- have to use the quotes, otherwise a script compile error
local sMessageID
on mouseUp
if (sAllowEditingFlag = FALSE) then
put TRUE into sAllowEditingFlag
send "editingTimeout" to me in 2 seconds
put the result into sMessageID
else
put FALSE into sAllowEditingFlag
// do your editing
end if
end mouseUp
on mouseDoubleUp
if (sAllowEditingFlag = TRUE) then
put FALSE into sAllowEditingFlag
cancel sMessageID
end if
end mouseDoubleUp
on editingTimeout
put FALSE into sAllowEditingFlag
end editingTimeout
Re: Click, Pause, Click Again to Edit a Line in a Field?
Hi.
A much more old fashioned way to to this, in the field script:
A much more old fashioned way to to this, in the field script:
Code: Select all
on mouseup
wait 15
if the mouseClick then
set the locktext of me to "false"
set the listbehavior of me to "false"
end if
end mouseup
on mouseLeave
set the locktext of me to "true"
set the listbehavior of me to "true"
end mouseLeave
-
- Livecode Opensource Backer
- Posts: 107
- Joined: Fri Nov 10, 2006 8:58 pm
- Contact:
Re: Click, Pause, Click Again to Edit a Line in a Field?
Thanks. One of the things I'll have to take into account is guarding against deletion of the line or of multiple lines while listBehavior is temporarily suspended. I'm surprised LiveCode doesn't include a built-in behavior or property to mimic the way Windows Explorer and Finder lists work since I imagine wanting to do so would be a common thing.
Re: Click, Pause, Click Again to Edit a Line in a Field?
If you don't mind using a datagrid (form not table) you can add the following to its behavior script.
Then comment out the double click handler that is in there. 35 seems to work pretty well, and there may be other issues that haven't occured to me yet with this method but for the moment it seems to work pretty well.
Code: Select all
local sClicked -- can declare here or at top
on mouseup
if not sClicked then
put true into sClicked
send "clearClick" to me in 35 -- adjust timing as you see fit
else
local theKey
if the dgProps["allow editing"] of the dgControl of me then
switch the short name of the target
case "Label"
put "Label 1" into theKey
EditFieldText the long ID of the target, the dgIndex of me, theKey
break
end switch
put false into sClicked
end if
end if
pass mouseUp
end mouseup
command clearClick
put false into sClicked
end clearClick
Re: Click, Pause, Click Again to Edit a Line in a Field?
EDITED: so that it might possibly work...
Actually, if you want doubleclick to still function for another purpose you can adjust like this:
Actually, if you want doubleclick to still function for another purpose you can adjust like this:
Code: Select all
on mouseDoubleUp pMouseBtnNum
## Whatever you want to happen with doubleclick goes here.
pass mouseDoubleUp
end mouseDoubleUp
local sClickStarted --the milliseconds of the first click
on mouseup
if not sClicked then
put the milliseconds into sClickStarted -- store the milliseconds
put true into sClicked --could probably drop this and just check of sClickStarted is empty /shrug
send "clearClick" to me in 60 --if the double click interval is 500, then any interval longer than 1/2 sec, up to 1 full sec will enter edit mode
else
if the milliseconds - sClickStarted > the doubleclickinterval then -- do the interval check
local theKey
if the dgProps["allow editing"] of the dgControl of me then
switch the short name of the target
case "Label"
put "Label 1" into theKey
EditFieldText the long ID of the target, the dgIndex of me, theKey
break
end switch
end if
put false into sClicked -- clear vars. Whether it was a double click or not, still clear here.
put empty into sClickStarted
end if
end if
pass mouseUp
end mouseup
command clearClick
put false into sClicked -- clears stray clicks longer than the max interval. Should probably check pending messages and make sure these aren't stacked in queue
end clearClick
-
- Livecode Opensource Backer
- Posts: 107
- Joined: Fri Nov 10, 2006 8:58 pm
- Contact:
Re: Click, Pause, Click Again to Edit a Line in a Field?
The solution I came up with is completely different, but it mimics what you see in the Mac Finder or Windows Explorer:
When the user clicks on a line in the list field, a heretofore invisible field appears, positioned exactly over the text on the underlying field. This newly visible field contains the same text as the clicked line, and that text is selected for immediate editing.
I temporarily delete the text from the underlying field's clicked line so that when the user begins typing, causing the size of the newly visible, overlaying field to initially shrink to a couple characters' width, the underlying text isn't visible, which would spoil the illusion.
I also put in safeguards so that if the user clicks out of the overlaying editable field while its contents are blank, the original text is restored to the underlying field.
Also, if you click the "Show Focus Border" checkbox for the overlaying field, it has a nice blue border around it just like when you're editing a line in the Mac Finder or Windows Explorer.
After coming up with this "work-around", I think this is may be more or less how the Finder and Windows Explorer handle editing entries.
When the user clicks on a line in the list field, a heretofore invisible field appears, positioned exactly over the text on the underlying field. This newly visible field contains the same text as the clicked line, and that text is selected for immediate editing.
I temporarily delete the text from the underlying field's clicked line so that when the user begins typing, causing the size of the newly visible, overlaying field to initially shrink to a couple characters' width, the underlying text isn't visible, which would spoil the illusion.
I also put in safeguards so that if the user clicks out of the overlaying editable field while its contents are blank, the original text is restored to the underlying field.
Also, if you click the "Show Focus Border" checkbox for the overlaying field, it has a nice blue border around it just like when you're editing a line in the Mac Finder or Windows Explorer.
After coming up with this "work-around", I think this is may be more or less how the Finder and Windows Explorer handle editing entries.
Re: Click, Pause, Click Again to Edit a Line in a Field?
Hi Stephen,
Best
Klaus
yep, and the DataGridstephenmcnutt wrote:...After coming up with this "work-around", I think this is may be more or less how the Finder and Windows Explorer handle editing entries.

Best
Klaus
-
- Posts: 919
- Joined: Wed Nov 04, 2009 11:41 am
Re: Click, Pause, Click Again to Edit a Line in a Field?
BUMP!!!!!!!
Just wanted to say thanks for the code snips - I have just used the simple old fashioned code presented by Dunbarx.



Just wanted to say thanks for the code snips - I have just used the simple old fashioned code presented by Dunbarx.

best wishes
Skids
Skids
Re: Click, Pause, Click Again to Edit a Line in a Field?
Simon.
That was a trick I made in HC about a million years ago. Looking at it again, maybe the 15 ticks wait period ought to be greater? Not everyone double-clicks as fast as I do.
Craig
That was a trick I made in HC about a million years ago. Looking at it again, maybe the 15 ticks wait period ought to be greater? Not everyone double-clicks as fast as I do.
Craig
Re: Click, Pause, Click Again to Edit a Line in a Field?
I posted an alternative method in Simon's related thread that doesn't rely on time intervals (it tracks which line is already hilited and if same line clicked again it turns the field into an edit field) - I also find it cumbersome to have to trigger mouseLeave to change back to a listField so I use mouseLine instead (economy of movement!)
https://forums.livecode.com/viewtopic.p ... 32#p224835
https://forums.livecode.com/viewtopic.p ... 32#p224835