Skip to content

Commit

Permalink
Migrate the SdkConfigurationNotificationProvider to the new EditorNot…
Browse files Browse the repository at this point in the history
…ificationProvider API (#7833)

This is progress on
#7830
  • Loading branch information
jwren authored Dec 2, 2024
1 parent 1db2d38 commit 9a1a246
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 29 deletions.
2 changes: 1 addition & 1 deletion flutter-idea/src/io/flutter/FlutterBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<EditorNotificationPanel>
implements DumbAware {
private static final Key<EditorNotificationPanel> 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<EditorNotificationPanel> getKey() {
return KEY;
}

@Override
public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file,
@NotNull FileEditor fileEditor,
@NotNull Project project) {
public @Nullable Function<? super @NotNull FileEditor, ? extends @Nullable JComponent> 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;

Expand All @@ -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;
}
}

0 comments on commit 9a1a246

Please sign in to comment.