Page 1 of 1
editing lines in a scrolling list field
Posted: Wed Aug 24, 2011 7:34 pm
by marksmithhfx
Hi, I've run into a bit of a brick wall and I am hoping someone can help me out. I am trying to implement the functionality that occurs in the bookmark folders section of Safari when you right click and select 'Edit Name'. In Safari the bookmark folders list functions like a scrolling list field in LC. When you right click and select 'Edit Name' it allows you to edit the bookmark folder selection that is under the mouse, a process which is terminated by return, tab or a click anywhere outside of the current selection. I have it all working except for the part about clicking outside the current entry. I cannot seem to detect any mouse clicks except a button 3 (right mouse click).... 1 and 2's are ignored. Is there a way I can force LC to send me a mouse click message while the field is being edited?
Thanks
-- Mark
Re: editing lines in a scrolling list field
Posted: Wed Aug 24, 2011 7:49 pm
by Dixie
Mark...
put
Code: Select all
on mouseLeave
set the lockText of me to true
end mouseLeave
into the script of your scrolling list field
be well
Dixie
Re: editing lines in a scrolling list field
Posted: Wed Aug 24, 2011 8:29 pm
by marksmithhfx
Dixie wrote:Mark...
put
Code: Select all
on mouseLeave
set the lockText of me to true
end mouseLeave
into the script of your scrolling list field
Hi John, better but..... if the user selects 'Edit Name' and then moves the mouse outside the field they can't actually edit the name? The actual effect in Safari is clicking anywhere outside the current selection, even the line above or below, ends editing and reverts to list behavior. To do that I would need to:
1. know that the mouse was clicked
2. determine that the click was outside the current line
But at the moment I cannot get a reliable indication that the mouse was clicked (btw, in the version I am uploading here do a right mouse button will show the effect I am looking for with a left click). I may have to go with your suggestion as the closest possible "work around". I am uploading the revised version here (this also has a better "indicator" of the editing/scroll behavior mode by reverting to highlighting text when not editing... I am not explaining that well but edit an entry and press enter, tab or the right mouse button and it will be obvious)
Thanks for the suggestion John!!!
-- Mark
Re: editing lines in a scrolling list field
Posted: Wed Aug 24, 2011 8:45 pm
by bn
Hi Mark,
add this to the code of your field:
Code: Select all
on selectionChanged
if the lockText of me is true then exit selectionChanged -- if field is locked then it is not editable, bail out
put the cSelectedLine of me into x
put the selectedline of me into tSelectedLine
-- put x && tSelectedLine -- for debugging
if x <> word 2 of tSelectedLine then
set the listbehavior of fld "Scrolling List Field" to true
set the locktext of fld "Scrolling List Field" to true
select line x of fld "Scrolling List Field"
-- empty cselectedline and cpreviousname so we don't accidently reuse them later
set the cselectedline of fld "Scrolling List Field" to empty
set the cpreviousname of fld "Scrolling List Field" to empty
end if
end selectionChanged
-- in case you also want to catch the mouse leaving the field as of Dixie's recommendation
on mouseLeave
if the lockText of me is true then exit mouseLeave -- if field is locked then it is not editable, bail out
put the cSelectedLine of me into x
set the listbehavior of fld "Scrolling List Field" to true
set the locktext of fld "Scrolling List Field" to true
select line x of fld "Scrolling List Field"
-- empty cselectedline and cpreviousname so we don't accidently reuse them later
set the cselectedline of fld "Scrolling List Field" to empty
set the cpreviousname of fld "Scrolling List Field" to empty
end mouseLeave
it tests if a selectionChanged message is sent and if the did change. If the selectedLine is changed it is assumed that the user did not edit the line anymore
in my limited testing it did work.
Kind regards
Bernd
Re: editing lines in a scrolling list field
Posted: Wed Aug 24, 2011 8:50 pm
by Dixie
Mark...
This seems to work... another handler to add to the collection in the listField ..

put this into the mouseDown handler... and notice the local variable theLine
Code: Select all
local theLine
on mousedown theButton
put word 2 of clickLine() into theLine
Code: Select all
on mouseMove
if the lockText of me is false AND word 2 of the mouseLine <> theLine then
set the lockText of me to true
end if
end mouseMove
be well,
Dixie
Hi Bernd, you must have been on your holidays, haven't seen you on the forum lately...
Re: editing lines in a scrolling list field
Posted: Wed Aug 24, 2011 9:02 pm
by bn
@Dixie,
hi
Hi Bernd, you must have been on your holidays, haven't seen you on the forum lately...
it is a lot worse

