|
7 | 7 |
|
8 | 8 | import com.intellij.openapi.actionSystem.*;
|
9 | 9 | import com.intellij.openapi.fileEditor.FileEditor;
|
10 |
| -import com.intellij.openapi.project.DumbAware; |
11 | 10 | import com.intellij.openapi.project.Project;
|
12 |
| -import com.intellij.openapi.util.Key; |
13 | 11 | import com.intellij.openapi.util.SystemInfo;
|
14 | 12 | import com.intellij.openapi.util.io.FileUtil;
|
15 | 13 | import com.intellij.openapi.vfs.VirtualFile;
|
16 | 14 | import com.intellij.ui.EditorNotificationPanel;
|
| 15 | +import com.intellij.ui.EditorNotificationProvider; |
17 | 16 | import com.intellij.ui.EditorNotifications;
|
18 | 17 | import icons.FlutterIcons;
|
19 | 18 | import io.flutter.FlutterBundle;
|
20 | 19 | import io.flutter.utils.UIUtils;
|
21 | 20 | import org.jetbrains.annotations.NotNull;
|
22 | 21 | import org.jetbrains.annotations.Nullable;
|
23 | 22 |
|
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; |
26 | 25 |
|
| 26 | +public class NativeEditorNotificationProvider implements EditorNotificationProvider { |
27 | 27 | private final Project project;
|
28 | 28 | private boolean showNotification = true;
|
29 | 29 |
|
30 | 30 | public NativeEditorNotificationProvider(@NotNull Project project) {
|
31 | 31 | this.project = project;
|
32 | 32 | }
|
33 | 33 |
|
34 |
| - @NotNull |
35 | 34 | @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) { |
45 | 37 | if (!file.isInLocalFileSystem() || !showNotification) {
|
46 | 38 | return null;
|
47 | 39 | }
|
48 |
| - return createPanelForFile(file, findRootDir(file, project.getBaseDir())); |
49 |
| - } |
50 | 40 |
|
51 |
| - @Nullable |
52 |
| - private EditorNotificationPanel createPanelForFile(@NotNull VirtualFile file, @Nullable VirtualFile root) { |
| 41 | + VirtualFile root = project.getBaseDir(); |
53 | 42 | if (root == null) {
|
54 | 43 | return null;
|
55 | 44 | }
|
56 |
| - return createPanelForAction(file, root, getActionName(root)); |
| 45 | + return fileEditor -> createPanelForAction(fileEditor, root, getActionName(root)); |
57 | 46 | }
|
58 | 47 |
|
59 | 48 | @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) { |
61 | 50 | if (actionName == null) {
|
62 | 51 | return null;
|
63 | 52 | }
|
64 |
| - final NativeEditorActionsPanel panel = new NativeEditorActionsPanel(file, root, actionName); |
| 53 | + final NativeEditorActionsPanel panel = new NativeEditorActionsPanel(fileEditor, root, actionName); |
65 | 54 | return panel.isValidForFile() ? panel : null;
|
66 | 55 | }
|
67 | 56 |
|
@@ -114,9 +103,9 @@ class NativeEditorActionsPanel extends EditorNotificationPanel {
|
114 | 103 | final AnAction myAction;
|
115 | 104 | final boolean isVisible;
|
116 | 105 |
|
117 |
| - NativeEditorActionsPanel(VirtualFile file, VirtualFile root, String actionName) { |
| 106 | + NativeEditorActionsPanel(@NotNull FileEditor fileEditor, @NotNull VirtualFile root, @NotNull String actionName) { |
118 | 107 | super(UIUtils.getEditorNotificationBackgroundColor());
|
119 |
| - myFile = file; |
| 108 | + myFile = fileEditor.getFile(); |
120 | 109 | myRoot = root;
|
121 | 110 | myAction = ActionManager.getInstance().getAction(actionName);
|
122 | 111 |
|
|
0 commit comments