<commit_before>/*
 * Copyright 2000-2010 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 git4idea.checkout.branches;

import com.intellij.ide.DataManager;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.actionSystem.impl.SimpleDataContext;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.MessageType;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.ui.popup.ListPopup;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.CustomStatusBarWidget;
import com.intellij.openapi.wm.StatusBar;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.openapi.wm.WindowManager;
import com.intellij.ui.awt.RelativePoint;
import com.intellij.util.ui.UIUtil;
import git4idea.GitUtil;
import git4idea.GitVcs;
import git4idea.commands.GitCommand;
import git4idea.commands.GitHandlerUtil;
import git4idea.commands.GitLineHandler;
import git4idea.ui.GitUIUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Collection;

/**
 * The git branches widget
 */
public class GitBranchesWidget extends JLabel implements CustomStatusBarWidget {
  /**
   * The logger
   */
  private static final Logger LOG = Logger.getInstance(GitBranchesWidget.class.getName());

  /**
   * The ID of the widget
   */
  public static final String ID = "git4idea.BranchConfigurations";
  /**
   * The listener
   */
  final GitBranchConfigurationsListener myConfigurationsListener;
  /**
   * The project
   */
  final Project myProject;
  /**
   * The configurations instance
   */
  private final GitBranchConfigurations myConfigurations;
  /**
   * The selectable configurations. Null if invalidated or non-initialized
   */
  private AnAction[] mySelectableConfigurations;
  /**
   * The candidate remote configurations. Null if invalidated or non-initialized
   */
  private AnAction[] myRemoveConfigurations;
  /**
   * The status bar
   */
  private StatusBar myStatusBar;
  /**
   * If true, the popup is enabled
   */
  private boolean myPopupEnabled = false;
  /**
   * The action group for pop up
   */
  private DefaultActionGroup myPopupActionGroup;
  /**
   * The current popup
   */
  private ListPopup myPopup;
  /**
   * The default foreground color
   */
  private final Color myDefaultForeground;


  /**
   * The constructor
   *
   * @param project the project instance
   */
  public GitBranchesWidget(Project project, GitBranchConfigurations configurations) {
    myProject = project;
    setBorder(WidgetBorder.INSTANCE);
    //setBorder(BorderFactory.createEtchedBorder());
    myConfigurations = configurations;
    myDefaultForeground = getForeground();
    myConfigurationsListener = new MyGitBranchConfigurationsListener();
    myConfigurations.addConfigurationListener(myConfigurationsListener);
    setIcon(IconLoader.findIcon("/icons/branch.png", getClass()));
    Disposer.register(myConfigurations, this);
    addMouseListener(new MouseAdapter() {
      @Override
      public void mouseClicked(MouseEvent e) {
        showPopup();
      }
    });
    updateLabel();
  }

  /**
   * Create and install widget
   *
   * @param project        the context project
   * @param configurations the configurations to use
   * @return the action that uninstalls widget
   */
  static Runnable install(final Project project, final GitBranchConfigurations configurations) {
    final Ref<GitBranchesWidget> widget = new Ref<GitBranchesWidget>();
    UIUtil.invokeAndWaitIfNeeded(new Runnable() {
      @Override
      public void run() {
        StatusBar statusBar = WindowManager.getInstance().getStatusBar(project);
        if (statusBar != null) {
          final GitBranchesWidget w = new GitBranchesWidget(project, configurations);
          statusBar.addWidget(w, "after InsertOverwrite", project);
          widget.set(w);
        }
      }
    });
    return new Runnable() {
      @Override
      public void run() {
        if (widget.get() != null) {
          UIUtil.invokeLaterIfNeeded(new Runnable() {
            @Override
            public void run() {
              Disposer.dispose(widget.get());
            }
          });
        }
      }
    };

  }

  /**
   * {@inheritDoc}
   */
  @Override
  public JComponent getComponent() {
    return this;
  }

