From 9a1a246dcbb02c4b7a52c051ba3f27f6064d9e95 Mon Sep 17 00:00:00 2001 From: Jaime Wren Date: Mon, 2 Dec 2024 14:17:07 -0800 Subject: [PATCH] Migrate the SdkConfigurationNotificationProvider to the new EditorNotificationProvider API (#7833) This is progress on https://github.com/flutter/flutter-intellij/issues/7830 --- .../src/io/flutter/FlutterBundle.properties | 2 +- .../SdkConfigurationNotificationProvider.java | 47 ++++++++----------- 2 files changed, 20 insertions(+), 29 deletions(-) diff --git a/flutter-idea/src/io/flutter/FlutterBundle.properties b/flutter-idea/src/io/flutter/FlutterBundle.properties index 35f90ef5fa..2b49eaa35b 100644 --- a/flutter-idea/src/io/flutter/FlutterBundle.properties +++ b/flutter-idea/src/io/flutter/FlutterBundle.properties @@ -34,7 +34,7 @@ error.sdk.not.found.in.specified.location=Flutter SDK is not found in the specif flutter.command.exception.message=Exception: {0} flutter.module.name=Flutter -flutter.no.sdk.warning=No Flutter SDK Configured. +flutter.no.sdk.warning=No Flutter SDK configured. flutter.project.description=Build high-performance, high-fidelity, apps using the Flutter framework. flutter.sdk.browse.path.label=Select Flutter SDK Path flutter.sdk.is.not.configured=The Flutter SDK is not configured diff --git a/flutter-idea/src/io/flutter/inspections/SdkConfigurationNotificationProvider.java b/flutter-idea/src/io/flutter/inspections/SdkConfigurationNotificationProvider.java index 978d383e4b..d7c9374f67 100644 --- a/flutter-idea/src/io/flutter/inspections/SdkConfigurationNotificationProvider.java +++ b/flutter-idea/src/io/flutter/inspections/SdkConfigurationNotificationProvider.java @@ -9,14 +9,12 @@ import com.intellij.openapi.fileEditor.FileEditor; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleUtilCore; -import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Key; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiManager; import com.intellij.ui.EditorNotificationPanel; -import com.intellij.ui.EditorNotifications; +import com.intellij.ui.EditorNotificationProvider; import com.jetbrains.lang.dart.DartFileType; import com.jetbrains.lang.dart.DartLanguage; import icons.FlutterIcons; @@ -25,39 +23,24 @@ import io.flutter.sdk.FlutterSdk; import io.flutter.utils.FlutterModuleUtils; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -public class SdkConfigurationNotificationProvider extends EditorNotifications.Provider - implements DumbAware { - private static final Key KEY = Key.create("FlutterWrongDartSdkNotification"); +import javax.swing.*; +import java.util.function.Function; +public class SdkConfigurationNotificationProvider implements EditorNotificationProvider { private static final Logger LOG = Logger.getInstance(SdkConfigurationNotificationProvider.class); - @NotNull private final Project project; + @NotNull + private final Project project; public SdkConfigurationNotificationProvider(@NotNull Project project) { this.project = project; } - @SuppressWarnings("SameReturnValue") - private static EditorNotificationPanel createNoFlutterSdkPanel(Project project) { - final EditorNotificationPanel panel = new EditorNotificationPanel(); - panel.icon(FlutterIcons.Flutter); - panel.setText(FlutterBundle.message("flutter.no.sdk.warning")); - panel.createActionLabel("Dismiss", () -> panel.setVisible(false)); - panel.createActionLabel("Open Flutter settings", () -> FlutterUtils.openFlutterSettings(project)); - return panel; - } - - @NotNull - @Override - public Key getKey() { - return KEY; - } - @Override - public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, - @NotNull FileEditor fileEditor, - @NotNull Project project) { + public @Nullable Function collectNotificationData(@NotNull Project project, + @NotNull VirtualFile file) { // If this is a Bazel configured Flutter project, exit immediately, neither of the notifications should be shown for this project type. if (FlutterModuleUtils.isFlutterBazelProject(project)) return null; @@ -71,9 +54,17 @@ public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file final FlutterSdk flutterSdk = FlutterSdk.getFlutterSdk(project); if (flutterSdk == null) { - return createNoFlutterSdkPanel(project); + return fileEditor -> createNoFlutterSdkPanel(fileEditor, project); } - return null; } + + private static EditorNotificationPanel createNoFlutterSdkPanel(@NotNull FileEditor fileEditor, @NotNull Project project) { + final EditorNotificationPanel panel = new EditorNotificationPanel(); + panel.icon(FlutterIcons.Flutter); + panel.setText(FlutterBundle.message("flutter.no.sdk.warning")); + panel.createActionLabel("Dismiss", () -> panel.setVisible(false)); + panel.createActionLabel("Open Flutter settings", () -> FlutterUtils.openFlutterSettings(project)); + return panel; + } }