From d8fa76b6538d0d8a4a342e370b91d92288fdef5a Mon Sep 17 00:00:00 2001 From: Julia Beliaeva Date: Tue, 19 Jul 2016 23:42:33 +0300 Subject: [PATCH] [file-history] move myOriginalComment field into MyCommentsPane --- .../vcs/history/FileHistoryPanelImpl.java | 102 ++++++++++-------- 1 file changed, 56 insertions(+), 46 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryPanelImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryPanelImpl.java index 9d9d8fa2c580..ff25a2e4553a 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryPanelImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryPanelImpl.java @@ -82,11 +82,7 @@ import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreeCellRenderer; import javax.swing.tree.TreePath; import java.awt.*; -import java.awt.datatransfer.Clipboard; -import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.StringSelection; -import java.awt.datatransfer.Transferable; -import java.awt.event.InputEvent; import java.io.IOException; import java.util.*; import java.util.List; @@ -102,7 +98,7 @@ public class FileHistoryPanelImpl extends PanelWithActionsAndCloseButton impleme private static final String COMMIT_MESSAGE_TITLE = VcsBundle.message("label.selected.revision.commit.message"); private static final String VCS_HISTORY_ACTIONS_GROUP = "VcsHistoryActionsGroup"; @NotNull private final Project myProject; - private final JEditorPane myComments; + private final MyCommentsPane myComments; private final StatusText myCommentsStatus; private final DefaultActionGroup myPopupActions; private final AbstractVcs myVcs; @@ -125,7 +121,6 @@ public class FileHistoryPanelImpl extends PanelWithActionsAndCloseButton impleme }; private JComponent myAdditionalDetails; private Consumer myListener; - private String myOriginalComment = ""; private VcsHistorySession myHistorySession; private VcsFileRevision myBottomRevisionForShowDiff; private volatile boolean myInRefresh; @@ -170,11 +165,17 @@ public class FileHistoryPanelImpl extends PanelWithActionsAndCloseButton impleme myCommentsStatus = new StatusText() { @Override protected boolean isStatusVisible() { - return StringUtil.isEmpty(myOriginalComment); + return myComments.isEmpty(); } }; myCommentsStatus.setText("Commit message"); - myComments = new MyCommentsPane(); + myComments = new MyCommentsPane() { + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + myCommentsStatus.paint(this, g); + } + }; myCommentsStatus.attachTo(myComments); myRevisionsOrder = new HashMap<>(); @@ -418,42 +419,10 @@ public class FileHistoryPanelImpl extends PanelWithActionsAndCloseButton impleme private void updateMessage() { List selection = getSelection(); + myComments.update(selection); if (selection.isEmpty()) { - myComments.setText(""); - myOriginalComment = ""; return; } - boolean addRevisionInfo = selection.size() > 1; - StringBuilder original = new StringBuilder(); - StringBuilder html = new StringBuilder(); - for (TreeNodeOnVcsRevision revision : selection) { - String message = revision.getCommitMessage(); - if (StringUtil.isEmpty(message)) continue; - if (original.length() > 0) { - original.append("\n\n"); - html.append("

"); - } - if (addRevisionInfo) { - String revisionInfo = getPresentableText(revision.getRevision(), false); - html.append("") - .append(getHtmlWithFonts(revisionInfo)).append("
"); - original.append(revisionInfo).append("\n"); - } - original.append(message); - html.append(getHtmlWithFonts(formatTextWithLinks(myVcs.getProject(), message))); - } - myOriginalComment = original.toString(); - if (StringUtil.isEmpty(myOriginalComment)) { - myComments.setText(""); - } - else { - myComments.setText("" + - UIUtil.getCssFontDeclaration(VcsHistoryUtil.getCommitDetailsFont()) + - "" + - html.toString() + - ""); - myComments.setCaretPosition(0); - } if (myListener != null) { myListener.consume(selection.get(0).getRevision()); } @@ -876,7 +845,9 @@ public class FileHistoryPanelImpl extends PanelWithActionsAndCloseButton impleme private static class AuthorCellRenderer extends ColoredTableCellRenderer { private String myTooltipText; - /** @noinspection MethodNamesDifferingOnlyByCase*/ + /** + * @noinspection MethodNamesDifferingOnlyByCase + */ public void setTooltipText(final String text) { myTooltipText = text; } @@ -1711,14 +1682,53 @@ public class FileHistoryPanelImpl extends PanelWithActionsAndCloseButton impleme } private class MyCommentsPane extends HtmlPanel implements DataProvider, CopyProvider { + private String myOriginalComment = ""; + public MyCommentsPane() { setPreferredSize(new Dimension(150, 100)); } - @Override - protected void paintComponent(Graphics g) { - super.paintComponent(g); - myCommentsStatus.paint(this, g); + public void update(@NotNull List selection) { + if (selection.isEmpty()) { + setText(""); + myOriginalComment = ""; + return; + } + boolean addRevisionInfo = selection.size() > 1; + StringBuilder original = new StringBuilder(); + StringBuilder html = new StringBuilder(); + for (TreeNodeOnVcsRevision revision : selection) { + String message = revision.getCommitMessage(); + if (StringUtil.isEmpty(message)) continue; + if (original.length() > 0) { + original.append("\n\n"); + html.append("

"); + } + if (addRevisionInfo) { + String revisionInfo = getPresentableText(revision.getRevision(), false); + html.append("") + .append(getHtmlWithFonts(revisionInfo)).append("
"); + original.append(revisionInfo).append("\n"); + } + original.append(message); + html.append(getHtmlWithFonts(formatTextWithLinks(myVcs.getProject(), message))); + } + myOriginalComment = original.toString(); + if (StringUtil.isEmpty(myOriginalComment)) { + setText(""); + } + else { + setText("" + + UIUtil.getCssFontDeclaration(VcsHistoryUtil.getCommitDetailsFont()) + + "" + + html.toString() + + ""); + setCaretPosition(0); + } + } + + public boolean isEmpty() { + return StringUtil.isEmpty(myOriginalComment); } @Override