use of com.intellij.openapi.fileEditor.TextEditor in project intellij-community by JetBrains.
the class DetectedIndentOptionsNotificationProvider method createNotificationPanel.
@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(@NotNull final VirtualFile file, @NotNull FileEditor fileEditor) {
Boolean notifiedFlag = fileEditor.getUserData(NOTIFIED_FLAG);
if (fileEditor instanceof TextEditor && notifiedFlag != null) {
final Editor editor = ((TextEditor) fileEditor).getEditor();
final Project project = editor.getProject();
if (project != null) {
Document document = editor.getDocument();
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
PsiFile psiFile = documentManager.getPsiFile(document);
final Ref<FileIndentOptionsProvider> indentOptionsProviderRef = new Ref<>();
if (psiFile != null) {
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(project);
CommonCodeStyleSettings.IndentOptions userOptions = settings.getIndentOptions(psiFile.getFileType());
CommonCodeStyleSettings.IndentOptions detectedOptions = CodeStyleSettingsManager.getSettings(project).getIndentOptionsByFile(psiFile, null, false, provider -> {
indentOptionsProviderRef.set(provider);
return false;
});
final FileIndentOptionsProvider provider = indentOptionsProviderRef.get();
EditorNotificationInfo info = provider != null && !provider.isAcceptedWithoutWarning(project, file) && !userOptions.equals(detectedOptions) ? provider.getNotificationInfo(project, file, fileEditor, userOptions, detectedOptions) : null;
if (info != null) {
EditorNotificationPanel panel = new EditorNotificationPanel().text(info.getTitle());
if (info.getIcon() != null) {
panel.icon(info.getIcon());
}
for (final ActionLabelData actionLabelData : info.getLabelAndActions()) {
Runnable onClickAction = () -> {
actionLabelData.action.run();
EditorNotifications.getInstance(project).updateAllNotifications();
};
panel.createActionLabel(actionLabelData.label, onClickAction);
}
if (ApplicationManager.getApplication().isUnitTestMode()) {
file.putUserData(DETECT_INDENT_NOTIFICATION_SHOWN_KEY, Boolean.TRUE);
}
return panel;
}
}
}
}
return null;
}
use of com.intellij.openapi.fileEditor.TextEditor in project intellij-community by JetBrains.
the class BaseRemoteFileEditor method contentLoaded.
protected final void contentLoaded() {
ApplicationManager.getApplication().assertIsDispatchThread();
Navigatable navigatable = myPendingNavigatable;
if (navigatable != null) {
myPendingNavigatable = null;
TextEditor editor = getTextEditor();
assert editor != null;
editor.navigateTo(navigatable);
}
if (myMockTextEditor != null) {
if (!myMockTextEditor.isDisposed()) {
EditorFactory.getInstance().releaseEditor(myMockTextEditor);
}
myMockTextEditor = null;
}
}
use of com.intellij.openapi.fileEditor.TextEditor in project intellij-community by JetBrains.
the class InplaceRefactoring method navigateToStarted.
private static void navigateToStarted(final Document oldDocument, final Project project, @Messages.YesNoResult final int exitCode) {
final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(oldDocument);
if (file != null) {
final VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile != null) {
final FileEditor[] editors = FileEditorManager.getInstance(project).getEditors(virtualFile);
for (FileEditor editor : editors) {
if (editor instanceof TextEditor) {
final Editor textEditor = ((TextEditor) editor).getEditor();
final TemplateState templateState = TemplateManagerImpl.getTemplateState(textEditor);
if (templateState != null) {
if (exitCode == Messages.YES) {
final TextRange range = templateState.getVariableRange(PRIMARY_VARIABLE_NAME);
if (range != null) {
new OpenFileDescriptor(project, virtualFile, range.getStartOffset()).navigate(true);
return;
}
} else if (exitCode > 0) {
templateState.gotoEnd();
return;
}
}
}
}
}
}
}
use of com.intellij.openapi.fileEditor.TextEditor in project intellij-community by JetBrains.
the class CCHideFromStudent method hideFromStudent.
public static void hideFromStudent(VirtualFile file, Project project, Map<String, TaskFile> taskFiles, TaskFile taskFile) {
if (!taskFile.getAnswerPlaceholders().isEmpty() && FileEditorManager.getInstance(project).isFileOpen(file)) {
for (FileEditor fileEditor : FileEditorManager.getInstance(project).getEditors(file)) {
if (fileEditor instanceof TextEditor) {
Editor editor = ((TextEditor) fileEditor).getEditor();
editor.getMarkupModel().removeAllHighlighters();
}
}
}
String taskRelativePath = StudyUtils.pathRelativeToTask(file);
VirtualFile patternFile = StudyUtils.getPatternFile(taskFile, taskRelativePath);
ApplicationManager.getApplication().runWriteAction(() -> {
if (patternFile != null) {
try {
patternFile.delete(CCHideFromStudent.class);
} catch (IOException e) {
LOG.info(e);
}
}
});
taskFiles.remove(taskRelativePath);
}
use of com.intellij.openapi.fileEditor.TextEditor in project intellij-community by JetBrains.
the class SourceCodeChecker method check.
private static ThreeState check(Location location, SourcePosition position, Project project) {
Method method = DebuggerUtilsEx.getMethod(location);
// for now skip constructors, bridges, lambdas etc.
if (method == null || method.isConstructor() || method.isSynthetic() || method.isBridge() || method.isStaticInitializer() || (method.declaringType() instanceof ClassType && ((ClassType) method.declaringType()).isEnum()) || DebuggerUtilsEx.isLambda(method)) {
return ThreeState.UNSURE;
}
List<Location> locations = DebuggerUtilsEx.allLineLocations(method);
if (ContainerUtil.isEmpty(locations)) {
return ThreeState.UNSURE;
}
if (position != null) {
return ReadAction.compute(() -> {
PsiFile psiFile = position.getFile();
if (!psiFile.getLanguage().isKindOf(JavaLanguage.INSTANCE)) {
// only for java for now
return ThreeState.UNSURE;
}
Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
if (document == null) {
return ThreeState.UNSURE;
}
boolean res = false;
PsiElement psiMethod = DebuggerUtilsEx.getContainingMethod(position);
if (psiMethod != null) {
TextRange range = psiMethod.getTextRange();
if (psiMethod instanceof PsiDocCommentOwner) {
PsiDocComment comment = ((PsiDocCommentOwner) psiMethod).getDocComment();
if (comment != null) {
range = new TextRange(comment.getTextRange().getEndOffset() + 1, range.getEndOffset());
}
}
int startLine = document.getLineNumber(range.getStartOffset()) + 1;
int endLine = document.getLineNumber(range.getEndOffset()) + 1;
res = getLinesStream(locations, psiFile).allMatch(line -> startLine <= line && line <= endLine);
if (!res) {
LOG.debug("Source check failed: Method " + method.name() + ", source: " + ((NavigationItem) psiMethod).getName() + "\nLines: " + getLinesStream(locations, psiFile).joining(", ") + "\nExpected range: " + startLine + "-" + endLine);
}
} else {
LOG.debug("Source check failed: method " + method.name() + " not found in sources");
}
if (!res) {
FileEditor editor = FileEditorManager.getInstance(project).getSelectedEditor(position.getFile().getVirtualFile());
if (editor instanceof TextEditor) {
AppUIUtil.invokeOnEdt(() -> HintManager.getInstance().showErrorHint(((TextEditor) editor).getEditor(), DebuggerBundle.message("warning.source.code.not.match")));
} else {
XDebugSessionImpl.NOTIFICATION_GROUP.createNotification(DebuggerBundle.message("warning.source.code.not.match"), NotificationType.WARNING).notify(project);
}
return ThreeState.NO;
}
return ThreeState.YES;
});
}
return ThreeState.YES;
}
Aggregations