void ShowTip(AnnotateRegion region) { Point mp = PointToClient(MousePosition); Rectangle rect = GetRectangle(region); if (rect.Contains(mp)) { AnnotateSource src = region.Source; StringBuilder sb = new StringBuilder(); if (src.Revision >= 0) { sb.AppendFormat(AnnotateResources.RevisonHead, src.Revision); sb.AppendLine(); sb.AppendFormat(AnnotateResources.AuthorHead, src.Author); sb.AppendLine(); sb.AppendFormat(AnnotateResources.TimeHead, src.Time.ToLocalTime()); if (!string.IsNullOrEmpty(src.LogMessage)) { sb.AppendLine(); sb.Append(src.LogMessage); } } else { sb.Append(AnnotateResources.LocalChange); } _toolTip.Show(sb.ToString(), this, mp); _tipSection = region; } }
public void AddLines(SvnOrigin origin, Collection <SvnBlameEventArgs> blameResult) { _origin = origin; SortedList <long, AnnotateSource> sources = new SortedList <long, AnnotateSource>(); AnnotateRegion section = null; blameSections.Clear(); foreach (SvnBlameEventArgs e in blameResult) { AnnotateSource src; if (!sources.TryGetValue(e.Revision, out src)) { sources.Add(e.Revision, src = new AnnotateSource(e, origin)); } int line = (int)e.LineNumber; if (section == null || section.Source != src) { section = new AnnotateRegion(line, src); blameSections.Add(section); } else { section.EndLine = line; } } blameMarginControl1.Invalidate(); }
bool IsSelected(AnnotateRegion region) { if (region == null) { throw new ArgumentNullException("region"); } else if (_control == null) { return(false); } AnnotateSource src = _control.Selected; if (src == null) { return(false); } if (region.Source == src) { return(true); } return(false); }
/// <summary> /// Initializes a new instance of the <see cref="AnnotateRegion"/> class. /// </summary> /// <param name="startLine">The start line.</param> /// <param name="endLine">The end line.</param> /// <param name="source">The source.</param> public AnnotateRegion(int line, AnnotateSource source) { if(source == null) throw new ArgumentNullException("source"); _source = source; _startLine = _endLine = line; }
internal void SetSelection(IAnnotateSection section) { // Check if necessary //Focus(); //Select(); _selected = (AnnotateSource)section; _map.NotifySelectionUpdated(); }
/// <summary> /// Initializes a new instance of the <see cref="AnnotateRegion"/> class. /// </summary> /// <param name="startLine">The start line.</param> /// <param name="endLine">The end line.</param> /// <param name="source">The source.</param> public AnnotateRegion(int line, AnnotateSource source) { if (source == null) { throw new ArgumentNullException("source"); } _source = source; _startLine = _endLine = line; }
protected override void OnPaint(PaintEventArgs e) { if (DesignMode) { return; } StringFormat sfr = new StringFormat(); sfr.Alignment = StringAlignment.Far; StringFormat sfl = new StringFormat(); sfl.Trimming = StringTrimming.EllipsisCharacter; sfl.FormatFlags = StringFormatFlags.NoWrap; using (Font f = new Font(Font.FontFamily, 7F)) using (Pen border = new Pen(Color.Gray)) using (Brush textColor = new SolidBrush(Color.Black)) using (Brush selectedTextColor = new SolidBrush(SystemColors.HighlightText)) using (Brush grayBg = new LinearGradientBrush(new Point(0, 0), new Point(Width, 0), BackColor, Color.LightGray)) using (Brush blueBg = new LinearGradientBrush(new Point(0, 0), new Point(Width, 0), BackColor, Color.LightBlue)) using (Brush selectedBg = new SolidBrush(SystemColors.Highlight)) using (SolidBrush localBg = new SolidBrush(SystemColors.Info)) { foreach (AnnotateRegion region in _regions) { // We try to draw a few regions above and below to fix up drawing // when the actual editor is smaller than our view. // (E.g. navigation bar for C# editor) if (region.EndLine < _firstLine - 4) { continue; } if (region.StartLine > _lastLine + 4) { break; } Rectangle rect = GetRectangle(region); if (!e.ClipRectangle.IntersectsWith(rect)) { continue; } if (IsSelected(region)) { e.Graphics.FillRectangle(selectedBg, rect); } else { if (region.Hovered) { e.Graphics.FillRectangle(blueBg, rect); } else if (region.Source.Revision >= 0) { e.Graphics.FillRectangle(grayBg, rect); } else { e.Graphics.FillRectangle(localBg, rect); } } e.Graphics.DrawRectangle(border, rect); AnnotateSource src = region.Source; if (src.Revision >= 0) { string revisionString = src.Revision.ToString(); string dateString = src.Time.ToShortDateString(); float rectTop = rect.Top + 2; // top padding of 2px float revisionWidth = e.Graphics.MeasureString(revisionString, f).Width; float dateWidth = e.Graphics.MeasureString(dateString, f).Width; // Calculate the author field based on the fields to the left and right of it // because we use ellipsis trimming when it's too small float authorWidth = Width - revisionWidth - dateWidth - 8; // left+right padding of both revision and date means 2+2+2+2 = 8 Brush color = IsSelected(region) ? selectedTextColor : textColor; e.Graphics.DrawString(revisionString, f, color, new RectangleF(3, rectTop, revisionWidth, LineHeight), sfr); // TODO: decide if this is the best way // If the authorWidth is negative, don't attempt to show the author. This case should only // occur with very long ShortDateStrings, or very long revision strings. if (authorWidth > 0) { e.Graphics.DrawString(src.Author, f, color, new RectangleF(revisionWidth + 5, rectTop, authorWidth, LineHeight), sfl); } e.Graphics.DrawString(dateString, f, color, new RectangleF(Width - dateWidth - 2, rectTop, dateWidth, LineHeight), sfr); } } Rectangle clip = e.ClipRectangle; using (SolidBrush sb = new SolidBrush(BackColor)) { if (_regions.Count > 0) { Rectangle rect = GetRectangle(_regions[0]); if (e.ClipRectangle.Top < rect.Top) { e.Graphics.FillRectangle(sb, clip.X, clip.Y, clip.Width, rect.Top - clip.Y); } rect = GetRectangle(_regions[_regions.Count - 1]); if (e.ClipRectangle.Bottom > rect.Bottom) { e.Graphics.FillRectangle(sb, clip.X, rect.Bottom + 1, rect.Width, clip.Y + clip.Height - rect.Bottom - 1); } } else { e.Graphics.FillRectangle(sb, clip); } } } }