Ejemplo n.º 1
0
        private void onDrawListBoxColorSchemeItemSelectorItem(DrawItemEventArgs e)
        {
            if (e.Index < 0)
            {
                return;
            }

            string          colorSchemeItemName = listBoxColorSchemeItemSelector.Items[e.Index].ToString();
            ColorSchemeItem colorSchemeItem     = _colorScheme.GetColor(colorSchemeItemName);

            if (colorSchemeItem == null)
            {
                return;
            }

            Color color      = colorSchemeItem.Color;
            bool  isSelected = (e.State & DrawItemState.Selected) == DrawItemState.Selected;

            WinFormsHelpers.FillRectangle(e, e.Bounds, color, isSelected);

            StringFormat format =
                new StringFormat
            {
                Trimming    = StringTrimming.EllipsisCharacter,
                FormatFlags = StringFormatFlags.NoWrap
            };

            string text = colorSchemeItem.DisplayName;
            Font   font = listBoxColorSchemeItemSelector.Font;

            if (isSelected)
            {
                using (Brush brush = new SolidBrush(color))
                {
                    e.Graphics.DrawString(text, font, brush, e.Bounds, format);
                }
            }
            else
            {
                e.Graphics.DrawString(text, font, SystemBrushes.ControlText, e.Bounds, format);
            }
        }
Ejemplo n.º 2
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);
            }
        }