<commit_before>/*
 * Copyright (c) 2000-2006 JetBrains s.r.o. All Rights Reserved.
 */

package com.intellij.openapi.vcs.changes.actions;

import com.intellij.CommonBundle;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DataKeys;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vcs.*;
import com.intellij.openapi.vcs.changes.ui.CommittedChangesFilterDialog;
import com.intellij.openapi.vcs.versionBrowser.ChangeBrowserSettings;
import com.intellij.openapi.vfs.VirtualFile;

/**
 * @author yole
 */
public class BrowseChangesAction extends AnAction {
  public void actionPerformed(AnActionEvent e) {
    final Project project = e.getData(DataKeys.PROJECT);
    VirtualFile vFile = e.getData(DataKeys.VIRTUAL_FILE);
    assert vFile != null;
    AbstractVcs vcs = ProjectLevelVcsManager.getInstance(project).getVcsFor(vFile);
    final CommittedChangesProvider provider = vcs.getCommittedChangesProvider();
    assert provider != null;
    ChangeBrowserSettings settings = provider.createDefaultSettings();
    CommittedChangesFilterDialog dlg = new CommittedChangesFilterDialog(project, provider.createFilterUI(true), settings);
    dlg.show();
    if (!dlg.isOK()) return;

    int maxCount = 0;
    if (!settings.isAnyFilterSpecified()) {
      int rc = Messages.showDialog(project, VcsBundle.message("browse.changes.no.filter.prompt"), VcsBundle.message("browse.changes.title"),
                                   new String[] {
                                     VcsBundle.message("browse.changes.show.all.button"),
                                     VcsBundle.message("browse.changes.show.recent.button"),
                                     CommonBundle.getCancelButtonText()
                                   }, 1, Messages.getQuestionIcon());
      if (rc == 2) {
        return;
      }
      if (rc == 1) {
        maxCount = 50;
      }
    }

    AbstractVcsHelper.getInstance(project).openCommittedChangesTab(provider, vFile, settings, maxCount, null);
  }

  public void update(AnActionEvent e) {
    e.getPresentation().setEnabled(isActionEnabled(e));
  }

  private static boolean isActionEnabled(final AnActionEvent e) {
    Project project = e.getData(DataKeys.PROJECT);
    if (project == null) return false;
    VirtualFile vFile = e.getData(DataKeys.VIRTUAL_FILE);
    if (vFile == null) return false;
    AbstractVcs vcs = ProjectLevelVcsManager.getInstance(project).getVcsFor(vFile);
    return vcs != null && vcs.getCommittedChangesProvider() != null;
  }
}<commit_msg>disable "browse changes" for files/directories not in VCS (IDEADEV-10933)<commit_after>/*
 * Copyright (c) 2000-2006 JetBrains s.r.o. All Rights Reserved.
 */

package com.intellij.openapi.vcs.changes.actions;

import com.intellij.CommonBundle;
import com.intellij.peer.PeerFactory;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DataKeys;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vcs.*;
import com.intellij.openapi.vcs.changes.ui.CommittedChangesFilterDialog;
import com.intellij.openapi.vcs.versionBrowser.ChangeBrowserSettings;
import com.intellij.openapi.vfs.VirtualFile;

/**
 * @author yole
 */
public class BrowseChangesAction extends AnAction {
  public void actionPerformed(AnActionEvent e) {
    final Project project = e.getData(DataKeys.PROJECT);
    VirtualFile vFile = e.getData(DataKeys.VIRTUAL_FILE);
    assert vFile != null;
    AbstractVcs vcs = ProjectLevelVcsManager.getInstance(project).getVcsFor(vFile);
    assert vcs != null;
    final CommittedChangesProvider provider = vcs.getCommittedChangesProvider();
    assert provider != null;
    ChangeBrowserSettings settings = provider.createDefaultSettings();
    CommittedChangesFilterDialog dlg = new CommittedChangesFilterDialog(project, provider.createFilterUI(true), settings);
    dlg.show();
    if (!dlg.isOK()) return;

    int maxCount = 0;
    if (!settings.isAnyFilterSpecified()) {
      int rc = Messages.showDialog(project, VcsBundle.message("browse.changes.no.filter.prompt"), VcsBundle.message("browse.changes.title"),
                                   new String[] {
                                     VcsBundle.message("browse.changes.show.all.button"),
                                     VcsBundle.message("browse.changes.show.recent.button"),
                                     CommonBundle.getCancelButtonText()
                                   }, 1, Messages.getQuestionIcon());
      if (rc == 2) {
        return;
      }
      if (rc == 1) {
        maxCount = 50;
      }
    }

    AbstractVcsHelper.getInstance(project).openCommittedChangesTab(provider, vFile, settings, maxCount, null);
  }

  public void update(AnActionEvent e) {
    e.getPresentation().setEnabled(isActionEnabled(e));
  }

  private static boolean isActionEnabled(final AnActionEvent e) {
    Project project = e.getData(DataKeys.PROJECT);
    if (project == null) return false;
    VirtualFile vFile = e.getData(DataKeys.VIRTUAL_FILE);
    if (vFile == null) return false;
    AbstractVcs vcs = ProjectLevelVcsManager.getInstance(project).getVcsFor(vFile);
    if (vcs == null || vcs.getCommittedChangesProvider() == null) {
      return false;
    }
    FilePath filePath = PeerFactory.getInstance().getVcsContextFactory().createFilePathOn(vFile);
    return vcs.fileExistsInVcs(filePath);
  }
}
{'fraction_non_alphanumeric': 0.10931102011750045, 'fraction_numerical': 0.005875022253872174, 'mean_word_length': 3.368584758942457, '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': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '18369', 'n_tokens_mistral': 1711, 'n_tokens_neox': 1650, 'n_words': 302}