<commit_before>package com.intellij.lang.ant.config.actions;

import com.intellij.lang.ant.AntBundle;
import com.intellij.lang.ant.config.AntBuildFile;
import com.intellij.lang.ant.config.AntConfiguration;
import com.intellij.lang.ant.config.AntNoFileException;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.fileTypes.FileTypeManager;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.ToolWindowId;
import com.intellij.openapi.wm.ToolWindowManager;

public class AddAntBuildFile extends AnAction {
  public void actionPerformed(AnActionEvent event) {
    DataContext dataContext = event.getDataContext();
    Project project = (Project)dataContext.getData(DataConstants.PROJECT);
    VirtualFile file = (VirtualFile)dataContext.getData(DataConstants.VIRTUAL_FILE);
    AntConfiguration antConfiguration = AntConfiguration.getInstance(project);
    try {
      antConfiguration.addBuildFile(file);
      ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.ANT_BUILD).activate(null);
    }
    catch (AntNoFileException e) {
      Messages.showWarningDialog(project, AntBundle.message("cannot.add.build.files.from.excluded.directories.error.message",
                                                            e.getFile().getPresentableUrl()),
                                          AntBundle.message("cannot.add.build.file.dialog.title"));
    }
  }

  public void update(AnActionEvent e) {
    DataContext dataContext = e.getDataContext();
    Presentation presentation = e.getPresentation();
    Project project = (Project)dataContext.getData(DataConstants.PROJECT);
    if (project == null) {
      presentation.setEnabled(false);
      presentation.setVisible(false);
      return;
    }
    VirtualFile file = (VirtualFile)dataContext.getData(DataConstants.VIRTUAL_FILE);
    if (file == null) {
      presentation.setEnabled(false);
      presentation.setVisible(false);
      return;
    }

    boolean isXml = StdFileTypes.XML.equals(FileTypeManager.getInstance().getFileTypeByFile(file));
    if (!isXml) {
      presentation.setEnabled(false);
      presentation.setVisible(false);
      return;
    }

    for (final AntBuildFile buildFile : AntConfiguration.getInstance(project).getBuildFiles()) {
      if (file.equals(buildFile.getVirtualFile())) {
        presentation.setEnabled(false);
        presentation.setVisible(false);
        return;
      }
    }<commit_msg>cosmetics<commit_after>package com.intellij.lang.ant.config.actions;

import com.intellij.lang.ant.AntBundle;
import com.intellij.lang.ant.config.AntBuildFile;
import com.intellij.lang.ant.config.AntConfiguration;
import com.intellij.lang.ant.config.AntNoFileException;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.fileTypes.FileTypeManager;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.ToolWindowId;
import com.intellij.openapi.wm.ToolWindowManager;

public class AddAntBuildFile extends AnAction {
  public void actionPerformed(AnActionEvent event) {
    DataContext dataContext = event.getDataContext();
    Project project = DataKeys.PROJECT.getData(dataContext);
    VirtualFile file = DataKeys.VIRTUAL_FILE.getData(dataContext);
    AntConfiguration antConfiguration = AntConfiguration.getInstance(project);
    try {
      antConfiguration.addBuildFile(file);
      ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.ANT_BUILD).activate(null);
    }
    catch (AntNoFileException e) {
      Messages.showWarningDialog(project, AntBundle.message("cannot.add.build.files.from.excluded.directories.error.message",
                                                            e.getFile().getPresentableUrl()),
                                          AntBundle.message("cannot.add.build.file.dialog.title"));
    }
  }

  public void update(AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    final Presentation presentation = e.getPresentation();
    Project project = DataKeys.PROJECT.getData(dataContext);
    if (project == null) {
      presentation.setEnabled(false);
      presentation.setVisible(false);
      return;
    }
    VirtualFile file = DataKeys.VIRTUAL_FILE.getData(dataContext);
    if (file == null) {
      presentation.setEnabled(false);
      presentation.setVisible(false);
      return;
    }

    boolean isXml = StdFileTypes.XML.equals(FileTypeManager.getInstance().getFileTypeByFile(file));
    if (!isXml) {
      presentation.setEnabled(false);
      presentation.setVisible(false);
      return;
    }

    for (final AntBuildFile buildFile : AntConfiguration.getInstance(project).getBuildFiles()) {
      if (file.equals(buildFile.getVirtualFile())) {
        presentation.setEnabled(false);
        presentation.setVisible(false);
        return;
      }
    }
{'fraction_non_alphanumeric': 0.10612563402262973, 'fraction_numerical': 0.0, 'mean_word_length': 3.6993583868010997, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4443492', 'n_tokens_mistral': 1447, 'n_tokens_neox': 1434, 'n_words': 208}