[vcs-log] action in quick settings to show/hide tag names in the table

This commit is contained in:
Julia Beliaeva
2016-12-08 00:10:03 +03:00
parent 2c8a4b25bc
commit f5f3cc57f8
13 changed files with 135 additions and 16 deletions
@@ -68,7 +68,7 @@ public interface VcsLogRefManager {
* All references given to this method are from the same commit.
*/
@NotNull
List<RefGroup> groupForTable(@NotNull Collection<VcsRef> refs);
List<RefGroup> groupForTable(@NotNull Collection<VcsRef> refs, boolean showTagNames);
/**
* Writes given reference type to the output.
@@ -32,6 +32,10 @@ public interface VcsLogUi {
boolean areGraphActionsEnabled();
boolean isShowTagNames();
void setShowTagNames(boolean show);
boolean isMultipleRoots();
boolean isShowRootNames();
@@ -41,6 +41,7 @@
<action class="com.intellij.vcs.log.ui.actions.VcsShowLogAction" id="Vcs.Show.Log" text="Show VCS Log">
<add-to-group group-id="Vcs.Show.Toolwindow.Tab"/>
</action>
<action class="com.intellij.vcs.log.ui.actions.ShowTagNamesAction" id="Vcs.Log.ShowTagNames"/>
<action class="com.intellij.vcs.log.ui.actions.CollapseGraphAction" id="Vcs.Log.CollapseAll"/>
<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"/>
@@ -62,6 +63,7 @@
<group id="Vcs.Log.Settings">
<reference id="Vcs.Log.ShowRootsColumnAction"/>
<reference id="Vcs.Log.ShowTagNames"/>
<separator/>
<reference id="Vcs.Log.CollapseAll"/>
<reference id="Vcs.Log.ExpandAll"/>
@@ -95,6 +97,7 @@
<reference ref="Vcs.Log.ShowLongEdges"/>
<separator/>
<reference ref="Vcs.Log.QuickSettings"/>
<reference ref="Vcs.Log.ShowTagNames"/>
<reference ref="Vcs.Log.ShowDetailsAction"/>
<reference ref="Vcs.Log.ShowRootsColumnAction"/>
<separator/>
@@ -56,4 +56,8 @@ public interface VcsLogUiProperties {
@Nullable
List<String> getFilterValues(@NotNull String filterName);
boolean isShowTagNames();
void setShowTagNames(boolean showTags);
}
@@ -37,6 +37,7 @@ public abstract class VcsLogUiPropertiesImpl implements PersistentStateComponent
public Deque<UserGroup> RECENTLY_FILTERED_BRANCH_GROUPS = new ArrayDeque<>();
public Map<String, Boolean> HIGHLIGHTERS = ContainerUtil.newTreeMap();
public Map<String, List<String>> 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<String> users = new ArrayList<>();
@@ -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<Boolean> jumpToCommit(@NotNull Hash commitHash, @NotNull VirtualFile root) {
SettableFuture<Boolean> future = SettableFuture.create();
@@ -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);
}
}
@@ -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;
@@ -37,13 +37,14 @@ public class GraphCommitCellRenderer extends TypeSafeTableCellRenderer<GraphComm
public GraphCommitCellRenderer(@NotNull VcsLogData logData,
@NotNull GraphCellPainter painter,
@NotNull VcsLogGraphTable table) {
@NotNull VcsLogGraphTable table,
boolean showTagNames) {
myLogData = logData;
myGraphTable = table;
myTooltipPainter = new LabelPainter(myLogData);
myComponent = new MyComponent(logData, painter, table);
myTemplateComponent = new MyComponent(logData, painter, table);
myTooltipPainter = new LabelPainter(myLogData, showTagNames);
myComponent = new MyComponent(logData, painter, table, showTagNames);
myTemplateComponent = new MyComponent(logData, painter, table, showTagNames);
}
@Override
@@ -110,6 +111,10 @@ public class GraphCommitCellRenderer extends TypeSafeTableCellRenderer<GraphComm
return myGraphTable.getColumnModel().getColumn(GraphTableModel.COMMIT_COLUMN).getWidth();
}
public void setShowTagsNames(boolean showTagNames) {
myComponent.getReferencePainter().setShowTagNames(showTagNames);
}
private static class MyComponent extends SimpleColoredRenderer {
@NotNull private final VcsLogData myLogData;
@NotNull private final VcsLogGraphTable myGraphTable;
@@ -121,12 +126,12 @@ public class GraphCommitCellRenderer extends TypeSafeTableCellRenderer<GraphComm
@NotNull private Font myFont;
private int myHeight;
public MyComponent(@NotNull VcsLogData data, @NotNull GraphCellPainter painter, @NotNull VcsLogGraphTable table) {
public MyComponent(@NotNull VcsLogData data, @NotNull GraphCellPainter painter, @NotNull VcsLogGraphTable table, boolean showTags) {
myLogData = data;
myPainter = painter;
myGraphTable = table;
myReferencePainter = new LabelPainter(myLogData);
myReferencePainter = new LabelPainter(myLogData, showTags);
myIssueLinkRenderer = new IssueLinkRenderer(myLogData.getProject(), this);
myFont = RectanglePainter.getFont();
@@ -77,9 +77,11 @@ public class LabelPainter {
@NotNull private Color myBackground = UIUtil.getTableBackground();
@Nullable private Color myGreyBackground = null;
@NotNull private Color myForeground = UIUtil.getTableForeground();
private boolean myShowTagNames;
public LabelPainter(@NotNull VcsLogData data) {
public LabelPainter(@NotNull VcsLogData data, boolean showTagNames) {
myLogData = data;
myShowTagNames = showTagNames;
}
@Nullable
@@ -106,7 +108,7 @@ public class LabelPainter {
myHeight = metrics.getHeight() + TOP_TEXT_PADDING + BOTTOM_TEXT_PADDING;
VcsLogRefManager manager = getRefManager(myLogData, references);
List<RefGroup> refGroups = manager == null ? ContainerUtil.emptyList() : manager.groupForTable(references);
List<RefGroup> refGroups = manager == null ? ContainerUtil.emptyList() : manager.groupForTable(references, myShowTagNames);
myGreyBackground = calculateGreyBackground(refGroups, background, isSelected);
Pair<List<Pair<String, LabelIcon>>, 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;
}
}
@@ -251,7 +251,7 @@ public class TestVcsLogProvider implements VcsLogProvider {
@NotNull
@Override
public List<RefGroup> groupForTable(@NotNull Collection<VcsRef> refs) {
public List<RefGroup> groupForTable(@NotNull Collection<VcsRef> refs, boolean showTagNames) {
return groupForBranchFilter(refs);
}
@@ -141,7 +141,7 @@ public class GitRefManager implements VcsLogRefManager {
@NotNull
@Override
public List<RefGroup> groupForTable(@NotNull Collection<VcsRef> references) {
public List<RefGroup> groupForTable(@NotNull Collection<VcsRef> references, boolean showTagNames) {
List<VcsRef> sortedReferences = ContainerUtil.sorted(references, myLabelsComparator);
Set<Map.Entry<VcsRefType, Collection<VcsRef>>> groupedRefs = ContainerUtil.groupBy(sortedReferences, VcsRef::getType).entrySet();
Map.Entry<VcsRefType, Collection<VcsRef>> 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());
@@ -112,7 +112,7 @@ public class HgRefManager implements VcsLogRefManager {
@NotNull
@Override
public List<RefGroup> groupForTable(@NotNull Collection<VcsRef> references) {
public List<RefGroup> groupForTable(@NotNull Collection<VcsRef> references, boolean showTagNames) {
List<VcsRef> sortedReferences = sort(references);
Set<Map.Entry<VcsRefType, Collection<VcsRef>>> groupedRefs = ContainerUtil.groupBy(sortedReferences, VcsRef::getType).entrySet();
Map.Entry<VcsRefType, Collection<VcsRef>> 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;
}