From 2fba4bc254a10d8a0a1e849c11e71d84aad2663e Mon Sep 17 00:00:00 2001 From: irengrig Date: Wed, 2 Nov 2011 18:53:50 +0400 Subject: [PATCH] File history: Show Diff action - if one revision selected - show diff between selected revision *and previous* ++ separate Show Diff With local action --- .../vcs/history/FileHistoryPanelImpl.java | 50 ++++++++++++++----- 1 file changed, 37 insertions(+), 13 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 9fc0fd8d1784..0cfcf6df3b90 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 @@ -742,6 +742,8 @@ public class FileHistoryPanelImpl extends PanelWithActionsAndCloseButton { else { diffAction.registerCustomShortcutSet(CommonShortcuts.getDiff(), this); } + final MyShowDiffWithLocalAction showDiffWithLocalAction = new MyShowDiffWithLocalAction(); + result.add(showDiffWithLocalAction); final AnAction diffGroup = ActionManager.getInstance().getAction(VCS_HISTORY_ACTIONS_GROUP); if (diffGroup != null) result.add(diffGroup); @@ -831,10 +833,14 @@ public class FileHistoryPanelImpl extends PanelWithActionsAndCloseButton { showDifferences(myVcs.getProject(), sel.get(0), sel.get(sel.size() - 1)); } else if (selectionSize == 1) { - if (ChangeListManager.getInstance(myVcs.getProject()).isFreezedWithNotification(null)) return; - final VcsRevisionNumber currentRevisionNumber = myHistorySession.getCurrentRevisionNumber(); - if (currentRevisionNumber != null) { - showDifferences(myVcs.getProject(), getFirstSelectedRevision(), new CurrentRevision(myFilePath.getVirtualFile(), currentRevisionNumber)); + final TableView flatView = myDualView.getFlatView(); + final TableViewModel model = flatView.getTableViewModel(); + final int selectedRow = flatView.getSelectedRow(); + if (selectedRow == (model.getRowCount() - 1)) { + // no previous + showDifferences(myVcs.getProject(), VcsFileRevision.NULL, getFirstSelectedRevision()); + } else { + showDifferences(myVcs.getProject(), (VcsFileRevision)model.getRowValue(selectedRow + 1), getFirstSelectedRevision()); } } } @@ -842,20 +848,14 @@ public class FileHistoryPanelImpl extends PanelWithActionsAndCloseButton { public void update(final AnActionEvent e) { super.update(e); final int selectionSize = getSelection().size(); - if (selectionSize == 1) { - e.getPresentation().setText(VcsBundle.message("action.name.compare.with.local")); - e.getPresentation().setDescription(VcsBundle.message("action.description.compare.with.local")); - } - else { - e.getPresentation().setText(VcsBundle.message("action.name.compare")); - e.getPresentation().setDescription(VcsBundle.message("action.description.compare")); - } + e.getPresentation().setEnabled(selectionSize > 0); } public boolean isEnabled() { final int selectionSize = getSelection().size(); if (selectionSize == 1) { - return isDiffWithCurrentEnabled(); + List sel = getSelection(); + return myHistorySession.isContentAvailable(sel.get(0)); } else if (selectionSize > 1) { return isDiffEnabled(); @@ -867,6 +867,24 @@ public class FileHistoryPanelImpl extends PanelWithActionsAndCloseButton { List sel = getSelection(); return myHistorySession.isContentAvailable(sel.get(0)) && myHistorySession.isContentAvailable(sel.get(sel.size() - 1)); } + } + + private class MyShowDiffWithLocalAction extends AbstractActionForSomeSelection { + private MyShowDiffWithLocalAction() { + super(VcsBundle.message("action.name.compare.with.local"), VcsBundle.message("action.description.compare.with.local"), "diffWithCurrent", 1, + FileHistoryPanelImpl.this); + } + + @Override + protected void actionPerformed() { + final List selection = getSelection(); + if (selection.size() != 1) return; + if (ChangeListManager.getInstance(myVcs.getProject()).isFreezedWithNotification(null)) return; + final VcsRevisionNumber currentRevisionNumber = myHistorySession.getCurrentRevisionNumber(); + if (currentRevisionNumber != null) { + showDifferences(myVcs.getProject(), getFirstSelectedRevision(), new CurrentRevision(myFilePath.getVirtualFile(), currentRevisionNumber)); + } + } private boolean isDiffWithCurrentEnabled() { if (myHistorySession.getCurrentRevisionNumber() == null) return false; @@ -874,6 +892,12 @@ public class FileHistoryPanelImpl extends PanelWithActionsAndCloseButton { if (!myHistorySession.isContentAvailable(getFirstSelectedRevision())) return false; return true; } + + @Override + public boolean isEnabled() { + final int size = getSelection().size(); + return size == 1 && isDiffWithCurrentEnabled(); + } } private class MyGetVersionAction extends AbstractActionForSomeSelection {