how to add items to pop-up menu

ScaleRichView support and discussion (TRichView add-on for WYSIWYG editing)
Post Reply
toolwiz
Posts: 150
Joined: Wed Nov 30, 2005 3:27 am

how to add items to pop-up menu

Post by toolwiz »

I asked this earlier but I don't think it was answered completely.

In the Actions Demo, you can right-click on the SRV area and a context menu appears. It's generated by the action framework. I'm not sure if it's one of the popup menus on the form, or if it's generated dynamically.

I added some buttons to the toolbar and created actions for them.

How can I get one of them to appear in the right-click menu? (I don't know where the popup is generated, so I don't know which OnPopup method to hook into.)

Thx
-David
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

You cannot add items in TRVAPopupMenu at designtime, you must do it at runtime, in code.

This menu is recreated (existing items are deleted, new items are added) every time before displaying.

First, the default menu items are added. Next, TRVAPopupMenu.OnPopup event occurs.
You can add new items in TRVAPopupMenu.OnPopup event.
toolwiz
Posts: 150
Joined: Wed Nov 30, 2005 3:27 am

Post by toolwiz »

We're going in circles here. I know how to use the OnPopup event. I assume it needs to be done at run-time. I'm just not sure which one to hook into. There are two popups on the Actions Demo form, but from what I can tell, neither one of them is the one that's used when you right-click on the SRV edit box. How do I find the one that IS used and hook into it without disabling it? It seems to be getting created dynamically. Where?

Thanks
-David
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

There is only one TRVAPopup menu in this demo (RVAPopupMenu1), and it is assinged to SRichViewEdit1.PopupMenu property. Use it.
For example, this code adds "Background..." command as the last item:

Code: Select all

procedure TForm3.RVAPopupMenu1Popup(Sender: TObject);
var mi: TMenuItem;
begin
  mi := TMenuItem.Create(RVAPopupMenu1);
  mi.Action := rvActionsResource.rvActionBackground1;
  RVAPopupMenu1.Items.Add(mi);
end;
The second popup menu in this demo (pmFakeDropDown) is assigned to DropDownMenu property of combo-toolbutton for table insertion. This menu is empty and never displayed, but its OnPopup event is used to display a table-size window.
toolwiz
Posts: 150
Joined: Wed Nov 30, 2005 3:27 am

Post by toolwiz »

Great! Thank you very much!

-David
futuremode
Posts: 14
Joined: Tue Jan 11, 2011 7:38 pm

How to implement additions to popup menu at runtime

Post by futuremode »

I am a newbie and was having trouble implementing the addition of actions to the popup menu so they appeared at runtime. Where do I install it in the app.
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Do you want to add action in TPopupMenu or in TRVAPopupMenu?
futuremode
Posts: 14
Joined: Tue Jan 11, 2011 7:38 pm

To TRVAPopupMenu

Post by futuremode »

Sergey Tkachenko wrote:Do you want to add action in TPopupMenu or in TRVAPopupMenu?
To TRVAPopupMenu. I have created an action and applied it to the main menu and a tool button but am having trouble with the right click popup menu in RichViewEdit1 of your demo Rich View Actions app.

I want users to right mouse click which opens up a list so they select data merge tags and drop them into the RichViewEdit1 doc. The main menu item and button are working fine.
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Please read this topic from the beginning.
It explains how to add items in TRVAPopupMenu.

Briefly: you cannot do it at designtime because TRVAPopupMenu clears all items before displaying, and then it recreates itself.
To add your item in this menu, use OnPopup event. The example is above in this topic.
futuremode
Posts: 14
Joined: Tue Jan 11, 2011 7:38 pm

Thanks Sergey

Post by futuremode »

I have only been programming with Delphi for around six months so it is a steep learning curve for me. I have it all working now.
Post Reply