use of com.intellij.openapi.actionSystem.AnActionEvent in project buck by facebook.
the class BuckBuildManager method showNoTargetMessage.
/**
* Print "no selected target" error message to console window.
* Also provide a hyperlink which can directly jump to "Choose Target" GUI window.
*/
public void showNoTargetMessage(Project project) {
BuckModule buckModule = project.getComponent(BuckModule.class);
buckModule.getBuckEventsConsumer().consumeConsoleEvent("Please choose a build target!");
BuckToolWindowFactory.outputConsoleMessage(project, "Please ", ConsoleViewContentType.ERROR_OUTPUT);
BuckToolWindowFactory.outputConsoleHyperlink(project, "choose a build target!\n", new HyperlinkInfo() {
@Override
public void navigate(Project project) {
JComponent frame = WindowManager.getInstance().getIdeFrame(project).getComponent();
AnAction action = ActionManager.getInstance().getAction("buck.ChooseTarget");
action.actionPerformed(new AnActionEvent(null, DataManager.getInstance().getDataContext(frame), ActionPlaces.UNKNOWN, action.getTemplatePresentation(), ActionManager.getInstance(), 0));
}
});
}
use of com.intellij.openapi.actionSystem.AnActionEvent in project intellij-community by JetBrains.
the class InplaceEditingLayer method startEditing.
public void startEditing(@Nullable InplaceContext inplaceContext) {
try {
List<RadComponent> selection = myDesigner.getSurfaceArea().getSelection();
if (selection.size() != 1) {
return;
}
myRadComponent = selection.get(0);
myProperties = myRadComponent.getInplaceProperties();
if (myProperties.isEmpty()) {
myRadComponent = null;
myProperties = null;
return;
}
myInplaceComponent = new JPanel(new GridLayoutManager(myProperties.size(), 2));
myInplaceComponent.setBorder(new LineMarginBorder(5, 5, 5, 5));
new AnAction() {
@Override
public void actionPerformed(AnActionEvent e) {
finishEditing(false);
}
}.registerCustomShortcutSet(CommonShortcuts.ESCAPE, myInplaceComponent);
myEditors = new ArrayList<>();
JComponent componentToFocus = null;
Font font = null;
if (inplaceContext == null) {
inplaceContext = new InplaceContext();
}
int row = 0;
for (Property property : myProperties) {
JLabel label = new JLabel(property.getName() + ":");
if (font == null) {
font = label.getFont().deriveFont(Font.BOLD);
}
label.setFont(font);
myInplaceComponent.add(label, new GridConstraints(row, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, 0, 0, null, null, null));
PropertyEditor editor = property.getEditor();
myEditors.add(editor);
JComponent component = editor.getComponent(myRadComponent, myDesigner, property.getValue(myRadComponent), inplaceContext);
myInplaceComponent.add(component, new GridConstraints(row++, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW, 0, null, null, null));
if (componentToFocus == null) {
componentToFocus = editor.getPreferredFocusedComponent();
}
}
for (PropertyEditor editor : myEditors) {
editor.addPropertyEditorListener(myEditorListener);
}
Rectangle bounds = myRadComponent.getBounds(this);
Dimension size = myInplaceComponent.getPreferredSize();
myPreferredWidth = Math.max(size.width, bounds.width);
myInplaceComponent.setBounds(bounds.x, bounds.y, myPreferredWidth, size.height);
add(myInplaceComponent);
myDesigner.getSurfaceArea().addSelectionListener(mySelectionListener);
if (componentToFocus == null) {
componentToFocus = IdeFocusTraversalPolicy.getPreferredFocusedComponent(myInplaceComponent);
}
if (componentToFocus == null) {
componentToFocus = myInplaceComponent;
}
if (componentToFocus.requestFocusInWindow()) {
myFocusWatcher.install(myInplaceComponent);
} else {
grabFocus();
final JComponent finalComponentToFocus = componentToFocus;
ApplicationManager.getApplication().invokeLater(() -> {
finalComponentToFocus.requestFocusInWindow();
myFocusWatcher.install(myInplaceComponent);
});
}
enableEvents(AWTEvent.MOUSE_EVENT_MASK);
repaint();
} catch (Throwable e) {
LOG.error(e);
}
}
use of com.intellij.openapi.actionSystem.AnActionEvent in project intellij-community by JetBrains.
the class DesignerToolWindow method createActions.
AnAction[] createActions() {
AnAction expandAll = new AnAction("Expand All", null, AllIcons.Actions.Expandall) {
@Override
public void actionPerformed(AnActionEvent e) {
if (myTreeBuilder != null) {
TreeUtil.expandAll(myComponentTree);
}
}
};
AnAction collapseAll = new AnAction("Collapse All", null, AllIcons.Actions.Collapseall) {
@Override
public void actionPerformed(AnActionEvent e) {
if (myTreeBuilder != null) {
TreeUtil.collapseAll(myComponentTree, 1);
}
}
};
return new AnAction[] { expandAll, collapseAll };
}
use of com.intellij.openapi.actionSystem.AnActionEvent in project intellij-community by JetBrains.
the class AbstractComboBoxAction method createPopupActionGroup.
@NotNull
@Override
protected DefaultActionGroup createPopupActionGroup(JComponent button) {
DefaultActionGroup actionGroup = new DefaultActionGroup();
for (final T item : myItems) {
if (addSeparator(actionGroup, item)) {
continue;
}
AnAction action = new AnAction() {
@Override
public void actionPerformed(AnActionEvent e) {
if (mySelection != item && selectionChanged(item)) {
mySelection = item;
AbstractComboBoxAction.this.update(item, myPresentation, false);
}
}
};
actionGroup.add(action);
Presentation presentation = action.getTemplatePresentation();
presentation.setIcon(mySelection == item ? CHECKED : null);
update(item, presentation, true);
}
return actionGroup;
}
use of com.intellij.openapi.actionSystem.AnActionEvent in project intellij-community by JetBrains.
the class PyConsoleUtil method createTabCompletionAction.
public static AnAction createTabCompletionAction(PythonConsoleView consoleView) {
final AnAction runCompletions = new AnAction() {
@Override
public void actionPerformed(AnActionEvent e) {
Editor editor = consoleView.getConsoleEditor();
if (LookupManager.getActiveLookup(editor) != null) {
AnAction replace = ActionManager.getInstance().getAction(IdeActions.ACTION_CHOOSE_LOOKUP_ITEM_REPLACE);
ActionUtil.performActionDumbAware(replace, e);
return;
}
AnAction completionAction = ActionManager.getInstance().getAction(IdeActions.ACTION_CODE_COMPLETION);
if (completionAction != null) {
ActionUtil.performActionDumbAware(completionAction, e);
}
}
@Override
public void update(AnActionEvent e) {
Editor editor = consoleView.getConsoleEditor();
if (LookupManager.getActiveLookup(editor) != null) {
e.getPresentation().setEnabled(false);
}
int offset = editor.getCaretModel().getOffset();
Document document = editor.getDocument();
int lineStart = document.getLineStartOffset(document.getLineNumber(offset));
String textToCursor = document.getText(new TextRange(lineStart, offset));
e.getPresentation().setEnabled(!CharMatcher.WHITESPACE.matchesAllOf(textToCursor));
}
};
runCompletions.registerCustomShortcutSet(KeyEvent.VK_TAB, 0, consoleView.getConsoleEditor().getComponent());
runCompletions.getTemplatePresentation().setVisible(false);
return runCompletions;
}
Aggregations