use of com.intellij.openapi.fileEditor.FileEditor 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.FileEditor in project intellij-community by JetBrains.
the class EditorFixture method getCurrentFile.
/**
* Returns the current file being shown in the editor, if there is a current
* editor open and it's a file editor
*
* @return the currently edited file or null
*/
@Nullable
public VirtualFile getCurrentFile() {
FileEditorManager manager = FileEditorManager.getInstance(myFrame.getProject());
VirtualFile[] selectedFiles = manager.getSelectedFiles();
if (selectedFiles.length > 0) {
// we should be sure that EditorComponent is already showing
VirtualFile selectedFile = selectedFiles[0];
if (manager.getEditors(selectedFile).length == 0)
return null;
else {
FileEditor editor = manager.getEditors(selectedFile)[0];
return editor.getComponent().isShowing() ? selectedFile : null;
}
}
return null;
}
use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.
the class EditorFixture method open.
/**
* Opens up a different file. This will run through the "Open File..." dialog to
* find and select the given file.
*
* @param file the file to open
* @param tab which tab to open initially, if there are multiple editors
*/
public EditorFixture open(@NotNull final VirtualFile file, @NotNull final Tab tab) {
execute(new GuiTask() {
@Override
protected void executeInEDT() throws Throwable {
// TODO: Use UI to navigate to the file instead
Project project = myFrame.getProject();
FileEditorManager manager = FileEditorManager.getInstance(project);
if (tab == Tab.EDITOR) {
manager.openTextEditor(new OpenFileDescriptor(project, file), true);
} else {
manager.openFile(file, true);
}
}
});
pause(new Condition("File " + quote(file.getPath()) + " to be opened") {
@Override
public boolean test() {
//noinspection ConstantConditions
return execute(new GuiQuery<Boolean>() {
@Override
protected Boolean executeInEDT() throws Throwable {
FileEditor[] editors = FileEditorManager.getInstance(myFrame.getProject()).getEditors(file);
if (editors.length == 0)
return false;
return editors[0].getComponent().isShowing();
}
});
}
}, SHORT_TIMEOUT);
// TODO: Maybe find a better way to keep Documents in sync with their VirtualFiles.
invokeActionViaKeystroke("Synchronize");
return this;
}
use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.
the class DetectableIndentOptionsProvider method getNotificationInfo.
@Nullable
@Override
public EditorNotificationInfo getNotificationInfo(@NotNull final Project project, @NotNull final VirtualFile file, @NotNull final FileEditor fileEditor, @NotNull IndentOptions userOptions, @NotNull IndentOptions detectedOptions) {
final NotificationLabels labels = getNotificationLabels(userOptions, detectedOptions);
final Editor editor = fileEditor instanceof TextEditor ? ((TextEditor) fileEditor).getEditor() : null;
if (labels == null || editor == null)
return null;
ActionLabelData okAction = new ActionLabelData(ApplicationBundle.message("code.style.indents.detector.accept"), () -> setAccepted(file));
ActionLabelData disableForSingleFile = new ActionLabelData(labels.revertToOldSettingsLabel, () -> {
disableForFile(file);
if (editor instanceof EditorEx) {
((EditorEx) editor).reinitSettings();
}
});
ActionLabelData showSettings = new ActionLabelData(ApplicationBundle.message("code.style.indents.detector.show.settings"), () -> ShowSettingsUtilImpl.showSettingsDialog(project, "preferences.sourceCode", "detect indent"));
final List<ActionLabelData> actions = ContainerUtil.newArrayList(okAction, disableForSingleFile, showSettings);
return new EditorNotificationInfo() {
@NotNull
@Override
public List<ActionLabelData> getLabelAndActions() {
return actions;
}
@NotNull
@Override
public String getTitle() {
return labels.title;
}
};
}
use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.
the class EditorMultiCaretStateRestoreTest method testRestoreState.
public void testRestoreState() throws Exception {
String text = "some<caret> text<caret>\n" + "some <selection><caret>other</selection> <selection>text<caret></selection>\n" + "<selection>ano<caret>ther</selection> line";
PsiFile psiFile = myFixture.configureByText(PlainTextFileType.INSTANCE, text);
VirtualFile virtualFile = psiFile.getVirtualFile();
assertNotNull(virtualFile);
myManager.openFile(virtualFile, false);
myManager.closeAllFiles();
FileEditor[] fileEditors = myManager.openFile(virtualFile, false);
assertNotNull(fileEditors);
assertEquals(1, fileEditors.length);
Editor editor = ((TextEditor) fileEditors[0]).getEditor();
verifyEditorState(editor, text);
}
Aggregations