Commit 890a6097 authored by Julia Beliaeva's avatar Julia Beliaeva
Browse files

[file-history] move diff preview to FileHistoryPanel from FileHistoryUi

parent cc05e9e3
Showing with 48 additions and 44 deletions
+48 -44
......@@ -17,6 +17,7 @@ package com.intellij.vcs.log.history;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.vcs.FilePath;
import com.intellij.openapi.vcs.VcsDataKeys;
......@@ -24,6 +25,7 @@ import com.intellij.openapi.vcs.changes.Change;
import com.intellij.openapi.vcs.history.VcsFileRevision;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.*;
import com.intellij.ui.components.JBPanel;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.vcs.log.CommitId;
import com.intellij.vcs.log.VcsCommitMetadata;
......@@ -44,8 +46,10 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.event.ListSelectionListener;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.util.Arrays;
import java.util.List;
import static com.intellij.util.ObjectUtils.notNull;
......@@ -55,6 +59,9 @@ public class FileHistoryPanel extends JPanel implements DataProvider, Disposable
@NotNull private final VcsLogGraphTable myGraphTable;
@NotNull private final DetailsPanel myDetailsPanel;
@NotNull private final JBSplitter myDetailsSplitter;
@Nullable private final FileHistoryDiffPreview myDiffPreview;
@NotNull private final OnePixelSplitter myDiffPreviewSplitter;
@NotNull private final FilePath myFilePath;
@NotNull private final FileHistoryUi myUi;
@NotNull private final VirtualFile myRoot;
......@@ -101,9 +108,31 @@ public class FileHistoryPanel extends JPanel implements DataProvider, Disposable
myDetailsPanel.installCommitSelectionListener(myGraphTable);
VcsLogUiUtil.installDetailsListeners(myGraphTable, myDetailsPanel, logData, this);
JBPanel tablePanel = new JBPanel(new BorderLayout());
tablePanel.add(myDetailsSplitter, BorderLayout.CENTER);
tablePanel.add(createActionsToolbar(), BorderLayout.WEST);
if (!myFilePath.isDirectory()) {
myDiffPreview = new FileHistoryDiffPreview(myUi.getLogData().getProject(), () -> myUi.getSelectedChange(), this);
ListSelectionListener selectionListener = e -> {
int[] selection = myGraphTable.getSelectedRows();
ApplicationManager.getApplication()
.invokeLater(() -> myDiffPreview.updatePreview(myUi.getProperties().get(CommonUiProperties.SHOW_DIFF_PREVIEW)),
o -> !Arrays.equals(selection, myGraphTable.getSelectedRows()));
};
myGraphTable.getSelectionModel().addListSelectionListener(selectionListener);
}
else {
myDiffPreview = null;
}
myDiffPreviewSplitter = new OnePixelSplitter(false, "vcs.history.diff.splitter.proportion", 0.7f);
myDiffPreviewSplitter.setHonorComponentsMinimumSize(false);
myDiffPreviewSplitter.setFirstComponent(tablePanel);
ApplicationManager.getApplication().invokeLater(() -> showDiffPreview(myUi.getProperties().get(CommonUiProperties.SHOW_DIFF_PREVIEW)));
setLayout(new BorderLayout());
add(myDetailsSplitter, BorderLayout.CENTER);
add(createActionsToolbar(), BorderLayout.WEST);
add(myDiffPreviewSplitter, BorderLayout.CENTER);
PopupHandler.installPopupHandler(myGraphTable, VcsLogActionPlaces.HISTORY_POPUP_ACTION_GROUP, VcsLogActionPlaces.VCS_HISTORY_PLACE);
invokeOnDoubleClick(ActionManager.getInstance().getAction(VcsLogActionPlaces.VCS_LOG_SHOW_DIFF_ACTION), tableWithProgress);
......@@ -142,12 +171,26 @@ public class FileHistoryPanel extends JPanel implements DataProvider, Disposable
public void updateDataPack(@NotNull VisiblePack visiblePack, boolean permanentGraphChanged) {
myGraphTable.updateDataPack(visiblePack, permanentGraphChanged);
if (myDiffPreview != null) {
myDiffPreview.updatePreview(myUi.getProperties().get(CommonUiProperties.SHOW_DIFF_PREVIEW));
}
}
public void showDetails(boolean show) {
myDetailsSplitter.setSecondComponent(show ? myDetailsPanel : null);
}
public boolean hasDiffPreview() {
return myDiffPreview != null;
}
void showDiffPreview(boolean state) {
if (myDiffPreview != null) {
myDiffPreview.updatePreview(state);
myDiffPreviewSplitter.setSecondComponent(state ? myDiffPreview.getComponent() : null);
}
}
@Nullable
@Override
public Object getData(@NotNull String dataId) {
......
......@@ -2,7 +2,6 @@
package com.intellij.vcs.log.history;
import com.google.common.util.concurrent.SettableFuture;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.Conditions;
import com.intellij.openapi.vcs.FilePath;
......@@ -10,7 +9,6 @@ import com.intellij.openapi.vcs.changes.Change;
import com.intellij.openapi.vcs.history.VcsFileRevision;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.JBColor;
import com.intellij.ui.OnePixelSplitter;
import com.intellij.ui.navigation.History;
import com.intellij.util.PairFunction;
import com.intellij.util.containers.ContainerUtil;
......@@ -37,8 +35,6 @@ import com.intellij.vcs.log.visible.VisiblePackRefresher;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.event.ListSelectionListener;
import java.awt.*;
import java.util.List;
import java.util.*;
......@@ -56,9 +52,6 @@ public class FileHistoryUi extends AbstractVcsLogUi {
@NotNull private final FileHistoryUiProperties myUiProperties;
@NotNull private final FileHistoryFilterUi myFilterUi;
@NotNull private final FileHistoryPanel myFileHistoryPanel;
@Nullable private final FileHistoryDiffPreview myDiffPreview;
@Nullable private final OnePixelSplitter myDiffPreviewSplitter;
@NotNull private final JComponent myMainComponent;
@NotNull private final Set<String> myHighlighterIds;
@NotNull private final MyPropertiesChangeListener myPropertiesChangeListener;
@NotNull private final History myHistory;
......@@ -82,28 +75,6 @@ public class FileHistoryUi extends AbstractVcsLogUi {
myFilterUi = new FileHistoryFilterUi(path, revision, root, uiProperties);
myFileHistoryPanel = new FileHistoryPanel(this, logData, myVisiblePack, path);
if (!myPath.isDirectory()) {
myDiffPreview = new FileHistoryDiffPreview(myProject, () -> getSelectedChange(), this);
ListSelectionListener selectionListener = e -> {
int[] selection = getTable().getSelectedRows();
ApplicationManager.getApplication()
.invokeLater(() -> myDiffPreview.updatePreview(myUiProperties.get(CommonUiProperties.SHOW_DIFF_PREVIEW)),
o -> !Arrays.equals(selection, getTable().getSelectedRows()));
};
getTable().getSelectionModel().addListSelectionListener(selectionListener);
myDiffPreviewSplitter = new OnePixelSplitter(false, "vcs.history.diff.splitter.proportion", 0.7f);
myDiffPreviewSplitter.setHonorComponentsMinimumSize(false);
myDiffPreviewSplitter.setFirstComponent(myFileHistoryPanel);
showDiffPreview(myUiProperties.get(CommonUiProperties.SHOW_DIFF_PREVIEW));
myMainComponent = myDiffPreviewSplitter;
}
else {
myDiffPreview = null;
myDiffPreviewSplitter = null;
myMainComponent = myFileHistoryPanel;
}
myHighlighterIds = myRevision == null
? ContainerUtil.newHashSet(MyCommitsHighlighter.Factory.ID,
CurrentBranchHighlighter.Factory.ID)
......@@ -128,7 +99,7 @@ public class FileHistoryUi extends AbstractVcsLogUi {
}
public boolean hasDiffPreview() {
return myDiffPreview != null;
return myFileHistoryPanel.hasDiffPreview();
}
@Nullable
......@@ -220,13 +191,6 @@ public class FileHistoryUi extends AbstractVcsLogUi {
return myPath.equals(targetPath) && Objects.equals(myRevision, targetRevision);
}
private void showDiffPreview(boolean state) {
if (myDiffPreview != null) {
myDiffPreview.updatePreview(state);
myDiffPreviewSplitter.setSecondComponent(state ? myDiffPreview.getComponent() : null);
}
}
@NotNull
@Override
public VcsLogFilterUi getFilterUi() {
......@@ -241,9 +205,6 @@ public class FileHistoryUi extends AbstractVcsLogUi {
@Override
protected void onVisiblePackUpdated(boolean permGraphChanged) {
myFileHistoryPanel.updateDataPack(myVisiblePack, permGraphChanged);
if (myDiffPreview != null) {
myDiffPreview.updatePreview(myUiProperties.get(CommonUiProperties.SHOW_DIFF_PREVIEW));
}
}
@NotNull
......@@ -255,7 +216,7 @@ public class FileHistoryUi extends AbstractVcsLogUi {
@NotNull
@Override
public Component getMainComponent() {
return myMainComponent;
return myFileHistoryPanel;
}
@Nullable
......@@ -302,7 +263,7 @@ public class FileHistoryUi extends AbstractVcsLogUi {
getTable().forceReLayout(((CommonUiProperties.TableColumnProperty)property).getColumn());
}
else if (CommonUiProperties.SHOW_DIFF_PREVIEW.equals(property)) {
showDiffPreview(myUiProperties.get(CommonUiProperties.SHOW_DIFF_PREVIEW));
myFileHistoryPanel.showDiffPreview(myUiProperties.get(CommonUiProperties.SHOW_DIFF_PREVIEW));
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment