Search in sources :

Example 1 with EditorPopupHandler

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();
            }
        }
    });
}
Also used : EditorPopupHandler(com.intellij.util.EditorPopupHandler) LexerEditorHighlighter(com.intellij.openapi.editor.ex.util.LexerEditorHighlighter) EditorMouseEvent(com.intellij.openapi.editor.event.EditorMouseEvent) IProperty(com.intellij.lang.properties.IProperty) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) XmlPropertiesFile(com.intellij.lang.properties.xml.XmlPropertiesFile) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) IncorrectOperationException(com.intellij.util.IncorrectOperationException)

Example 2 with EditorPopupHandler

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;
}
Also used : Project(com.intellij.openapi.project.Project) EditorMouseEvent(com.intellij.openapi.editor.event.EditorMouseEvent) MouseEvent(java.awt.event.MouseEvent) EditorMouseEvent(com.intellij.openapi.editor.event.EditorMouseEvent) ProjectManagerAdapter(com.intellij.openapi.project.ProjectManagerAdapter) EditorPopupHandler(com.intellij.util.EditorPopupHandler)

Example 3 with EditorPopupHandler

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);
            }
        }
    };
}
Also used : EditorMouseEvent(com.intellij.openapi.editor.event.EditorMouseEvent) ActionGroup(com.intellij.openapi.actionSystem.ActionGroup) EditorPopupHandler(com.intellij.util.EditorPopupHandler)

Aggregations

EditorMouseEvent (com.intellij.openapi.editor.event.EditorMouseEvent)3 EditorPopupHandler (com.intellij.util.EditorPopupHandler)3 IProperty (com.intellij.lang.properties.IProperty)1 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)1 XmlPropertiesFile (com.intellij.lang.properties.xml.XmlPropertiesFile)1 ActionGroup (com.intellij.openapi.actionSystem.ActionGroup)1 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)1 LexerEditorHighlighter (com.intellij.openapi.editor.ex.util.LexerEditorHighlighter)1 Project (com.intellij.openapi.project.Project)1 ProjectManagerAdapter (com.intellij.openapi.project.ProjectManagerAdapter)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 MouseEvent (java.awt.event.MouseEvent)1