dialogs: showAndAndGetOk() for notifiyng when focus is settled after the show

This commit is contained in:
Kirill Kalishev
2010-01-28 13:22:29 +03:00
parent 4f581c7735
commit 0e5cd44be6
4 changed files with 35 additions and 7 deletions
@@ -23,6 +23,7 @@ import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.help.HelpManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.StackingPopupDispatcher;
import com.intellij.openapi.util.AsyncResult;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.util.SystemInfo;
@@ -940,6 +941,12 @@ public abstract class DialogWrapper {
* @throws IllegalStateException if the dialog is invoked not on the event dispatch thread
*/
public void show() {
showAndGetOk();
}
public AsyncResult<Boolean> showAndGetOk() {
final AsyncResult<Boolean> result = new AsyncResult<Boolean>();
ensureEventDispatchThread();
registerKeyboardShortcuts();
@@ -949,7 +956,13 @@ public abstract class DialogWrapper {
Disposer.register(uiParent, myDisposable); // ensure everything is disposed on app quit
}
myPeer.show();
myPeer.show().doWhenProcessed(new Runnable() {
public void run() {
result.setDone(isOK());
}
});
return result;
}
/**
@@ -15,6 +15,7 @@
*/
package com.intellij.openapi.ui;
import com.intellij.openapi.util.ActionCallback;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
@@ -138,7 +139,7 @@ public abstract class DialogWrapperPeer {
*/
public abstract void setLocation(int x, int y);
public abstract void show();
public abstract ActionCallback show();
public abstract void setContentPane(JComponent content);
@@ -348,7 +348,9 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer implements FocusTra
myDialog.setLocation(x, y);
}
public void show() {
public ActionCallback show() {
final ActionCallback result = new ActionCallback();
LOG.assertTrue(EventQueue.isDispatchThread(), "Access is allowed from event dispatch thread only");
final AnCancelAction anCancelAction = new AnCancelAction();
@@ -397,7 +399,15 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer implements FocusTra
LaterInvocator.leaveModal(myDialog);
}
}
myDialog.getFocusManager().doWhenFocusSettlesDown(new Runnable() {
public void run() {
result.setDone();
}
});
}
return result;
}
//[kirillk] for now it only deals with the TaskWindow under Mac OS X: modal dialogs are shown behind JBPopup
@@ -674,15 +684,16 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer implements FocusTra
@Deprecated
public void hide() {
super.hide();
if (myFocusTrackback != null) {
if (myFocusTrackback != null && !(myFocusTrackback.isSheduledForRestore() || myFocusTrackback.isWillBeSheduledForRestore())) {
myFocusTrackback.setWillBeSheduledForRestore();
IdeFocusManager mgr = getFocusManager();
mgr.doWhenFocusSettlesDown(new Runnable() {
Runnable r = new Runnable() {
public void run() {
myFocusTrackback.restoreFocus();
myFocusTrackback = null;
}
});
};
mgr.doWhenFocusSettlesDown(r);
}
}
@@ -29,6 +29,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.DialogWrapperDialog;
import com.intellij.openapi.ui.DialogWrapperPeer;
import com.intellij.openapi.util.ActionCallback;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.wm.IdeFrame;
@@ -275,12 +276,14 @@ public class GlassPaneDialogWrapperPeer extends DialogWrapperPeer implements Foc
myDialog.setLocation(_x, _y);
}
public void show() {
public ActionCallback show() {
LOG.assertTrue(EventQueue.isDispatchThread(), "Access is allowed from event dispatch thread only");
hidePopupsIfNeeded();
myDialog.setVisible(true);
return new ActionCallback.Done();
}
public void setContentPane(final JComponent content) {