SOLVED (mostly): Right click to cut, copy, & paste
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
SOLVED (mostly): Right click to cut, copy, & paste
Is there a really simple, easy way to get fields in LC to support right clicking to (get a context menu for) cut, copy, & paste? I've been doing some searches trying to find something and I'm striking out.
EDIT: Some day, I will learn to keep searching for another few minutes before posting asking for help. Found this post and I'm on my way to getting that right click, context menu that I want.
Well, except, for one thing. How do you enable/disable items in the popup menu button? LIke, how do you make "Cut" greyed out and disabled if no text is highlighted?
EDIT: Some day, I will learn to keep searching for another few minutes before posting asking for help. Found this post and I'm on my way to getting that right click, context menu that I want.
Well, except, for one thing. How do you enable/disable items in the popup menu button? LIke, how do you make "Cut" greyed out and disabled if no text is highlighted?
Re: SOLVED (mostly): Right click to cut, copy, & paste
Hi tetsuo
would using "if..then" be what you are looking for ?
there is several steps to do this, maybe you can :
...showing what step is missing to it still...
see this step for instance :
https://livecode.fandom.com/wiki/Disabled
would using "if..then" be what you are looking for ?
there is several steps to do this, maybe you can :
Code: Select all
copy your code here
...showing what step is missing to it still...
see this step for instance :
https://livecode.fandom.com/wiki/Disabled
Re: SOLVED (mostly): Right click to cut, copy, & paste
What I was looking for was:
I just didn't realize that buttons would have menu items. It's a little counterintuitive.
And of course, I want to use some conditional, if/then statements. I now need to figure out the easiest way to determine if text is highlighted in a field.
Also, when I right click in the field, whatever is currently highlighted gets unselected. Do you know how I prevent that? That's not very useful if I want the user to be able to highlight text, then right click and choose, cut or copy from a popup menu.
Code: Select all
disable menuItem itemNumber of button
And of course, I want to use some conditional, if/then statements. I now need to figure out the easiest way to determine if text is highlighted in a field.
Also, when I right click in the field, whatever is currently highlighted gets unselected. Do you know how I prevent that? That's not very useful if I want the user to be able to highlight text, then right click and choose, cut or copy from a popup menu.
Re: SOLVED (mostly): Right click to cut, copy, & paste
I havent worked on the main GUI so far - just a bit on the Datagrid styling - if you start sharing your code here, it will be easier to help in a specific way...else, its too vague. I know there are focus features, so, verifying the property of a component, line or button "in focus"... you can then apply "if then" conditional actions. Have you downloaded some "samples stack" from the menu, there are plenty to learn from and probably one doing what you are looking for
Re: SOLVED (mostly): Right click to cut, copy, & paste
So, here's what I have so far.
I created a popup menu called "PopUp Menu Text Field". This is the code I have placed in it:
In my text field, I have placed the following code to respond to right mouse clicks:
In my popup menu:
menuItem 1 = cut
menuItem 2 = copy
menuItem 3 = paste
menuItem 4 = select all
Everything is working great but, if you look back at the code that I've placed in the popup menu, you may notice that it specifically pastes and selects all to the "FiledTitles" field. I'd like to figure out how to generalize it so that it determine which text field was right clicked in and respond appropriately.
I created a popup menu called "PopUp Menu Text Field". This is the code I have placed in it:
Code: Select all
on menuPick pItem
switch pItem
case "Cut"
cut
break
case "Copy"
copy
break
case "Paste"
send pasteKey to field "FieldTitles"
break
case "Select All"
select text of field "FieldTitles"
break
end switch
end menuPick
Code: Select all
on mouseUp pMouseButton
if pMouseButton = 3 then
-- disable menuItem 1 of button "PopUp Menu Text Field"
set the traversalOn of button "PopUp Menu Text Field" to false
if text of me = "" 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"
else
enable menuItem 4 of button "PopUp Menu Text Field"
if the selectedText of me = "" then
disable menuItem 1 of button "PopUp Menu Text Field"
disable menuItem 2 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"
end if
end if
popup button "PopUp Menu Text Field" at the clickLoc
else
-- do other stuff here
end if
end mouseUp
menuItem 1 = cut
menuItem 2 = copy
menuItem 3 = paste
menuItem 4 = select all
Everything is working great but, if you look back at the code that I've placed in the popup menu, you may notice that it specifically pastes and selects all to the "FiledTitles" field. I'd like to figure out how to generalize it so that it determine which text field was right clicked in and respond appropriately.
Re: SOLVED (mostly): Right click to cut, copy, & paste
ok, checking 2 points first...
1) when you refer to
2) Does your stack only include just a single Source .. FieldTitle...to copy/paste to... just 1 single Target Textfield ?
(Or are there several source and several possible Targets ?...many TextField/s)
PS: and "Pastkey"...
just a variable containing the text to be pasted, right ?
1) when you refer to
jus to confirm...what "field name" are you referring to above ?In my text field, I have placed the following code
2) Does your stack only include just a single Source .. FieldTitle...to copy/paste to... just 1 single Target Textfield ?
(Or are there several source and several possible Targets ?...many TextField/s)
PS: and "Pastkey"...
just a variable containing the text to be pasted, right ?
Re: SOLVED (mostly): Right click to cut, copy, & paste
Sorry tetsuo, I felt confuse about how you expect things to work between all fields...although you explained it quite well, so
I decided to go on creating this stack "inspired by" your code...more so...
differences :
- Here, I only use the popup button to do copy/pasting stuff...(no right clic in Cell stuff)
Action ;
It will totally deactivate action-menus - only - if the Source field is empty...
(you can eventually change that in the Source Field Script.)
- The popup script is hidden in the "STACK/EDIT" path...
for the rest, just play with it and it ll show what it is doing each time... *see Zip file
I Hope that it will be of some help for you to prepare zee pizza in the way you like it best !
I decided to go on creating this stack "inspired by" your code...more so...
differences :
- Here, I only use the popup button to do copy/pasting stuff...(no right clic in Cell stuff)
Action ;
It will totally deactivate action-menus - only - if the Source field is empty...
(you can eventually change that in the Source Field Script.)
- The popup script is hidden in the "STACK/EDIT" path...
for the rest, just play with it and it ll show what it is doing each time... *see Zip file
I Hope that it will be of some help for you to prepare zee pizza in the way you like it best !
Re: SOLVED (mostly): Right click to cut, copy, & paste
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:
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:
My code in my popup menu now uses the global "gTextFieldClicked" variable to respond appropriately depending on which text field was right clicked:
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.
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
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
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
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.
Re: SOLVED (mostly): Right click to cut, copy, & paste
something similar was happening to me lastnite...
right after selecting the "cut" option, and emptying the TextField content...all 4 menu options were still left activated.
So I logicaly came to the conclusion that - right after the source field becomes empty, one needs to to force this menu to be deactivated, and that is what I did, so now, each cut process is followed by a deactivation process...
since in the stack I shared - pressing the popup, was not enough to do that by itself at first
...maybe you can add some extra code and "force it to do what you want" in place of having to "left click outside" of the popup to reach the same result
right after selecting the "cut" option, and emptying the TextField content...all 4 menu options were still left activated.
So I logicaly came to the conclusion that - right after the source field becomes empty, one needs to to force this menu to be deactivated, and that is what I did, so now, each cut process is followed by a deactivation process...
since in the stack I shared - pressing the popup, was not enough to do that by itself at first
...maybe you can add some extra code and "force it to do what you want" in place of having to "left click outside" of the popup to reach the same result