IDEA-142305 Changes to files are not saved on frame deactivation
authorVassiliy.Kudryashov <Vassiliy.Kudryashov@jetbrains.com>
Tue, 21 Jul 2015 09:49:03 +0000 (12:49 +0300)
committerVassiliy.Kudryashov <Vassiliy.Kudryashov@jetbrains.com>
Tue, 21 Jul 2015 09:51:13 +0000 (12:51 +0300)
(revert of IDEA-142728 Slow actions update)

platform/platform-api/src/com/intellij/openapi/application/ApplicationActivationListener.java
platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java
platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java
platform/platform-impl/src/com/intellij/openapi/wm/impl/FocusManagerImpl.java

index 5d7cb9d..5ad5f6e 100644 (file)
@@ -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 applicationDeactivating(IdeFrame ideFrame);
+  void delayedApplicationDeactivated(IdeFrame ideFrame);
 
   abstract class Adapter implements ApplicationActivationListener {
     @Override
@@ -52,6 +52,6 @@ public interface ApplicationActivationListener {
     public void applicationDeactivated(IdeFrame ideFrame) { }
 
     @Override
-    public void applicationDeactivating(IdeFrame ideFrame) { }
+    public void delayedApplicationDeactivated(IdeFrame ideFrame) { }
   }
 }
index b8ac9c2..38b4efc 100644 (file)
@@ -812,30 +812,32 @@ public class IdeEventQueue extends EventQueue {
         //if () {
         //  getPopupManager().closeAllPopups();
         //}
-        appImpl.tryToApplyActivationState(eventWindow, true, true);
+        appImpl.myCancelDeactivation = true;
+        if (!appImpl.isActive()) {
+          appImpl.tryToApplyActivationState(eventWindow, true, false);
+        }
       }
       else if (we.getID() == WindowEvent.WINDOW_DEACTIVATED) {
         requestToDeactivateTime.getAndSet(System.currentTimeMillis());
 
-        // For stuff that cannot wait we notify about upcoming deactivation
-        appImpl.tryToApplyActivationState(eventWindow, false, false);
+        // For stuff that cannot wait we notify about deactivation immediately
+        appImpl.tryToApplyActivationState(eventWindow, false, true);
 
         // 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
-        if (appImpl.isActive() && !appImpl.isDeactivating()) {
+        appImpl.myCancelDeactivation = 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 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.setRepeats(false);
-          timer.start();
-        }
+        timer.setRepeats(false);
+        timer.start();
       }
 
       if (we.getID() == WindowEvent.WINDOW_DEACTIVATED || we.getID() == WindowEvent.WINDOW_LOST_FOCUS) {
index 6791904..04dc2c0 100644 (file)
@@ -128,15 +128,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 myDeactivating;
-  public volatile boolean myDeactivationCancelled;
+  private volatile boolean myActive;
+  private volatile boolean myActiveDelayed;
+  public volatile boolean myCancelDeactivation;
 
   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 isDeactivating() {
-    return myDeactivating;
+  public boolean isActiveDelayed() {
+    return myActiveDelayed;
   }
 
   private static class Status {
@@ -1189,8 +1189,8 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App
     return true;
   }
 
-  public boolean isDeactivationCancelled() {
-    return myDeactivationCancelled;
+  public boolean isDeactivationCanceled() {
+    return myCancelDeactivation;
   }
 
   /**
@@ -1211,14 +1211,13 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App
   public boolean tryToApplyActivationState(Window window, boolean activation, boolean immediate) {
     return activation ? applyActivation(window) :
            immediate ? applyDeactivation(window)
-                     : applyDeactivating(window);
+                     : applyDelayedDeactivation(window);
   }
 
   private boolean applyActivation(Window window) {
     if (!isActive()) {
-      myDeactivationCancelled = true;
       myActive = true;
-      myDeactivating = false;
+      myActiveDelayed = true;
       IdeFrame ideFrame = getIdeFrameFromWindow(window);
       if (ideFrame != null) {
         getMessageBus().syncPublisher(ApplicationActivationListener.TOPIC).applicationActivated(ideFrame);
@@ -1239,13 +1238,12 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App
     return false;
   }
 
-  private boolean applyDeactivating(Window window) {
-    if (isActive() && !myDeactivating) {
-      myDeactivationCancelled = false;
-      myDeactivating = true;
+  private boolean applyDelayedDeactivation(Window window) {
+    if (isActiveDelayed()) {
+      myActiveDelayed = false;
       IdeFrame ideFrame = getIdeFrameFromWindow(window);
       if (ideFrame != null) {
-        getMessageBus().syncPublisher(ApplicationActivationListener.TOPIC).applicationDeactivating(ideFrame);
+        getMessageBus().syncPublisher(ApplicationActivationListener.TOPIC).delayedApplicationDeactivated(ideFrame);
         return true;
       }
     }
@@ -1260,10 +1258,8 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App
   @Override
   public boolean isActive() {
    if (isUnitTestMode()) return true;
-    if (myActive == null) {//Here we get initial state that's been unknown before
-      myActive = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow() != null;
-    }
-   return myActive;
+
+   return KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow() != null || myActive;
   }
 
   @NotNull
index 0bd7e31..3e50443 100644 (file)
@@ -1085,7 +1085,7 @@ public class FocusManagerImpl extends IdeFocusManager implements Disposable {
     }
 
     @Override
-    public void applicationDeactivating(IdeFrame ideFrame) {
+    public void delayedApplicationDeactivated(IdeFrame ideFrame) {
         final Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
         Component parent = UIUtil.findUltimateParent(owner);