norgepaul / TChromeTabs

Comprehensive Delphi implementation of Chrome's tab system
Other
218 stars 78 forks source link

HideCloseButton causes OnButtonCloseTabClick to not fire #39

Closed djjd47130 closed 8 years ago

djjd47130 commented 8 years ago

I have a home tab which is to remain open at all times, pinned. Under no circumstances is the user allowed to close this tab. So I've enabled HideCloseButton on this tab, and it's also pinned.

I also implement the OnButtonCloseTabClick event to perform my own handling. Within here, I'm explicitly telling it not to allow deleting this particular tab. However, as long as HideCloseButton is enabled, and the user right-clicks the tab and chooses "Delete Tab", this event never gets fired, and thus the tab gets deleted anyway. I'd like to keep the original right-click menu, but this event needs to respond regardless of this HideCloseButton property. The result of this also causes a memory leak when using the tab control for managing these instances - since I don't have a chance to free it.

I would expect such an event to be for example OnTabDeleting which is guaranteed to always be triggered in the event of a tab being closed for any reason - even if calling in code Tabs.Delete(1); or even clearing the tabs - which would allow me to both specify whether it's allowed to close, and free any contained data.

norgepaul commented 8 years ago

I've added a new OnTabPopupMenu event. This allows you to remove the delete tab menu item for specific tabs. You can use the event something like this:

procedure TfrmMain.ChromeTabs1TabPopupMenu(Sender: TObject; const PopupMenu: TPopupMenu); var i: Integer; begin for i := 0 to pred(PopupMenu.Items.Count) do begin if PopupMenu.Items[i].Tag = 2 then begin // Hide the delete menu item PopupMenu.Items[i].Visible := False;

  Break;
end;

end; end;

Hope this helps.

Cheers, Paul

djjd47130 commented 8 years ago

Thanks, that's a nifty implementation. However it would be extremely ideal to pass the TChromeTab into this event. I shouldn't have to depend on whichever tab is currently active - but I should know which one was right-clicked. After all, the component itself has its own handling of what to show in the popup menu based on what tab was right-clicked. I don't want the tab to be selected when right-clicked. The current tab needs to stay the current tab.

To clarify, the pinned "Home" tab needs to always show, not allowing deletion - while the rest of the tabs are free to be deleted.

djjd47130 commented 8 years ago

I think the appropriate solution is to make sure OnButtonCloseTabClick is triggered regardless of whether HideCloseButton is enabled or not.

norgepaul commented 8 years ago

Hi,

Thanks, that's a nifty implementation. However it would be extremely ideal to pass the TChromeTab into this event. I shouldn't have to depend on whichever tab is currently active - but I should know which one was right-clicked.

I've added the ChromeTab reference to the event.

I think the appropriate solution is to make sure OnButtonCloseTabClick is triggered regardless of whether HideCloseButton is enabled or not.

As the event name suggests, OnButtonCloseTab fires when the button is clicked, not when the tab closes. Changing this event would break a behaviour that manhy people already rely on.

It should be possible to add an OnDeleteTab event, but the internal logic is a little complex and I don't think I have time right now to implement it.

/Paul

— Reply to this email directly or view it on GitHub https://github.com/norgepaul/TChromeTabs/issues/39#issuecomment-157581635 .

djjd47130 commented 8 years ago

Thank you. Just gave it a try, and ATab is coming in as nil.

norgepaul commented 8 years ago

Hi Jerry,

Thank you. Just gave it a try, and ATab is coming in as nil.

Fixed and updated.

/Paul