Skip to content

Commit

Permalink
#2764 CAMELCADE-10991 split editor notification creation to the bgt a…
Browse files Browse the repository at this point in the history
…nd edt parts

Computations are done before producing UI elements, platform invokes us on BGT under RA.

#CAMELCADE-10991 Fixed
Fixes #2764
  • Loading branch information
hurricup committed Oct 8, 2023
1 parent efe305d commit 46a5a10
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.NlsContexts.Label;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
Expand Down Expand Up @@ -46,28 +47,23 @@ public HTMLMasonPathsNotification(Project myProject) {
@Override
public @Nullable Function<? super @NotNull FileEditor, ? extends @Nullable JComponent> collectNotificationData(@NotNull Project project,
@NotNull VirtualFile file) {
return fileEditor -> createNotificationPanel(file);
}

private @Nullable EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file) {
if (file.getFileType() != HTMLMasonFileType.INSTANCE) {
return null;
}
String message = null;

if (HTMLMasonSettings.getInstance(myProject).getComponentsRoots().isEmpty()) {
message = HtmlMasonBundle.message("link.label.html.mason.components.roots.are.not.configured");
return fileEditor -> createNotificationPanel(HtmlMasonBundle.message("link.label.html.mason.components.roots.are.not.configured"));
}
else {
PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
if (psiFile instanceof HTMLMasonFileImpl && ((HTMLMasonFileImpl)psiFile).getComponentRoot() == null) {
message = HtmlMasonBundle.message("link.label.component.not.under.one.configured.roots");
return fileEditor -> createNotificationPanel(HtmlMasonBundle.message("link.label.component.not.under.one.configured.roots"));
}
}
return null;
}

if (message == null) {
return null;
}
private @NotNull EditorNotificationPanel createNotificationPanel(@NotNull @Label String message) {
EditorNotificationPanel panel = new EditorNotificationPanel();
panel.setText(message);
panel.createActionLabel(HtmlMasonBundle.message("link.label.configure"), () -> Perl5SettingsConfigurable.open(myProject));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.NlsContexts;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
Expand All @@ -45,28 +46,22 @@ public MasonPathsNotification(Project myProject) {
@Override
public @Nullable Function<? super @NotNull FileEditor, ? extends @Nullable JComponent> collectNotificationData(@NotNull Project project,
@NotNull VirtualFile file) {
return fileEditor -> createNotificationPanel(file);
}

private @Nullable EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file) {
if (!(file.getFileType() instanceof MasonPurePerlComponentFileType)) {
return null;
}
String message = null;

if (MasonSettings.getInstance(myProject).getComponentsRoots().isEmpty()) {
message = "Mason2 components roots are not configured";
return fileEditor -> createNotificationPanel("Mason2 components roots are not configured");

Check warning on line 53 in mason/mason2/core/src/main/java/com/perl5/lang/mason2/idea/editor/notification/MasonPathsNotification.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Hardcoded strings

Hardcoded string literal: "Mason2 components roots are not configured"
}
else {
PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
if (psiFile instanceof MasonFileImpl && ((MasonFileImpl)psiFile).getComponentRoot() == null) {
message = "Component is not under one of configured roots";
if (psiFile instanceof MasonFileImpl masonFile && masonFile.getComponentRoot() == null) {
return fileEditor -> createNotificationPanel("Component is not under one of configured roots");

Check warning on line 58 in mason/mason2/core/src/main/java/com/perl5/lang/mason2/idea/editor/notification/MasonPathsNotification.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Hardcoded strings

Hardcoded string literal: "Component is not under one of configured roots"
}
}
return null;
}

if (message == null) {
return null;
}
private @NotNull EditorNotificationPanel createNotificationPanel(@NotNull @NlsContexts.Label String message) {
EditorNotificationPanel panel = new EditorNotificationPanel();
panel.setText(message);
panel.createActionLabel("Configure", () -> Perl5SettingsConfigurable.open(myProject));

Check warning on line 67 in mason/mason2/core/src/main/java/com/perl5/lang/mason2/idea/editor/notification/MasonPathsNotification.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Hardcoded strings

Hardcoded string literal: "Configure"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2020 Alexandr Evstigneev
* Copyright 2015-2023 Alexandr Evstigneev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -45,15 +45,11 @@ public PerlInterpreterEditorNotification(Project myProject) {

@Override
public @Nullable Function<? super @NotNull FileEditor, ? extends @Nullable JComponent> collectNotificationData(@NotNull Project project,
@NotNull VirtualFile file) {
return fileEditor -> createNotificationPanel(file);
}


private @Nullable EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile virtualFile) {
@NotNull VirtualFile virtualFile) {
if (!(virtualFile.getFileType() instanceof PerlFileType) || virtualFile instanceof LightVirtualFile) {
return null;
}

final PerlLocalSettings perlLocalSettings = PerlLocalSettings.getInstance(myProject);
if (perlLocalSettings.DISABLE_NO_INTERPRETER_WARNING) {
return null;
Expand All @@ -62,7 +58,10 @@ public PerlInterpreterEditorNotification(Project myProject) {
if (PerlProjectManager.getSdk(myProject, virtualFile) != null) {
return null;
}
return fileEditor -> createNotificationPanel(perlLocalSettings);
}

private @NotNull EditorNotificationPanel createNotificationPanel(@NotNull PerlLocalSettings perlLocalSettings) {
EditorNotificationPanel panel = new EditorNotificationPanel();
panel.setText(PerlBundle.message("perl.notification.sdk.not.configured"));
panel.createActionLabel(PerlBundle.message("perl.notification.configure"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ public TemplateToolkitEditorNotificationsProvider(Project project) {
@Override
public @Nullable Function<? super @NotNull FileEditor, ? extends @Nullable JComponent> collectNotificationData(@NotNull Project project,
@NotNull VirtualFile file) {
return fileEditor -> createNotificationPanel(file);
}

private @Nullable EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file) {
if (file.getFileType() != TemplateToolkitFileType.INSTANCE) {
return null;
}
TemplateToolkitSettings settings = TemplateToolkitSettings.getInstance(myProject);
if (settings.isVirtualFileUnderRoot(file)) {
return null;
}
return fileEditor -> createNotificationPanel();
}

private @NotNull EditorNotificationPanel createNotificationPanel() {
EditorNotificationPanel panel = new EditorNotificationPanel();
panel.setText(TemplateToolkitBundle.message("tt2.error.file.not.in.root"));
panel.createActionLabel("Configure", () -> Perl5SettingsConfigurable.open(myProject));

Check warning on line 59 in tt2/core/src/main/java/com/perl5/lang/tt2/idea/editor/TemplateToolkitEditorNotificationsProvider.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Hardcoded strings

Hardcoded string literal: "Configure"
Expand Down

0 comments on commit 46a5a10

Please sign in to comment.