Lines 65-70
Link Here
|
65 |
import java.awt.event.*; |
65 |
import java.awt.event.*; |
66 |
import java.awt.font.FontRenderContext; |
66 |
import java.awt.font.FontRenderContext; |
67 |
import java.awt.font.TextLayout; |
67 |
import java.awt.font.TextLayout; |
|
|
68 |
import java.util.ArrayList; |
69 |
import java.util.Arrays; |
70 |
import java.util.Collection; |
71 |
import java.util.Collections; |
72 |
import java.util.HashSet; |
73 |
import java.util.LinkedList; |
74 |
import java.util.List; |
68 |
import java.util.Map; |
75 |
import java.util.Map; |
69 |
import java.util.logging.Level; |
76 |
import java.util.logging.Level; |
70 |
import java.util.logging.Logger; |
77 |
import java.util.logging.Logger; |
Lines 88-93
Link Here
|
88 |
import org.netbeans.api.editor.settings.EditorStyleConstants; |
95 |
import org.netbeans.api.editor.settings.EditorStyleConstants; |
89 |
import org.netbeans.api.editor.settings.FontColorNames; |
96 |
import org.netbeans.api.editor.settings.FontColorNames; |
90 |
import org.netbeans.api.editor.settings.FontColorSettings; |
97 |
import org.netbeans.api.editor.settings.FontColorSettings; |
|
|
98 |
import org.netbeans.editor.AnnotationType.CombinationMember; |
99 |
import org.netbeans.editor.Annotations.AnnotationCombination; |
91 |
import org.netbeans.modules.editor.lib.ColoringMap; |
100 |
import org.netbeans.modules.editor.lib.ColoringMap; |
92 |
import org.netbeans.modules.editor.lib2.view.*; |
101 |
import org.netbeans.modules.editor.lib2.view.*; |
93 |
import org.openide.util.ImageUtilities; |
102 |
import org.openide.util.ImageUtilities; |
Lines 874-906
Link Here
|
874 |
annos.activateNextAnnotation(line); |
883 |
annos.activateNextAnnotation(line); |
875 |
} else { |
884 |
} else { |
876 |
Action actions[] = ImplementationProvider.getDefault().getGlyphGutterActions(eui.getComponent()); |
885 |
Action actions[] = ImplementationProvider.getDefault().getGlyphGutterActions(eui.getComponent()); |
877 |
if (actions != null && actions.length >0) { |
886 |
if (actions == null && actions.length == 0) { |
878 |
Action a = actions[0]; //TODO - create GUI chooser |
887 |
Toolkit.getDefaultToolkit().beep(); |
879 |
if (a!=null && a.isEnabled()){ |
888 |
return; |
880 |
int currentLine = -1; |
889 |
} |
881 |
int line = getLineFromMouseEvent(e); |
890 |
int currentLine = -1; |
882 |
if (line == -1) return; |
891 |
int line = getLineFromMouseEvent(e); |
883 |
BaseDocument document = eui.getDocument(); |
892 |
if (line == -1) { |
884 |
try { |
893 |
Toolkit.getDefaultToolkit().beep(); |
885 |
currentLine = Utilities.getLineOffset(document, eui.getComponent().getCaret().getDot()); |
894 |
return; |
886 |
} catch (BadLocationException ex) { |
895 |
} |
887 |
return; |
896 |
Action toInvoke = null; |
|
|
897 |
Action defaultAction = null; |
898 |
AnnotationDesc active = annos.getActiveAnnotation(line); |
899 |
if (active == null || !isMouseOverGlyph(e)) { |
900 |
Collection<AnnotationDesc> base = new HashSet<AnnotationDesc>(); |
901 |
if (active != null) { |
902 |
base.add(active); |
903 |
} |
904 |
AnnotationDesc[] passive = annos.getPasiveAnnotations(line); |
905 |
if (passive != null) { |
906 |
base.addAll(Arrays.asList(passive)); |
907 |
} |
908 |
Collection<String> annotationTypes = computeAnnotationTypesToAnalyze(base); |
909 |
for (Action a : actions) { |
910 |
Object defAction = a.getValue("default-action"); |
911 |
if (toInvoke == null && defAction != null && ((Boolean) defAction)) { |
912 |
Object supportedAnnotationTypes = a.getValue("default-action-excluded-annotation-types"); |
913 |
if (supportedAnnotationTypes == null || !(supportedAnnotationTypes instanceof String[]) || Collections.disjoint(Arrays.asList((String[]) supportedAnnotationTypes), annotationTypes)) { |
914 |
toInvoke = a; |
915 |
} |
888 |
} |
916 |
} |
889 |
if (line != currentLine) { |
917 |
if (defaultAction == null && isLegacyAction(a)) { |
890 |
int offset = Utilities.getRowStartFromLineOffset(document, line); |
918 |
defaultAction = a; |
891 |
JumpList.checkAddEntry(); |
|
|
892 |
eui.getComponent().getCaret().setDot(offset); |
893 |
} |
919 |
} |
894 |
e.consume(); |
|
|
895 |
a.actionPerformed(new ActionEvent(eui.getComponent(), 0, "")); |
896 |
repaint(); |
897 |
} |
920 |
} |
898 |
} else { |
921 |
} else { |
|
|
922 |
Collection<String> annotationTypes = computeAnnotationTypesToAnalyze(Arrays.asList(active)); |
923 |
for (Action a : actions) { |
924 |
Object supportedAnnotationTypes = a.getValue("supported-annotation-types"); |
925 |
if (supportedAnnotationTypes instanceof String[]) { |
926 |
if (toInvoke == null && !Collections.disjoint(Arrays.asList((String[]) supportedAnnotationTypes), annotationTypes)) { |
927 |
toInvoke = a; |
928 |
} |
929 |
if (defaultAction == null && isLegacyAction(a)) { |
930 |
defaultAction = a; |
931 |
} |
932 |
} |
933 |
} |
934 |
} |
935 |
toInvoke = toInvoke != null ? toInvoke : defaultAction; |
936 |
if (toInvoke != null && toInvoke.isEnabled()){ |
937 |
BaseDocument document = eui.getDocument(); |
938 |
try { |
939 |
currentLine = Utilities.getLineOffset(document, eui.getComponent().getCaret().getDot()); |
940 |
} catch (BadLocationException ex) { |
941 |
return; |
942 |
} |
943 |
if (line != currentLine) { |
944 |
int offset = Utilities.getRowStartFromLineOffset(document, line); |
945 |
JumpList.checkAddEntry(); |
946 |
eui.getComponent().getCaret().setDot(offset); |
947 |
} |
948 |
e.consume(); |
949 |
toInvoke.actionPerformed(new ActionEvent(eui.getComponent(), 0, "")); |
950 |
repaint(); |
951 |
} else { |
899 |
Toolkit.getDefaultToolkit().beep(); |
952 |
Toolkit.getDefaultToolkit().beep(); |
900 |
} |
953 |
} |
901 |
} |
954 |
} |
902 |
} |
955 |
} |
903 |
} |
956 |
} |
|
|
957 |
|
958 |
private boolean isLegacyAction(Action a) { |
959 |
return a.getValue("default-action") == null && a.getValue("supported-annotation-types") == null; |
960 |
} |
961 |
|
962 |
private Collection<String> computeAnnotationTypesToAnalyze(Collection<AnnotationDesc> startAt) { |
963 |
Collection<String> annotationTypes = new HashSet<String>(); |
964 |
List<AnnotationDesc> combinationsToAnalyze = new LinkedList<AnnotationDesc>(startAt); |
965 |
|
966 |
while (!combinationsToAnalyze.isEmpty()) { |
967 |
AnnotationDesc desc = combinationsToAnalyze.remove(0); |
968 |
|
969 |
annotationTypes.add(desc.getAnnotationType()); |
970 |
|
971 |
if (!(desc instanceof AnnotationCombination)) continue; |
972 |
|
973 |
combinationsToAnalyze.addAll(((AnnotationCombination) desc).getCombinedAnnotations()); |
974 |
} |
975 |
|
976 |
return annotationTypes; |
977 |
} |
904 |
|
978 |
|
905 |
private void showPopup(MouseEvent e) { |
979 |
private void showPopup(MouseEvent e) { |
906 |
final EditorUI eui = editorUI; |
980 |
final EditorUI eui = editorUI; |