  /**
   * {@inheritDoc}
   */<commit_msg>fix git branches status bar widget: there is no InsertOverwrite widget on Macs :)<commit_after>/*
 * Copyright 2000-2010 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 git4idea.checkout.branches;

import com.intellij.ide.DataManager;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.actionSystem.impl.SimpleDataContext;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.MessageType;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.ui.popup.ListPopup;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.CustomStatusBarWidget;
import com.intellij.openapi.wm.StatusBar;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.openapi.wm.WindowManager;
import com.intellij.ui.awt.RelativePoint;
import com.intellij.util.ui.UIUtil;
import git4idea.GitUtil;
import git4idea.GitVcs;
import git4idea.commands.GitCommand;
import git4idea.commands.GitHandlerUtil;
import git4idea.commands.GitLineHandler;
import git4idea.ui.GitUIUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Collection;

/**
 * The git branches widget
 */
public class GitBranchesWidget extends JLabel implements CustomStatusBarWidget {
  /**
   * The logger
   */
  private static final Logger LOG = Logger.getInstance(GitBranchesWidget.class.getName());

  /**
   * The ID of the widget
   */
  public static final String ID = "git4idea.BranchConfigurations";
  /**
   * The listener
   */
  final GitBranchConfigurationsListener myConfigurationsListener;
  /**
   * The project
   */
  final Project myProject;
  /**
   * The configurations instance
   */
  private final GitBranchConfigurations myConfigurations;
  /**
   * The selectable configurations. Null if invalidated or non-initialized
   */
  private AnAction[] mySelectableConfigurations;
  /**
   * The candidate remote configurations. Null if invalidated or non-initialized
   */
  private AnAction[] myRemoveConfigurations;
  /**
   * The status bar
   */
  private StatusBar myStatusBar;
  /**
   * If true, the popup is enabled
   */
  private boolean myPopupEnabled = false;
  /**
   * The action group for pop up
   */
  private DefaultActionGroup myPopupActionGroup;
  /**
   * The current popup
   */
  private ListPopup myPopup;
  /**
   * The default foreground color
   */
  private final Color myDefaultForeground;


  /**
   * The constructor
   *
   * @param project the project instance
   */
  public GitBranchesWidget(Project project, GitBranchConfigurations configurations) {
    myProject = project;
    setBorder(WidgetBorder.INSTANCE);
    //setBorder(BorderFactory.createEtchedBorder());
    myConfigurations = configurations;
    myDefaultForeground = getForeground();
    myConfigurationsListener = new MyGitBranchConfigurationsListener();
    myConfigurations.addConfigurationListener(myConfigurationsListener);
    setIcon(IconLoader.findIcon("/icons/branch.png", getClass()));
    Disposer.register(myConfigurations, this);
    addMouseListener(new MouseAdapter() {
      @Override
      public void mouseClicked(MouseEvent e) {
        showPopup();
      }
    });
    updateLabel();
  }

  /**
   * Create and install widget
   *
   * @param project        the context project
   * @param configurations the configurations to use
   * @return the action that uninstalls widget
   */
  static Runnable install(final Project project, final GitBranchConfigurations configurations) {
    final Ref<GitBranchesWidget> widget = new Ref<GitBranchesWidget>();
    UIUtil.invokeAndWaitIfNeeded(new Runnable() {
      @Override
      public void run() {
        StatusBar statusBar = WindowManager.getInstance().getStatusBar(project);
        if (statusBar != null) {
          final GitBranchesWidget w = new GitBranchesWidget(project, configurations);
          statusBar.addWidget(w, "after " + (SystemInfo.isMac ? "Encoding" : "InsertOverwrite"), project);
          widget.set(w);
        }
      }
    });
    return new Runnable() {
      @Override
      public void run() {
        if (widget.get() != null) {
          UIUtil.invokeLaterIfNeeded(new Runnable() {
            @Override
            public void run() {
              Disposer.dispose(widget.get());
            }
          });
        }
      }
    };

  }

  /**
   * {@inheritDoc}
   */
  @Override
  public JComponent getComponent() {
    return this;
  }

  /**
   * {@inheritDoc}
   */
{'fraction_non_alphanumeric': 0.09885181198421242, 'fraction_numerical': 0.003588087549336204, 'mean_word_length': 3.6165631469979296, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3317145', 'n_tokens_mistral': 3244, 'n_tokens_neox': 3203, 'n_words': 791}