public static @Nullable Runnable addGlobalAction(@NotNull JComponent component, @NotNull Object actionInfo, @NotNull Runnable callback) {
    MyAnAction localAction = new MyAnAction() {
      @Override
      public void actionPerformed(@NotNull AnActionEvent e) {
        if (component.isShowing()) {
          callback.run();
        }
      }
    };

    if (actionInfo instanceof String) {
      AnAction action = ActionManager.getInstance().getAction((String)actionInfo);
      if (action == null) {
        return null;
      }
      localAction.copyShortcutFrom(action);
    }
    else if (actionInfo instanceof ShortcutSet) {
      localAction.setShortcutSet((ShortcutSet)actionInfo);
    }
    else {
      return null;
    }

    localAction.registerCustomShortcutSet(component.getRootPane(), null);

    return () -> localAction.unregisterCustomShortcutSet(component.getRootPane());
  }
public static @Nullable Runnable addGlobalAction(@NotNull JComponent component, @NotNull Object actionInfo, @NotNull Runnable callback)