diff --git a/java/idea-ui/src/com/intellij/codeInsight/daemon/impl/AttachSourcesNotificationProvider.java b/java/idea-ui/src/com/intellij/codeInsight/daemon/impl/AttachSourcesNotificationProvider.java index 0561b125e0e6..8c486c97c938 100644 --- a/java/idea-ui/src/com/intellij/codeInsight/daemon/impl/AttachSourcesNotificationProvider.java +++ b/java/idea-ui/src/com/intellij/codeInsight/daemon/impl/AttachSourcesNotificationProvider.java @@ -108,20 +108,35 @@ public class AttachSourcesNotificationProvider implements EditorNotifications.Pr defaultAction = new ChooseAndAttachSourcesAction(myProject, panel); } - TreeSet actions = new TreeSet( - new Comparator() { - public int compare(AttachSourcesProvider.AttachSourcesAction o1, AttachSourcesProvider.AttachSourcesAction o2) { - if (o1 == defaultAction) return 1; - if (o2 == defaultAction) return -1; - return o1.getName().compareToIgnoreCase(o2.getName()); + List actions = new ArrayList(); + + boolean hasNonLightAction = false; + + for (AttachSourcesProvider each : Extensions.getExtensions(EXTENSION_POINT_NAME)) { + for (AttachSourcesProvider.AttachSourcesAction action : each.getActions(libraries, psiFile)) { + if (hasNonLightAction) { + if (action instanceof AttachSourcesProvider.LightAttachSourcesAction) { + continue; // Don't add LightAttachSourcesAction if non light action exists. + } } + else { + if (!(action instanceof AttachSourcesProvider.LightAttachSourcesAction)) { + actions.clear(); // All previous actions is LightAttachSourcesAction and should be removed. + hasNonLightAction = true; + } + } + + actions.add(action); } - ); + } + + Collections.sort(actions, new Comparator() { + public int compare(AttachSourcesProvider.AttachSourcesAction o1, AttachSourcesProvider.AttachSourcesAction o2) { + return o1.getName().compareToIgnoreCase(o2.getName()); + } + }); actions.add(defaultAction); - for (AttachSourcesProvider each : Extensions.getExtensions(EXTENSION_POINT_NAME)) { - actions.addAll(each.getActions(libraries, psiFile)); - } for (final AttachSourcesProvider.AttachSourcesAction each : actions) { panel.createActionLabel(GuiUtils.getTextWithoutMnemonicEscaping(each.getName()), new Runnable() { diff --git a/java/openapi/src/com/intellij/codeInsight/AttachSourcesProvider.java b/java/openapi/src/com/intellij/codeInsight/AttachSourcesProvider.java index 7604b2ec4410..2bfdbb1fc738 100644 --- a/java/openapi/src/com/intellij/codeInsight/AttachSourcesProvider.java +++ b/java/openapi/src/com/intellij/codeInsight/AttachSourcesProvider.java @@ -32,4 +32,12 @@ public interface AttachSourcesProvider { String getBusyText(); ActionCallback perform(List orderEntriesContainingFile); } + + /** + * This marker interface means what this action will be shown only if it is single action. + */ + interface LightAttachSourcesAction extends AttachSourcesAction { + + } + } diff --git a/platform/platform-api/src/com/intellij/util/net/NetUtils.java b/platform/platform-api/src/com/intellij/util/net/NetUtils.java index 610b4b5d78eb..cc36bd8264af 100644 --- a/platform/platform-api/src/com/intellij/util/net/NetUtils.java +++ b/platform/platform-api/src/com/intellij/util/net/NetUtils.java @@ -102,7 +102,8 @@ public class NetUtils { * @param outputStream destination stream * @param expectedContentSize expected content size, used in progress indicator. can be -1. * @return bytes copied - * @throws IOException + * @throws IOException if IO error occur + * @throws com.intellij.openapi.progress.ProcessCanceledException if process was canceled. */ public static int copyStreamContent(@Nullable ProgressIndicator indicator, InputStream inputStream, @@ -129,6 +130,10 @@ public class NetUtils { } } + if (indicator != null) { + indicator.checkCanceled(); + } + return total; }