Detecting "Select All" command in a field
Posted: Sat Feb 23, 2013 10:31 pm
Hi all fomum gurus! Is rhere a way to detect when an user selects all the text of a field via Edit menu (Command-A)?
Questions and answers about the LiveCode platform.
https://www.forums.livecode.com/
Code: Select all
select after fld 1
Code: Select all
if the selection = the text of fld 1 then beep
Code: Select all
put the selectedtext into tTextSelected
if tTextSelected <> empty then
put the selectedchunk into tSC
put last word of tSC into tFld
if tTextSelected = fld tFld then
doMyHandler
end if
end if
Code: Select all
if the selectedText = char 1 to -1 of fld "myField" then myHandler
Code: Select all
local selectAllFlag
on mouseMove
if the mouseLoc is within the rect of me and the selection = me and selectAllFlag = "" then
put "full" into selectAllFlag
put "All in"
wait 20
put ""
else put "full" into selectAllFlag
end mouseMove
on mouseLeave
put "" into selectAllFlag
end mouseLeave
Code: Select all
--The following menuPick handler was generated by the Menu Builder.
on menuPick pWhich
switch pWhich
case "Cut"
--Insert script for Cut menu item here
-- I didn't bother to add scripting for cut
break
case "Select all"
--Insert script for Select all menu item here
-- you'll need to script when certain items are available, but for absolute bare minimum example this works.
-- when the keys are pressed all text of the focused object is selected
select the text of the focusedObject
-- then we send a message to the focusedObject to let it know that there was a selection change
send "selectionChanged" to the focusedObject
break
case "Copy"
-- added the script to grab the selected text
copy the selectedtext
--Insert script for Copy menu item here
break
case "Paste"
-- added the paste command
paste
--Insert script for Paste menu item here
break
case "Clear"
-- didn't bother with clear
--Insert script for Clear menu item here
break
case "Preferences"
--didn't bother
--Insert script for Preferences menu item here
break
end switch
end menuPick
Mag, if you add "Select All" to the Edit Menu of the Menu Builder and include the shortcut Cmd+A you can use this basic script, I normally start off with this as it mimics the basic Mac Edit menu for most apps. From what I've read of your posts I think this will do what you are looking for if the user presses cmd+A or chooses "select all", but Undo is a whole different ballgame!Mag wrote: I would like to update a field where I put the number of selected characters, to date I use this message "selectionChanged" which detects the user direct action on the field, but I need to know also when the the user select all, paste, undo and so on...
Code: Select all
## Edit Menu Script
on menuPick pWhich
if word 1 of the focusedObject = "field" then -- Check if the focused object is a field
switch pWhich
case "Cut"
cut the selection
break
case "Copy"
copy the selection
break
case "Paste"
if the clipboard is "text" then paste
break
case "Select All"
select the text of the focusedObject
-- If you need further action add it here
break
case "Clear"
delete the selection
break
case "Preferences"
go stack "Preferences" as sheet
break
end switch
else
exit to top
end if
end menuPick