Search in sources :

Example 1 with ScrollingModel

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

the class IntroduceParameterObjectHandler method invoke.

public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
    final ScrollingModel scrollingModel = editor.getScrollingModel();
    scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE);
    PsiMethod selectedMethod = getSelectedMethod(editor, file, dataContext);
    if (selectedMethod == null) {
        final String message = RefactorJBundle.message("cannot.perform.the.refactoring") + RefactorJBundle.message("the.caret.should.be.positioned.at.the.name.of.the.method.to.be.refactored");
        CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.IntroduceParameterObject);
        return;
    }
    invoke(project, selectedMethod, editor);
}
Also used : ScrollingModel(com.intellij.openapi.editor.ScrollingModel)

Example 2 with ScrollingModel

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

the class SyncScrollSupport method doScrollHorizontally.

private static void doScrollHorizontally(@NotNull Editor editor, int offset, boolean animated) {
    ScrollingModel model = editor.getScrollingModel();
    if (!animated)
        model.disableAnimation();
    model.scrollHorizontally(offset);
    if (!animated)
        model.enableAnimation();
}
Also used : ScrollingModel(com.intellij.openapi.editor.ScrollingModel)

Example 3 with ScrollingModel

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

the class ExtractClassHandler method invoke.

public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
    final ScrollingModel scrollingModel = editor.getScrollingModel();
    scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE);
    final CaretModel caretModel = editor.getCaretModel();
    final int position = caretModel.getOffset();
    final PsiElement element = file.findElementAt(position);
    final PsiMember selectedMember = PsiTreeUtil.getParentOfType(element, PsiMember.class, true);
    if (selectedMember == null) {
        //todo
        return;
    }
    PsiClass containingClass = selectedMember.getContainingClass();
    if (containingClass == null && selectedMember instanceof PsiClass) {
        containingClass = (PsiClass) selectedMember;
    }
    final String cannotRefactorMessage = getCannotRefactorMessage(containingClass);
    if (cannotRefactorMessage != null) {
        CommonRefactoringUtil.showErrorHint(project, editor, RefactorJBundle.message("cannot.perform.the.refactoring") + cannotRefactorMessage, ExtractClassProcessor.REFACTORING_NAME, getHelpID());
        return;
    }
    new ExtractClassDialog(containingClass, selectedMember).show();
}
Also used : CaretModel(com.intellij.openapi.editor.CaretModel) ScrollingModel(com.intellij.openapi.editor.ScrollingModel)

Example 4 with ScrollingModel

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

the class EditorWindow method syncCaretIfPossible.

/**
   * Tries to setup caret and viewport for the given editor from the selected one.
   *
   * @param toSync    editor to setup caret and viewport for
   */
private void syncCaretIfPossible(@Nullable FileEditor[] toSync) {
    if (toSync == null) {
        return;
    }
    final EditorWithProviderComposite from = getSelectedEditor();
    if (from == null) {
        return;
    }
    final FileEditor caretSource = from.getSelectedEditor();
    if (!(caretSource instanceof TextEditor)) {
        return;
    }
    final Editor editorFrom = ((TextEditor) caretSource).getEditor();
    final int offset = editorFrom.getCaretModel().getOffset();
    if (offset <= 0) {
        return;
    }
    final int scrollOffset = editorFrom.getScrollingModel().getVerticalScrollOffset();
    for (FileEditor fileEditor : toSync) {
        if (!(fileEditor instanceof TextEditor)) {
            continue;
        }
        final Editor editor = ((TextEditor) fileEditor).getEditor();
        if (editorFrom.getDocument() == editor.getDocument()) {
            editor.getCaretModel().moveToOffset(offset);
            final ScrollingModel scrollingModel = editor.getScrollingModel();
            scrollingModel.scrollVertically(scrollOffset);
            SwingUtilities.invokeLater(() -> {
                if (!editor.isDisposed()) {
                    scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE);
                }
            });
        }
    }
}
Also used : FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) ScrollingModel(com.intellij.openapi.editor.ScrollingModel) TextEditor(com.intellij.openapi.fileEditor.TextEditor) Editor(com.intellij.openapi.editor.Editor) FileEditor(com.intellij.openapi.fileEditor.FileEditor)

Example 5 with ScrollingModel

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

the class WrapReturnValueHandler method invoke.

public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
    final ScrollingModel scrollingModel = editor.getScrollingModel();
    scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE);
    final PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
    PsiMethod selectedMethod = null;
    if (element instanceof PsiMethod) {
        selectedMethod = (PsiMethod) element;
    } else {
        final CaretModel caretModel = editor.getCaretModel();
        final int position = caretModel.getOffset();
        PsiElement selectedElement = file.findElementAt(position);
        while (selectedElement != null) {
            if (selectedElement instanceof PsiMethod) {
                selectedMethod = (PsiMethod) selectedElement;
                break;
            }
            selectedElement = selectedElement.getParent();
        }
    }
    if (selectedMethod == null) {
        CommonRefactoringUtil.showErrorHint(project, editor, RefactorJBundle.message("cannot.perform.the.refactoring") + RefactorJBundle.message("the.caret.should.be.positioned.at.the.name.of.the.method.to.be.refactored"), REFACTORING_NAME, this.getHelpID());
        return;
    }
    invoke(project, selectedMethod, editor);
}
Also used : CaretModel(com.intellij.openapi.editor.CaretModel) ScrollingModel(com.intellij.openapi.editor.ScrollingModel)

Aggregations

ScrollingModel (com.intellij.openapi.editor.ScrollingModel)10 Editor (com.intellij.openapi.editor.Editor)3 CaretModel (com.intellij.openapi.editor.CaretModel)2 Disposable (com.intellij.openapi.Disposable)1 MergeActionGroup (com.intellij.openapi.diff.actions.MergeActionGroup)1 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)1 VisibleAreaListener (com.intellij.openapi.editor.event.VisibleAreaListener)1 EditorEx (com.intellij.openapi.editor.ex.EditorEx)1 EditorMarkupModel (com.intellij.openapi.editor.ex.EditorMarkupModel)1 FileEditor (com.intellij.openapi.fileEditor.FileEditor)1 TextEditor (com.intellij.openapi.fileEditor.TextEditor)1 PsiElement (com.intellij.psi.PsiElement)1 PsiField (com.intellij.psi.PsiField)1 MouseListener (java.awt.event.MouseListener)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1