Skip to content

Commit

Permalink
Migrate the NativeEditorNotificationProvider to the new EditorNotific…
Browse files Browse the repository at this point in the history
…ationProvider API (#7840)

This is progress on
#7830
  • Loading branch information
jwren authored Dec 3, 2024
1 parent 9a1a246 commit 5e388b6
Showing 1 changed file with 12 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,61 +7,50 @@

import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.EditorNotificationPanel;
import com.intellij.ui.EditorNotificationProvider;
import com.intellij.ui.EditorNotifications;
import icons.FlutterIcons;
import io.flutter.FlutterBundle;
import io.flutter.utils.UIUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

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

public class NativeEditorNotificationProvider implements EditorNotificationProvider {
private final Project project;
private boolean showNotification = true;

public NativeEditorNotificationProvider(@NotNull Project project) {
this.project = project;
}

@NotNull
@Override
public Key<EditorNotificationPanel> getKey() {
return KEY;
}

@Nullable
@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 (!file.isInLocalFileSystem() || !showNotification) {
return null;
}
return createPanelForFile(file, findRootDir(file, project.getBaseDir()));
}

@Nullable
private EditorNotificationPanel createPanelForFile(@NotNull VirtualFile file, @Nullable VirtualFile root) {
VirtualFile root = project.getBaseDir();
if (root == null) {
return null;
}
return createPanelForAction(file, root, getActionName(root));
return fileEditor -> createPanelForAction(fileEditor, root, getActionName(root));
}

@Nullable
private EditorNotificationPanel createPanelForAction(@NotNull VirtualFile file, @NotNull VirtualFile root, @Nullable String actionName) {
private EditorNotificationPanel createPanelForAction(@NotNull FileEditor fileEditor, @NotNull VirtualFile root, @Nullable String actionName) {
if (actionName == null) {
return null;
}
final NativeEditorActionsPanel panel = new NativeEditorActionsPanel(file, root, actionName);
final NativeEditorActionsPanel panel = new NativeEditorActionsPanel(fileEditor, root, actionName);
return panel.isValidForFile() ? panel : null;
}

Expand Down Expand Up @@ -114,9 +103,9 @@ class NativeEditorActionsPanel extends EditorNotificationPanel {
final AnAction myAction;
final boolean isVisible;

NativeEditorActionsPanel(VirtualFile file, VirtualFile root, String actionName) {
NativeEditorActionsPanel(@NotNull FileEditor fileEditor, @NotNull VirtualFile root, @NotNull String actionName) {
super(UIUtils.getEditorNotificationBackgroundColor());
myFile = file;
myFile = fileEditor.getFile();
myRoot = root;
myAction = ActionManager.getInstance().getAction(actionName);

Expand Down

0 comments on commit 5e388b6

Please sign in to comment.