DataManager.getDataContextFromFocus() introduced, the old one -- deprectated
authorKirill Kalishev <kirill.kalishev@jetbrains.com>
Mon, 26 Apr 2010 11:07:04 +0000 (15:07 +0400)
committerKirill Kalishev <kirill.kalishev@jetbrains.com>
Mon, 26 Apr 2010 11:08:47 +0000 (15:08 +0400)
platform/platform-api/src/com/intellij/ide/DataManager.java
platform/platform-impl/src/com/intellij/ide/impl/DataManagerImpl.java

index 021f993e24b885dd7807c12fbe6fdb6ca548ec8b..7b49b2d854269976918fab650304ce44c12bcb05 100644 (file)
@@ -17,6 +17,7 @@ package com.intellij.ide;
 
 import com.intellij.openapi.actionSystem.DataContext;
 import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.util.AsyncResult;
 import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.NotNull;
 
@@ -31,9 +32,12 @@ public abstract class DataManager {
 
   /**
    * @return {@link DataContext} constructed by the current focused component
+   * @deprecated use either {@link #getDataContext(java.awt.Component)} or {@link #getDataContextFromFocus())
    */
   public abstract DataContext getDataContext();
 
+  public abstract AsyncResult<DataContext> getDataContextFromFocus();
+
   /**
    * @return {@link DataContext} constructed by the specified <code>component</code>
    */
index 649f6708c328137f6a5e0bb956b19a0dfa97f7ed..7d55ebd986c0ebc98dc99cec15be8d74b30ed09d 100644 (file)
@@ -26,6 +26,7 @@ import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.extensions.Extensions;
 import com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher;
 import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.AsyncResult;
 import com.intellij.openapi.util.registry.Registry;
 import com.intellij.openapi.wm.IdeFocusManager;
 import com.intellij.openapi.wm.ex.WindowManagerEx;
@@ -199,6 +200,19 @@ public class DataManagerImpl extends DataManager implements ApplicationComponent
     return getDataContext(getFocusedComponent());
   }
 
+  @Override
+  public AsyncResult<DataContext> getDataContextFromFocus() {
+    final AsyncResult<DataContext> context = new AsyncResult<DataContext>();
+
+    IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(new Runnable() {
+      public void run() {
+        context.setDone(getDataContext());
+      }
+    });
+
+    return context;
+  }
+
   public DataContext getDataContextTest(Component component) {
     DataContext dataContext = getDataContext(component);
     if (myWindowManager == null) {