/*
 * Copyright 2000-2009 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.intellij.openapi.editor.actions;

import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.PsiFile;
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;

import javax.annotation.Nullable;

/**
 * @author Dmitry Avdeev
 */
public class ToggleShowImportPopupsAction extends ToggleAction {

  @Override
  public boolean isSelected(AnActionEvent e) {
    return getAnalyzer(e).isImportHintsEnabled(getFile(e));
  }

  @Override
  public void setSelected(AnActionEvent e, boolean state) {
    getAnalyzer(e).setImportHintsEnabled(getFile(e), state);
  }

  @Override
  public void update(AnActionEvent e) {
    if (getFile(e) == null) {
      e.getPresentation().setEnabled(false);
      e.getPresentation().setVisible(false);
    }
    else {
      e.getPresentation().setEnabled(true);
      e.getPresentation().setVisible(true);
      super.update(e);
    }
  }

  private DaemonCodeAnalyzer getAnalyzer(AnActionEvent e) {
    return DaemonCodeAnalyzer.getInstance(e.getData(CommonDataKeys.PROJECT));
  }

  @Nullable
  private static PsiFile getFile(AnActionEvent e) {
    Editor editor = e.getData(PlatformDataKeys.EDITOR);
    return editor == null ? null : e.getData(LangDataKeys.PSI_FILE);
  }
}

@@ -20,10 +20,10 @@
 0-20
-09
+14
  Jet
@@ -665,30 +665,213 @@
 lij.
-openapi.actionSystem.*
+codeInsight.daemon.DaemonCodeAnalyzer;%0Aimport com.intellij.openapi.actionSystem.AnActionEvent;%0Aimport com.intellij.openapi.actionSystem.CommonDataKeys;%0Aimport com.intellij.openapi.actionSystem.ToggleAction
 ;%0Aim
@@ -957,58 +957,83 @@
 t co
-m.intellij.codeInsight.daemon.DaemonCodeAnalyzer;%0A
+nsulo.annotations.RequiredDispatchThread;%0A%0Aimport javax.annotation.Nonnull;
 %0Aimp
@@ -1162,17 +1162,16 @@
 ction %7B%0A
-%0A
   @Overr
@@ -1229,28 +1229,110 @@
     
-return getAnalyzer(e
+PsiFile file = getFile(e);%0A    return file != null && DaemonCodeAnalyzer.getInstance(file.getProject()
 ).is
@@ -1350,26 +1350,20 @@
 Enabled(
-getFile(e)
+file
 );%0A  %7D%0A%0A
@@ -1442,21 +1442,113 @@
     
-getAnalyzer(e
+PsiFile file = getFile(e);%0A    if (file != null) %7B%0A      DaemonCodeAnalyzer.getInstance(file.getProject()
 ).se
@@ -1567,26 +1567,20 @@
 Enabled(
-getFile(e)
+file
 , state)
@@ -1579,26 +1579,58 @@
 , state);%0A  
-%7D%0A
+  %7D%0A  %7D%0A%0A  @RequiredDispatchThread
 %0A  @Override
@@ -1651,16 +1651,25 @@
  update(
+@Nonnull 
 AnAction
@@ -1687,143 +1687,44 @@
     
-if (getFile(e) == null) %7B%0A      e.getPresentation().setEnabled(false);%0A      e.getPresentation().setVisible(false);%0A    %7D%0A    else %7B%0A  
+boolean works = getFile(e) != null;%0A
     
@@ -1754,29 +1754,28 @@
 Enabled(
-true
+works
 );%0A    
-  
 e.getPre
@@ -1801,17 +1801,16 @@
 ble(
-true
+works
 );%0A
-  
     
@@ -1830,157 +1830,8 @@
 e);%0A
-    %7D%0A  %7D%0A%0A  private DaemonCodeAnalyzer getAnalyzer(AnActionEvent e) %7B%0A    return DaemonCodeAnalyzer.getInstance(e.getData(CommonDataKeys.PROJECT));%0A
   %7D%0A
@@ -1929,16 +1929,14 @@
 ata(
-Platform
+Common
 Data
@@ -1998,12 +1998,14 @@
 ata(
-Lang
+Common
 Data

fix npe (just merge from idea)