use of com.intellij.openapi.actionSystem.AnActionEvent in project intellij-community by JetBrains.
the class EditorNotificationPanel method executeAction.
protected void executeAction(final String actionId) {
final AnAction action = ActionManager.getInstance().getAction(actionId);
final AnActionEvent event = AnActionEvent.createFromAnAction(action, null, ActionPlaces.UNKNOWN, DataManager.getInstance().getDataContext(this));
action.beforeActionPerformedUpdate(event);
action.update(event);
if (event.getPresentation().isEnabled() && event.getPresentation().isVisible()) {
action.actionPerformed(event);
}
}
use of com.intellij.openapi.actionSystem.AnActionEvent in project intellij-community by JetBrains.
the class QuickChangeLookAndFeel method fillActions.
protected void fillActions(Project project, @NotNull DefaultActionGroup group, @NotNull DataContext dataContext) {
LafManager lafMan = LafManager.getInstance();
UIManager.LookAndFeelInfo[] lfs = lafMan.getInstalledLookAndFeels();
UIManager.LookAndFeelInfo current = lafMan.getCurrentLookAndFeel();
for (UIManager.LookAndFeelInfo lf : lfs) {
group.add(new DumbAwareAction(lf.getName(), "", lf == current ? ourCurrentAction : ourNotCurrentAction) {
public void actionPerformed(AnActionEvent e) {
switchLafAndUpdateUI(lafMan, lf);
}
});
}
}
use of com.intellij.openapi.actionSystem.AnActionEvent in project intellij-community by JetBrains.
the class BalloonImpl method show.
private void show(PositionTracker<Balloon> tracker, AbstractPosition position) {
assert !myDisposed : "Balloon is already disposed";
if (isVisible())
return;
final Component comp = tracker.getComponent();
if (!comp.isShowing())
return;
myTracker = tracker;
myTracker.init(this);
JRootPane root = ObjectUtils.notNull(UIUtil.getRootPane(comp));
myVisible = true;
myLayeredPane = root.getLayeredPane();
myPosition = position;
UIUtil.setFutureRootPane(myContent, root);
myFocusManager = IdeFocusManager.findInstanceByComponent(myLayeredPane);
final Ref<Component> originalFocusOwner = new Ref<>();
final Ref<FocusRequestor> focusRequestor = new Ref<>();
final Ref<ActionCallback> proxyFocusRequest = new Ref<>(ActionCallback.DONE);
boolean mnemonicsFix = myDialogMode && SystemInfo.isMac && Registry.is("ide.mac.inplaceDialogMnemonicsFix");
if (mnemonicsFix) {
final IdeGlassPaneEx glassPane = (IdeGlassPaneEx) IdeGlassPaneUtil.find(myLayeredPane);
assert glassPane != null;
proxyFocusRequest.set(new ActionCallback());
myFocusManager.doWhenFocusSettlesDown(new ExpirableRunnable() {
@Override
public boolean isExpired() {
return isDisposed();
}
@Override
public void run() {
IdeEventQueue.getInstance().disableInputMethods(BalloonImpl.this);
originalFocusOwner.set(myFocusManager.getFocusOwner());
focusRequestor.set(myFocusManager.getFurtherRequestor());
}
});
}
if (myRequestFocus) {
myFocusManager.doWhenFocusSettlesDown(new ExpirableRunnable() {
@Override
public boolean isExpired() {
return isDisposed();
}
@Override
public void run() {
myOriginalFocusOwner = myFocusManager.getFocusOwner();
// Set the accessible parent so that screen readers don't announce
// a window context change -- the tooltip is "logically" hosted
// inside the component (e.g. editor) it appears on top of.
AccessibleContextUtil.setParent(myContent, myOriginalFocusOwner);
// Set the focus to "myContent"
myFocusManager.requestFocus(getContentToFocus(), true);
}
});
}
myLayeredPane.addComponentListener(myComponentListener);
myTargetPoint = myPosition.getShiftedPoint(myTracker.recalculateLocation(this).getPoint(myLayeredPane), myCalloutShift);
int positionChangeFix = 0;
if (myShowPointer) {
Rectangle rec = getRecForPosition(myPosition, true);
if (!myPosition.isOkToHavePointer(myTargetPoint, rec, getPointerLength(myPosition), getPointerWidth(myPosition), getArc())) {
rec = getRecForPosition(myPosition, false);
Rectangle lp = new Rectangle(new Point(myContainerInsets.left, myContainerInsets.top), myLayeredPane.getSize());
lp.width -= myContainerInsets.right;
lp.height -= myContainerInsets.bottom;
if (!lp.contains(rec)) {
Rectangle2D currentSquare = lp.createIntersection(rec);
double maxSquare = currentSquare.getWidth() * currentSquare.getHeight();
AbstractPosition targetPosition = myPosition;
for (AbstractPosition eachPosition : myPosition.getOtherPositions()) {
Rectangle2D eachIntersection = lp.createIntersection(getRecForPosition(eachPosition, false));
double eachSquare = eachIntersection.getWidth() * eachIntersection.getHeight();
if (maxSquare < eachSquare) {
maxSquare = eachSquare;
targetPosition = eachPosition;
}
}
myPosition = targetPosition;
positionChangeFix = myPosition.getChangeShift(position, myPositionChangeXShift, myPositionChangeYShift);
}
}
}
if (myPosition != position) {
myTargetPoint = myPosition.getShiftedPoint(myTracker.recalculateLocation(this).getPoint(myLayeredPane), myCalloutShift > 0 ? myCalloutShift + positionChangeFix : positionChangeFix);
}
createComponent();
myComp.validate();
Rectangle rec = myComp.getContentBounds();
if (myShowPointer && !myPosition.isOkToHavePointer(myTargetPoint, rec, getPointerLength(myPosition), getPointerWidth(myPosition), getArc())) {
myShowPointer = false;
myComp.removeAll();
myLayeredPane.remove(myComp);
createComponent();
if (!new Rectangle(myLayeredPane.getSize()).contains(new Rectangle(myComp.getSize()))) {
// Balloon is bigger than window, don't show it at all.
myComp.removeAll();
myLayeredPane.remove(myComp);
myLayeredPane = null;
hide();
return;
}
}
for (JBPopupListener each : myListeners) {
each.beforeShown(new LightweightWindowEvent(this));
}
runAnimation(true, myLayeredPane, null);
myLayeredPane.revalidate();
myLayeredPane.repaint();
if (mnemonicsFix) {
proxyFocusRequest.get().doWhenDone(() -> myFocusManager.requestFocus(originalFocusOwner.get(), true));
}
Toolkit.getDefaultToolkit().addAWTEventListener(myAwtActivityListener, AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK | AWTEvent.KEY_EVENT_MASK);
if (ApplicationManager.getApplication() != null) {
ActionManager.getInstance().addAnActionListener(new AnActionListener.Adapter() {
@Override
public void beforeActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) {
if (myHideOnAction) {
hide();
}
}
}, this);
}
if (myHideOnLinkClick) {
JEditorPane editorPane = UIUtil.uiTraverser(myContent).traverse().filter(JEditorPane.class).first();
if (editorPane != null) {
editorPane.addHyperlinkListener(new HyperlinkAdapter() {
@Override
protected void hyperlinkActivated(HyperlinkEvent e) {
hide();
}
});
}
}
}
use of com.intellij.openapi.actionSystem.AnActionEvent in project intellij-community by JetBrains.
the class OpenSelectedProjectsAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
List<AnAction> elements = getSelectedElements(e);
e = new AnActionEvent(e.getInputEvent(), e.getDataContext(), e.getPlace(), e.getPresentation(), e.getActionManager(), InputEvent.SHIFT_MASK);
for (AnAction element : elements) {
if (element instanceof ProjectGroupActionGroup) {
for (AnAction action : ((ProjectGroupActionGroup) element).getChildren(e)) {
action.actionPerformed(e);
}
} else {
element.actionPerformed(e);
}
}
}
use of com.intellij.openapi.actionSystem.AnActionEvent in project intellij-community by JetBrains.
the class LocalHistoryActionsTest method assertStatus.
private void assertStatus(AnAction a, VirtualFile[] files, Project p, boolean isEnabled) {
AnActionEvent e = createEventFor(a, files, p);
a.update(e);
assertEquals(isEnabled, e.getPresentation().isEnabled());
}
Aggregations