<commit_before>// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.ide.lightEdit.actions;

import com.intellij.ide.lightEdit.LightEdit;
import com.intellij.ide.lightEdit.LightEditCompatible;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.fileChooser.FileSystemTree;
import com.intellij.openapi.fileChooser.actions.FileChooserAction;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NotNull;

public final class LightEditGotoOpenedFileAction extends FileChooserAction implements LightEditCompatible {

  @Override
  protected void actionPerformed(@NotNull FileSystemTree fileSystemTree, @NotNull AnActionEvent e) {
    Project project = e.getProject();
    if (project != null) {
      VirtualFile file = ArrayUtil.getFirstElement(FileEditorManager.getInstance(project).getSelectedFiles());
      if (file != null) {
        fileSystemTree.select(file, () -> fileSystemTree.expand(file, null));
      }
    }
  }

  @Override
  protected void update(@NotNull FileSystemTree fileChooser, @NotNull AnActionEvent e) {
    Project project = e.getProject();
    if (LightEdit.owns(project)) {
      e.getPresentation().setEnabled(FileEditorManager.getInstance(project).hasOpenFiles());
    }
    else {
      e.getPresentation().setEnabledAndVisible(false);
    }
  }
}
<commit_msg>light edit: disable "Select Opened File" action for non-existent files (IDEA-237793)<commit_after>// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.ide.lightEdit.actions;

import com.intellij.ide.lightEdit.LightEdit;
import com.intellij.ide.lightEdit.LightEditCompatible;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.fileChooser.FileSystemTree;
import com.intellij.openapi.fileChooser.actions.FileChooserAction;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public final class LightEditGotoOpenedFileAction extends FileChooserAction implements LightEditCompatible {

  @Override
  protected void actionPerformed(@NotNull FileSystemTree fileSystemTree, @NotNull AnActionEvent e) {
    Project project = e.getProject();
    VirtualFile file = getSelectedFile(fileSystemTree, project);
    if (project != null && file != null) {
      fileSystemTree.select(file, () -> fileSystemTree.expand(file, null));
    }
  }

  @Override
  protected void update(@NotNull FileSystemTree fileSystemTree, @NotNull AnActionEvent e) {
    Project project = e.getProject();
    if (LightEdit.owns(project)) {
      e.getPresentation().setEnabled(getSelectedFile(fileSystemTree, project) != null);
    }
    else {
      e.getPresentation().setEnabledAndVisible(false);
    }
  }

  private static @Nullable VirtualFile getSelectedFile(@NotNull FileSystemTree fileSystemTree, @Nullable Project project) {
    if (LightEdit.owns(project)) {
      VirtualFile file = ArrayUtil.getFirstElement(FileEditorManager.getInstance(project).getSelectedFiles());
      return file != null && file.getParent() != null && fileSystemTree.isUnderRoots(file) ? file : null;
    }
    return null;
  }
}

{'fraction_non_alphanumeric': 0.09966960352422907, 'fraction_numerical': 0.007158590308370044, 'mean_word_length': 4.975328947368421, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '988281', 'n_tokens_mistral': 1096, 'n_tokens_neox': 1057, 'n_words': 231}