Search in sources :

Example 1 with EditorMouseEvent

use of com.intellij.openapi.editor.event.EditorMouseEvent 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 EditorMouseEvent

use of com.intellij.openapi.editor.event.EditorMouseEvent 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 EditorMouseEvent

use of com.intellij.openapi.editor.event.EditorMouseEvent in project intellij-community by JetBrains.

the class ConsoleViewImpl method createConsoleEditor.

@NotNull
private EditorEx createConsoleEditor() {
    return ReadAction.compute(() -> {
        EditorEx editor = doCreateConsoleEditor();
        LOG.assertTrue(UndoUtil.isUndoDisabledFor(editor.getDocument()));
        // disabling default context menu
        editor.setContextMenuGroupId(null);
        editor.addEditorMouseListener(new EditorPopupHandler() {

            @Override
            public void invokePopup(final EditorMouseEvent event) {
                popupInvoked(event.getMouseEvent());
            }
        });
        int bufferSize = ConsoleBuffer.useCycleBuffer() ? ConsoleBuffer.getCycleBufferSize() : 0;
        editor.getDocument().setCyclicBufferSize(bufferSize);
        editor.putUserData(CONSOLE_VIEW_IN_EDITOR_VIEW, this);
        // We want to fold long soft-wrapped command lines
        editor.getSettings().setAllowSingleLogicalLineFolding(true);
        return editor;
    });
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) EditorMouseEvent(com.intellij.openapi.editor.event.EditorMouseEvent) RelativePoint(com.intellij.ui.awt.RelativePoint) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with EditorMouseEvent

use of com.intellij.openapi.editor.event.EditorMouseEvent in project intellij-community by JetBrains.

the class EditorActionUtil method showEditorPopup.

private static void showEditorPopup(final EditorMouseEvent event, @NotNull final ActionGroup group) {
    if (!event.isConsumed() && event.getArea() == EditorMouseEventArea.EDITING_AREA) {
        ActionPopupMenu popupMenu = ActionManager.getInstance().createActionPopupMenu(ActionPlaces.EDITOR_POPUP, group);
        MouseEvent e = event.getMouseEvent();
        final Component c = e.getComponent();
        if (c != null && c.isShowing()) {
            popupMenu.getComponent().show(c, e.getX(), e.getY());
        }
        e.consume();
    }
}
Also used : MouseEvent(java.awt.event.MouseEvent) EditorMouseEvent(com.intellij.openapi.editor.event.EditorMouseEvent) ActionPopupMenu(com.intellij.openapi.actionSystem.ActionPopupMenu)

Example 5 with EditorMouseEvent

use of com.intellij.openapi.editor.event.EditorMouseEvent 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)8 EditorPopupHandler (com.intellij.util.EditorPopupHandler)3 MouseEvent (java.awt.event.MouseEvent)3 HintManager (com.intellij.codeInsight.hint.HintManager)1 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 ActionPopupMenu (com.intellij.openapi.actionSystem.ActionPopupMenu)1 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)1 EditorMouseListener (com.intellij.openapi.editor.event.EditorMouseListener)1 EditorMouseMotionAdapter (com.intellij.openapi.editor.event.EditorMouseMotionAdapter)1 EditorMouseMotionListener (com.intellij.openapi.editor.event.EditorMouseMotionListener)1 EditorEx (com.intellij.openapi.editor.ex.EditorEx)1 LexerEditorHighlighter (com.intellij.openapi.editor.ex.util.LexerEditorHighlighter)1 Project (com.intellij.openapi.project.Project)1 ProjectManagerAdapter (com.intellij.openapi.project.ProjectManagerAdapter)1 LightweightHint (com.intellij.ui.LightweightHint)1 RelativePoint (com.intellij.ui.awt.RelativePoint)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1