Merge branch 'master' of git.labs.intellij.net:idea/community
authorRoman Shevchenko <roman.shevchenko@jetbrains.com>
Wed, 25 Feb 2015 14:31:17 +0000 (15:31 +0100)
committerRoman Shevchenko <roman.shevchenko@jetbrains.com>
Wed, 25 Feb 2015 14:31:17 +0000 (15:31 +0100)
14 files changed:
build/scripts/libLicenses.gant
java/java-tests/testSrc/com/intellij/psi/impl/smartPointers/SmartPsiElementPointersTest.java
platform/editor-ui-api/src/com/intellij/openapi/actionSystem/ActionManager.java
platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionPreselectionBehaviourProvider.java [new file with mode: 0644]
platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java
platform/lang-impl/src/com/intellij/openapi/editor/richcopy/TextWithMarkupProcessor.java
platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionManagerImpl.java
platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionToolbarImpl.java
platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ToolbarUpdater.java
platform/platform-resources/src/META-INF/LangExtensionPoints.xml
platform/platform-tests/testSrc/com/intellij/openapi/editor/richcopy/SyntaxInfoConstructionTest.java
platform/testFramework/src/com/intellij/testFramework/TestActionEvent.java
platform/util/resources/misc/registry.properties
plugins/tasks/tasks-tests/test/com/intellij/tasks/TaskUiTest.java

