use of com.intellij.psi.codeStyle.EditorNotificationInfo.ActionLabelData 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.psi.codeStyle.EditorNotificationInfo.ActionLabelData 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;
}
Aggregations