Detecting "Select All" command in a field
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Detecting "Select All" command in a field
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)?
-
- Livecode Opensource Backer
- Posts: 1336
- Joined: Sun Jul 12, 2009 10:53 am
- Location: Bordeaux, France
Re: Detecting "Select All" command in a field
Code: Select all
select after fld 1
Edit: Oops sorry, that's not what you wanted.,,, rather...
Code: Select all
if the selection = the text of fld 1 then beep
Last edited by Dixie on Sat Feb 23, 2013 11:08 pm, edited 1 time in total.
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: Detecting "Select All" command in a field
Hi Mag,
This script does the job. The question is which send it. (Mousemove, mouseleave ?)
Best
Jean-Marc
This script does the job. The question is which send it. (Mousemove, mouseleave ?)
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
Jean-Marc
https://alternatic.ch
-
- VIP Livecode Opensource Backer
- Posts: 253
- Joined: Fri Dec 09, 2011 11:17 am
- Location: Warszawa / Poland
Re: Detecting "Select All" command in a field
Code: Select all
if the selectedText = char 1 to -1 of fld "myField" then myHandler
-
- VIP Livecode Opensource Backer
- Posts: 9665
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Detecting "Select All" command in a field
Hi.
Both Jean-Marc and Dixie are correct in that they have told you how to detect if the entirety of a field's text has been selected. Do you see this? If the selection is the same as the contents of the field, then...
But I think you were asking how to detect when the user selected all the text, and that has me puzzled. No messages are generated when a selection is being made, that is, when the cursor is being dragged across text in a field with the mouse down.
I think.
Of course, you can detect if the user does a "select all" sort of thing, but I am talking about an active text selection with the mouse.
Even a "mouseMove" handler in the field, with the filter that the mouseLoc has to be within the rect of that field, is suppressed during click and drag event. I thought i might be able to exploit this, checking the selection before and after. I will play around for a while. This kind of works, but has issues:
Craig Newman
Both Jean-Marc and Dixie are correct in that they have told you how to detect if the entirety of a field's text has been selected. Do you see this? If the selection is the same as the contents of the field, then...
But I think you were asking how to detect when the user selected all the text, and that has me puzzled. No messages are generated when a selection is being made, that is, when the cursor is being dragged across text in a field with the mouse down.
I think.
Of course, you can detect if the user does a "select all" sort of thing, but I am talking about an active text selection with the mouse.
Even a "mouseMove" handler in the field, with the filter that the mouseLoc has to be within the rect of that field, is suppressed during click and drag event. I thought i might be able to exploit this, checking the selection before and after. I will play around for a while. This kind of works, but has issues:
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
Re: Detecting "Select All" command in a field
Thank you so much for your posts, great info, I will study all of them.
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...
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...
Re: Detecting "Select All" command in a field
YOu need to override the system level handling of the keys. Basically you use the menu builder to create your menus, adding "Select all" to the edit menu.
You specify the hotkeys in question (on mac, cmd + a)
Then you edit the script of the edit menu in the menu builder.
You can autogenerate the initial menu, then you need to adapt it to your needs.
Just messing around real quickly, here is a simple script to do what you want for the edit menu.
You specify the hotkeys in question (on mac, cmd + a)
Then you edit the script of the edit menu in the menu builder.
You can autogenerate the initial menu, then you need to adapt it to your needs.
Just messing around real quickly, here is a simple script to do what you want for the edit menu.
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
-
- VIP Livecode Opensource Backer
- Posts: 9665
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Detecting "Select All" command in a field
So dumb.
Forgot about the new, fabulous, "selectionChanged" message.
Craig Newman
Forgot about the new, fabulous, "selectionChanged" message.
Craig Newman
Re: Detecting "Select All" command in a field
selectionChanged does work with a mouse drag (when the mouse is released, tested it real quick) but those pesky ctrl-a's and pastes and such just don't.
Would be really nice if the message fired no matter how the selection ended up changed. (except for that whole recursion problem of a selection changing selectionChanged handler of course)
Is there another way to do this that avoids the whole menu editing thing?
Would be really nice if the message fired no matter how the selection ended up changed. (except for that whole recursion problem of a selection changing selectionChanged handler of course)
Is there another way to do this that avoids the whole menu editing thing?
-
- Livecode Opensource Backer
- Posts: 1336
- Joined: Sun Jul 12, 2009 10:53 am
- Location: Bordeaux, France
Re: Detecting "Select All" command in a field
Craig...
I too had forgotten all about the 'selectionChanged' message... Is there room for two dunces in the corner ?
be well,
Dixie
I too had forgotten all about the 'selectionChanged' message... Is there room for two dunces in the corner ?
be well,
Dixie
-
- VIP Livecode Opensource Backer
- Posts: 129
- Joined: Sun Feb 20, 2011 4:26 pm
- Location: Vancouver Island, BC, Canada. ex.UK
- Contact:
Re: Detecting "Select All" command in a field
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! selectionChanged within the field script as the others have suggested may be your best route there.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
Re: Detecting "Select All" command in a field
Thank you all so much! Great advices, I will try to implement the Menu Builder way. Indeed will be useful also for other features I would like to implement to my project.
PS
This is my first OS X project so I have to learn all about Menu Builder
PS
This is my first OS X project so I have to learn all about Menu Builder