public static InputEvent getInputEvent(String actionName) {
    final Shortcut[] shortcuts =
        KeymapManager.getInstance().getActiveKeymap().getShortcuts(actionName);
    KeyStroke keyStroke = null;
    for (Shortcut each : shortcuts) {
      if (each instanceof KeyboardShortcut) {
        keyStroke = ((KeyboardShortcut) each).getFirstKeyStroke();
        if (keyStroke != null) break;
      }
    }

    if (keyStroke != null) {
      return new KeyEvent(
          JOptionPane.getRootFrame(),
          KeyEvent.KEY_PRESSED,
          System.currentTimeMillis(),
          keyStroke.getModifiers(),
          keyStroke.getKeyCode(),
          keyStroke.getKeyChar(),
          KeyEvent.KEY_LOCATION_STANDARD);
    } else {
      return new MouseEvent(
          JOptionPane.getRootFrame(),
          MouseEvent.MOUSE_PRESSED,
          0,
          0,
          0,
          0,
          1,
          false,
          MouseEvent.BUTTON1);
    }
  }
Example #2
0
  protected DialogWrapperPeerImpl(
      @NotNull DialogWrapper wrapper,
      @Nullable Project project,
      boolean canBeParent,
      @NotNull DialogWrapper.IdeModalityType ideModalityType) {
    myWrapper = wrapper;
    myTypeAheadCallback = myWrapper.isTypeAheadEnabled() ? new ActionCallback() : null;
    myWindowManager = null;
    Application application = ApplicationManager.getApplication();
    if (application != null && application.hasComponent(WindowManager.class)) {
      myWindowManager = (WindowManagerEx) WindowManager.getInstance();
    }

    Window window = null;
    if (myWindowManager != null) {

      if (project == null) {
        //noinspection deprecation
        project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext());
      }

      myProject = project;

      window = myWindowManager.suggestParentWindow(project);
      if (window == null) {
        Window focusedWindow = myWindowManager.getMostRecentFocusedWindow();
        if (focusedWindow instanceof IdeFrameImpl) {
          window = focusedWindow;
        }
      }
      if (window == null) {
        IdeFrame[] frames = myWindowManager.getAllProjectFrames();
        for (IdeFrame frame : frames) {
          if (frame instanceof IdeFrameImpl && ((IdeFrameImpl) frame).isActive()) {
            window = (IdeFrameImpl) frame;
            break;
          }
        }
      }
    }

    Window owner;
    if (window != null) {
      owner = window;
    } else {
      if (!isHeadless()) {
        owner = JOptionPane.getRootFrame();
      } else {
        owner = null;
      }
    }

    createDialog(owner, canBeParent, ideModalityType);
  }
Example #3
0
  /**
   * @param parent parent component which is used to calculate heavy weight window ancestor. <code>
   *     parent</code> cannot be <code>null</code> and must be showing.
   */
  protected DialogWrapperPeerImpl(
      @NotNull DialogWrapper wrapper, @NotNull Component parent, boolean canBeParent) {
    myWrapper = wrapper;
    if (!parent.isShowing() && parent != JOptionPane.getRootFrame()) {
      throw new IllegalArgumentException("parent must be showing: " + parent);
    }
    myWindowManager = null;
    Application application = ApplicationManager.getApplication();
    if (application != null && application.hasComponent(WindowManager.class)) {
      myWindowManager = (WindowManagerEx) WindowManager.getInstance();
    }

    Window owner =
        parent instanceof Window
            ? (Window) parent
            : (Window) SwingUtilities.getAncestorOfClass(Window.class, parent);
    if (!(owner instanceof Dialog) && !(owner instanceof Frame)) {
      owner = JOptionPane.getRootFrame();
    }
    createDialog(owner, canBeParent);
  }