use of com.intellij.util.EditorPopupHandler in project intellij-community by JetBrains.
the class ResourceBundleEditor method reinitSettings.
private void reinitSettings(final EditorEx editor) {
EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
editor.setColorsScheme(scheme);
editor.setBorder(BorderFactory.createLineBorder(JBColor.border(), 1));
EditorSettings settings = editor.getSettings();
settings.setLineNumbersShown(false);
settings.setWhitespacesShown(false);
settings.setLineMarkerAreaShown(false);
settings.setIndentGuidesShown(false);
settings.setFoldingOutlineShown(false);
settings.setAdditionalColumnsCount(0);
settings.setAdditionalLinesCount(0);
settings.setRightMarginShown(true);
settings.setRightMargin(60);
settings.setVirtualSpace(false);
editor.setHighlighter(new LexerEditorHighlighter(new PropertiesValueHighlighter(), scheme));
editor.setVerticalScrollbarVisible(true);
// disabling default context menu
editor.setContextMenuGroupId(null);
editor.addEditorMouseListener(new EditorPopupHandler() {
@Override
public void invokePopup(EditorMouseEvent event) {
if (!event.isConsumed() && event.getArea() == EditorMouseEventArea.EDITING_AREA) {
DefaultActionGroup group = new DefaultActionGroup();
group.add(CustomActionsSchema.getInstance().getCorrectedAction(IdeActions.GROUP_CUT_COPY_PASTE));
group.add(CustomActionsSchema.getInstance().getCorrectedAction(IdeActions.ACTION_EDIT_SOURCE));
group.addSeparator();
group.add(new AnAction("Propagate Value Across of Resource Bundle") {
@Override
public void actionPerformed(AnActionEvent e) {
final String valueToPropagate = editor.getDocument().getText();
final String currentSelectedProperty = getSelectedPropertyName();
if (currentSelectedProperty == null) {
return;
}
ApplicationManager.getApplication().runWriteAction(() -> WriteCommandAction.runWriteCommandAction(myProject, () -> {
try {
final PropertiesFile[] propertiesFiles = myResourceBundle.getPropertiesFiles().stream().filter(f -> {
final IProperty property = f.findPropertyByKey(currentSelectedProperty);
return property == null || !valueToPropagate.equals(property.getValue());
}).toArray(PropertiesFile[]::new);
final PsiFile[] filesToPrepare = Arrays.stream(propertiesFiles).map(PropertiesFile::getContainingFile).toArray(PsiFile[]::new);
if (FileModificationService.getInstance().preparePsiElementsForWrite(filesToPrepare)) {
for (PropertiesFile file : propertiesFiles) {
myPropertiesInsertDeleteManager.insertOrUpdateTranslation(currentSelectedProperty, valueToPropagate, file);
}
recreateEditorsPanel();
}
} catch (final IncorrectOperationException e1) {
LOG.error(e1);
}
}));
}
});
EditorPopupHandler handler = EditorActionUtil.createEditorPopupHandler(group);
handler.invokePopup(event);
event.consume();
}
}
});
}
use of com.intellij.util.EditorPopupHandler in project intellij-community by JetBrains.
the class EventLogConsole method createLogEditor.
private Editor createLogEditor() {
Project project = myProjectModel.getProject();
final EditorEx editor = ConsoleViewUtil.setupConsoleEditor(project, false, false);
editor.getSettings().setWhitespacesShown(false);
installNotificationsFont(editor);
myProjectModel.getProject().getMessageBus().connect().subscribe(ProjectManager.TOPIC, new ProjectManagerAdapter() {
@Override
public void projectClosed(Project project) {
if (project == myProjectModel.getProject()) {
EditorFactory.getInstance().releaseEditor(editor);
}
}
});
((EditorMarkupModel) editor.getMarkupModel()).setErrorStripeVisible(true);
final ClearLogAction clearLog = new ClearLogAction(this);
clearLog.registerCustomShortcutSet(ActionManager.getInstance().getAction(IdeActions.CONSOLE_CLEAR_ALL).getShortcutSet(), editor.getContentComponent());
// disabling default context menu
editor.setContextMenuGroupId(null);
editor.addEditorMouseListener(new EditorPopupHandler() {
public void invokePopup(final EditorMouseEvent event) {
final ActionManager actionManager = ActionManager.getInstance();
DefaultActionGroup actions = createPopupActions(actionManager, clearLog, editor, event);
final ActionPopupMenu menu = actionManager.createActionPopupMenu(ActionPlaces.EDITOR_POPUP, actions);
final MouseEvent mouseEvent = event.getMouseEvent();
menu.getComponent().show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY());
}
});
return editor;
}
use of com.intellij.util.EditorPopupHandler in project intellij-community by JetBrains.
the class EditorActionUtil method createEditorPopupHandler.
public static EditorPopupHandler createEditorPopupHandler(@NotNull final String groupId) {
return new EditorPopupHandler() {
@Override
public void invokePopup(final EditorMouseEvent event) {
if (!event.isConsumed() && event.getArea() == EditorMouseEventArea.EDITING_AREA) {
ActionGroup group = (ActionGroup) CustomActionsSchema.getInstance().getCorrectedAction(groupId);
showEditorPopup(event, group);
}
}
};
}
Aggregations