IDEA-136058 Show "Indent options for the file are overwritten" warning only when I try to edit a file

This commit is contained in:
Rustam Vishnyakov
2015-02-12 13:02:07 +03:00
parent 44af95272f
commit ca7c3b01e9
2 changed files with 21 additions and 1 deletions
@@ -15,9 +15,11 @@
*/
package com.intellij.psi.codeStyle.autodetect;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileEditor.TextEditor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
@@ -39,6 +41,7 @@ import static com.intellij.psi.codeStyle.EditorNotificationInfo.*;
*/
public class DetectedIndentOptionsNotificationProvider extends EditorNotifications.Provider<EditorNotificationPanel> {
private static final Key<EditorNotificationPanel> KEY = Key.create("indent.options.notification.provider");
private static final Key<Boolean> NOTIFIED_FLAG = Key.create("indent.options.notification.provider.status");
@NotNull
@Override
@@ -49,7 +52,8 @@ public class DetectedIndentOptionsNotificationProvider extends EditorNotificatio
@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(@NotNull final VirtualFile file, @NotNull FileEditor fileEditor) {
if (fileEditor instanceof TextEditor) {
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) {
@@ -96,4 +100,17 @@ public class DetectedIndentOptionsNotificationProvider extends EditorNotificatio
}
return null;
}
public static void updateIndentNotification(@NotNull PsiFile file, boolean enforce) {
if (!(ApplicationManager.getApplication().isHeadlessEnvironment() || ApplicationManager.getApplication().isUnitTestMode())) {
FileEditor fileEditor = FileEditorManager.getInstance(file.getProject()).getSelectedEditor(file.getVirtualFile());
if (fileEditor != null) {
Boolean notifiedFlag = fileEditor.getUserData(NOTIFIED_FLAG);
if (notifiedFlag == null || enforce) {
fileEditor.putUserData(NOTIFIED_FLAG, Boolean.TRUE);
EditorNotifications.getInstance(file.getProject()).updateNotifications(file.getVirtualFile());
}
}
}
}
}
@@ -33,6 +33,7 @@ import com.intellij.openapi.util.TextRange;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.*;
import com.intellij.psi.codeStyle.Indent;
import com.intellij.psi.codeStyle.autodetect.DetectedIndentOptionsNotificationProvider;
import com.intellij.psi.formatter.FormatterUtil;
import com.intellij.psi.impl.CheckUtil;
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
@@ -237,6 +238,7 @@ public class CodeStyleManagerImpl extends CodeStyleManager {
}
if (editor instanceof EditorEx && isFullReformat) {
((EditorEx)editor).reinitSettings();
DetectedIndentOptionsNotificationProvider.updateIndentNotification(file, true);
}
}
@@ -314,6 +316,7 @@ public class CodeStyleManagerImpl extends CodeStyleManager {
@Override
public int adjustLineIndent(@NotNull final PsiFile file, final int offset) throws IncorrectOperationException {
DetectedIndentOptionsNotificationProvider.updateIndentNotification(file, false);
return PostprocessReformattingAspect.getInstance(file.getProject()).disablePostprocessFormattingInside(new Computable<Integer>() {
@Override
public Integer compute() {