Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use TAction shortcuts only when apt 1

Status
Not open for further replies.

donvittorio

Programmer
Jul 17, 2003
122
GB
Hi, I'll try and keep the description of my problem short.
I have a program with two TStringGrids, one a parent and one a child, both of which allow editing.
I have written some functionality in the program which allows you to copy and paste parent items, which is assigned to TAction.OnExecute events (one for copy and one for paste, of course), and the actions are assigned to TMenuItems in a TMainMenu and a TPopupMenu.
I would like to allow the user to use CTRL+C and CTRL+V to call these events, but if I assign these as the shortcuts of the TActions then CTRL+C/CTRL+v will always call these events, regardless of what the user is doing. For example this would remove the ability to use CTRL+C/CTRL+V to copy and paste text when editing cells of the grid. So I would like to call them only if the parent grid has focus and is not in EditorMode.
I hope that made sense, an example of similar behaviour is in Windows Explorer, if file is highlighted and you press CTRL+C then you copy the file, but if the file is being renamed then you copy the text in the filename instead.
I can't figure out a way of doing this, does anybody have any ideas?

Thanks in advance

Steve
 
yep, in the TAction.OnExecute I could check whether I should execute my new copy and paste functionality. But if I shouldn't (e.g. if the grid is being edited) then how do I pass the message on to Delphi/Windows to invoke the standard copy and paste functionality (e.g. to copy the highlighted text).
This is the problem that I have, by assigning CTRL+C and CTRL+V shortcuts to my actions I would remove the usual copy and paste functionality that a user would expect (sorry, I didn't make that clear in my original post).

Steve
 
something like this (psuedo code)

Code:
var msg : tmessage;
...
case action of 
 AcCopy: mes.msg := wm_copy;
 AcCut:  mes.msg := wm_cut;
 AcPast: mes.msg := wm_paste;
 AcUndo: mes.msg := wm_undo;
end;
screen.activecontrol.dispatch(mes);
...


-----------------------------------------------------
 What You See Is What You Get
Never underestimate tha powah of tha google!
 
whosrdaddy, thanks for your solution, that's pretty much exactly what I wanted to do. Easy when you know how isn't it?
Actually it isn't quite that straightforward, because to copy and paste text in a TStringGrid you have to send the message to the InplaceEditor rather than the grid itself, and to make it even more awkward the InplaceEditor is protected. Where there's a will there's a way though, and I've got it working now.

Thanks again

Steve
 
Glad you sorted it out Steve!

Cheers,
Daddy



[thumbsup2]

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top