Esempio n. 1
0
        protected override void OnDrawSubItem(DrawListViewSubItemEventArgs e)
        {
            base.OnDrawSubItem(e);

            if (e.Item.ListView == null)
            {
                return; // is being removed
            }

            int iidColumnIndex           = getColumnByTag("IId").Index;
            int labelsColumnIndex        = getColumnByTag("Labels").Index;
            int?resolvedCountColumnIndex = getColumnByTag("Resolved")?.Index;
            int?totalTimeColumnIndex     = getColumnByTag("TotalTime")?.Index;
            int?titleColumnIndex         = getColumnByTag("Title")?.Index;
            int?sourceBranchColumnIndex  = getColumnByTag("SourceBranch")?.Index;
            int?targetBranchColumnIndex  = getColumnByTag("TargetBranch")?.Index;
            int?jiraColumnIndex          = getColumnByTag("Jira")?.Index;
            int?authorColumnIndex        = getColumnByTag("Author")?.Index;

            bool isIIdColumnItem          = e.ColumnIndex == iidColumnIndex;
            bool isLabelsColumnItem       = e.ColumnIndex == labelsColumnIndex;
            bool isResolvedColumnItem     = resolvedCountColumnIndex.HasValue && e.ColumnIndex == resolvedCountColumnIndex.Value;
            bool isTotalTimeColumnItem    = totalTimeColumnIndex.HasValue && e.ColumnIndex == totalTimeColumnIndex.Value;
            bool isTitleColumnItem        = titleColumnIndex.HasValue && e.ColumnIndex == titleColumnIndex.Value;
            bool isSourceBranchColumnItem = sourceBranchColumnIndex.HasValue && e.ColumnIndex == sourceBranchColumnIndex.Value;
            bool isTargetBranchColumnItem = targetBranchColumnIndex.HasValue && e.ColumnIndex == targetBranchColumnIndex.Value;
            bool isJiraColumnItem         = jiraColumnIndex.HasValue && e.ColumnIndex == jiraColumnIndex.Value;
            bool isAuthorColumnItem       = authorColumnIndex.HasValue && e.ColumnIndex == authorColumnIndex.Value;

            bool isWrappableColumnItem =
                isTitleColumnItem ||
                isSourceBranchColumnItem ||
                isTargetBranchColumnItem ||
                isJiraColumnItem ||
                isAuthorColumnItem;
            bool needWordWrap             = isWrappableColumnItem && Program.Settings.WordWrapLongRows;
            StringFormatFlags formatFlags = needWordWrap ? StringFormatFlags.LineLimit : StringFormatFlags.NoWrap;
            StringFormat      format      = new StringFormat
            {
                Trimming    = StringTrimming.EllipsisCharacter,
                FormatFlags = formatFlags
            };

            Rectangle bounds = e.Bounds;

            if (e.ColumnIndex == 0 && e.Item.ListView.Columns[0].DisplayIndex != 0)
            {
                bounds = WinFormsHelpers.GetFirstColumnCorrectRectangle(e.Item.ListView, e.Item);
            }

            bool isSelected         = e.Item.Selected;
            FullMergeRequestKey fmk = (FullMergeRequestKey)(e.Item.Tag);
            Color backgroundColor   = getMergeRequestColor(fmk, Color.Transparent, true);

            WinFormsHelpers.FillRectangle(e, bounds, backgroundColor, isSelected);

            string text        = ((ListViewSubItemInfo)(e.SubItem.Tag)).Text;
            bool   isClickable = ((ListViewSubItemInfo)(e.SubItem.Tag)).Clickable;

            if (isIIdColumnItem)
            {
                FontStyle fontStyle = isClickable ? FontStyle.Underline : FontStyle.Regular;
                using (Font font = new Font(e.Item.ListView.Font, fontStyle))
                {
                    e.Graphics.DrawString(text, font, Brushes.Blue, bounds, format);
                    if (isMuted(fmk))
                    {
                        drawEllipseForIId(e.Graphics, format, bounds, fmk, font);
                    }
                }
            }
            else if (isClickable)
            {
                using (Font font = new Font(e.Item.ListView.Font, FontStyle.Underline))
                {
                    Brush brush = Brushes.Blue;
                    e.Graphics.DrawString(text, font, brush, bounds, format);
                }
            }
            else if (isSelected && isLabelsColumnItem)
            {
                using (Brush brush = new SolidBrush(getMergeRequestColor(fmk, SystemColors.Window, true)))
                {
                    e.Graphics.DrawString(text, e.Item.ListView.Font, brush, bounds, format);
                }
            }
            else if (isResolvedColumnItem)
            {
                using (Brush brush = new SolidBrush(getDiscussionCountColor(fmk, isSelected)))
                {
                    e.Graphics.DrawString(text, e.Item.ListView.Font, brush, bounds, format);
                }
            }
            else if (isTotalTimeColumnItem)
            {
                Brush brush = text == Constants.NotAllowedTimeTrackingText ? Brushes.Gray : Brushes.Black;
                e.Graphics.DrawString(text, e.Item.ListView.Font, brush, bounds, format);
            }
            else
            {
                Brush textBrush = isSelected ? SystemBrushes.HighlightText : SystemBrushes.ControlText;
                e.Graphics.DrawString(text, e.Item.ListView.Font, textBrush, bounds, format);
            }
        }