mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-182327 add description and enabled in modal context
This commit is contained in:
@@ -15,52 +15,24 @@
|
||||
*/
|
||||
package com.intellij.ui;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
|
||||
import javax.swing.Action;
|
||||
import javax.swing.ActionMap;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JScrollPane;
|
||||
import java.awt.Component;
|
||||
import java.awt.KeyboardFocusManager;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
import static com.intellij.openapi.actionSystem.PlatformDataKeys.CONTEXT_COMPONENT;
|
||||
import static com.intellij.util.ui.UIUtil.getParentOfType;
|
||||
|
||||
/**
|
||||
* @author Sergey.Malenkov
|
||||
*/
|
||||
public abstract class ScrollPaneActions extends AnAction {
|
||||
private final String mySwingActionId;
|
||||
|
||||
public abstract class ScrollPaneActions extends SwingActionDelegate {
|
||||
private ScrollPaneActions(String actionId) {
|
||||
mySwingActionId = actionId;
|
||||
super(actionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent event) {
|
||||
JScrollPane pane = getScrollPane(event);
|
||||
event.getPresentation().setEnabled(pane != null && null != getSwingAction(pane));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent event) {
|
||||
JScrollPane pane = getScrollPane(event);
|
||||
if (pane == null) return;
|
||||
Action action = getSwingAction(pane);
|
||||
if (action == null) return;
|
||||
action.actionPerformed(new ActionEvent(pane, ActionEvent.ACTION_PERFORMED, mySwingActionId));
|
||||
}
|
||||
|
||||
private JScrollPane getScrollPane(AnActionEvent event) {
|
||||
Component component = event.getData(CONTEXT_COMPONENT);
|
||||
return UIUtil.getParentOfType(JScrollPane.class, component);
|
||||
}
|
||||
|
||||
private Action getSwingAction(JScrollPane pane) {
|
||||
ActionMap map = pane.getActionMap();
|
||||
return map == null ? null : map.get(mySwingActionId);
|
||||
protected JComponent getComponent(AnActionEvent event) {
|
||||
return getParentOfType(JScrollPane.class, super.getComponent(event));
|
||||
}
|
||||
|
||||
public static final class Home extends ScrollPaneActions {
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.intellij.ui;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
|
||||
import javax.swing.Action;
|
||||
import javax.swing.ActionMap;
|
||||
import javax.swing.JComponent;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
import static com.intellij.openapi.actionSystem.PlatformDataKeys.CONTEXT_COMPONENT;
|
||||
import static com.intellij.util.ui.UIUtil.getParentOfType;
|
||||
|
||||
/**
|
||||
* @author Sergey.Malenkov
|
||||
*/
|
||||
public class SwingActionDelegate extends AnAction {
|
||||
private final String mySwingActionId;
|
||||
|
||||
protected SwingActionDelegate(String actionId) {
|
||||
setEnabledInModalContext(true);
|
||||
mySwingActionId = actionId;
|
||||
}
|
||||
|
||||
protected JComponent getComponent(AnActionEvent event) {
|
||||
return getParentOfType(JComponent.class, event.getData(CONTEXT_COMPONENT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void update(AnActionEvent event) {
|
||||
event.getPresentation().setEnabled(null != getSwingAction(getComponent(event)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void actionPerformed(AnActionEvent event) {
|
||||
JComponent component = getComponent(event);
|
||||
Action action = getSwingAction(component);
|
||||
if (action != null) action.actionPerformed(new ActionEvent(component, ActionEvent.ACTION_PERFORMED, mySwingActionId));
|
||||
}
|
||||
|
||||
private Action getSwingAction(JComponent component) {
|
||||
if (component == null) return null;
|
||||
ActionMap map = component.getActionMap();
|
||||
return map == null ? null : map.get(mySwingActionId);
|
||||
}
|
||||
}
|
||||
@@ -22,16 +22,36 @@
|
||||
<group id="VcsGeneral.KeymapGroup"/> <!-- grouping for Settings -> Keymap -> Version Control Systems -->
|
||||
|
||||
<group id="ScrollPaneActions" text="Scroll">
|
||||
<action id="ScrollPane-scrollHome" text="Scroll Home" class="com.intellij.ui.ScrollPaneActions$Home"/>
|
||||
<action id="ScrollPane-scrollEnd" text="Scroll End" class="com.intellij.ui.ScrollPaneActions$End"/>
|
||||
<action id="ScrollPane-unitScrollUp" text="Scroll Up" class="com.intellij.ui.ScrollPaneActions$Up"/>
|
||||
<action id="ScrollPane-unitScrollDown" text="Scroll Down" class="com.intellij.ui.ScrollPaneActions$Down"/>
|
||||
<action id="ScrollPane-unitScrollLeft" text="Scroll Left" class="com.intellij.ui.ScrollPaneActions$Left"/>
|
||||
<action id="ScrollPane-unitScrollRight" text="Scroll Right" class="com.intellij.ui.ScrollPaneActions$Right"/>
|
||||
<action id="ScrollPane-scrollUp" text="Scroll Page Up" class="com.intellij.ui.ScrollPaneActions$PageUp"/>
|
||||
<action id="ScrollPane-scrollDown" text="Scroll Page Down" class="com.intellij.ui.ScrollPaneActions$PageDown"/>
|
||||
<action id="ScrollPane-scrollLeft" text="Scroll Page Left" class="com.intellij.ui.ScrollPaneActions$PageLeft"/>
|
||||
<action id="ScrollPane-scrollRight" text="Scroll Page Right" class="com.intellij.ui.ScrollPaneActions$PageRight"/>
|
||||
<action id="ScrollPane-scrollHome" text="Scroll Home"
|
||||
description="Scrolls the surrounding scrollable area to the top."
|
||||
class="com.intellij.ui.ScrollPaneActions$Home"/>
|
||||
<action id="ScrollPane-scrollEnd" text="Scroll End"
|
||||
description="Scrolls the surrounding scrollable area to the bottom."
|
||||
class="com.intellij.ui.ScrollPaneActions$End"/>
|
||||
<action id="ScrollPane-unitScrollUp" text="Scroll Up"
|
||||
description="Scrolls the surrounding scrollable area up by one unit."
|
||||
class="com.intellij.ui.ScrollPaneActions$Up"/>
|
||||
<action id="ScrollPane-unitScrollDown" text="Scroll Down"
|
||||
description="Scrolls the surrounding scrollable area down by one unit."
|
||||
class="com.intellij.ui.ScrollPaneActions$Down"/>
|
||||
<action id="ScrollPane-unitScrollLeft" text="Scroll Left"
|
||||
description="Scrolls the surrounding scrollable area left by one unit."
|
||||
class="com.intellij.ui.ScrollPaneActions$Left"/>
|
||||
<action id="ScrollPane-unitScrollRight" text="Scroll Right"
|
||||
description="Scrolls the surrounding scrollable area right by one unit."
|
||||
class="com.intellij.ui.ScrollPaneActions$Right"/>
|
||||
<action id="ScrollPane-scrollUp" text="Scroll Page Up"
|
||||
description="Scrolls the surrounding scrollable area up by one page."
|
||||
class="com.intellij.ui.ScrollPaneActions$PageUp"/>
|
||||
<action id="ScrollPane-scrollDown" text="Scroll Page Down"
|
||||
description="Scrolls the surrounding scrollable area down by one page."
|
||||
class="com.intellij.ui.ScrollPaneActions$PageDown"/>
|
||||
<action id="ScrollPane-scrollLeft" text="Scroll Page Left"
|
||||
description="Scrolls the surrounding scrollable area left by one page."
|
||||
class="com.intellij.ui.ScrollPaneActions$PageLeft"/>
|
||||
<action id="ScrollPane-scrollRight" text="Scroll Page Right"
|
||||
description="Scrolls the surrounding scrollable area right by one page."
|
||||
class="com.intellij.ui.ScrollPaneActions$PageRight"/>
|
||||
|
||||
<add-to-group group-id="Other.KeymapGroup"/>
|
||||
</group>
|
||||
|
||||
Reference in New Issue
Block a user