use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.
the class HighlightUtil method highlightElements.
public static void highlightElements(@NotNull final Collection<? extends PsiElement> elementCollection, @NotNull final String statusBarText) {
if (elementCollection.isEmpty()) {
return;
}
final Application application = ApplicationManager.getApplication();
application.invokeLater(() -> {
final PsiElement[] elements = PsiUtilCore.toPsiElementArray(elementCollection);
final PsiElement firstElement = elements[0];
if (!firstElement.isValid()) {
return;
}
final Project project = firstElement.getProject();
final FileEditorManager editorManager = FileEditorManager.getInstance(project);
final EditorColorsManager editorColorsManager = EditorColorsManager.getInstance();
final Editor editor = editorManager.getSelectedTextEditor();
if (editor == null) {
return;
}
final EditorColorsScheme globalScheme = editorColorsManager.getGlobalScheme();
final TextAttributes textattributes = globalScheme.getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
final HighlightManager highlightManager = HighlightManager.getInstance(project);
highlightManager.addOccurrenceHighlights(editor, elements, textattributes, true, null);
final FindManager findmanager = FindManager.getInstance(project);
FindModel findmodel = findmanager.getFindNextModel();
if (findmodel == null) {
findmodel = findmanager.getFindInFileModel();
}
findmodel.setSearchHighlighters(true);
findmanager.setFindWasPerformed();
findmanager.setFindNextModel(findmodel);
application.invokeLater(() -> {
final WindowManager windowManager = WindowManager.getInstance();
final StatusBar statusBar = windowManager.getStatusBar(project);
if (statusBar != null) {
statusBar.setInfo(statusBarText);
}
});
});
}
use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.
the class HighlightUtil method showRenameTemplate.
public static void showRenameTemplate(PsiElement context, PsiNameIdentifierOwner element) {
context = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(context);
final Query<PsiReference> query = ReferencesSearch.search(element, element.getUseScope());
final Collection<PsiReference> references = query.findAll();
final Project project = context.getProject();
final FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
final Editor editor = fileEditorManager.getSelectedTextEditor();
if (editor == null) {
return;
}
final TemplateBuilderImpl builder = new TemplateBuilderImpl(context);
final Expression macroCallNode = new MacroCallNode(new SuggestVariableNameMacro());
final PsiElement identifier = element.getNameIdentifier();
builder.replaceElement(identifier, "PATTERN", macroCallNode, true);
for (PsiReference reference : references) {
builder.replaceElement(reference, "PATTERN", "PATTERN", false);
}
final Template template = builder.buildInlineTemplate();
final TextRange textRange = context.getTextRange();
final int startOffset = textRange.getStartOffset();
editor.getCaretModel().moveToOffset(startOffset);
final TemplateManager templateManager = TemplateManager.getInstance(project);
templateManager.startTemplate(editor, template);
}
use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.
the class EditSourceInNewWindowAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
Project project = e.getRequiredData(CommonDataKeys.PROJECT);
final FileEditorManager manager = FileEditorManager.getInstance(project);
((FileEditorManagerImpl) manager).openFileInNewWindow(getVirtualFiles(e)[0]);
}
use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.
the class FileFixture method isOpenAndSelected.
private boolean isOpenAndSelected() {
FileEditorManager editorManager = FileEditorManager.getInstance(myProject);
FileEditor selectedEditor = editorManager.getSelectedEditor(myVirtualFile);
if (selectedEditor != null) {
JComponent component = selectedEditor.getComponent();
if (component.isVisible() && component.isShowing()) {
Document document = FileDocumentManager.getInstance().getDocument(myVirtualFile);
if (document != null) {
PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(document);
if (psiFile != null) {
DaemonCodeAnalyzerEx codeAnalyzer = DaemonCodeAnalyzerEx.getInstanceEx(myProject);
//noinspection ConstantConditions
boolean isRunning = method("isRunning").withReturnType(boolean.class).in(codeAnalyzer).invoke();
return !isRunning;
}
}
}
}
return false;
}
use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.
the class EditorFixture method getFocusedEditor.
/**
* Requests focus in the editor, waits and returns editor component
*/
@Nullable
private JComponent getFocusedEditor() {
Editor editor = execute(new GuiQuery<Editor>() {
@Override
@Nullable
protected Editor executeInEDT() throws Throwable {
FileEditorManager manager = FileEditorManager.getInstance(myFrame.getProject());
// Must be called from the EDT
return manager.getSelectedTextEditor();
}
});
//wait when TextEditor ContentComponent will showing
pause(new Condition("Waiting for showing focused textEditor") {
@Override
public boolean test() {
return editor.getContentComponent().isShowing();
}
}, SHORT_TIMEOUT);
if (editor != null) {
JComponent contentComponent = editor.getContentComponent();
new ComponentDriver(robot).focusAndWaitForFocusGain(contentComponent);
assertSame(contentComponent, FocusManager.getCurrentManager().getFocusOwner());
return contentComponent;
} else {
fail("Expected to find editor to focus, but there is no current editor");
return null;
}
}
Aggregations