IDEA-66737 Copy text from quick doc popup doesn't work

1. Provided dedicated action that allows to copy text from quick doc hint to the clipboard;
2. Green cody policy is partially applied at the affected classed;
This commit is contained in:
Denis Zhdanov
2011-03-29 15:24:13 +04:00
parent d856bda110
commit 2236f1bed0
7 changed files with 99 additions and 35 deletions
@@ -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);
@@ -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")));
@@ -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<String> 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<JBPopup> pinCallback = new Processor<JBPopup>() {
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<Pair<ActionListener, KeyStroke>> actions = Collections.singletonList(Pair.<ActionListener, KeyStroke>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<DataContext> 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);
}
}
};
@@ -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));
}
}
@@ -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);
}
@@ -136,7 +136,7 @@
<separator/>
<group id="CodeEditorViewGroup">
<action id="FileStructurePopup" class="com.intellij.ide.actions.ViewStructureAction"/>
<action id="QuickJavaDoc" class="com.intellij.codeInsight.documentation.actions.ShowJavaDocInfoAction"/>
<action id="QuickJavaDoc" class="com.intellij.codeInsight.documentation.actions.ShowQuickDocInfoAction"/>
<action id="ExternalJavaDoc" class="com.intellij.ide.actions.ExternalJavaDocAction"/>
<action id="SelectIn" class="com.intellij.ide.actions.SelectInAction"/>
<action id="ParameterInfo" class="com.intellij.codeInsight.hint.actions.ShowParameterInfoAction"/>
@@ -19,6 +19,7 @@
<action id="TextComponent.ClearAction" class="com.intellij.ui.ClearTextAction"/>
<action id="Switcher" class="com.intellij.ide.actions.Switcher" text="Switcher"/>
<action id="QuickDocCopy" class="com.intellij.codeInsight.documentation.actions.CopyQuickDocAction" use-shortcut-of="$Copy"/>
<group id="EditorActions">
<action id="EditorPageUp" class="com.intellij.openapi.editor.actions.PageUpAction"/>