<commit_before>/*
 * Copyright 2000-2009 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.ide.actions;

import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DataConstants;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.ShadowAction;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowManager;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;

public class ShowContentAction extends AnAction {
  private ToolWindow myWindow;

  public ShowContentAction() {
  }

  public ShowContentAction(ToolWindow window, JComponent c) {
    myWindow = window;
    AnAction original = ActionManager.getInstance().getAction("ShowContent");
    new ShadowAction(this, original, c);
    copyFrom(original);
  }

  @Override
  public void update(AnActionEvent e) {
    e.getPresentation().setEnabled(getWindow(e) != null);
  }

  @Override
  public void actionPerformed(AnActionEvent e) {
    getWindow(e).showContentPopup(e.getInputEvent());
  }

  @Nullable
  private ToolWindow getWindow(AnActionEvent event) {
    if (myWindow != null) return myWindow;

    Project project = (Project)event.getDataContext().getData(DataConstants.PROJECT);
    if (project == null) return null;

    ToolWindowManager manager = ToolWindowManager.getInstance(project);

    return manager.getToolWindow(manager.getActiveToolWindowId());
  }<commit_msg>[r=kb] Fix conflict of ShowContentAction and TabSwitcher. Ctrl+Down with tabSwitcher shown must move selection to next line instead of showing content.<commit_after>/*
 * Copyright 2000-2009 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.ide.actions;

import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.ShadowAction;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowManager;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.awt.*;

public class ShowContentAction extends AnAction {
  private ToolWindow myWindow;

  public ShowContentAction() {
  }

  public ShowContentAction(ToolWindow window, JComponent c) {
    myWindow = window;
    AnAction original = ActionManager.getInstance().getAction("ShowContent");
    new ShadowAction(this, original, c);
    copyFrom(original);
  }

  @Override
  public void update(AnActionEvent e) {
    e.getPresentation().setEnabled(getWindow(e) != null);
  }

  @Override
  public void actionPerformed(AnActionEvent e) {
    getWindow(e).showContentPopup(e.getInputEvent());
  }

  @Nullable
  private ToolWindow getWindow(AnActionEvent event) {
    if (myWindow != null) return myWindow;

    Project project = PlatformDataKeys.PROJECT.getData(event.getDataContext());
    if (project == null) return null;

    ToolWindowManager manager = ToolWindowManager.getInstance(project);
    final ToolWindow window = manager.getToolWindow(manager.getActiveToolWindowId());

    final Component context = PlatformDataKeys.CONTEXT_COMPONENT.getData(event.getDataContext());

    return context == null || SwingUtilities.isDescendingFrom(window.getComponent(), context) ? window : null;
  }
{'fraction_non_alphanumeric': 0.09398907103825137, 'fraction_numerical': 0.005245901639344262, 'mean_word_length': 4.807106598984771, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5109185', 'n_tokens_mistral': 1302, 'n_tokens_neox': 1275, 'n_words': 367}