use of com.intellij.openapi.editor.markup.GutterIconRenderer in project intellij-community by JetBrains.
the class PyExecuteFileLineMarkerProvider method collectSlowLineMarkers.
@Override
public void collectSlowLineMarkers(@NotNull List<PsiElement> elements, @NotNull Collection<LineMarkerInfo> result) {
if (elements.isEmpty()) {
return;
}
Optional<PsiElement> psiElement = elements.stream().filter((element) -> element instanceof PsiFile).findFirst();
if (!psiElement.isPresent())
return;
final PsiElement file = psiElement.get();
final RunContextAction runAction = new PyStudyRunContextAction(DefaultRunExecutor.getRunExecutorInstance());
final PyExecuteFileExtensionPoint[] extensions = ApplicationManager.getApplication().getExtensions(PyExecuteFileExtensionPoint.EP_NAME);
final List<AnAction> actions = new ArrayList<>();
final DefaultActionGroup group = new DefaultActionGroup();
if (PlatformUtils.isPyCharmEducational()) {
group.add(runAction);
}
for (PyExecuteFileExtensionPoint extension : extensions) {
AnAction action = extension.getRunAction();
if (action != null && extension.accept(file.getProject())) {
actions.add(action);
group.add(action);
}
}
if (actions.isEmpty() && !PlatformUtils.isPyCharmEducational()) {
return;
}
Icon icon = PlatformUtils.isPyCharmEducational() ? AllIcons.Actions.Execute : actions.get(0).getTemplatePresentation().getIcon();
final LineMarkerInfo<PsiElement> markerInfo = new LineMarkerInfo<PsiElement>(file, file.getTextRange(), icon, Pass.LINE_MARKERS, e -> {
String text = "Execute '" + e.getContainingFile().getName() + "'";
return PlatformUtils.isPyCharmEducational() ? text : actions.get(0).getTemplatePresentation().getText();
}, null, GutterIconRenderer.Alignment.RIGHT) {
@Nullable
@Override
public GutterIconRenderer createGutterRenderer() {
return new LineMarkerGutterIconRenderer<PsiElement>(this) {
@Override
public AnAction getClickAction() {
return PlatformUtils.isPyCharmEducational() ? runAction : actions.get(0);
}
@Nullable
@Override
public ActionGroup getPopupMenuActions() {
if (!PlatformUtils.isPyCharmEducational() && actions.isEmpty()) {
return null;
}
if (actions.size() == 1) {
return null;
}
return group;
}
};
}
};
result.add(markerInfo);
}
use of com.intellij.openapi.editor.markup.GutterIconRenderer in project intellij-community by JetBrains.
the class EditorImpl method handleDrop.
static boolean handleDrop(@NotNull EditorImpl editor, @NotNull final Transferable t, int dropAction) {
final EditorDropHandler dropHandler = editor.getDropHandler();
if (Registry.is("debugger.click.disable.breakpoints")) {
try {
if (t.isDataFlavorSupported(GutterDraggableObject.flavor)) {
Object attachedObject = t.getTransferData(GutterDraggableObject.flavor);
if (attachedObject instanceof GutterIconRenderer) {
GutterDraggableObject object = ((GutterIconRenderer) attachedObject).getDraggableObject();
if (object != null) {
object.remove();
Point mouseLocationOnScreen = MouseInfo.getPointerInfo().getLocation();
JComponent editorComponent = editor.getComponent();
Point editorComponentLocationOnScreen = editorComponent.getLocationOnScreen();
IdeGlassPaneUtil.installPainter(editorComponent, new ExplosionPainter(new Point(mouseLocationOnScreen.x - editorComponentLocationOnScreen.x, mouseLocationOnScreen.y - editorComponentLocationOnScreen.y), editor.getGutterComponentEx().getDragImage((GutterIconRenderer) attachedObject)), editor.getDisposable());
return true;
}
}
}
} catch (UnsupportedFlavorException | IOException e) {
LOG.warn(e);
}
}
if (dropHandler != null && dropHandler.canHandleDrop(t.getTransferDataFlavors())) {
dropHandler.handleDrop(t, editor.getProject(), null, dropAction);
return true;
}
final int caretOffset = editor.getCaretModel().getOffset();
if (editor.myDraggedRange != null && editor.myDraggedRange.getStartOffset() <= caretOffset && caretOffset < editor.myDraggedRange.getEndOffset()) {
return false;
}
if (editor.myDraggedRange != null) {
editor.getCaretModel().moveToOffset(editor.mySavedCaretOffsetForDNDUndoHack);
}
CommandProcessor.getInstance().executeCommand(editor.myProject, () -> {
try {
editor.getSelectionModel().removeSelection();
final int offset;
if (editor.myDraggedRange != null) {
editor.getCaretModel().moveToOffset(caretOffset);
offset = caretOffset;
} else {
offset = editor.getCaretModel().getOffset();
}
if (editor.getDocument().getRangeGuard(offset, offset) != null) {
return;
}
editor.putUserData(LAST_PASTED_REGION, null);
EditorActionHandler pasteHandler = EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_PASTE);
LOG.assertTrue(pasteHandler instanceof EditorTextInsertHandler);
((EditorTextInsertHandler) pasteHandler).execute(editor, editor.getDataContext(), () -> t);
TextRange range = editor.getUserData(LAST_PASTED_REGION);
if (range != null) {
editor.getCaretModel().moveToOffset(range.getStartOffset());
editor.getSelectionModel().setSelection(range.getStartOffset(), range.getEndOffset());
}
} catch (Exception exception) {
LOG.error(exception);
}
}, EditorBundle.message("paste.command.name"), DND_COMMAND_KEY, UndoConfirmationPolicy.DEFAULT, editor.getDocument());
return true;
}
use of com.intellij.openapi.editor.markup.GutterIconRenderer in project intellij-community by JetBrains.
the class XBreakpointUtil method findSelectedBreakpoint.
@NotNull
public static Pair<GutterIconRenderer, Object> findSelectedBreakpoint(@NotNull final Project project, @NotNull final Editor editor) {
int offset = editor.getCaretModel().getOffset();
Document editorDocument = editor.getDocument();
DebuggerSupport[] debuggerSupports = DebuggerSupport.getDebuggerSupports();
for (DebuggerSupport debuggerSupport : debuggerSupports) {
final BreakpointPanelProvider<?> provider = debuggerSupport.getBreakpointPanelProvider();
final int textLength = editor.getDocument().getTextLength();
if (offset > textLength) {
offset = textLength;
}
Object breakpoint = provider.findBreakpoint(project, editorDocument, offset);
if (breakpoint != null) {
final GutterIconRenderer iconRenderer = provider.getBreakpointGutterIconRenderer(breakpoint);
return Pair.create(iconRenderer, breakpoint);
}
}
return Pair.create(null, null);
}
use of com.intellij.openapi.editor.markup.GutterIconRenderer in project android by JetBrains.
the class AndroidColorAnnotatorTest method checkAnnotationColor.
private static void checkAnnotationColor(Annotation annotation, Color expectedColor) {
GutterIconRenderer renderer = annotation.getGutterIconRenderer();
assertThat(renderer).isNotNull();
Icon icon = renderer.getIcon();
assertThat(icon).isInstanceOf(ColorIcon.class);
ColorIcon colorIcon = (ColorIcon) icon;
Color color = colorIcon.getIconColor();
assertThat(color).isEqualTo(expectedColor);
}
use of com.intellij.openapi.editor.markup.GutterIconRenderer in project intellij-community by JetBrains.
the class GutterIntentionAction method addActions.
private static void addActions(@NotNull Project project, @NotNull RangeHighlighterEx info, @NotNull List<HighlightInfo.IntentionActionDescriptor> descriptors, @NotNull AnActionEvent event) {
final GutterIconRenderer r = info.getGutterIconRenderer();
if (r == null || DumbService.isDumb(project) && !DumbService.isDumbAware(r)) {
return;
}
List<HighlightInfo.IntentionActionDescriptor> list = new ArrayList<>();
for (AnAction action : ar(r.getClickAction(), r.getMiddleButtonClickAction(), r.getRightButtonClickAction(), r.getPopupMenuActions())) {
if (action != null) {
addActions(action, list, r, 0, event);
}
}
if (list.isEmpty())
return;
if (list.size() == 1) {
descriptors.addAll(list);
} else {
HighlightInfo.IntentionActionDescriptor first = list.get(0);
List<IntentionAction> options = ContainerUtil.map(list.subList(1, list.size()), HighlightInfo.IntentionActionDescriptor::getAction);
descriptors.add(new HighlightInfo.IntentionActionDescriptor(first.getAction(), options, null, first.getIcon()));
}
}
Aggregations