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);
}
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();
}
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();
}
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);
}
});
}
}
}
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);
}
Aggregations