diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/AddJavadocIntention.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/AddJavadocIntention.java index a26e78ac85c7..22abefb01c98 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/AddJavadocIntention.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/AddJavadocIntention.java @@ -16,6 +16,7 @@ package com.intellij.codeInsight.intention.impl; import com.intellij.codeInsight.editorActions.FixDocCommentAction; +import com.intellij.codeInsight.intention.LowPriorityAction; import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; @@ -26,7 +27,7 @@ import org.jetbrains.annotations.NotNull; /** * @author Dmitry Batkovich */ -public class AddJavadocIntention extends PsiElementBaseIntentionAction { +public class AddJavadocIntention extends PsiElementBaseIntentionAction implements LowPriorityAction { @Override public void invoke(@NotNull final Project project, final Editor editor, @NotNull final PsiElement element) throws IncorrectOperationException { final PsiDocCommentOwner docCommentOwner = (PsiDocCommentOwner)element.getParent(); diff --git a/java/java-impl/src/com/intellij/find/findUsages/JavaFindUsagesHandler.java b/java/java-impl/src/com/intellij/find/findUsages/JavaFindUsagesHandler.java index f420f24349f9..1791fd0d6e8e 100644 --- a/java/java-impl/src/com/intellij/find/findUsages/JavaFindUsagesHandler.java +++ b/java/java-impl/src/com/intellij/find/findUsages/JavaFindUsagesHandler.java @@ -348,6 +348,9 @@ public class JavaFindUsagesHandler extends FindUsagesHandler{ } else if (classOptions.isImplementingClasses){ if (!addImplementingClasses(psiClass, processor, classOptions)) return false; + } + + if (classOptions.isImplementingClasses) { FunctionalExpressionSearch.search(psiClass, classOptions.searchScope).forEach(new PsiElementProcessorAdapter( new PsiElementProcessor() { @Override diff --git a/java/java-impl/src/com/intellij/refactoring/inline/InlineLocalDialog.java b/java/java-impl/src/com/intellij/refactoring/inline/InlineLocalDialog.java index 78d96096a8e7..f994eeb07db0 100644 --- a/java/java-impl/src/com/intellij/refactoring/inline/InlineLocalDialog.java +++ b/java/java-impl/src/com/intellij/refactoring/inline/InlineLocalDialog.java @@ -23,15 +23,15 @@ import com.intellij.refactoring.HelpID; import com.intellij.refactoring.JavaRefactoringSettings; import com.intellij.refactoring.RefactoringBundle; -public class InlineLocalDialog extends InlineOptionsDialog { +public class InlineLocalDialog extends AbstractInlineLocalDialog { public static final String REFACTORING_NAME = RefactoringBundle.message("inline.method.title"); private final PsiVariable myVariable; private int myOccurrencesNumber = -1; - public InlineLocalDialog(Project project, PsiVariable variable, PsiJavaCodeReferenceElement ref, int occurrencesCount) { - super(project, true, variable); + public InlineLocalDialog(Project project, PsiVariable variable, final PsiJavaCodeReferenceElement ref, int occurrencesCount) { + super(project, variable, ref, occurrencesCount); myVariable = variable; myInvokedOnReference = ref != null; diff --git a/java/java-impl/src/com/intellij/refactoring/inline/InlineLocalHandler.java b/java/java-impl/src/com/intellij/refactoring/inline/InlineLocalHandler.java index 44fd8cb8f724..42a15b2cf741 100644 --- a/java/java-impl/src/com/intellij/refactoring/inline/InlineLocalHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/inline/InlineLocalHandler.java @@ -26,6 +26,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.colors.EditorColors; import com.intellij.openapi.editor.colors.EditorColorsManager; +import com.intellij.openapi.editor.ex.EditorSettingsExternalizable; import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Ref; @@ -147,15 +148,18 @@ public class InlineLocalHandler extends JavaInlineActionHandler { final Ref inlineAll = new Ref(true); if (editor != null && !ApplicationManager.getApplication().isUnitTestMode()) { int occurrencesCount = refsToInlineList.size(); - final InlineLocalDialog inlineLocalDialog = new InlineLocalDialog(project, local, refExpr, occurrencesCount); - inlineLocalDialog.show(); - if (!inlineLocalDialog.isOK()){ - WindowManager.getInstance().getStatusBar(project).setInfo(RefactoringBundle.message("press.escape.to.remove.the.highlighting")); - return; - } - if (refExpr != null && inlineLocalDialog.isInlineThis()) { - refsToInlineList = Collections.singletonList(refExpr); - inlineAll.set(false); + if (refExpr != null && occurrencesCount > 1 || EditorSettingsExternalizable.getInstance().isShowInlineLocalDialog()) { + final InlineLocalDialog inlineLocalDialog = new InlineLocalDialog(project, local, refExpr, occurrencesCount); + inlineLocalDialog.show(); + if (!inlineLocalDialog.isOK()){ + WindowManager.getInstance().getStatusBar(project).setInfo(RefactoringBundle.message("press.escape.to.remove.the.highlighting")); + return; + } + + if (refExpr != null && inlineLocalDialog.isInlineThis()) { + refsToInlineList = Collections.singletonList(refExpr); + inlineAll.set(false); + } } } diff --git a/platform/lang-impl/src/com/intellij/application/options/editor/EditorOptionsPanel.form b/platform/lang-impl/src/com/intellij/application/options/editor/EditorOptionsPanel.form index 3e5c8a0f1d88..586f9b48779e 100644 --- a/platform/lang-impl/src/com/intellij/application/options/editor/EditorOptionsPanel.form +++ b/platform/lang-impl/src/com/intellij/application/options/editor/EditorOptionsPanel.form @@ -417,7 +417,7 @@ - + @@ -444,6 +444,14 @@ + + + + + + + + diff --git a/platform/lang-impl/src/com/intellij/application/options/editor/EditorOptionsPanel.java b/platform/lang-impl/src/com/intellij/application/options/editor/EditorOptionsPanel.java index 9e5d8558b4d1..3646e2632273 100644 --- a/platform/lang-impl/src/com/intellij/application/options/editor/EditorOptionsPanel.java +++ b/platform/lang-impl/src/com/intellij/application/options/editor/EditorOptionsPanel.java @@ -97,6 +97,7 @@ public class EditorOptionsPanel { private JBLabel myQuickDocDelayLabel; private JTextField myQuickDocDelayTextField; private JComboBox myRichCopyColorSchemeComboBox; + private JCheckBox myShowInlineDialogForCheckBox; private static final String ACTIVE_COLOR_SCHEME = ApplicationBundle.message("combobox.richcopy.color.scheme.active"); @@ -206,6 +207,7 @@ public class EditorOptionsPanel { myCbRenameLocalVariablesInplace.setSelected(editorSettings.isVariableInplaceRenameEnabled()); myPreselectCheckBox.setSelected(editorSettings.isPreselectRename()); + myShowInlineDialogForCheckBox.setSelected(editorSettings.isShowInlineLocalDialog()); myShowReformatCodeDialogCheckBox.setSelected(editorSettings.getOptions().SHOW_REFORMAT_DIALOG); myShowOptimizeImportsDialogCheckBox.setSelected(editorSettings.getOptions().SHOW_OPIMIZE_IMPORTS_DIALOG); @@ -301,6 +303,7 @@ public class EditorOptionsPanel { editorSettings.setVariableInplaceRenameEnabled(myCbRenameLocalVariablesInplace.isSelected()); editorSettings.setPreselectRename(myPreselectCheckBox.isSelected()); + editorSettings.setShowInlineLocalDialog(myShowInlineDialogForCheckBox.isSelected()); editorSettings.getOptions().SHOW_REFORMAT_DIALOG = myShowReformatCodeDialogCheckBox.isSelected(); editorSettings.getOptions().SHOW_OPIMIZE_IMPORTS_DIALOG = myShowOptimizeImportsDialogCheckBox.isSelected(); @@ -442,6 +445,7 @@ public class EditorOptionsPanel { isModified |= isModified(myCommandsHistoryLimitField, UISettings.getInstance().CONSOLE_COMMAND_HISTORY_LIMIT); isModified |= isModified(myCbRenameLocalVariablesInplace, editorSettings.isVariableInplaceRenameEnabled()); isModified |= isModified(myPreselectCheckBox, editorSettings.isPreselectRename()); + isModified |= isModified(myShowInlineDialogForCheckBox, editorSettings.isShowInlineLocalDialog()); isModified |= isModified(myShowReformatCodeDialogCheckBox, editorSettings.getOptions().SHOW_REFORMAT_DIALOG); isModified |= isModified(myShowOptimizeImportsDialogCheckBox, editorSettings.getOptions().SHOW_OPIMIZE_IMPORTS_DIALOG); 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 4b1a7d73a1e4..cf9b5ad22798 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationComponent.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationComponent.java @@ -40,6 +40,7 @@ import com.intellij.openapi.options.FontSize; import com.intellij.openapi.ui.popup.JBPopup; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.registry.Registry; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.wm.ex.WindowManagerEx; import com.intellij.pom.Navigatable; import com.intellij.psi.PsiElement; @@ -65,6 +66,7 @@ import javax.swing.event.HyperlinkListener; import javax.swing.text.*; import java.awt.*; import java.awt.event.*; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Stack; @@ -98,6 +100,7 @@ public class DocumentationComponent extends JPanel implements Disposable, DataPr private final JComponent mySettingsPanel; private final MyShowSettingsButton myShowSettingsButton; private boolean myIgnoreFontSizeSliderChange; + private String myEffectiveExternalUrl; private static class Context { final SmartPsiElementPointer element; @@ -461,7 +464,7 @@ public class DocumentationComponent extends JPanel implements Disposable, DataPr myForwardStack.clear(); } updateControlState(); - setData(element, text, clearHistory); + setData(element, text, clearHistory, null); if (clean) { myIsEmpty = false; } @@ -480,7 +483,8 @@ public class DocumentationComponent extends JPanel implements Disposable, DataPr myBackStack.clear(); } - public void setData(PsiElement _element, String text, final boolean clearHistory) { + public void setData(PsiElement _element, String text, final boolean clearHistory, String effectiveExternalUrl) { + myEffectiveExternalUrl = effectiveExternalUrl; if (myElement != null) { myBackStack.push(saveContext()); myForwardStack.clear(); @@ -683,10 +687,16 @@ public class DocumentationComponent extends JPanel implements Disposable, DataPr } if (!processed) { - final List urls = provider.getUrlFor(element, originalElement); - assert urls != null : provider; - assert !urls.isEmpty() : provider; - ExternalJavaDocAction.showExternalJavadoc(urls); + final Component component = PlatformDataKeys.CONTEXT_COMPONENT.getData(e.getDataContext()); + final List urls; + if (!StringUtil.isEmptyOrSpaces(myEffectiveExternalUrl)) { + urls = Collections.singletonList(myEffectiveExternalUrl); + } else { + urls = provider.getUrlFor(element, originalElement); + assert urls != null : provider; + assert !urls.isEmpty() : provider; + } + ExternalJavaDocAction.showExternalJavadoc(urls, component); } } } 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 c81b505dec37..df55cbad9346 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationManager.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationManager.java @@ -615,99 +615,7 @@ public class DocumentationManager extends DockablePopupManager() { - @Override - public DocumentationProvider compute() { - return getProviderFromElement(element, originalElement); - } - } - ); - if (myParameterInfoController != null) { - final String doc = ApplicationManager.getApplication().runReadAction( - new NullableComputable() { - @Override - public String compute() { - return generateParameterInfoDocumentation(provider); - } - } - ); - if (doc != null) return doc; - } - if (provider instanceof ExternalDocumentationProvider) { - final List urls = ApplicationManager.getApplication().runReadAction( - new NullableComputable>() { - @Override - public List compute() { - final SmartPsiElementPointer originalElementPtr = element.getUserData(ORIGINAL_ELEMENT_KEY); - final PsiElement originalElement = originalElementPtr != null ? originalElementPtr.getElement() : null; - if (((ExternalDocumentationProvider)provider).hasDocumentationFor(element, originalElement)) { - return provider.getUrlFor(element, originalElement); - } - return null; - } - } - ); - if (urls != null) { - final String doc = ((ExternalDocumentationProvider)provider).fetchExternalDocumentation(myProject, element, urls); - if (doc != null) return doc; - } - } - return ApplicationManager.getApplication().runReadAction( - new Computable() { - @Override - @Nullable - public String compute() { - final SmartPsiElementPointer originalElement = element.getUserData(ORIGINAL_ELEMENT_KEY); - return provider.generateDoc(element, originalElement != null ? originalElement.getElement() : null); - } - } - ); - } - - @Nullable - private String generateParameterInfoDocumentation(DocumentationProvider provider) { - final Object[] objects = myParameterInfoController.getSelectedElements(); - - if (objects.length > 0) { - @NonNls StringBuffer sb = null; - - for (Object o : objects) { - PsiElement parameter = null; - if (o instanceof PsiElement) { - parameter = (PsiElement)o; - } - - if (parameter != null) { - final SmartPsiElementPointer originalElement = parameter.getUserData(ORIGINAL_ELEMENT_KEY); - final String str2 = provider.generateDoc(parameter, originalElement != null ? originalElement.getElement() : null); - if (str2 == null) continue; - if (sb == null) sb = new StringBuffer(); - sb.append(str2); - sb.append("
"); - } - else { - sb = null; - break; - } - } - - if (sb != null) return sb.toString(); - } - return null; - } - - @Override - @Nullable - public PsiElement getElement() { - return element.isValid() ? element : null; - } - }; + return new DefaultDocumentationCollector(element, originalElement); } @Nullable @@ -813,7 +721,7 @@ public class DocumentationManager extends DockablePopupManager() { + @Override + public DocumentationProvider compute() { + return getProviderFromElement(myElement, myOriginalElement); + } + } + ); + if (myParameterInfoController != null) { + final String doc = ApplicationManager.getApplication().runReadAction( + new NullableComputable() { + @Override + public String compute() { + return generateParameterInfoDocumentation(provider); + } + } + ); + if (doc != null) return doc; + } + if (provider instanceof ExternalDocumentationProvider) { + final List urls = ApplicationManager.getApplication().runReadAction( + new NullableComputable>() { + @Override + public List compute() { + final SmartPsiElementPointer originalElementPtr = myElement.getUserData(ORIGINAL_ELEMENT_KEY); + final PsiElement originalElement = originalElementPtr != null ? originalElementPtr.getElement() : null; + if (((ExternalDocumentationProvider)provider).hasDocumentationFor(myElement, originalElement)) { + return provider.getUrlFor(myElement, originalElement); + } + return null; + } + } + ); + if (urls != null) { + for (String url : urls) { + final String doc = ((ExternalDocumentationProvider)provider).fetchExternalDocumentation(myProject, myElement, Collections.singletonList(url)); + if (doc != null) { + myEffectiveUrl = url; + return doc; + } + } + } + } + return ApplicationManager.getApplication().runReadAction( + new Computable() { + @Override + @Nullable + public String compute() { + final SmartPsiElementPointer originalElement = myElement.getUserData(ORIGINAL_ELEMENT_KEY); + return provider.generateDoc(myElement, originalElement != null ? originalElement.getElement() : null); + } + } + ); + } + + @Nullable + private String generateParameterInfoDocumentation(DocumentationProvider provider) { + final Object[] objects = myParameterInfoController.getSelectedElements(); + + if (objects.length > 0) { + @NonNls StringBuffer sb = null; + + for (Object o : objects) { + PsiElement parameter = null; + if (o instanceof PsiElement) { + parameter = (PsiElement)o; + } + + if (parameter != null) { + final SmartPsiElementPointer originalElement = parameter.getUserData(ORIGINAL_ELEMENT_KEY); + final String str2 = provider.generateDoc(parameter, originalElement != null ? originalElement.getElement() : null); + if (str2 == null) continue; + if (sb == null) sb = new StringBuffer(); + sb.append(str2); + sb.append("
"); + } + else { + sb = null; + break; + } + } + + if (sb != null) return sb.toString(); + } + return null; + } + + @Override + @Nullable + public PsiElement getElement() { + return myElement.isValid() ? myElement : null; + } + + @Nullable + @Override + public String getEffectiveExternalUrl() { + return myEffectiveUrl; + } } } diff --git a/platform/lang-impl/src/com/intellij/ide/actions/ExternalJavaDocAction.java b/platform/lang-impl/src/com/intellij/ide/actions/ExternalJavaDocAction.java index 156e3a1e5d08..71b02f867d8a 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/ExternalJavaDocAction.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/ExternalJavaDocAction.java @@ -37,6 +37,7 @@ import com.intellij.psi.PsiReference; import com.intellij.util.ArrayUtil; import org.jetbrains.annotations.Nullable; +import java.awt.*; import java.util.HashSet; import java.util.List; @@ -79,7 +80,7 @@ public class ExternalJavaDocAction extends AnAction { final List urls = provider.getUrlFor(element, originalElement); if (urls != null && !urls.isEmpty()) { - showExternalJavadoc(urls); + showExternalJavadoc(urls, PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext)); } else if (provider instanceof ExternalDocumentationProvider) { final ExternalDocumentationProvider externalDocumentationProvider = (ExternalDocumentationProvider)provider; @@ -89,7 +90,7 @@ public class ExternalJavaDocAction extends AnAction { } } - public static void showExternalJavadoc(List urls) { + public static void showExternalJavadoc(List urls, Component component) { final HashSet set = new HashSet(urls); if (set.size() > 1) { JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep("Choose external documentation root", ArrayUtil.toStringArray(set)) { @@ -98,7 +99,7 @@ public class ExternalJavaDocAction extends AnAction { BrowserUtil.browse(selectedValue); return FINAL_CHOICE; } - }).showInBestPositionFor(DataManager.getInstance().getDataContext()); + }).showInBestPositionFor(DataManager.getInstance().getDataContext(component)); } else if (set.size() == 1) { BrowserUtil.browse(urls.get(0)); diff --git a/platform/lang-impl/src/com/intellij/refactoring/inline/AbstractInlineLocalDialog.java b/platform/lang-impl/src/com/intellij/refactoring/inline/AbstractInlineLocalDialog.java new file mode 100644 index 000000000000..2bdf0256ef1a --- /dev/null +++ b/platform/lang-impl/src/com/intellij/refactoring/inline/AbstractInlineLocalDialog.java @@ -0,0 +1,58 @@ +/* + * Copyright 2000-2014 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.refactoring.inline; + +import com.intellij.CommonBundle; +import com.intellij.openapi.editor.ex.EditorSettingsExternalizable; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiReference; +import org.jetbrains.annotations.NotNull; + +public abstract class AbstractInlineLocalDialog extends InlineOptionsDialog { + public AbstractInlineLocalDialog(Project project, PsiElement variable, final PsiReference ref, int occurrencesCount) { + super(project, true, variable); + if (ref == null || occurrencesCount == 1) { + setDoNotAskOption(new DoNotAskOption() { + @Override + public boolean isToBeShown() { + return EditorSettingsExternalizable.getInstance().isShowInlineLocalDialog(); + } + + @Override + public void setToBeShown(boolean value, int exitCode) { + EditorSettingsExternalizable.getInstance().setShowInlineLocalDialog(value); + } + + @Override + public boolean canBeHidden() { + return true; + } + + @Override + public boolean shouldSaveOptionsOnCancel() { + return false; + } + + @NotNull + @Override + public String getDoNotShowMessage() { + return CommonBundle.message("dialog.options.do.not.show"); + } + }); + } + } +} diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/ex/EditorSettingsExternalizable.java b/platform/platform-impl/src/com/intellij/openapi/editor/ex/EditorSettingsExternalizable.java index 0f4ba21a227f..590fe8b83b8c 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/ex/EditorSettingsExternalizable.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/ex/EditorSettingsExternalizable.java @@ -73,6 +73,8 @@ public class EditorSettingsExternalizable implements NamedJDOMExternalizable, Ex public boolean RENAME_VARIABLES_INPLACE = true; public boolean PRESELECT_RENAME = true; + public boolean SHOW_INLINE_DIALOG = true; + public boolean REFRAIN_FROM_SCROLLING = false; public boolean SHOW_REFORMAT_DIALOG = true; @@ -522,4 +524,14 @@ public class EditorSettingsExternalizable implements NamedJDOMExternalizable, Ex public void setPreselectRename(final boolean val) { myOptions.PRESELECT_RENAME = val; } + + public boolean isShowInlineLocalDialog() { + return myOptions.SHOW_INLINE_DIALOG; + } + + public void setShowInlineLocalDialog(final boolean val) { + myOptions.SHOW_INLINE_DIALOG = val; + } + + }