From f5f3cc57f8734fdb82f27635ffa81969bea25ad2 Mon Sep 17 00:00:00 2001 From: Julia Beliaeva Date: Sat, 19 Nov 2016 01:23:38 +0300 Subject: [PATCH] [vcs-log] action in quick settings to show/hide tag names in the table --- .../intellij/vcs/log/VcsLogRefManager.java | 2 +- .../src/com/intellij/vcs/log/VcsLogUi.java | 4 ++ .../vcs-log/impl/src/META-INF/vcs-log.xml | 3 + .../vcs/log/data/VcsLogUiProperties.java | 4 ++ .../vcs/log/data/VcsLogUiPropertiesImpl.java | 11 +++ .../com/intellij/vcs/log/ui/VcsLogUiImpl.java | 11 +++ .../log/ui/actions/ShowTagNamesAction.java | 69 +++++++++++++++++++ .../vcs/log/ui/frame/VcsLogGraphTable.java | 7 +- .../ui/render/GraphCommitCellRenderer.java | 17 +++-- .../vcs/log/ui/render/LabelPainter.java | 10 ++- .../vcs/log/impl/TestVcsLogProvider.java | 2 +- .../src/git4idea/log/GitRefManager.java | 4 +- .../org/zmlx/hg4idea/log/HgRefManager.java | 7 +- 13 files changed, 135 insertions(+), 16 deletions(-) create mode 100644 platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/ShowTagNamesAction.java diff --git a/platform/vcs-log/api/src/com/intellij/vcs/log/VcsLogRefManager.java b/platform/vcs-log/api/src/com/intellij/vcs/log/VcsLogRefManager.java index 9224eed78aaf..798596114c23 100644 --- a/platform/vcs-log/api/src/com/intellij/vcs/log/VcsLogRefManager.java +++ b/platform/vcs-log/api/src/com/intellij/vcs/log/VcsLogRefManager.java @@ -68,7 +68,7 @@ public interface VcsLogRefManager { * All references given to this method are from the same commit. */ @NotNull - List groupForTable(@NotNull Collection refs); + List groupForTable(@NotNull Collection refs, boolean showTagNames); /** * Writes given reference type to the output. diff --git a/platform/vcs-log/api/src/com/intellij/vcs/log/VcsLogUi.java b/platform/vcs-log/api/src/com/intellij/vcs/log/VcsLogUi.java index db3af328b652..e87fb5b7e9bf 100644 --- a/platform/vcs-log/api/src/com/intellij/vcs/log/VcsLogUi.java +++ b/platform/vcs-log/api/src/com/intellij/vcs/log/VcsLogUi.java @@ -32,6 +32,10 @@ public interface VcsLogUi { boolean areGraphActionsEnabled(); + boolean isShowTagNames(); + + void setShowTagNames(boolean show); + boolean isMultipleRoots(); boolean isShowRootNames(); diff --git a/platform/vcs-log/impl/src/META-INF/vcs-log.xml b/platform/vcs-log/impl/src/META-INF/vcs-log.xml index 9305816dc5c7..e2417e187bef 100644 --- a/platform/vcs-log/impl/src/META-INF/vcs-log.xml +++ b/platform/vcs-log/impl/src/META-INF/vcs-log.xml @@ -41,6 +41,7 @@ + @@ -62,6 +63,7 @@ + @@ -95,6 +97,7 @@ + diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/VcsLogUiProperties.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/VcsLogUiProperties.java index b3c68c292f26..491484a7afd9 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/VcsLogUiProperties.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/VcsLogUiProperties.java @@ -56,4 +56,8 @@ public interface VcsLogUiProperties { @Nullable List getFilterValues(@NotNull String filterName); + + boolean isShowTagNames(); + + void setShowTagNames(boolean showTags); } diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/VcsLogUiPropertiesImpl.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/VcsLogUiPropertiesImpl.java index d05a5cd53f05..e8fbf1ce6e57 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/VcsLogUiPropertiesImpl.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/VcsLogUiPropertiesImpl.java @@ -37,6 +37,7 @@ public abstract class VcsLogUiPropertiesImpl implements PersistentStateComponent public Deque RECENTLY_FILTERED_BRANCH_GROUPS = new ArrayDeque<>(); public Map HIGHLIGHTERS = ContainerUtil.newTreeMap(); public Map> FILTERS = ContainerUtil.newTreeMap(); + public boolean SHOW_TAG_NAMES = false; } @NotNull @@ -153,6 +154,16 @@ public abstract class VcsLogUiPropertiesImpl implements PersistentStateComponent return getState().FILTERS.get(filterName); } + @Override + public boolean isShowTagNames() { + return getState().SHOW_TAG_NAMES; + } + + @Override + public void setShowTagNames(boolean showTags) { + getState().SHOW_TAG_NAMES = showTags; + } + public static class UserGroup { public List users = new ArrayList<>(); diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/VcsLogUiImpl.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/VcsLogUiImpl.java index 8a036e5e859b..53f86a232889 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/VcsLogUiImpl.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/VcsLogUiImpl.java @@ -192,6 +192,17 @@ public class VcsLogUiImpl implements VcsLogUi, Disposable { myUiProperties.setShowDetails(showDetails); } + @Override + public boolean isShowTagNames() { + return myUiProperties.isShowTagNames(); + } + + @Override + public void setShowTagNames(boolean show) { + myUiProperties.setShowTagNames(show); + myMainFrame.getGraphTable().setShowTagNames(show); + } + @NotNull public Future jumpToCommit(@NotNull Hash commitHash, @NotNull VirtualFile root) { SettableFuture future = SettableFuture.create(); diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/ShowTagNamesAction.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/ShowTagNamesAction.java new file mode 100644 index 000000000000..69a1b2d5461f --- /dev/null +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/ShowTagNamesAction.java @@ -0,0 +1,69 @@ +/* + * Copyright 2000-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.vcs.log.ui.actions; + +/* + * Copyright 2000-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.ToggleAction; +import com.intellij.openapi.project.DumbAware; +import com.intellij.vcs.log.VcsLogDataKeys; +import com.intellij.vcs.log.VcsLogUi; +import org.jetbrains.annotations.NotNull; + +public class ShowTagNamesAction extends ToggleAction implements DumbAware { + + public ShowTagNamesAction() { + super("Show Tag Names", "Show Tag Names in the Table", null); + } + + @Override + public boolean isSelected(AnActionEvent e) { + VcsLogUi ui = e.getData(VcsLogDataKeys.VCS_LOG_UI); + if (ui == null) return false; + return ui.isShowTagNames(); + } + + @Override + public void setSelected(AnActionEvent e, boolean state) { + VcsLogUi ui = e.getData(VcsLogDataKeys.VCS_LOG_UI); + if (ui != null) { + ui.setShowTagNames(state); + } + } + + @Override + public void update(@NotNull AnActionEvent e) { + e.getPresentation().setEnabledAndVisible(e.getData(VcsLogDataKeys.VCS_LOG_UI) != null); + + super.update(e); + } +} + diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/VcsLogGraphTable.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/VcsLogGraphTable.java index 1ea80df287c6..45474404a6fe 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/VcsLogGraphTable.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/VcsLogGraphTable.java @@ -112,7 +112,7 @@ public class VcsLogGraphTable extends TableWithProgress implements DataProvider, return VcsLogGraphTable.this.getRowHeight(); } }; - myGraphCommitCellRenderer = new GraphCommitCellRenderer(logData, graphCellPainter, this); + myGraphCommitCellRenderer = new GraphCommitCellRenderer(logData, graphCellPainter, this, ui.isShowTagNames()); myStringCellRenderer = new StringCellRenderer(); myLogData.getProgress().addProgressIndicatorListener(new MyProgressListener(), ui); @@ -424,6 +424,11 @@ public class VcsLogGraphTable extends TableWithProgress implements DataProvider, myController.showTooltip(row); } + public void setShowTagNames(boolean showTagsNames) { + myGraphCommitCellRenderer.setShowTagsNames(showTagsNames); + repaint(); + } + static class Selection { @NotNull private final VcsLogGraphTable myTable; @NotNull private final TIntHashSet mySelectedCommits; diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/render/GraphCommitCellRenderer.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/render/GraphCommitCellRenderer.java index bc186c32d80e..5b98bc454767 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/render/GraphCommitCellRenderer.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/render/GraphCommitCellRenderer.java @@ -37,13 +37,14 @@ public class GraphCommitCellRenderer extends TypeSafeTableCellRenderer refGroups = manager == null ? ContainerUtil.emptyList() : manager.groupForTable(references); + List refGroups = manager == null ? ContainerUtil.emptyList() : manager.groupForTable(references, myShowTagNames); myGreyBackground = calculateGreyBackground(refGroups, background, isSelected); Pair>, Integer> presentation = @@ -246,5 +248,9 @@ public class LabelPainter { Font font = RectanglePainter.getFont(); return font.deriveFont(font.getSize() - 1f); } + + public void setShowTagNames(boolean showTagNames) { + myShowTagNames = showTagNames; + } } diff --git a/platform/vcs-log/impl/test/com/intellij/vcs/log/impl/TestVcsLogProvider.java b/platform/vcs-log/impl/test/com/intellij/vcs/log/impl/TestVcsLogProvider.java index adb007fe72e1..7e99e8e174a8 100644 --- a/platform/vcs-log/impl/test/com/intellij/vcs/log/impl/TestVcsLogProvider.java +++ b/platform/vcs-log/impl/test/com/intellij/vcs/log/impl/TestVcsLogProvider.java @@ -251,7 +251,7 @@ public class TestVcsLogProvider implements VcsLogProvider { @NotNull @Override - public List groupForTable(@NotNull Collection refs) { + public List groupForTable(@NotNull Collection refs, boolean showTagNames) { return groupForBranchFilter(refs); } diff --git a/plugins/git4idea/src/git4idea/log/GitRefManager.java b/plugins/git4idea/src/git4idea/log/GitRefManager.java index fd9e8e8af0d4..bcc52fef6911 100644 --- a/plugins/git4idea/src/git4idea/log/GitRefManager.java +++ b/plugins/git4idea/src/git4idea/log/GitRefManager.java @@ -141,7 +141,7 @@ public class GitRefManager implements VcsLogRefManager { @NotNull @Override - public List groupForTable(@NotNull Collection references) { + public List groupForTable(@NotNull Collection references, boolean showTagNames) { List sortedReferences = ContainerUtil.sorted(references, myLabelsComparator); Set>> groupedRefs = ContainerUtil.groupBy(sortedReferences, VcsRef::getType).entrySet(); Map.Entry> firstGroup = ContainerUtil.getFirstItem(groupedRefs); @@ -166,7 +166,7 @@ public class GitRefManager implements VcsLogRefManager { VcsRef firstRef = ObjectUtils.assertNotNull(ContainerUtil.getFirstItem(firstGroup.getValue())); VcsRefType firstRefType = firstGroup.getKey(); - String name = firstRefType.isBranch() && !firstRefType.equals(HEAD) ? firstRef.getName() : ""; + String name = (showTagNames || firstRefType.isBranch()) && !firstRefType.equals(HEAD) ? firstRef.getName() : ""; if (firstRefType.equals(LOCAL_BRANCH)) { GitRepository repository = myRepositoryManager.getRepositoryForRoot(firstRef.getRoot()); diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/log/HgRefManager.java b/plugins/hg4idea/src/org/zmlx/hg4idea/log/HgRefManager.java index da53654bc4b8..0a6d221ab71e 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/log/HgRefManager.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/log/HgRefManager.java @@ -112,7 +112,7 @@ public class HgRefManager implements VcsLogRefManager { @NotNull @Override - public List groupForTable(@NotNull Collection references) { + public List groupForTable(@NotNull Collection references, boolean showTagNames) { List sortedReferences = sort(references); Set>> groupedRefs = ContainerUtil.groupBy(sortedReferences, VcsRef::getType).entrySet(); Map.Entry> firstGroup = @@ -129,8 +129,9 @@ public class HgRefManager implements VcsLogRefManager { VcsRefType firstRefType = firstGroup.getKey(); groups.add( - new SimpleRefGroup(firstRefType.isBranch() && !firstRefType.equals(TIP) && !firstRefType.equals(HEAD) ? firstRef.getName() : "", - sortedReferences)); + new SimpleRefGroup( + (showTagNames || firstRefType.isBranch()) && !firstRefType.equals(TIP) && !firstRefType.equals(HEAD) ? firstRef.getName() : "", + sortedReferences)); return groups; }