Skip to content

Commit 9a1a246

Browse files
authored
Migrate the SdkConfigurationNotificationProvider to the new EditorNotificationProvider API (#7833)
This is progress on #7830
1 parent 1db2d38 commit 9a1a246

File tree

2 files changed

+20
-29
lines changed

2 files changed

+20
-29
lines changed

flutter-idea/src/io/flutter/FlutterBundle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ error.sdk.not.found.in.specified.location=Flutter SDK is not found in the specif
3434

3535
flutter.command.exception.message=Exception: {0}
3636
flutter.module.name=Flutter
37-
flutter.no.sdk.warning=No Flutter SDK Configured.
37+
flutter.no.sdk.warning=No Flutter SDK configured.
3838
flutter.project.description=Build high-performance, high-fidelity, apps using the Flutter framework.
3939
flutter.sdk.browse.path.label=Select Flutter SDK Path
4040
flutter.sdk.is.not.configured=The Flutter SDK is not configured

flutter-idea/src/io/flutter/inspections/SdkConfigurationNotificationProvider.java

+19-28
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@
99
import com.intellij.openapi.fileEditor.FileEditor;
1010
import com.intellij.openapi.module.Module;
1111
import com.intellij.openapi.module.ModuleUtilCore;
12-
import com.intellij.openapi.project.DumbAware;
1312
import com.intellij.openapi.project.Project;
14-
import com.intellij.openapi.util.Key;
1513
import com.intellij.openapi.vfs.VirtualFile;
1614
import com.intellij.psi.PsiFile;
1715
import com.intellij.psi.PsiManager;
1816
import com.intellij.ui.EditorNotificationPanel;
19-
import com.intellij.ui.EditorNotifications;
17+
import com.intellij.ui.EditorNotificationProvider;
2018
import com.jetbrains.lang.dart.DartFileType;
2119
import com.jetbrains.lang.dart.DartLanguage;
2220
import icons.FlutterIcons;
@@ -25,39 +23,24 @@
2523
import io.flutter.sdk.FlutterSdk;
2624
import io.flutter.utils.FlutterModuleUtils;
2725
import org.jetbrains.annotations.NotNull;
26+
import org.jetbrains.annotations.Nullable;
2827

29-
public class SdkConfigurationNotificationProvider extends EditorNotifications.Provider<EditorNotificationPanel>
30-
implements DumbAware {
31-
private static final Key<EditorNotificationPanel> KEY = Key.create("FlutterWrongDartSdkNotification");
28+
import javax.swing.*;
29+
import java.util.function.Function;
3230

31+
public class SdkConfigurationNotificationProvider implements EditorNotificationProvider {
3332
private static final Logger LOG = Logger.getInstance(SdkConfigurationNotificationProvider.class);
3433

35-
@NotNull private final Project project;
34+
@NotNull
35+
private final Project project;
3636

3737
public SdkConfigurationNotificationProvider(@NotNull Project project) {
3838
this.project = project;
3939
}
4040

41-
@SuppressWarnings("SameReturnValue")
42-
private static EditorNotificationPanel createNoFlutterSdkPanel(Project project) {
43-
final EditorNotificationPanel panel = new EditorNotificationPanel();
44-
panel.icon(FlutterIcons.Flutter);
45-
panel.setText(FlutterBundle.message("flutter.no.sdk.warning"));
46-
panel.createActionLabel("Dismiss", () -> panel.setVisible(false));
47-
panel.createActionLabel("Open Flutter settings", () -> FlutterUtils.openFlutterSettings(project));
48-
return panel;
49-
}
50-
51-
@NotNull
52-
@Override
53-
public Key<EditorNotificationPanel> getKey() {
54-
return KEY;
55-
}
56-
5741
@Override
58-
public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file,
59-
@NotNull FileEditor fileEditor,
60-
@NotNull Project project) {
42+
public @Nullable Function<? super @NotNull FileEditor, ? extends @Nullable JComponent> collectNotificationData(@NotNull Project project,
43+
@NotNull VirtualFile file) {
6144
// If this is a Bazel configured Flutter project, exit immediately, neither of the notifications should be shown for this project type.
6245
if (FlutterModuleUtils.isFlutterBazelProject(project)) return null;
6346

@@ -71,9 +54,17 @@ public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file
7154

7255
final FlutterSdk flutterSdk = FlutterSdk.getFlutterSdk(project);
7356
if (flutterSdk == null) {
74-
return createNoFlutterSdkPanel(project);
57+
return fileEditor -> createNoFlutterSdkPanel(fileEditor, project);
7558
}
76-
7759
return null;
7860
}
61+
62+
private static EditorNotificationPanel createNoFlutterSdkPanel(@NotNull FileEditor fileEditor, @NotNull Project project) {
63+
final EditorNotificationPanel panel = new EditorNotificationPanel();
64+
panel.icon(FlutterIcons.Flutter);
65+
panel.setText(FlutterBundle.message("flutter.no.sdk.warning"));
66+
panel.createActionLabel("Dismiss", () -> panel.setVisible(false));
67+
panel.createActionLabel("Open Flutter settings", () -> FlutterUtils.openFlutterSettings(project));
68+
return panel;
69+
}
7970
}

0 commit comments

Comments
 (0)