[vcs-log] use VcsLogUiProperty for diff preview setting

This commit is contained in:
Julia Beliaeva
2018-05-09 19:31:33 +03:00
parent dcfd3f6707
commit f8d4e42974
6 changed files with 42 additions and 26 deletions
@@ -67,6 +67,7 @@
<action class="com.intellij.vcs.log.ui.actions.ExpandGraphAction" id="Vcs.Log.ExpandAll"/>
<action class="com.intellij.vcs.log.ui.actions.ShowLongEdgesAction" id="Vcs.Log.ShowLongEdges"/>
<action class="com.intellij.vcs.log.ui.actions.ShowDetailsAction" id="Vcs.Log.ShowDetailsAction"/>
<action class="com.intellij.vcs.log.ui.actions.ShowDiffPreviewAction" id="Vcs.Log.ShowDiffPreview"/>
<action class="com.intellij.vcs.log.ui.actions.ShowChangesFromParentsAction" id="Vcs.Log.ShowChangesFromParents"/>
<action class="com.intellij.vcs.log.ui.actions.ShowRootsColumnAction" id="Vcs.Log.ShowRootsColumnAction"/>
<action class="com.intellij.vcs.log.ui.actions.FocusTextFilterAction" id="Vcs.Log.FocusTextFilter">
@@ -128,6 +129,7 @@
<reference id="Vcs.RepositoryChangesBrowserToolbar"/>
<separator/>
<reference id="Vcs.Log.ShowDetailsAction"/>
<reference id="Vcs.Log.ShowDiffPreview"/>
</group>
<group id="Vcs.Log.ChangesBrowser.Menu">
<reference id="Vcs.RepositoryChangesBrowserMenu"/>
@@ -176,6 +178,7 @@
<separator/>
<reference ref="Vcs.Log.ShowDetailsAction"/>
<reference ref="Vcs.Log.ShowChangesFromParents"/>
<reference ref="Vcs.Log.ShowDiffPreview"/>
<separator/>
<reference ref="Vcs.Log.Refresh"/>
<reference ref="Vcs.Log.OpenAnotherTab"/>
@@ -25,6 +25,7 @@ import java.util.Map;
public class CommonUiProperties {
public static final VcsLogUiProperty<Boolean> SHOW_DETAILS = new VcsLogUiProperty<>("Window.ShowDetails");
public static final VcsLogUiProperty<Boolean> SHOW_DIFF_PREVIEW = new VcsLogUiProperty<>("Window.ShowDiffPreview");
public static final Map<Integer, VcsLogUiProperty<Integer>> COLUMN_WIDTH = ContainerUtil.newHashMap();
public static final VcsLogUiProperty<List<Integer>> COLUMN_ORDER = new VcsLogUiProperty<>("Table.ColumnOrder");
public static final VcsLogUiProperty<Boolean> SHOW_ROOT_NAMES = new VcsLogUiProperty<>("Table.ShowRootNames");
@@ -10,6 +10,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.Set;
import static com.intellij.vcs.log.impl.CommonUiProperties.SHOW_DIFF_PREVIEW;
import static com.intellij.vcs.log.impl.MainVcsLogUiProperties.*;
@State(name = "Vcs.Log.App.Settings", storages = {@Storage("vcs.xml")})
@@ -27,7 +28,7 @@ public class VcsLogApplicationSettings implements PersistentStateComponent<VcsLo
public void loadState(@NotNull State state) {
myState = state;
}
@SuppressWarnings("unchecked")
@NotNull
@Override
@@ -41,6 +42,9 @@ public class VcsLogApplicationSettings implements PersistentStateComponent<VcsLo
else if (SHOW_CHANGES_FROM_PARENTS.equals(property)) {
return (T)Boolean.valueOf(myState.SHOW_CHANGES_FROM_PARENTS);
}
else if (SHOW_DIFF_PREVIEW.equals(property)) {
return (T)Boolean.valueOf(myState.SHOW_DIFF_PREVIEW);
}
throw new UnsupportedOperationException("Property " + property + " does not exist");
}
@@ -55,6 +59,9 @@ public class VcsLogApplicationSettings implements PersistentStateComponent<VcsLo
else if (SHOW_CHANGES_FROM_PARENTS.equals(property)) {
myState.SHOW_CHANGES_FROM_PARENTS = (Boolean)value;
}
else if (SHOW_DIFF_PREVIEW.equals(property)) {
myState.SHOW_DIFF_PREVIEW = (Boolean)value;
}
else {
throw new UnsupportedOperationException("Property " + property + " does not exist");
}
@@ -64,7 +71,7 @@ public class VcsLogApplicationSettings implements PersistentStateComponent<VcsLo
@Override
public <T> boolean exists(@NotNull VcsLogUiProperty<T> property) {
return COMPACT_REFERENCES_VIEW.equals(property) || SHOW_TAG_NAMES.equals(property) ||
SHOW_CHANGES_FROM_PARENTS.equals(property);
SHOW_CHANGES_FROM_PARENTS.equals(property) || SHOW_DIFF_PREVIEW.equals(property);
}
public void addChangeListener(@NotNull VcsLogUiProperties.PropertiesChangeListener listener) {
@@ -79,5 +86,6 @@ public class VcsLogApplicationSettings implements PersistentStateComponent<VcsLo
public boolean COMPACT_REFERENCES_VIEW = true;
public boolean SHOW_TAG_NAMES = false;
public boolean SHOW_CHANGES_FROM_PARENTS = false;
public boolean SHOW_DIFF_PREVIEW = false;
}
}
@@ -156,6 +156,9 @@ public class VcsLogUiImpl extends AbstractVcsLogUi {
if (CommonUiProperties.SHOW_DETAILS.equals(property)) {
myMainFrame.showDetails(myUiProperties.get(CommonUiProperties.SHOW_DETAILS));
}
else if (CommonUiProperties.SHOW_DIFF_PREVIEW.equals(property)) {
myMainFrame.showDiffPreview(myUiProperties.get(CommonUiProperties.SHOW_DIFF_PREVIEW));
}
else if (MainVcsLogUiProperties.SHOW_LONG_EDGES.equals(property)) {
onShowLongEdgesChanged();
}
@@ -0,0 +1,18 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.vcs.log.ui.actions;
import com.intellij.icons.AllIcons;
import com.intellij.vcs.log.impl.CommonUiProperties;
import com.intellij.vcs.log.impl.VcsLogUiProperties;
public class ShowDiffPreviewAction extends BooleanPropertyToggleAction {
public ShowDiffPreviewAction() {
super("Preview Diff", "Show Diff Preview Panel in Vcs Log", AllIcons.Actions.PreviewDetails);
}
@Override
protected VcsLogUiProperties.VcsLogUiProperty<Boolean> getProperty() {
return CommonUiProperties.SHOW_DIFF_PREVIEW;
}
}
@@ -7,14 +7,11 @@ import com.intellij.openapi.actionSystem.ex.ActionUtil;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.keymap.KeymapUtil;
import com.intellij.openapi.progress.util.ProgressWindow;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Splitter;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.vcs.VcsConfiguration;
import com.intellij.openapi.vcs.VcsDataKeys;
import com.intellij.openapi.vcs.changes.Change;
import com.intellij.openapi.vcs.changes.PreviewDiffSplitterComponent;
import com.intellij.openapi.vcs.changes.actions.ShowDiffPreviewAction;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.OnePixelSplitter;
import com.intellij.ui.PopupHandler;
@@ -68,7 +65,6 @@ public class MainFrame extends JPanel implements DataProvider, Disposable {
@NotNull private final AbstractVcsLogUi myUi;
@NotNull private final VcsLog myLog;
@NotNull private final VcsLogClassicFilterUi myFilterUi;
@NotNull private final VcsConfiguration myVcsConfiguration;
@NotNull private final JBLoadingPanel myChangesLoadingPane;
@NotNull private final VcsLogGraphTable myGraphTable;
@@ -93,9 +89,6 @@ public class MainFrame extends JPanel implements DataProvider, Disposable {
myLog = log;
myUiProperties = uiProperties;
Project project = logData.getProject();
myVcsConfiguration = VcsConfiguration.getInstance(project);
myFilterUi = new VcsLogClassicFilterUi(ui, logData, myUiProperties, initialDataPack);
// initialize components
@@ -110,12 +103,11 @@ public class MainFrame extends JPanel implements DataProvider, Disposable {
}
};
myChangesBrowser = new VcsLogChangesBrowser(project, myUiProperties, (commitId) -> {
myChangesBrowser = new VcsLogChangesBrowser(logData.getProject(), myUiProperties, (commitId) -> {
int index = myLogData.getCommitIndex(commitId.getHash(), commitId.getRoot());
return myLogData.getMiniDetailsGetter().getCommitData(index, Collections.singleton(index));
}, this);
myChangesBrowser.getDiffAction().registerCustomShortcutSet(myChangesBrowser.getDiffAction().getShortcutSet(), getGraphTable());
myChangesBrowser.addToolbarAction(new MyToggleDetailsAction());
myChangesLoadingPane = new JBLoadingPanel(new BorderLayout(), this, ProgressWindow.DEFAULT_PROGRESS_DIALOG_POSTPONE_TIME_MILLIS);
myChangesLoadingPane.add(myChangesBrowser);
@@ -124,9 +116,9 @@ public class MainFrame extends JPanel implements DataProvider, Disposable {
setupDetailsSplitter(myUiProperties.get(CommonUiProperties.SHOW_DETAILS));
VcsLogChangeProcessor changeProcessor = new VcsLogChangeProcessor(project, myChangesBrowser, this);
VcsLogChangeProcessor changeProcessor = new VcsLogChangeProcessor(logData.getProject(), myChangesBrowser, this);
myPreviewDiffSplitter = new PreviewDiffSplitterComponent(myDetailsSplitter, changeProcessor, PREVIEW_DIFF_SPLITTER_PROPORTION,
myVcsConfiguration.VCS_LOG_DETAILS_PREVIEW_SHOWN);
myUiProperties.get(CommonUiProperties.SHOW_DIFF_PREVIEW));
Runnable changesListener = () -> {
ApplicationManager.getApplication().invokeLater(() -> {
@@ -288,6 +280,10 @@ public class MainFrame extends JPanel implements DataProvider, Disposable {
myDetailsSplitter.setSecondComponent(state ? myDetailsPanel : null);
}
public void showDiffPreview(boolean state) {
myPreviewDiffSplitter.setDetailsOn(state);
}
@Override
public void dispose() {
myGraphTable.getSelectionModel().removeListSelectionListener(mySelectionListenerForDiff);
@@ -370,17 +366,4 @@ public class MainFrame extends JPanel implements DataProvider, Disposable {
}
}
}
private class MyToggleDetailsAction extends ShowDiffPreviewAction {
@Override
public void setSelected(AnActionEvent e, boolean state) {
myPreviewDiffSplitter.setDetailsOn(state);
myVcsConfiguration.VCS_LOG_DETAILS_PREVIEW_SHOWN = state;
}
@Override
public boolean isSelected(AnActionEvent e) {
return myVcsConfiguration.VCS_LOG_DETAILS_PREVIEW_SHOWN;
}
}
}