Search in sources :

Example 1 with FocusTrackback

use of com.intellij.ui.FocusTrackback in project intellij-community by JetBrains.

the class FrameWrapper method show.

public void show(boolean restoreBounds) {
    myFocusedCallback = new ActionCallback();
    if (myProject != null) {
        IdeFocusManager.getInstance(myProject).typeAheadUntil(myFocusedCallback);
    }
    final Window frame = getFrame();
    if (myStatusBar != null) {
        myStatusBar.install((IdeFrame) frame);
    }
    myFocusTrackback = new FocusTrackback(this, IdeFocusManager.findInstance().getFocusOwner(), true);
    if (frame instanceof JFrame) {
        ((JFrame) frame).setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    } else {
        ((JDialog) frame).setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    }
    final WindowAdapter focusListener = new WindowAdapter() {

        public void windowOpened(WindowEvent e) {
            IdeFocusManager fm = IdeFocusManager.getInstance(myProject);
            JComponent toFocus = getPreferredFocusedComponent();
            if (toFocus == null) {
                toFocus = fm.getFocusTargetFor(myComponent);
            }
            if (toFocus != null) {
                fm.requestFocus(toFocus, true).notify(myFocusedCallback);
            } else {
                myFocusedCallback.setRejected();
            }
        }
    };
    frame.addWindowListener(focusListener);
    if (Registry.is("ide.perProjectModality")) {
        frame.setAlwaysOnTop(true);
    }
    Disposer.register(this, new Disposable() {

        @Override
        public void dispose() {
            frame.removeWindowListener(focusListener);
        }
    });
    if (myCloseOnEsc)
        addCloseOnEsc((RootPaneContainer) frame);
    ((RootPaneContainer) frame).getContentPane().add(myComponent, BorderLayout.CENTER);
    if (frame instanceof JFrame) {
        ((JFrame) frame).setTitle(myTitle);
    } else {
        ((JDialog) frame).setTitle(myTitle);
    }
    if (myImageWasChanged && myImage != null) {
        // unwrap the image before setting as frame's icon
        frame.setIconImage(ImageUtil.toBufferedImage(myImage));
    } else {
        AppUIUtil.updateWindowIcon(myFrame);
    }
    if (restoreBounds) {
        loadFrameState();
    }
    myFocusWatcher = new FocusWatcher() {

        protected void focusLostImpl(final FocusEvent e) {
            myFocusTrackback.consume();
        }
    };
    myFocusWatcher.install(myComponent);
    myShown = true;
    frame.setVisible(true);
    if (UIUtil.isUnderAlloyLookAndFeel() && frame instanceof JFrame) {
        //please ask [kb] before remove it
        ((JFrame) frame).setMaximizedBounds(null);
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) ActionCallback(com.intellij.openapi.util.ActionCallback) FocusTrackback(com.intellij.ui.FocusTrackback)

Example 2 with FocusTrackback

use of com.intellij.ui.FocusTrackback in project intellij-community by JetBrains.

the class ProgressDialog method show.

void show() {
    myWasShown = true;
    if (ApplicationManager.getApplication().isHeadlessEnvironment())
        return;
    if (myParentWindow == null)
        return;
    if (myPopup != null) {
        myPopup.close(DialogWrapper.CANCEL_EXIT_CODE);
    }
    myPopup = myParentWindow.isShowing() ? new MyDialogWrapper(myParentWindow, myProgressWindow.myShouldShowCancel) : new MyDialogWrapper(myProgressWindow.myProject, myProgressWindow.myShouldShowCancel);
    myPopup.setUndecorated(true);
    if (SystemInfo.isAppleJvm) {
        // With Apple JDK we look for MacMessage parent by the window title.
        // Let's set just the title as the window title for simplicity.
        myPopup.setTitle(myProgressWindow.getTitle());
    }
    if (myPopup.getPeer() instanceof DialogWrapperPeerImpl) {
        ((DialogWrapperPeerImpl) myPopup.getPeer()).setAutoRequestFocus(false);
        if (isWriteActionProgress()) {
            // display the dialog and continue with EDT execution, don't block it forever
            myPopup.setModal(false);
        }
    }
    myPopup.pack();
    SwingUtilities.invokeLater(() -> {
        if (myPopup != null) {
            if (myPopup.getPeer() instanceof FocusTrackbackProvider) {
                final FocusTrackback focusTrackback = ((FocusTrackbackProvider) myPopup.getPeer()).getFocusTrackback();
                if (focusTrackback != null) {
                    focusTrackback.consume();
                }
            }
            myProgressWindow.getFocusManager().requestFocusInProject(myCancelButton, myProgressWindow.myProject).doWhenDone(myRepaintRunnable);
        }
    });
    myPopup.show();
}
Also used : DialogWrapperPeerImpl(com.intellij.openapi.ui.impl.DialogWrapperPeerImpl) FocusTrackback(com.intellij.ui.FocusTrackback) FocusTrackbackProvider(com.intellij.openapi.ui.impl.FocusTrackbackProvider)

Aggregations

FocusTrackback (com.intellij.ui.FocusTrackback)2 Disposable (com.intellij.openapi.Disposable)1 DialogWrapperPeerImpl (com.intellij.openapi.ui.impl.DialogWrapperPeerImpl)1 FocusTrackbackProvider (com.intellij.openapi.ui.impl.FocusTrackbackProvider)1 ActionCallback (com.intellij.openapi.util.ActionCallback)1