Skip to content

Migrate the NativeEditorNotificationProvider to the new EditorNotificationProvider API #7840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading