From 3b27fff9afa9fcb0ded65a63fdebfbc1491b6642 Mon Sep 17 00:00:00 2001 From: Julia Beliaeva Date: Wed, 7 Feb 2018 17:45:02 +0300 Subject: [PATCH] [vcs-log] check that commit message margins are actually enabled --- .../CommitMessageInspectionProfile.java | 2 +- .../log/ui/frame/CommitPresentationUtil.java | 27 +++++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/vcs/commit/CommitMessageInspectionProfile.java b/platform/vcs-impl/src/com/intellij/vcs/commit/CommitMessageInspectionProfile.java index 42a826ce1f53..85385f10610f 100644 --- a/platform/vcs-impl/src/com/intellij/vcs/commit/CommitMessageInspectionProfile.java +++ b/platform/vcs-impl/src/com/intellij/vcs/commit/CommitMessageInspectionProfile.java @@ -77,7 +77,7 @@ public class CommitMessageInspectionProfile extends InspectionProfileImpl return getTool(SubjectLimitInspection.class).RIGHT_MARGIN; } - private T getTool(Class aClass) { + public T getTool(Class aClass) { InspectionToolWrapper tool = getInspectionTool(InspectionProfileEntry.getShortName(aClass.getSimpleName()), myProject); //noinspection unchecked return (T)ObjectUtils.notNull(tool).getTool(); diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/CommitPresentationUtil.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/CommitPresentationUtil.java index 26b302a5fb34..608c46a4a772 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/CommitPresentationUtil.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/CommitPresentationUtil.java @@ -1,6 +1,7 @@ // Copyright 2000-2017 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.frame; +import com.intellij.codeInspection.ex.Tools; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.ui.FontUtil; @@ -11,7 +12,9 @@ import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.Convertor; import com.intellij.util.containers.MultiMap; import com.intellij.util.text.DateFormatUtil; +import com.intellij.vcs.commit.BaseCommitMessageInspection; import com.intellij.vcs.commit.CommitMessageInspectionProfile; +import com.intellij.vcs.commit.SubjectLimitInspection; import com.intellij.vcs.log.CommitId; import com.intellij.vcs.log.VcsFullCommitDetails; import com.intellij.vcs.log.VcsUser; @@ -112,11 +115,13 @@ public class CommitPresentationUtil { return formatText(project, fullMessage, font, font.getStyle(), convertor); } - int margin = CommitMessageInspectionProfile.getSubjectRightMargin(project); - if (subject.length() > margin) { - String tail = subject.substring(margin - ELLIPSIS.length()); - subject = subject.substring(0, margin - ELLIPSIS.length()) + ELLIPSIS; - description = "\n\n" + ELLIPSIS + tail + description; + if (isSubjectMarginEnabled(project)) { + int margin = CommitMessageInspectionProfile.getSubjectRightMargin(project); + if (subject.length() > margin) { + String tail = subject.substring(margin - ELLIPSIS.length()); + subject = subject.substring(0, margin - ELLIPSIS.length()) + ELLIPSIS; + description = "\n\n" + ELLIPSIS + tail + description; + } } return "" + @@ -125,6 +130,18 @@ public class CommitPresentationUtil { formatText(project, description, font, font.getStyle(), convertor); } + public static boolean isSubjectMarginEnabled(@NotNull Project project) { + return isInspectionEnabled(project, SubjectLimitInspection.class); + } + + private static boolean isInspectionEnabled(@NotNull Project project, + @NotNull Class inspectionClass) { + CommitMessageInspectionProfile inspectionProfile = CommitMessageInspectionProfile.getInstance(project); + List tools = inspectionProfile.getAllEnabledInspectionTools(project); + T inspection = inspectionProfile.getTool(inspectionClass); + return ContainerUtil.find(tools, tool -> tool.getTool().getTool().equals(inspection)) != null; + } + @NotNull private static String formatText(@NotNull Project project, @NotNull String text,