/*
 * Copyright 2017 The Chromium Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */
package io.flutter.actions;

import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.vfs.VirtualFile;
import io.flutter.FlutterUtils;


public class FlutterExternalIdeActionGroup extends DefaultActionGroup {
  @Override
  public void update(AnActionEvent e) {
    final boolean enabled =  SystemInfo.isMac && isXcodeFile(e);
    final Presentation presentation = e.getPresentation();
    presentation.setEnabled(enabled);
    presentation.setVisible(enabled);
  }

  private boolean isXcodeFile(AnActionEvent e) {
    final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
    return file != null && file.exists() && FlutterUtils.isXcodeProjectFileName(file.getName());
  }
}

@@ -423,16 +423,61 @@
 tation;%0A
+import com.intellij.openapi.project.Project;%0A
 import c
@@ -513,16 +513,16 @@
 emInfo;%0A
-
 import c
@@ -590,16 +590,101 @@
 rUtils;%0A
+import org.jetbrains.annotations.NotNull;%0Aimport org.jetbrains.annotations.Nullable;%0A
 %0A%0Apublic
@@ -828,17 +828,16 @@
 nabled =
- 
  SystemI
@@ -1148,96 +1148,563 @@
     
-return file != null && file.exists() && FlutterUtils.isXcodeProjectFileName(file.getName
+if (file == null %7C%7C !file.exists()) return false;%0A    final Project project = e.getProject();%0A    return%0A      isProjectDirectory(file, project) %7C%7C isIOsDirectory(file) %7C%7C FlutterUtils.isXcodeProjectFileName(file.getName());%0A  %7D%0A%0A  private boolean isIOsDirectory(@NotNull VirtualFile file) %7B%0A    return file.isDirectory() && file.getName().equals(%22ios%22);%0A  %7D%0A%0A  private boolean isProjectDirectory(@NotNull VirtualFile file, @Nullable Project project) %7B%0A    return file.isDirectory() && project != null && project.getBaseDir().getPath().equals(file.getPath
 ());

Improve “Open in Xcode” filtering (#880) (#1086)