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);
}
}
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);
}
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);
}
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));
}
}
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);
}
Aggregations