Skip to content

Commit 5e388b6

Browse files
authored
Migrate the NativeEditorNotificationProvider to the new EditorNotificationProvider API (#7840)
This is progress on #7830
1 parent 9a1a246 commit 5e388b6

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

flutter-idea/src/io/flutter/editor/NativeEditorNotificationProvider.java

+12-23
Original file line numberDiff line numberDiff line change
@@ -7,61 +7,50 @@
77

88
import com.intellij.openapi.actionSystem.*;
99
import com.intellij.openapi.fileEditor.FileEditor;
10-
import com.intellij.openapi.project.DumbAware;
1110
import com.intellij.openapi.project.Project;
12-
import com.intellij.openapi.util.Key;
1311
import com.intellij.openapi.util.SystemInfo;
1412
import com.intellij.openapi.util.io.FileUtil;
1513
import com.intellij.openapi.vfs.VirtualFile;
1614
import com.intellij.ui.EditorNotificationPanel;
15+
import com.intellij.ui.EditorNotificationProvider;
1716
import com.intellij.ui.EditorNotifications;
1817
import icons.FlutterIcons;
1918
import io.flutter.FlutterBundle;
2019
import io.flutter.utils.UIUtils;
2120
import org.jetbrains.annotations.NotNull;
2221
import org.jetbrains.annotations.Nullable;
2322

24-
public class NativeEditorNotificationProvider extends EditorNotifications.Provider<EditorNotificationPanel> implements DumbAware {
25-
private static final Key<EditorNotificationPanel> KEY = Key.create("flutter.native.editor.notification");
23+
import javax.swing.*;
24+
import java.util.function.Function;
2625

26+
public class NativeEditorNotificationProvider implements EditorNotificationProvider {
2727
private final Project project;
2828
private boolean showNotification = true;
2929

3030
public NativeEditorNotificationProvider(@NotNull Project project) {
3131
this.project = project;
3232
}
3333

34-
@NotNull
3534
@Override
36-
public Key<EditorNotificationPanel> getKey() {
37-
return KEY;
38-
}
39-
40-
@Nullable
41-
@Override
42-
public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file,
43-
@NotNull FileEditor fileEditor,
44-
@NotNull Project project) {
35+
public @Nullable Function<? super @NotNull FileEditor, ? extends @Nullable JComponent> collectNotificationData(@NotNull Project project,
36+
@NotNull VirtualFile file) {
4537
if (!file.isInLocalFileSystem() || !showNotification) {
4638
return null;
4739
}
48-
return createPanelForFile(file, findRootDir(file, project.getBaseDir()));
49-
}
5040

51-
@Nullable
52-
private EditorNotificationPanel createPanelForFile(@NotNull VirtualFile file, @Nullable VirtualFile root) {
41+
VirtualFile root = project.getBaseDir();
5342
if (root == null) {
5443
return null;
5544
}
56-
return createPanelForAction(file, root, getActionName(root));
45+
return fileEditor -> createPanelForAction(fileEditor, root, getActionName(root));
5746
}
5847

5948
@Nullable
60-
private EditorNotificationPanel createPanelForAction(@NotNull VirtualFile file, @NotNull VirtualFile root, @Nullable String actionName) {
49+
private EditorNotificationPanel createPanelForAction(@NotNull FileEditor fileEditor, @NotNull VirtualFile root, @Nullable String actionName) {
6150
if (actionName == null) {
6251
return null;
6352
}
64-
final NativeEditorActionsPanel panel = new NativeEditorActionsPanel(file, root, actionName);
53+
final NativeEditorActionsPanel panel = new NativeEditorActionsPanel(fileEditor, root, actionName);
6554
return panel.isValidForFile() ? panel : null;
6655
}
6756

@@ -114,9 +103,9 @@ class NativeEditorActionsPanel extends EditorNotificationPanel {
114103
final AnAction myAction;
115104
final boolean isVisible;
116105

117-
NativeEditorActionsPanel(VirtualFile file, VirtualFile root, String actionName) {
106+
NativeEditorActionsPanel(@NotNull FileEditor fileEditor, @NotNull VirtualFile root, @NotNull String actionName) {
118107
super(UIUtils.getEditorNotificationBackgroundColor());
119-
myFile = file;
108+
myFile = fileEditor.getFile();
120109
myRoot = root;
121110
myAction = ActionManager.getInstance().getAction(actionName);
122111

0 commit comments

Comments
 (0)