diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/DefaultCompletionContributor.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/DefaultCompletionContributor.java index 4b196a0b3f59..cbe534857650 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/DefaultCompletionContributor.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/DefaultCompletionContributor.java @@ -15,7 +15,7 @@ */ package com.intellij.codeInsight.completion; -import com.intellij.codeInsight.documentation.actions.ShowJavaDocInfoAction; +import com.intellij.codeInsight.documentation.actions.ShowQuickDocInfoAction; import com.intellij.codeInsight.hint.actions.ShowImplementationsAction; import com.intellij.codeInsight.lookup.LookupElement; import com.intellij.lang.LangBundle; @@ -23,6 +23,7 @@ import com.intellij.openapi.actionSystem.IdeActions; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.util.text.StringUtil; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Random; @@ -31,6 +32,7 @@ import java.util.Random; */ public class DefaultCompletionContributor extends CompletionContributor { + @Nullable public static String getDefaultAdvertisementText(@NotNull final CompletionParameters parameters) { final Random random = new Random(); if (random.nextInt(5) < 2 && CompletionUtil.shouldShowFeature(parameters, CodeCompletionFeatures.EDITING_COMPLETION_FINISH_BY_DOT_ETC)) { @@ -56,8 +58,8 @@ public class DefaultCompletionContributor extends CompletionContributor { } if (random.nextInt(5) < 2 && - (CompletionUtil.shouldShowFeature(parameters, ShowJavaDocInfoAction.CODEASSISTS_QUICKJAVADOC_FEATURE) || - CompletionUtil.shouldShowFeature(parameters, ShowJavaDocInfoAction.CODEASSISTS_QUICKJAVADOC_LOOKUP_FEATURE))) { + (CompletionUtil.shouldShowFeature(parameters, ShowQuickDocInfoAction.CODEASSISTS_QUICKJAVADOC_FEATURE) || + CompletionUtil.shouldShowFeature(parameters, ShowQuickDocInfoAction.CODEASSISTS_QUICKJAVADOC_LOOKUP_FEATURE))) { final String shortcut = getActionShortcut(IdeActions.ACTION_QUICK_JAVADOC); if (shortcut != null) { return LangBundle.message("completion.quick.javadoc.ad", shortcut); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationComponent.java b/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationComponent.java index 665c62d71953..5e98b4da87b6 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationComponent.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationComponent.java @@ -62,8 +62,8 @@ import java.awt.event.*; import java.util.List; import java.util.Stack; -public class DocumentationComponent extends JPanel implements Disposable { - +public class DocumentationComponent extends JPanel implements Disposable, DataProvider { + private static final DataContext EMPTY_DATA_CONTEXT = new DataContext() { @Override public Object getData(@NonNls String dataId) { @@ -318,6 +318,15 @@ public class DocumentationComponent extends JPanel implements Disposable { this(manager, null); } + @Override + public Object getData(@NonNls String dataId) { + if (DocumentationManager.SELECTED_QUICK_DOC_TEXT.getName().equals(dataId)) { + return myEditorPane.getSelectedText(); + } + + return null; + } + private JComponent createSettingsPanel() { JPanel result = new JPanel(new FlowLayout(FlowLayout.RIGHT, 3, 0)); result.add(new JLabel(ApplicationBundle.message("label.font.size"))); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationManager.java b/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationManager.java index 8606406f6a06..626a74ef2d8b 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationManager.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationManager.java @@ -43,7 +43,6 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.OrderEntry; @@ -83,10 +82,14 @@ import java.util.*; import java.util.List; public class DocumentationManager { + + @NonNls public static final String JAVADOC_LOCATION_AND_SIZE = "javadoc.popup"; + public static final DataKey SELECTED_QUICK_DOC_TEXT = DataKey.create("QUICK_DOC.SELECTED_TEXT"); + private static final Logger LOG = Logger.getInstance("#" + DocumentationManager.class.getName()); private static final String SHOW_DOCUMENTATION_IN_TOOL_WINDOW = "ShowDocumentationInToolWindow"; private static final String DOCUMENTATION_AUTO_UPDATE_ENABLED = "DocumentationAutoUpdateEnabled"; - @NonNls public static final String JAVADOC_LOCATION_AND_SIZE = "javadoc.popup"; + private final Project myProject; private Editor myEditor = null; private ParameterInfoController myParameterInfoController; @@ -203,14 +206,11 @@ public class DocumentationManager { DocumentationProvider documentationProvider = getProviderFromElement(file); - PsiElement element = null; - if (documentationProvider!=null) { - element = documentationProvider.getDocumentationElementForLookupItem( - PsiManager.getInstance(myProject), - lookupIteObject, - originalElement - ); - } + PsiElement element = documentationProvider.getDocumentationElementForLookupItem( + PsiManager.getInstance(myProject), + lookupIteObject, + originalElement + ); if (element == null) return; @@ -235,7 +235,7 @@ public class DocumentationManager { Project project = getProject(element); if (myToolWindow == null && PropertiesComponent.getInstance().isTrueValue(SHOW_DOCUMENTATION_IN_TOOL_WINDOW)) { - createToolWindow(element, originalElement, true); + createToolWindow(element, originalElement); return; } else if (myToolWindow != null) { @@ -270,7 +270,7 @@ public class DocumentationManager { }); Processor pinCallback = new Processor() { public boolean process(JBPopup popup) { - createToolWindow(element, originalElement, true); + createToolWindow(element, originalElement); popup.cancel(); return false; } @@ -279,7 +279,7 @@ public class DocumentationManager { final KeyboardShortcut keyboardShortcut = ActionManagerEx.getInstanceEx().getKeyboardShortcut("QuickJavaDoc"); final List> actions = Collections.singletonList(Pair.create(new ActionListener() { public void actionPerformed(ActionEvent e) { - createToolWindow(element, originalElement, false); + createToolWindow(element, originalElement); final JBPopup hint = getDocInfoHint(); if (hint != null && hint.isVisible()) hint.cancel(); } @@ -344,7 +344,7 @@ public class DocumentationManager { } } - private void createToolWindow(final PsiElement element, PsiElement originalElement, final boolean automatic) { + private void createToolWindow(final PsiElement element, PsiElement originalElement) { assert myToolWindow == null; final DocumentationComponent component = new DocumentationComponent(this, new AnAction[]{ @@ -423,24 +423,30 @@ public class DocumentationManager { public void run() { if (myProject.isDisposed()) return; - final DataContext dataContext = DataManager.getInstance().getDataContext(); + AsyncResult asyncResult = DataManager.getInstance().getDataContextFromFocus(); + DataContext dataContext = asyncResult.getResult(); + if (dataContext == null) { + return; + } final Editor editor = PlatformDataKeys.EDITOR.getData(dataContext); - if (editor != null) { - final PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, myProject); + if (editor == null) { + return; + } - final Editor injectedEditor = InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(editor, file); - if (injectedEditor != null) { - final PsiFile psiFile = PsiUtilBase.getPsiFileInEditor(injectedEditor, myProject); - if (psiFile != null) { - showJavaDocInfo(injectedEditor, psiFile, false, true); - return; - } - } + final PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, myProject); - if (file != null) { - showJavaDocInfo(editor, file, false, true); + final Editor injectedEditor = InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(editor, file); + if (injectedEditor != null) { + final PsiFile psiFile = PsiUtilBase.getPsiFileInEditor(injectedEditor, myProject); + if (psiFile != null) { + showJavaDocInfo(injectedEditor, psiFile, false, true); + return; } } + + if (file != null) { + showJavaDocInfo(editor, file, false, true); + } } }; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/documentation/actions/CopyQuickDocAction.java b/platform/lang-impl/src/com/intellij/codeInsight/documentation/actions/CopyQuickDocAction.java new file mode 100644 index 000000000000..d7fcebe61cab --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/documentation/actions/CopyQuickDocAction.java @@ -0,0 +1,46 @@ +/* + * Copyright 2000-2011 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.documentation.actions; + +import com.intellij.codeInsight.documentation.DocumentationManager; +import com.intellij.codeInsight.hint.HintManagerImpl; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.ide.CopyPasteManager; +import com.intellij.openapi.project.DumbAware; + +import java.awt.datatransfer.StringSelection; + +/** + * @author Denis Zhdanov + * @since 3/29/11 1:28 PM + */ +public class CopyQuickDocAction extends AnAction implements DumbAware, HintManagerImpl.ActionToIgnore { + + public CopyQuickDocAction() { + setEnabledInModalContext(true); + } + + @Override + public void actionPerformed(AnActionEvent e) { + String selected = e.getData(DocumentationManager.SELECTED_QUICK_DOC_TEXT); + if (selected == null || selected.isEmpty()) { + return; + } + + CopyPasteManager.getInstance().setContents(new StringSelection(selected)); + } +} diff --git a/platform/lang-impl/src/com/intellij/codeInsight/documentation/actions/ShowJavaDocInfoAction.java b/platform/lang-impl/src/com/intellij/codeInsight/documentation/actions/ShowQuickDocInfoAction.java similarity index 96% rename from platform/lang-impl/src/com/intellij/codeInsight/documentation/actions/ShowJavaDocInfoAction.java rename to platform/lang-impl/src/com/intellij/codeInsight/documentation/actions/ShowQuickDocInfoAction.java index cea5400d218f..ea8339928dc0 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/documentation/actions/ShowJavaDocInfoAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/documentation/actions/ShowQuickDocInfoAction.java @@ -34,11 +34,11 @@ import com.intellij.psi.*; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; -public class ShowJavaDocInfoAction extends BaseCodeInsightAction implements HintManagerImpl.ActionToIgnore, DumbAware, PopupAction { +public class ShowQuickDocInfoAction extends BaseCodeInsightAction implements HintManagerImpl.ActionToIgnore, DumbAware, PopupAction { @NonNls public static final String CODEASSISTS_QUICKJAVADOC_LOOKUP_FEATURE = "codeassists.quickjavadoc.lookup"; @NonNls public static final String CODEASSISTS_QUICKJAVADOC_FEATURE = "codeassists.quickjavadoc"; - public ShowJavaDocInfoAction() { + public ShowQuickDocInfoAction() { setEnabledInModalContext(true); setInjectedContext(true); } diff --git a/platform/platform-resources/src/idea/LangActions.xml b/platform/platform-resources/src/idea/LangActions.xml index b53b214ad8ae..c5a7d3c54158 100644 --- a/platform/platform-resources/src/idea/LangActions.xml +++ b/platform/platform-resources/src/idea/LangActions.xml @@ -136,7 +136,7 @@ - + diff --git a/platform/platform-resources/src/idea/PlatformActions.xml b/platform/platform-resources/src/idea/PlatformActions.xml index 22b63fd3e470..bcda6f9e02e8 100644 --- a/platform/platform-resources/src/idea/PlatformActions.xml +++ b/platform/platform-resources/src/idea/PlatformActions.xml @@ -19,6 +19,7 @@ +