Introduce CopyCommitSubjectAction
[idea/community.git] / platform / vcs-impl / src / com / intellij / openapi / vcs / history / actions / CopyCommitSubjectAction.java
1 // Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
2 package com.intellij.openapi.vcs.history.actions;
3
4 import com.intellij.openapi.actionSystem.AnActionEvent;
5 import com.intellij.openapi.ide.CopyPasteManager;
6 import com.intellij.openapi.project.DumbAwareAction;
7 import com.intellij.openapi.util.text.StringUtil;
8 import com.intellij.openapi.vcs.VcsDataKeys;
9 import org.jetbrains.annotations.NotNull;
10
11 import java.awt.datatransfer.StringSelection;
12
13 public class CopyCommitSubjectAction extends DumbAwareAction {
14
15   @Override
16   public void actionPerformed(@NotNull AnActionEvent e) {
17     String[] subjects = e.getData(VcsDataKeys.VCS_COMMIT_SUBJECTS);
18     if (subjects == null || subjects.length == 0) return;
19     CopyPasteManager.getInstance().setContents(new StringSelection(StringUtil.join(subjects, "\n")));
20   }
21
22   @Override
23   public void update(@NotNull AnActionEvent e) {
24     String[] subjects = e.getData(VcsDataKeys.VCS_COMMIT_SUBJECTS);
25     e.getPresentation().setEnabled(subjects != null && subjects.length > 0);
26   }
27 }