use of com.intellij.openapi.actionSystem.AnActionEvent in project intellij-community by JetBrains.
the class AbstractGithubTagDownloadedProjectGenerator method createGitHubLink.
public ActionLink createGitHubLink() {
final ActionLink link = new ActionLink(getName() + " on GitHub", new AnAction() {
@Override
public void actionPerformed(AnActionEvent e) {
BrowserUtil.open("https://github.com/" + getGithubUserName() + "/" + getGithubRepositoryName());
}
});
link.setFont(UIUtil.getLabelFont(UIUtil.FontSize.SMALL));
return link;
}
use of com.intellij.openapi.actionSystem.AnActionEvent in project intellij-community by JetBrains.
the class AnnotateStackTraceAction method actionPerformed.
@Override
public void actionPerformed(final AnActionEvent e) {
myIsLoading = true;
ProgressManager.getInstance().run(new Task.Backgroundable(myEditor.getProject(), "Getting File History", true) {
private final Object LOCK = new Object();
private final MergingUpdateQueue myUpdateQueue = new MergingUpdateQueue("AnnotateStackTraceAction", 200, true, null);
private MyActiveAnnotationGutter myGutter;
@Override
public void onCancel() {
myEditor.getGutter().closeAllAnnotations();
}
@Override
public void onFinished() {
myIsLoading = false;
Disposer.dispose(myUpdateQueue);
}
@Override
public void run(@NotNull ProgressIndicator indicator) {
MultiMap<VirtualFile, Integer> files2lines = new MultiMap<>();
Map<Integer, LastRevision> revisions = ContainerUtil.newHashMap();
ApplicationManager.getApplication().runReadAction(() -> {
for (int line = 0; line < myEditor.getDocument().getLineCount(); line++) {
indicator.checkCanceled();
VirtualFile file = getHyperlinkVirtualFile(myHyperlinks.findAllHyperlinksOnLine(line));
if (file == null)
continue;
files2lines.putValue(file, line);
}
});
files2lines.entrySet().forEach(entry -> {
indicator.checkCanceled();
VirtualFile file = entry.getKey();
Collection<Integer> lines = entry.getValue();
LastRevision revision = getLastRevision(file);
if (revision == null)
return;
synchronized (LOCK) {
for (Integer line : lines) {
revisions.put(line, revision);
}
}
myUpdateQueue.queue(new Update("update") {
@Override
public void run() {
updateGutter(indicator, revisions);
}
});
});
// myUpdateQueue can be disposed before the last revisions are passed to the gutter
ApplicationManager.getApplication().invokeLater(() -> updateGutter(indicator, revisions));
}
@CalledInAwt
private void updateGutter(@NotNull ProgressIndicator indicator, @NotNull Map<Integer, LastRevision> revisions) {
if (indicator.isCanceled())
return;
if (myGutter == null) {
myGutter = new MyActiveAnnotationGutter(getProject(), myHyperlinks, indicator);
myEditor.getGutter().registerTextAnnotation(myGutter, myGutter);
}
Map<Integer, LastRevision> revisionsCopy;
synchronized (LOCK) {
revisionsCopy = ContainerUtil.newHashMap(revisions);
}
myGutter.updateData(revisionsCopy);
((EditorGutterComponentEx) myEditor.getGutter()).revalidateMarkup();
}
@Nullable
private LastRevision getLastRevision(@NotNull VirtualFile file) {
try {
AbstractVcs vcs = VcsUtil.getVcsFor(myEditor.getProject(), file);
if (vcs == null)
return null;
VcsHistoryProvider historyProvider = vcs.getVcsHistoryProvider();
if (historyProvider == null)
return null;
FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(file);
if (historyProvider instanceof VcsHistoryProviderEx) {
VcsFileRevision revision = ((VcsHistoryProviderEx) historyProvider).getLastRevision(filePath);
if (revision == null)
return null;
return LastRevision.create(revision);
} else {
VcsHistorySession session = historyProvider.createSessionFor(filePath);
if (session == null)
return null;
List<VcsFileRevision> list = session.getRevisionList();
if (list == null || list.isEmpty())
return null;
return LastRevision.create(list.get(0));
}
} catch (VcsException ignored) {
LOG.warn(ignored);
return null;
}
}
});
}
use of com.intellij.openapi.actionSystem.AnActionEvent in project intellij-community by JetBrains.
the class JavaChangeSignatureDialog method createAdditionalPanels.
@NotNull
protected List<Pair<String, JPanel>> createAdditionalPanels() {
// this method is invoked before constructor body
myExceptionsModel = new ExceptionsTableModel(myMethod.getMethod().getThrowsList());
myExceptionsModel.setTypeInfos(myMethod.getMethod());
final JBTable table = new JBTable(myExceptionsModel);
table.setStriped(true);
table.setRowHeight(20);
table.getColumnModel().getColumn(0).setCellRenderer(new CodeFragmentTableCellRenderer(myProject));
final JavaCodeFragmentTableCellEditor cellEditor = new JavaCodeFragmentTableCellEditor(myProject);
cellEditor.addDocumentListener(new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent e) {
final int row = table.getSelectedRow();
final int col = table.getSelectedColumn();
myExceptionsModel.setValueAt(cellEditor.getCellEditorValue(), row, col);
updateSignature();
}
});
table.getColumnModel().getColumn(0).setCellEditor(cellEditor);
table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.getSelectionModel().setSelectionInterval(0, 0);
table.setSurrendersFocusOnKeystroke(true);
myPropExceptionsButton = new AnActionButton(RefactoringBundle.message("changeSignature.propagate.exceptions.title"), null, AllIcons.Hierarchy.Caller) {
@Override
public void actionPerformed(AnActionEvent e) {
final Ref<JavaCallerChooser> chooser = new Ref<>();
Consumer<Set<PsiMethod>> callback = psiMethods -> {
myMethodsToPropagateExceptions = psiMethods;
myExceptionPropagationTree = chooser.get().getTree();
};
chooser.set(new JavaCallerChooser(myMethod.getMethod(), myProject, RefactoringBundle.message("changeSignature.exception.caller.chooser"), myExceptionPropagationTree, callback));
chooser.get().show();
}
};
myPropExceptionsButton.setShortcut(CustomShortcutSet.fromString("alt X"));
final JPanel panel = ToolbarDecorator.createDecorator(table).addExtraAction(myPropExceptionsButton).createPanel();
panel.setBorder(IdeBorderFactory.createEmptyBorder());
myExceptionsModel.addTableModelListener(mySignatureUpdater);
final ArrayList<Pair<String, JPanel>> result = new ArrayList<>();
final String message = RefactoringBundle.message("changeSignature.exceptions.panel.border.title");
result.add(Pair.create(message, panel));
return result;
}
use of com.intellij.openapi.actionSystem.AnActionEvent in project intellij-community by JetBrains.
the class BaseGenerateTestSupportMethodAction method createEditTemplateAction.
@Nullable
@Override
public AnAction createEditTemplateAction(DataContext dataContext) {
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
final Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
final PsiFile file = CommonDataKeys.PSI_FILE.getData(dataContext);
final PsiClass targetClass = editor == null || file == null ? null : getTargetClass(editor, file);
if (targetClass != null) {
final List<TestFramework> frameworks = TestIntegrationUtils.findSuitableFrameworks(targetClass);
final TestIntegrationUtils.MethodKind methodKind = ((MyHandler) getHandler()).myMethodKind;
if (!frameworks.isEmpty()) {
return new AnAction("Edit Template") {
@Override
public void actionPerformed(AnActionEvent e) {
chooseAndPerform(editor, frameworks, framework -> {
final FileTemplateDescriptor descriptor = methodKind.getFileTemplateDescriptor(framework);
if (descriptor != null) {
final String fileName = descriptor.getFileName();
AllFileTemplatesConfigurable.editCodeTemplate(FileUtil.getNameWithoutExtension(fileName), project);
} else {
HintManager.getInstance().showErrorHint(editor, "No template found for " + framework.getName() + ":" + BaseGenerateTestSupportMethodAction.this.getTemplatePresentation().getText());
}
});
}
};
}
}
return null;
}
use of com.intellij.openapi.actionSystem.AnActionEvent in project intellij-community by JetBrains.
the class ScrollingUtil method installActions.
public static void installActions(final JTable table, final boolean cycleScrolling, JComponent focusParent) {
ActionMap actionMap = table.getActionMap();
actionMap.put(SCROLLUP_ACTION_ID, new MoveAction(SCROLLUP_ACTION_ID, table, cycleScrolling));
actionMap.put(SCROLLDOWN_ACTION_ID, new MoveAction(SCROLLDOWN_ACTION_ID, table, cycleScrolling));
actionMap.put(SELECT_PREVIOUS_ROW_ACTION_ID, new MoveAction(SELECT_PREVIOUS_ROW_ACTION_ID, table, cycleScrolling));
actionMap.put(SELECT_NEXT_ROW_ACTION_ID, new MoveAction(SELECT_NEXT_ROW_ACTION_ID, table, cycleScrolling));
actionMap.put(SELECT_LAST_ROW_ACTION_ID, new MoveAction(SELECT_LAST_ROW_ACTION_ID, table, cycleScrolling));
actionMap.put(SELECT_FIRST_ROW_ACTION_ID, new MoveAction(SELECT_FIRST_ROW_ACTION_ID, table, cycleScrolling));
maybeInstallDefaultShortcuts(table);
JComponent target = focusParent == null ? table : focusParent;
new MyScrollingAction(table) {
@Override
public void actionPerformed(AnActionEvent e) {
moveHome(table);
}
}.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0)), table);
new MyScrollingAction(table) {
@Override
public void actionPerformed(AnActionEvent e) {
moveEnd(table);
}
}.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0)), table);
if (!(focusParent instanceof JTextComponent)) {
new MyScrollingAction(table) {
@Override
public void actionPerformed(AnActionEvent e) {
moveHome(table);
}
}.registerCustomShortcutSet(CommonShortcuts.getMoveHome(), target);
new MyScrollingAction(table) {
@Override
public void actionPerformed(AnActionEvent e) {
moveEnd(table);
}
}.registerCustomShortcutSet(CommonShortcuts.getMoveEnd(), target);
}
new MyScrollingAction(table) {
@Override
public void actionPerformed(AnActionEvent e) {
moveDown(table, e.getModifiers(), cycleScrolling);
}
}.registerCustomShortcutSet(CommonShortcuts.getMoveDown(), target);
new MyScrollingAction(table) {
@Override
public void actionPerformed(AnActionEvent e) {
moveUp(table, e.getModifiers(), cycleScrolling);
}
}.registerCustomShortcutSet(CommonShortcuts.getMoveUp(), target);
new MyScrollingAction(table) {
@Override
public void actionPerformed(AnActionEvent e) {
movePageUp(table);
}
}.registerCustomShortcutSet(CommonShortcuts.getMovePageUp(), target);
new MyScrollingAction(table) {
@Override
public void actionPerformed(AnActionEvent e) {
movePageDown(table);
}
}.registerCustomShortcutSet(CommonShortcuts.getMovePageDown(), target);
}
Aggregations