IDEA-142728 Slow actions update

This commit is contained in:
Vassiliy.Kudryashov
2015-07-16 23:28:38 +03:00
parent 83e6930772
commit 3ceb953657
4 changed files with 35 additions and 33 deletions
@@ -42,7 +42,7 @@ public interface ApplicationActivationListener {
* The shortcoming of the method is that a notification is delivered
* with a delay. See {code app.deactivation.timeout} key in the registry
*/
void delayedApplicationDeactivated(IdeFrame ideFrame);
void applicationDeactivating(IdeFrame ideFrame);
abstract class Adapter implements ApplicationActivationListener {
@Override
@@ -52,6 +52,6 @@ public interface ApplicationActivationListener {
public void applicationDeactivated(IdeFrame ideFrame) { }
@Override
public void delayedApplicationDeactivated(IdeFrame ideFrame) { }
public void applicationDeactivating(IdeFrame ideFrame) { }
}
}
@@ -812,32 +812,30 @@ public class IdeEventQueue extends EventQueue {
//if () {
// getPopupManager().closeAllPopups();
//}
appImpl.myCancelDeactivation = true;
if (!appImpl.isActive()) {
appImpl.tryToApplyActivationState(eventWindow, true, false);
}
appImpl.tryToApplyActivationState(eventWindow, true, true);
}
else if (we.getID() == WindowEvent.WINDOW_DEACTIVATED) {
requestToDeactivateTime.getAndSet(System.currentTimeMillis());
// For stuff that cannot wait we notify about deactivation immediately
appImpl.tryToApplyActivationState(eventWindow, false, true);
// For stuff that cannot wait we notify about upcoming deactivation
appImpl.tryToApplyActivationState(eventWindow, false, false);
// We do not know for sure that application is going to be inactive,
// we could just be showing a popup or another transient window.
// So let's postpone the application deactivation for a while
appImpl.myCancelDeactivation = false;
if (appImpl.isActive() && !appImpl.isDeactivating()) {
Timer timer = new Timer(Registry.intValue("app.deactivation.timeout"), new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (appImpl.isActiveDelayed() && !appImpl.isDeactivationCanceled()) {
appImpl.tryToApplyActivationState(eventWindow, false, false);
Timer timer = new Timer(Registry.intValue("app.deactivation.timeout"), new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (!appImpl.isDeactivationCancelled()) {
appImpl.tryToApplyActivationState(eventWindow, false, true);
}
}
}
});
});
timer.setRepeats(false);
timer.start();
timer.setRepeats(false);
timer.start();
}
}
if (we.getID() == WindowEvent.WINDOW_DEACTIVATED || we.getID() == WindowEvent.WINDOW_LOST_FOCUS) {
@@ -125,15 +125,15 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App
private boolean myLoaded;
private static final String WAS_EVER_SHOWN = "was.ever.shown";
private volatile boolean myActive;
private volatile boolean myActiveDelayed;
public volatile boolean myCancelDeactivation;
private volatile Boolean myActive;
private volatile boolean myDeactivating;
public volatile boolean myDeactivationCancelled;
private static final int IS_EDT_FLAG = 1<<30; // we don't mess with sign bit since we want to do arithmetic
private static final int IS_READ_LOCK_ACQUIRED_FLAG = 1<<29;
public boolean isActiveDelayed() {
return myActiveDelayed;
public boolean isDeactivating() {
return myDeactivating;
}
private static class Status {
@@ -1177,8 +1177,8 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App
return true;
}
public boolean isDeactivationCanceled() {
return myCancelDeactivation;
public boolean isDeactivationCancelled() {
return myDeactivationCancelled;
}
/**
@@ -1199,13 +1199,14 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App
public boolean tryToApplyActivationState(Window window, boolean activation, boolean immediate) {
return activation ? applyActivation(window) :
immediate ? applyDeactivation(window)
: applyDelayedDeactivation(window);
: applyDeactivating(window);
}
private boolean applyActivation(Window window) {
if (!isActive()) {
myDeactivationCancelled = true;
myActive = true;
myActiveDelayed = true;
myDeactivating = false;
IdeFrame ideFrame = getIdeFrameFromWindow(window);
if (ideFrame != null) {
getMessageBus().syncPublisher(ApplicationActivationListener.TOPIC).applicationActivated(ideFrame);
@@ -1226,12 +1227,13 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App
return false;
}
private boolean applyDelayedDeactivation(Window window) {
if (isActiveDelayed()) {
myActiveDelayed = false;
private boolean applyDeactivating(Window window) {
if (isActive() && !myDeactivating) {
myDeactivationCancelled = false;
myDeactivating = true;
IdeFrame ideFrame = getIdeFrameFromWindow(window);
if (ideFrame != null) {
getMessageBus().syncPublisher(ApplicationActivationListener.TOPIC).delayedApplicationDeactivated(ideFrame);
getMessageBus().syncPublisher(ApplicationActivationListener.TOPIC).applicationDeactivating(ideFrame);
return true;
}
}
@@ -1246,8 +1248,10 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App
@Override
public boolean isActive() {
if (isUnitTestMode()) return true;
return KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow() != null || myActive;
if (myActive == null) {//Here we get initial state that's been unknown before
myActive = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow() != null;
}
return myActive;
}
@NotNull
@@ -1085,7 +1085,7 @@ public class FocusManagerImpl extends IdeFocusManager implements Disposable {
}
@Override
public void delayedApplicationDeactivated(IdeFrame ideFrame) {
public void applicationDeactivating(IdeFrame ideFrame) {
final Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
Component parent = UIUtil.findUltimateParent(owner);