FastInv icon indicating copy to clipboard operation
FastInv copied to clipboard

Added clear and remove methods for handlers

Open Tigerpanzer02 opened this issue 2 years ago • 4 comments

In my case it was useful to have a clearCloseHandler (having a default close handler which gets removed after something in gui got accepeted). I just added it for the other handlers in this pr, too. Just in case someone else needs it.

[A different way would be to make the handlers list public / accesable]

Tigerpanzer02 avatar Aug 15 '23 13:08 Tigerpanzer02

Hi, wouldn't be easier to add a condition in the [close/click/open] handler to "remove" it when it's not needed ? Like in the example in the README

MrMicky-FR avatar Aug 15 '23 14:08 MrMicky-FR

Can you Show me the Part on the readme, I cant find.

Tigerpanzer02 avatar Aug 15 '23 20:08 Tigerpanzer02

My bad it’s not directly in the README, but for example you can do this:

boolean ignoreClicks = false;

inv.addClickHandler(e -> {
  if (ignoreClicks) {
    return;
  }
  
  if (someConditionThatShouldRemoveHandler) {
    ignoreClicks = true;
  }
});

MrMicky-FR avatar Aug 16 '23 06:08 MrMicky-FR

Yep thats possible but if I cold remove all added handlers with Just one Line as the inventory should Close without any Interactions it would be way easier. Also it would be possible to create multiple default handlers which I can add and remove Like I want for the inventory 😅 To make it more understanble if you do a refreshable gui out of fastinv such as paged ones or updated inventories. It will be very useful.

Tigerpanzer02 avatar Aug 16 '23 06:08 Tigerpanzer02