Hello, I appreciate your interest liveme. I am making progress and I think I've figured out nearly everything to make it work how I'd like.
pasteKey is an even that objects respond to when the user presses the keystroke to paste on their platform. Since my text field (named "FieldTitles") already contained a pasteKey handler, I have my popup menu send that message to the text field.
I have 2 text fields that I want to be able to right click in and get a popup menu with cut, copy, paste, select all.
I have generalized my code in the following way:
I moved my mouseUp handler to the card's script and added a global variable for keeping track of which text field received the mouseUp message:
Code: Select all
global gTextFieldClicked
on mouseUp pMouseButton
if the short name of the target is "FieldTitles" or the short name of the target is "FieldVBScriptBody" then
if pMouseButton = 3 then
put the short name of the target into gTextFieldClicked
handleRightClickInTextField
else
-- do other stuff here
pass mouseUp
end if
else
pass mouseUp
end if
end mouseUp
I put all the conditional statements that enable/disable the items in my popup menu into a custom handler called "handleRightClickInTextField" because my mouseUp "if pMouseButton = 3" section was getting unwieldy with nested if statements.
It looks like this:
Code: Select all
on handleRightClickInTextField
if the short name of the focusedObject <> gTextFieldClicked then
focus on field gTextFieldClicked
select text of field gTextFieldClicked
enable menuItem 1 of button "Popup Menu Text Field"
enable menuItem 2 of button "Popup Menu Text Field"
disable menuItem 4 of button "PopUp Menu Text Field"
disable menuItem 5 of button "PopUp Menu Text Field"
disable menuItem 6 of button "PopUp Menu Text Field"
disable menuItem 7 of button "PopUp Menu Text Field"
else if text of field gTextFieldClicked = "" then
disable menuItem 1 of button "PopUp Menu Text Field"
disable menuItem 2 of button "PopUp Menu Text Field"
disable menuItem 4 of button "PopUp Menu Text Field"
disable menuItem 5 of button "PopUp Menu Text Field"
disable menuItem 6 of button "PopUp Menu Text Field"
disable menuItem 7 of button "PopUp Menu Text Field"
else
enable menuItem 4 of button "PopUp Menu Text Field"
if the selectedText of field gTextFieldClicked = "" then
disable menuItem 1 of button "PopUp Menu Text Field"
disable menuItem 2 of button "PopUp Menu Text Field"
disable menuItem 5 of button "PopUp Menu Text Field"
disable menuItem 6 of button "PopUp Menu Text Field"
disable menuItem 7 of button "PopUp Menu Text Field"
else
enable menuItem 1 of button "Popup Menu Text Field"
enable menuItem 2 of button "Popup Menu Text Field"
enable menuItem 5 of button "PopUp Menu Text Field"
enable menuItem 6 of button "PopUp Menu Text Field"
enable menuItem 7 of button "PopUp Menu Text Field"
end if
end if
set the traversalOn of button "PopUp Menu Text Field" to false
popup button "PopUp Menu Text Field" at the clickLoc
end handleRightClickInTextField
My code in my popup menu now uses the global "gTextFieldClicked" variable to respond appropriately depending on which text field was right clicked:
Code: Select all
global gTextFieldClicked
on menuPick pItem
switch pItem
case "Cut"
cut
break
case "Copy"
copy
break
case "Paste"
if gTextFieldClicked is "FieldTitles" then
send "pasteKey" to field "FieldTitles"
else
paste
end if
break
case "Select All"
select text of field gTextFieldClicked
break
case "Set Artist"
set text of field "FieldArtist" to selectedText of field gTextFieldClicked
break
case "Set Album"
put selectedText of field gTextFieldClicked into field "FieldAlbum"
break
case "Set Genre"
put selectedText of field gTextFieldClicked into field "FieldGenre"
break
end switch
end menuPick
You may notice that my "Paste" case sends the "pasteKey" message to my "FieldTitles" field and just calls the default "paste" method for my other field.
Everything works like I want. The only UI anomaly that exists at this point is that it takes a left click outside of the popup menu to dismiss it without choosing an item inside of it. I don't understand why a right click outside of the popup menu doesn't cause it to be dismissed without making a selection but, I'm thinking I may have introduced a logical error in how I'm catching mouseUp in my card's script and when I'm choosing to pass mouseUp. It is however, a very minor annoyance at this point.
Maybe I shouldn't have even started this thread because shortly after making the post, I found the initial answer I was looking for about the need to implement a popup menu to accommodate right clicks in text fields to get the expected, cut, copy, paste, select all items that users would be used to. I was hoping that LC had a method of providing these without the need to write your own code- like it would be sweet if there was a checkbox in the properties of text fields that enabled standard right click behavior without the need to write your own code to get it.
So, the only thing I'm trying to figure out at this point is why it requires a left click outside of my popup menu in order to dismiss it.
Thanks again for your interest and responses.