Search in sources :

Example 6 with InputEvent

use of java.awt.event.InputEvent in project intellij-community by JetBrains.

the class SelectInContextImpl method getEventComponent.

@Nullable
private static JComponent getEventComponent(AnActionEvent event) {
    InputEvent inputEvent = event.getInputEvent();
    Object source;
    if (inputEvent != null && (source = inputEvent.getSource()) instanceof JComponent) {
        return (JComponent) source;
    } else {
        return safeCast(PlatformDataKeys.CONTEXT_COMPONENT.getData(event.getDataContext()), JComponent.class);
    }
}
Also used : InputEvent(java.awt.event.InputEvent) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with InputEvent

use of java.awt.event.InputEvent in project intellij-community by JetBrains.

the class BaseCodeCompletionAction method invokeCompletion.

protected void invokeCompletion(AnActionEvent e, CompletionType type, int time) {
    Project project = e.getData(CommonDataKeys.PROJECT);
    Editor editor = e.getData(CommonDataKeys.EDITOR);
    assert project != null;
    assert editor != null;
    InputEvent inputEvent = e.getInputEvent();
    createHandler(type, true, false, true).invokeCompletion(project, editor, time, inputEvent != null && inputEvent.getModifiers() != 0, false);
}
Also used : Project(com.intellij.openapi.project.Project) InputEvent(java.awt.event.InputEvent) Editor(com.intellij.openapi.editor.Editor)

Example 8 with InputEvent

use of java.awt.event.InputEvent in project intellij-community by JetBrains.

the class JdkPopupAction method actionPerformed.

@Override
public void actionPerformed(final AnActionEvent e) {
    final JComponent component;
    final boolean showInMiddle;
    InputEvent inputEvent = e.getInputEvent();
    Object source = inputEvent != null ? inputEvent.getSource() : null;
    if (source instanceof JComponent) {
        component = (JComponent) source;
        showInMiddle = false;
    } else {
        Component c = e.getData(PlatformDataKeys.CONTEXT_COMPONENT);
        component = c instanceof JComponent ? (JComponent) c : null;
        showInMiddle = true;
    }
    if (!isEnabledInCurrentOS() || component == null)
        return;
    ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
        final ArrayList<Pair<File, String>> jdkLocations = retrieveJDKLocations();
        if (jdkLocations.isEmpty()) {
            return;
        }
        ApplicationManager.getApplication().invokeLater(() -> showPopupMenu(e, jdkLocations, showInMiddle, component));
    }, "Looking for JDK locations...", false, e.getProject(), component);
}
Also used : InputEvent(java.awt.event.InputEvent) Pair(com.intellij.openapi.util.Pair)

Example 9 with InputEvent

use of java.awt.event.InputEvent in project intellij-community by JetBrains.

the class StopAction method actionPerformed.

@Override
public void actionPerformed(final AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    Project project = e.getProject();
    List<Pair<TaskInfo, ProgressIndicator>> cancellableProcesses = getCancellableProcesses(project);
    List<RunContentDescriptor> stoppableDescriptors = getActiveStoppableDescriptors(dataContext);
    if (isPlaceGlobal(e)) {
        int todoSize = cancellableProcesses.size() + stoppableDescriptors.size();
        if (todoSize == 1) {
            if (!stoppableDescriptors.isEmpty()) {
                ExecutionManagerImpl.stopProcess(stoppableDescriptors.get(0));
            } else {
                cancellableProcesses.get(0).second.cancel();
            }
            return;
        }
        Pair<List<HandlerItem>, HandlerItem> handlerItems = getItemsList(cancellableProcesses, stoppableDescriptors, getRecentlyStartedContentDescriptor(dataContext));
        if (handlerItems == null || handlerItems.first.isEmpty()) {
            return;
        }
        final JBList list = new JBList(handlerItems.first);
        if (handlerItems.second != null)
            list.setSelectedValue(handlerItems.second, true);
        list.setCellRenderer(new GroupedItemsListRenderer(new ListItemDescriptorAdapter() {

            @Nullable
            @Override
            public String getTextFor(Object value) {
                return value instanceof HandlerItem ? ((HandlerItem) value).displayName : null;
            }

            @Nullable
            @Override
            public Icon getIconFor(Object value) {
                return value instanceof HandlerItem ? ((HandlerItem) value).icon : null;
            }

            @Override
            public boolean hasSeparatorAboveOf(Object value) {
                return value instanceof HandlerItem && ((HandlerItem) value).hasSeparator;
            }
        }));
        JBPopup popup = JBPopupFactory.getInstance().createListPopupBuilder(list).setMovable(true).setTitle(handlerItems.first.size() == 1 ? "Confirm process stop" : "Stop process").setFilteringEnabled(o -> ((HandlerItem) o).displayName).setItemChoosenCallback(() -> {
            List valuesList = list.getSelectedValuesList();
            for (Object o : valuesList) {
                if (o instanceof HandlerItem)
                    ((HandlerItem) o).stop();
            }
        }).setRequestFocus(true).createPopup();
        InputEvent inputEvent = e.getInputEvent();
        Component component = inputEvent != null ? inputEvent.getComponent() : null;
        if (component != null && ActionPlaces.MAIN_TOOLBAR.equals(e.getPlace())) {
            popup.showUnderneathOf(component);
        } else if (project == null) {
            popup.showInBestPositionFor(dataContext);
        } else {
            popup.showCenteredInCurrentWindow(project);
        }
    } else {
        ExecutionManagerImpl.stopProcess(getRecentlyStartedContentDescriptor(dataContext));
    }
}
Also used : InputEvent(java.awt.event.InputEvent) AllIcons(com.intellij.icons.AllIcons) ExecutionManager(com.intellij.execution.ExecutionManager) ArrayList(java.util.ArrayList) Project(com.intellij.openapi.project.Project) ExecutionBundle(com.intellij.execution.ExecutionBundle) JBList(com.intellij.ui.components.JBList) TaskInfo(com.intellij.openapi.progress.TaskInfo) StringUtil(com.intellij.openapi.util.text.StringUtil) ListItemDescriptorAdapter(com.intellij.openapi.ui.popup.ListItemDescriptorAdapter) RunProfile(com.intellij.execution.configurations.RunProfile) JBPopup(com.intellij.openapi.ui.popup.JBPopup) ProcessHandler(com.intellij.execution.process.ProcessHandler) KillableProcess(com.intellij.execution.KillableProcess) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) List(java.util.List) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) GroupedItemsListRenderer(com.intellij.ui.popup.list.GroupedItemsListRenderer) Pair(com.intellij.openapi.util.Pair) ExecutionManagerImpl(com.intellij.execution.impl.ExecutionManagerImpl) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) IconUtil(com.intellij.util.IconUtil) javax.swing(javax.swing) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ListItemDescriptorAdapter(com.intellij.openapi.ui.popup.ListItemDescriptorAdapter) Project(com.intellij.openapi.project.Project) GroupedItemsListRenderer(com.intellij.ui.popup.list.GroupedItemsListRenderer) ArrayList(java.util.ArrayList) JBList(com.intellij.ui.components.JBList) List(java.util.List) JBList(com.intellij.ui.components.JBList) InputEvent(java.awt.event.InputEvent) JBPopup(com.intellij.openapi.ui.popup.JBPopup) Pair(com.intellij.openapi.util.Pair)

