mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[vcs-log] copy in graph table copies exactly what is seen in the table
IDEA-158862
This commit is contained in:
@@ -23,10 +23,8 @@ import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.ide.CopyPasteManager;
|
||||
import com.intellij.openapi.ui.LoadingDecorator;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Couple;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.ui.*;
|
||||
import com.intellij.ui.components.JBLabel;
|
||||
@@ -35,7 +33,9 @@ import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.text.DateFormatUtil;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import com.intellij.vcs.log.*;
|
||||
import com.intellij.vcs.log.VcsCommitStyleFactory;
|
||||
import com.intellij.vcs.log.VcsLogHighlighter;
|
||||
import com.intellij.vcs.log.VcsShortCommitDetails;
|
||||
import com.intellij.vcs.log.data.LoadingDetails;
|
||||
import com.intellij.vcs.log.data.VcsLogData;
|
||||
import com.intellij.vcs.log.data.VcsLogProgress;
|
||||
@@ -290,12 +290,18 @@ public class VcsLogGraphTable extends TableWithProgress implements DataProvider,
|
||||
|
||||
@Override
|
||||
public void performCopy(@NotNull DataContext dataContext) {
|
||||
VcsLog log = VcsLogDataKeys.VCS_LOG.getData(dataContext);
|
||||
if (log == null) return;
|
||||
List<VcsFullCommitDetails> details = VcsLogUtil.collectFirstPackOfLoadedSelectedDetails(log);
|
||||
if (details.isEmpty()) return;
|
||||
String text = StringUtil.join(details, VcsLogGraphTable::getPresentableText, "\n");
|
||||
CopyPasteManager.getInstance().setContents(new StringSelection(text));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
int[] selectedRows = getSelectedRows();
|
||||
for (int i = 0; i < Math.min(VcsLogUtil.MAX_SELECTED_COMMITS, selectedRows.length); i++) {
|
||||
int row = selectedRows[i];
|
||||
sb.append(getModel().getValueAt(row, GraphTableModel.COMMIT_COLUMN).toString());
|
||||
sb.append(" ").append(getModel().getValueAt(row, GraphTableModel.AUTHOR_COLUMN).toString());
|
||||
sb.append(" ").append(getModel().getValueAt(row, GraphTableModel.DATE_COLUMN).toString());
|
||||
if (i != selectedRows.length - 1) sb.append("\n");
|
||||
}
|
||||
|
||||
CopyPasteManager.getInstance().setContents(new StringSelection(sb.toString()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -303,21 +309,6 @@ public class VcsLogGraphTable extends TableWithProgress implements DataProvider,
|
||||
return getSelectedRowCount() > 0;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String getPresentableText(@NotNull VcsFullCommitDetails commit) {
|
||||
// implementation reflected by com.intellij.openapi.vcs.history.FileHistoryPanelImpl.getPresentableText()
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(commit.getId().toShortString()).append(" ");
|
||||
sb.append(commit.getAuthor().getName());
|
||||
long time = commit.getAuthorTime();
|
||||
sb.append(" on ").append(DateFormatUtil.formatDate(time)).append(" at ").append(DateFormatUtil.formatTime(time));
|
||||
if (!Comparing.equal(commit.getAuthor(), commit.getCommitter())) {
|
||||
sb.append(" (committed by ").append(commit.getCommitter().getName()).append(")");
|
||||
}
|
||||
sb.append(" ").append(commit.getSubject());
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCopyVisible(@NotNull DataContext dataContext) {
|
||||
return true;
|
||||
|
||||
@@ -12,7 +12,9 @@ public class GraphCommitCell {
|
||||
@NotNull private final Collection<VcsRef> myRefsToThisCommit;
|
||||
@NotNull private final Collection<? extends PrintElement> myPrintElements;
|
||||
|
||||
public GraphCommitCell(@NotNull String text, @NotNull Collection<VcsRef> refsToThisCommit, @NotNull Collection<? extends PrintElement> printElements) {
|
||||
public GraphCommitCell(@NotNull String text,
|
||||
@NotNull Collection<VcsRef> refsToThisCommit,
|
||||
@NotNull Collection<? extends PrintElement> printElements) {
|
||||
myText = text;
|
||||
myRefsToThisCommit = refsToThisCommit;
|
||||
myPrintElements = printElements;
|
||||
@@ -32,4 +34,9 @@ public class GraphCommitCell {
|
||||
public Collection<? extends PrintElement> getPrintElements() {
|
||||
return myPrintElements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return myText;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user