I am refurbishing my house, knocking down walls, insulation, new roof, the works. I would prefer to spend more time on the forum.
Kind regards
Bernd
Re: editing lines in a scrolling list field
Posted: Wed Aug 24, 2011 10:45 pm
by marksmithhfx
bn wrote:Hi Mark,
add this to the code of your field:
Code: Select all
on selectionChanged
if the lockText of me is true then exit selectionChanged -- if field is locked then it is not editable, bail out
it tests if a selectionChanged message is sent and if the did change. If the selectedLine is changed it is assumed that the user did not edit the line anymore
Bernd
Hey Bernd, you nailed it. Kudos to you and Dixie... I've uploaded the final version with all of your suggestions.
You guys are fast... I'm coming back here for all my questions now!!!!!
-- Mark
Re: editing lines in a scrolling list field
Posted: Thu Aug 25, 2011 6:10 pm
by bn
Hi Mark,
I'm coming back here for all my questions now!!!!!
I am still waiting for your questions regarding the arrowKeys and the backspace / delete key. (if the user uses them this could mess up your list in no time)
Since I could not wait any longer

(as you know I am not supposed to be on the forum but on my construction site) here is my take:
Add this to the script of your scrolling list field:
Code: Select all
on arrowKey pTheKey
if pTheKey is "up" or pTheKey is "down" then exit arrowKey
put the cSelectedLine of me into x
put the selectedChunk into tSelectedChunk
put word 2 of tSelectedChunk into tStart
put word 4 of tSelectedChunk into tEnd
if pTheKey is "left" then
if the number of lines of char 1 to tEnd of me = x then
pass arrowKey
end if
end if
if pTheKey is "right" then
if the number of lines of char 1 to tStart + 1 of me = x then
pass arrowKey
end if
end if
end arrowKey
-- watch out for the delete key /backspace key
on rawKeyDown pKey
if pKey <> "65288" then pass rawKeyDown -- backspace or delete key = 65288
put the cSelectedLine of me into x
put the selectedChunk into tSelectedChunk
put word 2 of tSelectedChunk into tStart
put word 4 of tSelectedChunk into tEnd
if the number of lines of char 1 to tEnd of me = x then pass rawKeyDown
end rawKeyDown
it is tedious to catch all possibilities, I hope we accounted for most.
Kind regards
Bernd
Re: editing lines in a scrolling list field
Posted: Thu Aug 25, 2011 9:57 pm
by bn
Hi Mark,
I guess you also might want the user to be able to use the arrowkeys up / down on the locked list field to change the selection.
If you change the beginning of above "on arrowKey" handler to this code it should work. Includes a little workaround in case the field does not have focus and you tab into the field to give it focus the arrowkeys will not work right away without the workaround. See comment in code. Without the workaround you would have to click into the field first for the arrowkeys to start working.
Code: Select all
on arrowKey pTheKey
--if (pTheKey is "up" or pTheKey is "down") then exit arrowKey -- old code
if (pTheKey is "up" and the locktext of me is true) or (pTheKey is "down" and the locktext of me is true) then
select line word 2 of the selectedLine of me of me -- a workaround since if you tab into the field the arrowkeys dont work
pass arrowKey -- move selection up an down if field is locked
end if
-- rest of old code
I guess I better start to try to mindreading, else I start talking to myself

But what you want shows nicely how you can change/adapt the behavior of a list field.
Kind regards
Bernd
Re: editing lines in a scrolling list field
Posted: Fri Aug 26, 2011 12:21 am
by marksmithhfx
bn wrote:Hi Mark,
I guess you also might want the user to be able to use the arrowkeys up / down on the locked list field to change the selection.
I guess I better start to try to mindreading, else I start talking to myself

But what you want shows nicely how you can change/adapt the behavior of a list field.
Bernd
Hi Bernd, thanks so much for this.... I was away busy working on another problem (see your email!) and didn't see your posts... The drag and drop problem has kind of worn me out but I will look at all of this good stuff tomorrow. It'll be fun to put it all together!!!!!
-- Mark
Re: editing lines in a scrolling list field
Posted: Fri Aug 26, 2011 12:50 am
by marksmithhfx
bn wrote:Hi Mark,
I am still waiting for your questions regarding the arrowKeys and the backspace / delete key. (if the user uses them this could mess up your list in no time)
Since I could not wait any longer

(as you know I am not supposed to be on the forum but on my construction site) here is my take:
it is tedious to catch all possibilities, I hope we accounted for most.
Bernd
Hi Bernd,
Sheesh, how can I repay you!! That is some terrific code and you caught problems I never thought of (so I guess that makes you a kind of mind reader). If anyone else is following along I highly recommend adding Bernd's latest suggestions to the "editing" example posted previously.
Thank you!
-- Mark