Search in sources :

Example 1 with GutterIconRenderer

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);
}
Also used : AllIcons(com.intellij.icons.AllIcons) GutterIconRenderer(com.intellij.openapi.editor.markup.GutterIconRenderer) Collection(java.util.Collection) PlatformUtils(com.intellij.util.PlatformUtils) AnAction(com.intellij.openapi.actionSystem.AnAction) RunContextAction(com.intellij.execution.actions.RunContextAction) ActionGroup(com.intellij.openapi.actionSystem.ActionGroup) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) Pass(com.intellij.codeHighlighting.Pass) ArrayList(java.util.ArrayList) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) PsiElement(com.intellij.psi.PsiElement) ApplicationManager(com.intellij.openapi.application.ApplicationManager) PsiFile(com.intellij.psi.PsiFile) Optional(java.util.Optional) LineMarkerProvider(com.intellij.codeInsight.daemon.LineMarkerProvider) NotNull(org.jetbrains.annotations.NotNull) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) javax.swing(javax.swing) RunContextAction(com.intellij.execution.actions.RunContextAction) ArrayList(java.util.ArrayList) AnAction(com.intellij.openapi.actionSystem.AnAction) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement)

Example 2 with GutterIconRenderer

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;
}
Also used : GutterDraggableObject(com.intellij.openapi.editor.markup.GutterDraggableObject) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) GutterDraggableObject(com.intellij.openapi.editor.markup.GutterDraggableObject) GutterIconRenderer(com.intellij.openapi.editor.markup.GutterIconRenderer)

Example 3 with GutterIconRenderer

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);
}
Also used : Document(com.intellij.openapi.editor.Document) DebuggerSupport(com.intellij.xdebugger.impl.DebuggerSupport) GutterIconRenderer(com.intellij.openapi.editor.markup.GutterIconRenderer) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with GutterIconRenderer

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);
}
Also used : ColorIcon(com.intellij.util.ui.ColorIcon) ColorIcon(com.intellij.util.ui.ColorIcon) GutterIconRenderer(com.intellij.openapi.editor.markup.GutterIconRenderer)

Example 5 with GutterIconRenderer

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()));
    }
}
Also used : AbstractIntentionAction(com.intellij.codeInsight.intention.AbstractIntentionAction) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) ArrayList(java.util.ArrayList) GutterIconRenderer(com.intellij.openapi.editor.markup.GutterIconRenderer)

Aggregations

GutterIconRenderer (com.intellij.openapi.editor.markup.GutterIconRenderer)11 ActionGroup (com.intellij.openapi.actionSystem.ActionGroup)3 AnAction (com.intellij.openapi.actionSystem.AnAction)3 PsiElement (com.intellij.psi.PsiElement)3 NotNull (org.jetbrains.annotations.NotNull)3 Pass (com.intellij.codeHighlighting.Pass)2 LineMarkerInfo (com.intellij.codeInsight.daemon.LineMarkerInfo)2 AllIcons (com.intellij.icons.AllIcons)2 DataContext (com.intellij.openapi.actionSystem.DataContext)2 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)2 Document (com.intellij.openapi.editor.Document)2 Editor (com.intellij.openapi.editor.Editor)2 PsiFile (com.intellij.psi.PsiFile)2 ColorIcon (com.intellij.util.ui.ColorIcon)2 ArrayList (java.util.ArrayList)2 javax.swing (javax.swing)2 Nullable (org.jetbrains.annotations.Nullable)2 GutterMark (com.intellij.codeInsight.daemon.GutterMark)1 LineMarkerProvider (com.intellij.codeInsight.daemon.LineMarkerProvider)1 LineMarkerProviderDescriptor (com.intellij.codeInsight.daemon.LineMarkerProviderDescriptor)1