Jump to content

How to add popupmenu on right click on tabsheet title


delagoutte

Recommended Posts

2 hours ago, delagoutte said:

if i do a right click on the title of tabsheet i would like display a unipopupmenu.

how can i do this?

For example:

1. UniPageControl1.ClientEvents.ExtEvents ->

function boxready(sender, width, height, eOpts)
{
    var tab = sender;
    tab.getEl().on('contextmenu', function(e, target, options) {
        var totalOffsetX = target.offsetLeft + 20;
        var totalOffsetY = target.offsetTop + 20;
        ajaxRequest(tab, 'contextmenu', ['tabIndx='+tab.tabPanel.tabBar.getRefItems().findIndex(item => item.id === target.getAttribute('data-componentid')), 'x='+totalOffsetX, 'y='+totalOffsetY]);
    }, tab.getEl(), {
        preventDefault: true,
        delegate: '.x-tab'
    });
}

2. UniPageControl1.OnAjaxEvent ->

procedure TMainForm.UniPageControl1AjaxEvent(Sender: TComponent;
  EventName: string; Params: TUniStrings);
begin
  if EventName = 'contextmenu' then
  begin
    with (Sender as TUniPageControl) do
      CustomAttribs.Values['contextTab'] := Pages[Params.Values['tabIndx'].ToInteger()].Caption;

    UniPopupMenu1.Popup(Params.Values['x'].ToInteger(), Params.Values['y'].ToInteger(), Sender);
  end;
end;

3. UniPopupMenu1 -> item GetTabTitle

4. 

procedure TMainForm.GetTabTitle1Click(Sender: TObject);
begin
  ShowMessage(UniPageControl1.CustomAttribs.Values['contextTab']);
end;

image.png.4dd2afc7600783d8b9e14cac16ab7b6c.png

  • Like 1
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...