index 333c8135687b97a933ff1ad291689ab528b4e8fc..4578e007fefb43c19865137f8baaebdee50354d9 100644 (file)
@@ -207,6 +207,7 @@ libraryLicense(name: "JUnit", libraryName: "JUnit3", version: "3.8.1", license:
 libraryLicense(name: "JUnit", libraryName: "JUnit4", version: "4.11", license: "CPL 1.0", url: "http://junit.org/")
 libraryLicense(name: "Log4j", libraryName: "Log4J", version: "1.2.17", license: "Apache 2.0", url: "http://logging.apache.org/log4j/1.2/index.html", licenseUrl: "http://logging.apache.org/license.html")
 libraryLicense(name: "markdownj", libraryName: "markdownj", version: "0.4.2", license: "New BSD", url: "https://code.google.com/p/markdownj/", licenseUrl: "http://opensource.org/licenses/BSD-3-Clause")
+libraryLicense(name: "markdown4j", libraryName: "markdown4j-2.2", version: "2.2", license: "New BSD", url: "https://code.google.com/p/markdown4j/", licenseUrl: "http://opensource.org/licenses/BSD-3-Clause")
 libraryLicense(name: "Maven", version: "2.2.1", license: "Apache 2.0", url: "http://maven.apache.org/", licenseUrl: "http://maven.apache.org/license.html")
 libraryLicense(name: "plexus-util", version: "2.0.6", license: "Apache 2.0", url: "http://maven.apache.org/", libraryNames:['plexus-utils-2.0.6.jar'], licenseUrl: "http://apache.org/licenses/LICENSE-2.0")
 libraryLicense(name: "plexus-archiver", libraryName: "plexus-archiver-2.4.4.jar", version: "2.4.4", license: "Apache 2.0", url: "http://plexus.codehaus.org/plexus-components/plexus-archiver", licenseUrl: "http://apache.org/licenses/LICENSE-2.0")
index 3e389146db80f2b8158420ab94d163848c9c4e0f..4702973e3daa023d803b7f940ee67d0a61f379d5 100644 (file)
@@ -161,7 +161,7 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase {
   }
 
   public void testPsiChangesWithLazyPointers() throws Exception {
-    PsiClass aClass = myJavaFacade.findClass("AClass",GlobalSearchScope.allScope(getProject()));
+    PsiClass aClass = myJavaFacade.findClass("AClass", GlobalSearchScope.allScope(getProject()));
     assertNotNull(aClass);
 
     final SmartPsiElementPointer<PsiIdentifier> pointer =
@@ -512,6 +512,58 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase {
     assertNotNull(newSelect);
     assertEquals("select", newSelect.getName());
   }
+
+  public void testInXml2() {
+    final PsiFile file = configureByText(HtmlFileType.INSTANCE,
+                                         "<!DOCTYPE html>\n" +
+                                         "<html>\n" +
+                                         "<head>\n" +
+                                         "    <title></title>\n" +
+                                         "</head>\n" +
+                                         "<body>\n" +
+                                         "<div class=\"cls\">\n" +
+                                         "    <ul class=\"dropdown-menu\">\n" +
+                                         "        <li><a href=\"#\">Action</a></li>\n" +
+                                         "        <li><a href=\"#\">Another action</a></li>\n" +
+                                         "        <li><a href=\"#\">Something else here</a></li>\n" +
+                                         "        <li class=\"divider\"></li>\n" +
+                                         "        <li class=\"dropdown-header\">Nav header</li>\n" +
+                                         "        <li><a href=\"#\">Separated link</a></li>\n" +
+                                         "        <li><a href=\"#\">One more separated link</a></li>\n" +
+                                         "    </ul>\n" +
+                                         "<caret>\n" +
+                                         "</div>\n" +
+                                         "</body>\n" +
+                                         "</html>"
+    );
+
+    final XmlTag ul = PsiTreeUtil.getParentOfType(file.findElementAt(file.getText().indexOf("ul")), XmlTag.class);
+    assertNotNull(ul);
+    assertEquals("ul", ul.getName());
+    assertEquals("dropdown-menu", ul.getAttributeValue("class"));
+
+    final SmartPsiElementPointer<XmlTag> ulPointer = SmartPointerManager.getInstance(getProject()).createSmartPsiElementPointer(
+      ul);
+
+    WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() {
+      @Override
+      public void run() {
+        getEditor().getDocument().insertString(getEditor().getCaretModel().getOffset(), "    <ul class=\"nav navbar-nav navbar-right\">\n" +
+                                                                                        "        <li><a href=\"../navbar/\">Default</a></li>\n" +
+                                                                                        "        <li class=\"active\"><a href=\"./\">Static top</a></li>\n" +
+                                                                                        "        <li><a href=\"../navbar-fixed-top/\">Fixed top</a></li>\n" +
+                                                                                        "    </ul>\n");
+      }
+    });
+
+    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
+
+    final XmlTag newUl = ulPointer.getElement();
+    assertNotNull(newUl);
+    assertEquals("ul", newUl.getName());
+    assertEquals("dropdown-menu", newUl.getAttributeValue("class"));
+  }
+
   public void testInsertImport() {
     final PsiFile file = configureByText(JavaFileType.INSTANCE,
                                          "class S {\n" +
index ee850c3fe060994a11bfcea69e652d9aae000eda..bf83aee99f7d968b282dbea3de9f9ae6790110e9 100644 (file)
@@ -20,7 +20,6 @@ import com.intellij.openapi.actionSystem.ex.AnActionListener;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.components.ApplicationComponent;
 import com.intellij.openapi.extensions.PluginId;
-import com.intellij.openapi.project.ProjectType;
 import com.intellij.openapi.util.ActionCallback;
 import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.NotNull;
@@ -89,20 +88,6 @@ public abstract class ActionManager implements ApplicationComponent {
    */
   public abstract AnAction getAction(@NonNls @NotNull String actionId);
 
-  /**
-   * Returns action associated with the specified actionId.
-   *
-   * @param actionId Id of the registered action
-   *
-   * @return Action associated with the specified actionId, <code>null</code> if
-   *  there is no actions associated with the specified actionId
-   *
-   * @exception java.lang.IllegalArgumentException if <code>actionId</code> is <code>null</code>
-   *
-   * @see com.intellij.openapi.actionSystem.IdeActions
-   */
-  public abstract AnAction getAction(@NonNls @NotNull String actionId, @Nullable ProjectType projectType);
-
   /**
    * Returns actionId associated with the specified action.
    *
diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionPreselectionBehaviourProvider.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionPreselectionBehaviourProvider.java
new file mode 100644 (file)
index 0000000..f6cd174
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2000-2015 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.codeInsight.completion;
+
+import com.intellij.openapi.extensions.ExtensionPointName;
+import org.jetbrains.annotations.NotNull;
+
+public abstract class CompletionPreselectionBehaviourProvider {
+  public static ExtensionPointName<CompletionPreselectionBehaviourProvider> EP_NAME = ExtensionPointName.create("com.intellij.completion.completionBehaviourProvider");
+
+  public boolean shouldPreselectFirstSuggestion(@NotNull CompletionParameters parameters) {
+    return true;
+  }
+}
index 5daf8d4801977f9951bb7d1ccdb58145c681473b..8f96ed1bf0e8a2fd9903e6a6967205081cf9b22e 100644 (file)
@@ -41,6 +41,7 @@ import com.intellij.openapi.command.WriteCommandAction;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.editor.Caret;
 import com.intellij.openapi.editor.Editor;
+import com.intellij.openapi.extensions.Extensions;
 import com.intellij.openapi.progress.ProcessCanceledException;
 import com.intellij.openapi.progress.ProgressManager;
 import com.intellij.openapi.progress.util.ProgressIndicatorBase;
@@ -727,6 +728,14 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
       return false;
     }
 
+    if (Registry.is("ide.completion.lookup.element.preselect.depends.on.context")) {
+      for (CompletionPreselectionBehaviourProvider provider : Extensions.getExtensions(CompletionPreselectionBehaviourProvider.EP_NAME)) {
+        if (!provider.shouldPreselectFirstSuggestion(parameters)) {
+          return false;
+        }
+      }
+    }
+
     if (!ApplicationManager.getApplication().isUnitTestMode()) {
       return true;
     }
index cdabd8b98641acc4c0ae59b4760cf148ba257ee8..c9ad612753a79876367be221ea5d5a96df201138 100644 (file)
@@ -95,7 +95,8 @@ public class TextWithMarkupProcessor extends CopyPastePostProcessor<RawTextWithM
       logInitial(editor, startOffsets, endOffsets, indentSymbolsToStrip, firstLineStartOffset);
       CharSequence text = editor.getDocument().getCharsSequence();
       EditorColorsScheme schemeToUse = settings.getColorsScheme(editor.getColorsScheme());
-      EditorHighlighter highlighter = HighlighterFactory.createHighlighter(file.getVirtualFile(), schemeToUse, file.getProject());
+      EditorHighlighter highlighter = HighlighterFactory.createHighlighter(file.getViewProvider().getVirtualFile(),
+                                                                           schemeToUse, file.getProject());
       highlighter.setText(text);
       MarkupModel markupModel = DocumentMarkupModel.forDocument(editor.getDocument(), file.getProject(), false);
       Context context = new Context(text, schemeToUse, indentSymbolsToStrip);
index 4406c6da5d1241be081cf69db1c7a04695ae4295..72dc1ee4d063ff0967ce52a62237e3e96ec714b8 100644 (file)
@@ -486,28 +486,12 @@ public final class ActionManagerImpl extends ActionManagerEx implements Applicat
 
   @Override
   public AnAction getAction(@NotNull String id) {
-    return getActionImpl(id, false, null);
+    return getActionImpl(id, false);
   }
 
-  @Override
-  public AnAction getAction(@NonNls @NotNull String actionId, @Nullable ProjectType projectType) {
-    return getActionImpl(actionId, false, projectType);
-  }
-
-  private AnAction getActionImpl(String id, boolean canReturnStub, ProjectType projectType) {
+  private AnAction getActionImpl(String id, boolean canReturnStub) {
     synchronized (myLock) {
-      AnAction action;
-      Object o = myId2Action.get(id);
-      if (o == null) {
-        return null;
-      }
-      if (o instanceof AnAction) {
-        action = (AnAction)o;
-      }
-      else {
-        //noinspection unchecked
-        action = ((Map<ProjectType, AnAction>)o).get(projectType);
-      }
+      AnAction action = myId2Action.get(id);
       if (!canReturnStub && action instanceof ActionStub) {
         action = convert((ActionStub)action);
       }
@@ -558,7 +542,7 @@ public final class ActionManagerImpl extends ActionManagerEx implements Applicat
 
   @Override
   public boolean isGroup(@NotNull String actionId) {
-    return getActionImpl(actionId, true, null) instanceof ActionGroup;
+    return getActionImpl(actionId, true) instanceof ActionGroup;
   }
 
   @Override
@@ -568,7 +552,7 @@ public final class ActionManagerImpl extends ActionManagerEx implements Applicat
 
   @Override
   public AnAction getActionOrStub(String id) {
-    return getActionImpl(id, true, null);
+    return getActionImpl(id, true);
   }
 
   /**
@@ -863,10 +847,10 @@ public final class ActionManagerImpl extends ActionManagerEx implements Applicat
       reportActionError(pluginId, actionName + ": attribute \"group-id\" should be defined");
       return null;
     }
-    AnAction parentGroup = getActionImpl(groupId, true, null);
+    AnAction parentGroup = getActionImpl(groupId, true);
     if (parentGroup == null) {
       reportActionError(pluginId, actionName + ": group with id \"" + groupId + "\" isn't registered; action will be added to the \"Other\" group");
-      parentGroup = getActionImpl(IdeActions.GROUP_OTHER_MENU, true, null);
+      parentGroup = getActionImpl(IdeActions.GROUP_OTHER_MENU, true);
     }
     if (!(parentGroup instanceof DefaultActionGroup)) {
       reportActionError(pluginId, actionName + ": group with id \"" + groupId + "\" should be instance of " + DefaultActionGroup.class.getName() +
@@ -963,7 +947,7 @@ public final class ActionManagerImpl extends ActionManagerEx implements Applicat
       return null;
     }
 
-    AnAction action = getActionImpl(ref, true, null);
+    AnAction action = getActionImpl(ref, true);
 
     if (action == null) {
       if (!myNotRegisteredInternalActionIds.contains(ref)) {
index 3c943299f0d632797d1d5dc6d4ff42075ba66667..1cc9733569d3478aae8abf18ca0694bd5836408b 100644 (file)
@@ -25,7 +25,6 @@ import com.intellij.openapi.actionSystem.ex.ActionManagerEx;
 import com.intellij.openapi.actionSystem.ex.AnActionListener;
 import com.intellij.openapi.actionSystem.ex.CustomComponentAction;
 import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.application.ModalityState;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.keymap.ex.KeymapManagerEx;
 import com.intellij.openapi.project.DumbAwareRunnable;
@@ -47,6 +46,7 @@ import com.intellij.util.ui.JBUI;
 import com.intellij.util.ui.UIUtil;
 import com.intellij.util.ui.update.UiNotifyConnector;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.TestOnly;
 
 import javax.swing.*;
 import javax.swing.border.EmptyBorder;
@@ -1273,4 +1273,9 @@ public class ActionToolbarImpl extends JPanel implements ActionToolbar {
     myAddSeparatorFirst = addSeparatorFirst;
     myUpdater.updateActions(false, true);
   }
+
+  @TestOnly
+  public Presentation getPresentation(AnAction action) {
+    return myPresentationFactory.getPresentation(action);
+  }
 }
index e9a35a33b6e63c72d4f913ad4ffd23fa1f7d7500..e5574d6a18c94b74cc2944ae1dc3ee35d0b1bd34 100644 (file)
@@ -95,15 +95,15 @@ public abstract class ToolbarUpdater implements Activatable {
 
   private void updateActions(boolean now, final boolean transparentOnly, final boolean forced) {
     final Runnable updateRunnable = new MyUpdateRunnable(this, transparentOnly, forced);
+    final Application app = ApplicationManager.getApplication();
 
-    if (now) {
+    if (now || app.isUnitTestMode()) {
       updateRunnable.run();
     }
     else {
-      final Application app = ApplicationManager.getApplication();
       final IdeFocusManager fm = IdeFocusManager.getInstance(null);
 
-      if (!app.isUnitTestMode() && !app.isHeadlessEnvironment()) {
+      if (!app.isHeadlessEnvironment()) {
         if (app.isDispatchThread()) {
           fm.doWhenFocusSettlesDown(updateRunnable);
         }
index 17f7ca8c11d01bfb9082d16b0f272c7ac8509dbb..421905911dbd57802853e53d39f379117158427b 100644 (file)
       <with attribute="implementationClass" implements="com.intellij.codeInsight.completion.CompletionConfidence"/>
     </extensionPoint>
 
+    <extensionPoint name="completion.completionBehaviourProvider"
+                    interface="com.intellij.codeInsight.completion.CompletionPreselectionBehaviourProvider"/>
+
     <extensionPoint name="completion.skip" interface="com.intellij.codeInsight.completion.CompletionPreselectSkipper"/>
     <extensionPoint name="lookup.charFilter" interface="com.intellij.codeInsight.lookup.CharFilter"/>
     <extensionPoint name="lookup.actionProvider" interface="com.intellij.codeInsight.lookup.LookupActionProvider"/>
index bdeffd5a13dbd6e77dec30fc4cea55adc0278074..95803eb58ed5c1629812f301678a11c91cd08821 100644 (file)
 package com.intellij.openapi.editor.richcopy;
 
 import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.editor.Editor;
-import com.intellij.openapi.editor.LogicalPosition;
-import com.intellij.openapi.editor.SelectionModel;
+import com.intellij.openapi.editor.*;
 import com.intellij.openapi.editor.ex.EditorEx;
 import com.intellij.openapi.editor.impl.DocumentImpl;
 import com.intellij.openapi.editor.richcopy.model.ColorRegistry;
 import com.intellij.openapi.editor.richcopy.model.MarkupHandler;
 import com.intellij.openapi.editor.richcopy.model.SyntaxInfo;
+import com.intellij.openapi.fileEditor.FileDocumentManager;
+import com.intellij.openapi.fileTypes.FileType;
+import com.intellij.openapi.fileTypes.FileTypeRegistry;
 import com.intellij.openapi.util.text.StringUtil;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.psi.PsiFile;
+import com.intellij.psi.PsiFileFactory;
 import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;
 import com.intellij.ui.JBColor;
-import junit.framework.TestCase;
 
 /**
  * @author Denis Zhdanov
@@ -164,13 +167,13 @@ public class SyntaxInfoConstructionTest extends LightPlatformCodeInsightFixtureT
                       "\n" +
                       "text=}\n";
 
-    TestCase.assertEquals(expected, getSyntaxInfo());
+    verifySyntaxInfo(expected);
     
     selectionModel.setSelection(selectionStart - 2, selectionEnd);
-    TestCase.assertEquals(expected, getSyntaxInfo());
+    verifySyntaxInfo(expected);
 
     selectionModel.setSelection(selectionStart - 4, selectionEnd);
-    TestCase.assertEquals(expected, getSyntaxInfo());
+    verifySyntaxInfo(expected);
   }
 
   public void testIncorrectFirstLineCalculationOffset() {
@@ -291,11 +294,35 @@ public class SyntaxInfoConstructionTest extends LightPlatformCodeInsightFixtureT
                      "\n" +
                      "text=}\n");
   }
+  
+  public void testNonPhysicalFile() throws Exception {
+    String fileName = "Test.java";
+    FileType fileType = FileTypeRegistry.getInstance().getFileTypeByFileName(fileName);
+    PsiFile psiFile = PsiFileFactory.getInstance(getProject()).createFileFromText(fileName, fileType, "class Test {}", 0, false);
+    VirtualFile virtualFile = psiFile.getViewProvider().getVirtualFile();
+    Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
+    assertNotNull(document);
+    EditorFactory editorFactory = EditorFactory.getInstance();
+    Editor editor = editorFactory.createViewer(document, getProject());
+    try {
+      editor.getSelectionModel().setSelection(0, document.getTextLength());
+      String syntaxInfo = getSyntaxInfo(editor, psiFile);
+      assertEquals("foreground=java.awt.Color[r=0,g=0,b=128],fontStyle=1,text=class \n" +
+                   "foreground=java.awt.Color[r=0,g=0,b=0],fontStyle=0,text=Test {}\n", syntaxInfo);
+    }
+    finally {
+      editorFactory.releaseEditor(editor);
+    }
+  }
 
   private String getSyntaxInfo() {
+    return getSyntaxInfo(myFixture.getEditor(), myFixture.getFile());
+  }
+  
+  private static String getSyntaxInfo(Editor editor, PsiFile psiFile) {
     final StringBuilder builder = new StringBuilder();
-    final Editor editor = myFixture.getEditor();
-    String selectedText = editor.getSelectionModel().getSelectedText(true);
+    SelectionModel selectionModel = editor.getSelectionModel();
+    String selectedText = selectionModel.getSelectedText(true);
     assertNotNull(selectedText);
     final String text = StringUtil.convertLineSeparators(selectedText);
 
@@ -305,7 +332,7 @@ public class SyntaxInfoConstructionTest extends LightPlatformCodeInsightFixtureT
         final ColorRegistry colorRegistry = syntaxInfo.getColorRegistry();
         assertEquals(JBColor.BLACK, colorRegistry.dataById(syntaxInfo.getDefaultForeground()));
         assertEquals(JBColor.WHITE, colorRegistry.dataById(syntaxInfo.getDefaultBackground()));
-        assertEquals((float)getFontSize(), syntaxInfo.getFontSize(), 0.01f);
+        assertEquals((float)editor.getColorsScheme().getEditorFontSize(), syntaxInfo.getFontSize(), 0.01f);
         syntaxInfo.processOutputInfo(new MarkupHandler() {
           @Override
           public void handleText(int startOffset, int endOffset) throws Exception {
@@ -339,8 +366,7 @@ public class SyntaxInfoConstructionTest extends LightPlatformCodeInsightFixtureT
         });
       }
     };
-    SelectionModel selectionModel = editor.getSelectionModel();
-    processor.collectTransferableData(myFixture.getFile(), editor, selectionModel.getBlockSelectionStarts(), selectionModel.getBlockSelectionEnds());
+    processor.collectTransferableData(psiFile, editor, selectionModel.getBlockSelectionStarts(), selectionModel.getBlockSelectionEnds());
 
     return builder.toString();
   }
@@ -367,10 +393,6 @@ public class SyntaxInfoConstructionTest extends LightPlatformCodeInsightFixtureT
     assertEquals(info, getSyntaxInfo());
   }
 
-  private int getFontSize() {
-    return myFixture.getEditor().getColorsScheme().getEditorFontSize();
-  }
-
   @Override
   protected boolean isWriteActionRequired() {
     return false;
index 0f5ab8b3c8ae4bd0c6c8c7513131ecc24bcf6566..23dc823dcd2d1cac87889cb3d4fd2477062bee7f 100644 (file)
@@ -33,6 +33,10 @@ public class TestActionEvent extends AnActionEvent {
     this(DataManager.getInstance().getDataContext(), action);
   }
 
+  public TestActionEvent(Presentation presentation) {
+    super(null, DataManager.getInstance().getDataContext(), "", presentation, ActionManager.getInstance(), 0);
+  }
+
   public TestActionEvent() {
     super(null, DataManager.getInstance().getDataContext(), "", new Presentation(), ActionManager.getInstance(), 0);
   }
index 114892b0266ecbed936185da101d79c27bead421..d923bebb4649070723385ce313609d1ab41b80d9 100644 (file)
@@ -275,6 +275,10 @@ ide.completion.delay.autopopup.until.completed.description=Controls if completio
 
 ide.completion.middle.matching=true
 ide.completion.middle.matching.description=Suggest items in completion that contain the entered string somewhere in the middle.
+
+ide.completion.lookup.element.preselect.depends.on.context=true
+ide.completion.lookup.element.preselect.depends.on.context.description=Preselection of the first element in completion list depends on context
+
 ide.goto.middle.matching=true
 ide.goto.middle.matching.description=Suggest items in goto actions that contain the entered string somewhere in the middle.
 ide.goto.rebuild.delay=0
index b63382fbb36acbda8bc011bbb7c5cba852eee2fb..25e844cc9efa8fa50f50093170847de09f5b0bf9 100644 (file)
@@ -15,8 +15,9 @@
  */
 package com.intellij.tasks;
 
-import com.intellij.openapi.actionSystem.AnAction;
-import com.intellij.openapi.actionSystem.Presentation;
+import com.intellij.ide.ui.customization.CustomActionsSchema;
+import com.intellij.openapi.actionSystem.*;
+import com.intellij.openapi.actionSystem.impl.ActionToolbarImpl;
 import com.intellij.tasks.actions.SwitchTaskCombo;
 import com.intellij.tasks.config.TaskSettings;
 import com.intellij.testFramework.IdeaTestCase;
@@ -31,19 +32,32 @@ public class TaskUiTest extends CodeInsightFixtureTestCase {
 
   public void testTaskComboVisible() throws Exception {
 
-    TaskManager manager = TaskManager.getManager(getProject());
-    SwitchTaskCombo combo = new SwitchTaskCombo();
+    SwitchTaskCombo combo = null;
+    ActionGroup group = (ActionGroup)CustomActionsSchema.getInstance().getCorrectedAction(IdeActions.GROUP_MAIN_TOOLBAR);
+    ActionToolbarImpl toolbar = (ActionToolbarImpl)ActionManager.getInstance().createActionToolbar(ActionPlaces.MAIN_TOOLBAR, group, true);
+    AnAction[] children = group.getChildren(new TestActionEvent());
+    for (AnAction child : children) {
+      if (child instanceof ActionGroup) {
+        AnAction[] actions = ((ActionGroup)child).getChildren(new TestActionEvent());
+        for (AnAction action : actions) {
+          if (action instanceof SwitchTaskCombo) {
+            combo = (SwitchTaskCombo)action;
+          }
+        }
+      }
+    }
 
+    TaskManager manager = TaskManager.getManager(getProject());
     LocalTask defaultTask = manager.getActiveTask();
     assertTrue(defaultTask.isDefault());
     assertEquals(defaultTask.getCreated(), defaultTask.getUpdated());
 
-    Presentation presentation = doTest(combo);
+    Presentation presentation = doTest(combo, toolbar);
     assertFalse(presentation.isVisible());
 
     try {
       TaskSettings.getInstance().ALWAYS_DISPLAY_COMBO = true;
-      presentation = doTest(combo);
+      presentation = doTest(combo, toolbar);
       assertTrue(presentation.isVisible());
     }
     finally {
@@ -53,14 +67,14 @@ public class TaskUiTest extends CodeInsightFixtureTestCase {
     LocalTask task = manager.createLocalTask("test");
     manager.activateTask(task, false);
 
-    presentation = doTest(combo);
+    presentation = doTest(combo, toolbar);
     assertTrue(presentation.isVisible());
 
     manager.activateTask(defaultTask, false);
     task = manager.getActiveTask();
     assertTrue(task.isDefault());
 
-    presentation = doTest(combo);
+    presentation = doTest(combo, toolbar);
     if (!presentation.isVisible()) {
       LocalTask activeTask = manager.getActiveTask();
       System.out.println(activeTask);
@@ -70,8 +84,8 @@ public class TaskUiTest extends CodeInsightFixtureTestCase {
     }
   }
 
-  private static Presentation doTest(AnAction action) {
-    TestActionEvent event = new TestActionEvent(action);
+  private static Presentation doTest(AnAction action, ActionToolbarImpl toolbar) {
+    TestActionEvent event = new TestActionEvent(toolbar.getPresentation(action));
     action.update(event);
     return event.getPresentation();
   }