mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
get DataContext from correct place when ActionButton shows a popup menu (IDEA-79386)
This commit is contained in:
+10
-3
@@ -21,6 +21,7 @@ import com.intellij.openapi.actionSystem.ex.ActionButtonLook;
|
||||
import com.intellij.openapi.actionSystem.ex.ActionManagerEx;
|
||||
import com.intellij.openapi.actionSystem.ex.ActionUtil;
|
||||
import com.intellij.openapi.actionSystem.ex.CustomComponentAction;
|
||||
import com.intellij.openapi.util.Getter;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.util.ui.EmptyIcon;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
@@ -129,7 +130,7 @@ public class ActionButton extends JComponent implements ActionButtonComponent, A
|
||||
if (component != null && !component.isShowing()) {
|
||||
return;
|
||||
}
|
||||
actionPerfomed(event);
|
||||
actionPerformed(event);
|
||||
manager.queueActionPerformedEvent(myAction, dataContext, event);
|
||||
}
|
||||
}
|
||||
@@ -138,10 +139,10 @@ public class ActionButton extends JComponent implements ActionButtonComponent, A
|
||||
return DataManager.getInstance().getDataContext();
|
||||
}
|
||||
|
||||
private void actionPerfomed(final AnActionEvent event) {
|
||||
private void actionPerformed(final AnActionEvent event) {
|
||||
if (myAction instanceof ActionGroup && !(myAction instanceof CustomComponentAction) && ((ActionGroup)myAction).isPopup()) {
|
||||
final ActionManagerImpl am = (ActionManagerImpl)ActionManager.getInstance();
|
||||
ActionPopupMenu popupMenu = am.createActionPopupMenu(event.getPlace(), (ActionGroup)myAction, new MenuItemPresentationFactory() {
|
||||
ActionPopupMenuImpl popupMenu = (ActionPopupMenuImpl)am.createActionPopupMenu(event.getPlace(), (ActionGroup)myAction, new MenuItemPresentationFactory() {
|
||||
@Override
|
||||
protected Presentation processPresentation(Presentation presentation) {
|
||||
if (myNoIconsInPopup) {
|
||||
@@ -151,6 +152,12 @@ public class ActionButton extends JComponent implements ActionButtonComponent, A
|
||||
return presentation;
|
||||
}
|
||||
});
|
||||
popupMenu.setDataContextProvider(new Getter<DataContext>() {
|
||||
@Override
|
||||
public DataContext get() {
|
||||
return ActionButton.this.getDataContext();
|
||||
}
|
||||
});
|
||||
if (ActionPlaces.isToolbarPlace(event.getPlace())) {
|
||||
popupMenu.getComponent().show(this, 0, getHeight());
|
||||
}
|
||||
|
||||
+7
-1
@@ -23,6 +23,7 @@ import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationActivationListener;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.util.Getter;
|
||||
import com.intellij.openapi.wm.IdeFrame;
|
||||
import com.intellij.ui.ScreenUtil;
|
||||
import com.intellij.util.ReflectionUtil;
|
||||
@@ -48,6 +49,7 @@ final class ActionPopupMenuImpl implements ActionPopupMenu, ApplicationActivatio
|
||||
|
||||
private final Application myApp;
|
||||
private IdeFrame myFrame;
|
||||
@Nullable private Getter<DataContext> myDataContextProvider;
|
||||
|
||||
public ActionPopupMenuImpl(String place, @NotNull ActionGroup group, ActionManagerImpl actionManager, @Nullable PresentationFactory factory) {
|
||||
myManager = actionManager;
|
||||
@@ -59,6 +61,10 @@ final class ActionPopupMenuImpl implements ActionPopupMenu, ApplicationActivatio
|
||||
return myMenu;
|
||||
}
|
||||
|
||||
public void setDataContextProvider(@Nullable Getter<DataContext> dataContextProvider) {
|
||||
myDataContextProvider = dataContextProvider;
|
||||
}
|
||||
|
||||
private class MyMenu extends JPopupMenu {
|
||||
private final String myPlace;
|
||||
private final ActionGroup myGroup;
|
||||
@@ -85,7 +91,7 @@ final class ActionPopupMenuImpl implements ActionPopupMenu, ApplicationActivatio
|
||||
int x2 = Math.min(Math.max(0, x), component.getWidth() - 1); // fit x into [0, width-1]
|
||||
int y2 = Math.min(Math.max(0, y), component.getHeight() - 1); // fit y into [0, height-1]
|
||||
|
||||
myContext = DataManager.getInstance().getDataContext(component, x2, y2);
|
||||
myContext = myDataContextProvider != null ? myDataContextProvider.get() : DataManager.getInstance().getDataContext(component, x2, y2);
|
||||
Utils.fillMenu(myGroup, this, true, myPresentationFactory, myContext, myPlace, false, false);
|
||||
if (getComponentCount() == 0) {
|
||||
return;
|
||||
|
||||
+2
-2
@@ -798,13 +798,13 @@ public class ActionToolbarImpl extends JPanel implements ActionToolbar {
|
||||
updateActions(true, false, false);
|
||||
}
|
||||
|
||||
private void updateActions(boolean now, final boolean transparrentOnly, final boolean forced) {
|
||||
private void updateActions(boolean now, final boolean transparentOnly, final boolean forced) {
|
||||
final IdRunnable updateRunnable = new IdRunnable(this) {
|
||||
public void run() {
|
||||
myNewVisibleActions.clear();
|
||||
final DataContext dataContext = getDataContext();
|
||||
|
||||
Utils.expandActionGroup(myActionGroup, myNewVisibleActions, myPresentationFactory, dataContext, myPlace, myActionManager, transparrentOnly);
|
||||
Utils.expandActionGroup(myActionGroup, myNewVisibleActions, myPresentationFactory, dataContext, myPlace, myActionManager, transparentOnly);
|
||||
|
||||
if (forced || !myNewVisibleActions.equals(myVisibleActions)) {
|
||||
// should rebuild UI
|
||||
|
||||
Reference in New Issue
Block a user