Example 10 with InputEvent

use of java.awt.event.InputEvent in project intellij-community by JetBrains.

the class OpenInEditorWithMouseAction method update.

@Override
public void update(@NotNull AnActionEvent e) {
    InputEvent inputEvent = e.getInputEvent();
    if (!(inputEvent instanceof MouseEvent)) {
        e.getPresentation().setEnabledAndVisible(false);
        return;
    }
    if (e.getProject() == null) {
        e.getPresentation().setEnabledAndVisible(false);
        return;
    }
    if (e.getData(OpenInEditorAction.KEY) == null) {
        e.getPresentation().setEnabledAndVisible(false);
        return;
    }
    Component component = inputEvent.getComponent();
    if (component == null) {
        e.getPresentation().setEnabledAndVisible(false);
        return;
    }
    Point point = ((MouseEvent) inputEvent).getPoint();
    Component componentAt = SwingUtilities.getDeepestComponentAt(component, point.x, point.y);
    if (!(componentAt instanceof EditorGutterComponentEx)) {
        e.getPresentation().setEnabledAndVisible(false);
        return;
    }
    Editor editor = getEditor(componentAt);
    if (editor == null) {
        e.getPresentation().setEnabledAndVisible(false);
        return;
    }
    MouseEvent convertedEvent = SwingUtilities.convertMouseEvent(inputEvent.getComponent(), (MouseEvent) inputEvent, componentAt);
    EditorMouseEventArea area = editor.getMouseEventArea(convertedEvent);
    if (area != EditorMouseEventArea.LINE_NUMBERS_AREA) {
        e.getPresentation().setEnabledAndVisible(false);
        return;
    }
    e.getPresentation().setEnabledAndVisible(true);
}
Also used : EditorGutterComponentEx(com.intellij.openapi.editor.ex.EditorGutterComponentEx) MouseEvent(java.awt.event.MouseEvent) InputEvent(java.awt.event.InputEvent) EditorMouseEventArea(com.intellij.openapi.editor.event.EditorMouseEventArea) Editor(com.intellij.openapi.editor.Editor)

Aggregations

InputEvent (java.awt.event.InputEvent)21 MouseEvent (java.awt.event.MouseEvent)7 Editor (com.intellij.openapi.editor.Editor)4 Project (com.intellij.openapi.project.Project)4 NotNull (org.jetbrains.annotations.NotNull)4 ListPopup (com.intellij.openapi.ui.popup.ListPopup)3 AWTEvent (java.awt.AWTEvent)3 ActionEvent (java.awt.event.ActionEvent)3 Presentation (com.intellij.openapi.actionSystem.Presentation)2 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)2 ActionCallback (com.intellij.openapi.util.ActionCallback)2 Pair (com.intellij.openapi.util.Pair)2 JBList (com.intellij.ui.components.JBList)2 Nullable (org.jetbrains.annotations.Nullable)2 ExecutionBundle (com.intellij.execution.ExecutionBundle)1 ExecutionManager (com.intellij.execution.ExecutionManager)1 Executor (com.intellij.execution.Executor)1 KillableProcess (com.intellij.execution.KillableProcess)1 Location (com.intellij.execution.Location)1 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1