Ejemplo n.º 1
0
        /// <summary>
        /// Blames the by line by command line.
        /// </summary>
        /// <param name="list">The list param.</param>
        /// <param name="line">The line param.</param>
        /// <returns>
        /// Returns blame line.
        /// </returns>
        private BlameLine BlameByLineByCommandLine(GitBlame list, int line)
        {
            if (line >= list.Lines.Count)
            {
                return(null);
            }

            var lineBlame = list.Lines[line - 1];

            foreach (var item in list.Headers)
            {
                if (item.CommitGuid.Equals(lineBlame.CommitGuid))
                {
                    var blame = new BlameLine();
                    blame.Author  = item.Author;
                    blame.Email   = item.AuthorMail.TrimEnd('>').TrimStart('<').Trim();
                    blame.Date    = item.CommitterTime;
                    blame.Line    = line;
                    blame.Guid    = item.CommitGuid;
                    blame.Summary = item.Summary;
                    return(blame);
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        public BlameLine[] GetSelectedLines()
        {
            if (_selStart == -1)
            {
                return(new BlameLine[0]);
            }
            int offset = 0;
            int i      = 0;
            int num    = _selStart;

            while (BlameFile[i].Count <= num)
            {
                int lc = BlameFile[i].Count;
                offset += lc;
                num    -= lc;
                ++i;
            }
            int count = _selEnd - _selStart + 1;
            var res   = new BlameLine[count];
            int id    = 0;

            while (id != res.Length)
            {
                res[id++] = BlameFile[i][num++];
                if (num >= BlameFile[i].Count)
                {
                    ++i;
                    num = 0;
                }
            }
            return(res);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Blames the by line.
        /// </summary>
        /// <param name="blameInfo">The blame information.</param>
        /// <param name="line">The line param.</param>
        /// <returns>Returns null if not found.</returns>
        private BlameLine BlameByLine(BlameHunkCollection blameInfo, int line)
        {
            var enumerator = blameInfo.GetEnumerator();

            enumerator.MoveNext();
            var prev = enumerator.Current;

            while (enumerator.MoveNext())
            {
                var curr = enumerator.Current;

                Debug.WriteLine(prev.FinalSignature.Name + "    " + prev.FinalSignature.When + " === " + prev.FinalStartLineNumber + " === " + curr.FinalStartLineNumber + "     " + line.ToString());

                if (line >= prev.FinalStartLineNumber && line < curr.FinalStartLineNumber)
                {
                    var blame = new BlameLine();
                    blame.Line   = line;
                    blame.Author = prev.FinalSignature.Name;
                    blame.Date   = prev.FinalSignature.When.LocalDateTime;
                    blame.Email  = prev.FinalSignature.Email;
                    return(blame);
                }

                prev = enumerator.Current;
            }

            return(null);
        }
Ejemplo n.º 4
0
        public BlameFile ParseBlameFile(string fileName)
        {
            var         cache = new Dictionary <Hash, BlameCommit>(Hash.EqualityComparer);
            int         lineN = 1;
            BlameCommit prev  = null;
            var         hunks = new List <BlameHunk>();
            var         lines = new List <BlameLine>();

            while (!IsAtEndOfString)
            {
                var commit = ParseCommitInfo(cache);
                Skip();
                if (IsAtEndOfString)
                {
                    break;
                }

                int    eol = FindLfLineEnding();
                string ending;
                if (String[eol - 1] == '\r')
                {
                    --eol;
                    ending = LineEnding.CrLf;
                }
                else
                {
                    ending = LineEnding.Lf;
                }
                var line = new BlameLine(commit, lineN++, ReadStringUpTo(eol, ending.Length), ending);

                if (commit != prev)
                {
                    if (lines.Count != 0)
                    {
                        hunks.Add(new BlameHunk(prev, lines));
                        lines.Clear();
                    }
                }
                lines.Add(line);
                prev = commit;
            }
            if (lines.Count != 0)
            {
                hunks.Add(new BlameHunk(prev, lines));
                lines.Clear();
            }

            return(new BlameFile(fileName, hunks));
        }
Ejemplo n.º 5
0
        private void PaintLine(int lineIndex, BlameHunk hunk, BlameLine line, bool paintHeader, int digits, Graphics graphics, Font font, bool hover, bool selected, bool alternate, int x, int y, int width)
        {
            Brush backgroundBrush;

            var rcColNumbers = new Rectangle(x, y, (digits + 1) * CellSize.Width + 2, CellSize.Height);

            graphics.SmoothingMode = SmoothingMode.Default;
            using (backgroundBrush = hover ?
                                     GetLineNumberHoverBackground() :
                                     GetLineNumberBackground())
            {
                graphics.FillRectangle(backgroundBrush, rcColNumbers);
            }
            graphics.SmoothingMode = SmoothingMode.AntiAlias;
            var num  = line.Number;
            var temp = num;
            int d    = 0;

            while (temp != 0)
            {
                temp /= 10;
                ++d;
            }
            int lx = x + ((digits - d)) * CellSize.Width + CellSize.Width / 2;

            using (var brush = GetLineNumberText())
            {
                GitterApplication.TextRenderer.DrawText(
                    graphics,
                    num.ToString(CultureInfo.InvariantCulture),
                    font,
                    brush,
                    lx, y,
                    ContentFormat);
            }
            int lineX = x;

            graphics.DrawLine(Pens.Gray, lineX, y, lineX, y + CellSize.Height);
            lineX = x + (digits + 1) * CellSize.Width + 1;
            graphics.DrawLine(Pens.Gray, lineX, y, lineX, y + CellSize.Height);
            lineX = x + width - Margin * 2;
            graphics.DrawLine(Pens.Gray, lineX, y, lineX, y + CellSize.Height);
            var rcLine = new Rectangle(
                x + rcColNumbers.Width, y,
                width - 2 * Margin - rcColNumbers.Width, CellSize.Height);

            graphics.SmoothingMode = SmoothingMode.Default;
            if (hover)
            {
                backgroundBrush = selected ?
                                  GetLineSelectedHoverBackground() :
                                  GetLineHoverBackground();
            }
            else
            {
                backgroundBrush = selected ?
                                  GetLineSelectedBackground() :
                                  (alternate ?
                                   new SolidBrush(Style.Colors.Alternate) :
                                   new SolidBrush(Style.Colors.LineContextBackground));
            }
            using (backgroundBrush)
            {
                graphics.FillRectangle(backgroundBrush, rcLine);
            }
            lineX = x + digits * CellSize.Width + _hashColumnWidth + _autorColumnWidth + 1;
            graphics.DrawLine(Pens.Gray, lineX, y, lineX, y + CellSize.Height);
            using (var brush = new SolidBrush(Style.Colors.WindowText))
            {
                if (paintHeader)
                {
                    var rcHash   = new Rectangle(rcLine.X, rcLine.Y, _hashColumnWidth, rcLine.Height);
                    var rcAuthor = new Rectangle(rcLine.X + _hashColumnWidth, rcLine.Y, _autorColumnWidth, rcLine.Height);
                    GitterApplication.TextRenderer.DrawText(
                        graphics, hunk.Commit.Hash.ToString(7), font, brush,
                        rcHash.X + CellSize.Width / 2, rcHash.Y, ContentFormat);
                    GitterApplication.TextRenderer.DrawText(
                        graphics, hunk.Commit.Author, font, brush,
                        rcAuthor.X + CellSize.Width / 2, rcAuthor.Y, ContentFormat);
                }

                rcLine.X     += _hashColumnWidth + _autorColumnWidth;
                rcLine.Width -= _hashColumnWidth + _autorColumnWidth;
                GitterApplication.TextRenderer.DrawText(
                    graphics, line.Text, font, brush,
                    rcLine.X, rcLine.Y, ContentFormat);
            }
        }
Ejemplo n.º 6
0
 protected override Size OnMeasure(FlowPanelMeasureEventArgs measureEventArgs)
 {
     if (BlameFile == null)
     {
         return(Size.Empty);
     }
     if (_size.IsEmpty)
     {
         int       maxLength     = 0;
         BlameLine longestLine   = null;
         string    longestAuthor = string.Empty;
         foreach (var hunk in BlameFile)
         {
             foreach (var line in hunk)
             {
                 int l = line.GetCharacterPositions(TabSize);
                 if (l > maxLength)
                 {
                     maxLength   = l;
                     longestLine = line;
                 }
             }
             if (hunk.Commit.Author.Length > longestAuthor.Length)
             {
                 longestAuthor = hunk.Commit.Author;
             }
         }
         var digits = GetDecimalDigits(BlameFile.LineCount) + 1;
         var font   = GitterApplication.FontManager.ViewerFont.Font;
         int w      = CellSize.Width * digits + 2 * Margin;
         if (longestLine != null)
         {
             int longestLineWidth;
             try
             {
                 longestLineWidth = GitterApplication.TextRenderer.MeasureText(
                     measureEventArgs.Graphics, longestLine.Text, font, int.MaxValue, ContentFormat).Width + (CellSize.Width / 2);
             }
             catch (Exception exc) when(!exc.IsCritical())
             {
                 longestLineWidth = (int)(maxLength * CellSize.Width);
             }
             int longestAuthorWidth;
             try
             {
                 longestAuthorWidth = GitterApplication.TextRenderer.MeasureText(
                     measureEventArgs.Graphics, longestAuthor, font, int.MaxValue, ContentFormat).Width + CellSize.Width;
             }
             catch (Exception exc) when(!exc.IsCritical())
             {
                 longestAuthorWidth = (int)(longestAuthor.Length * CellSize.Width);
             }
             longestAuthorWidth += CellSize.Width;
             _autorColumnWidth   = longestAuthorWidth;
             w += longestLineWidth + longestAuthorWidth;
             _hashColumnWidth = CellSize.Width * 7 + CellSize.Width;
             w += _hashColumnWidth;
         }
         var h = BlameFile.LineCount * CellSize.Height;
         if (ShowHeader)
         {
             h += HeaderHeight;
         }
         if (BlameFile.LineCount != 0)
         {
             h += 2;
         }
         _size = new Size(w, h);
     }
     return(_size);
 }
Ejemplo n.º 7
0
        public BlameFile ParseBlameFile(string fileName)
        {
            var cache = new Dictionary<Hash, BlameCommit>(Hash.EqualityComparer);
            int lineN = 1;
            BlameCommit prev = null;
            var hunks = new List<BlameHunk>();
            var lines = new List<BlameLine>();

            while(!IsAtEndOfString)
            {
                var commit = ParseCommitInfo(cache);
                Skip();
                if(IsAtEndOfString) break;

                int eol = FindLfLineEnding();
                string ending;
                if(String[eol - 1] == '\r')
                {
                    --eol;
                    ending = LineEnding.CrLf;
                }
                else
                {
                    ending = LineEnding.Lf;
                }
                var line = new BlameLine(commit, lineN++, ReadStringUpTo(eol, ending.Length), ending);

                if(commit != prev)
                {
                    if(lines.Count != 0)
                    {
                        hunks.Add(new BlameHunk(prev, lines));
                        lines.Clear();
                    }
                }
                lines.Add(line);
                prev = commit;
            }
            if(lines.Count != 0)
            {
                hunks.Add(new BlameHunk(prev, lines));
                lines.Clear();
            }

            return new BlameFile(fileName, hunks);
        }
Ejemplo n.º 8
0
        private void PaintLine(int lineIndex, BlameHunk hunk, BlameLine line, bool paintHeader, int digits, Graphics graphics, Font font, bool hover, bool selected, bool alternate, int x, int y, int width)
        {
            Brush backgroundBrush;

            var rcColNumbers = new Rectangle(x, y, (digits + 1) * CellSize.Width + 2, CellSize.Height);
            graphics.SmoothingMode = SmoothingMode.Default;
            using(backgroundBrush = hover ?
                GetLineNumberHoverBackground() :
                GetLineNumberBackground())
            {
                graphics.FillRectangle(backgroundBrush, rcColNumbers);
            }
            graphics.SmoothingMode = SmoothingMode.AntiAlias;
            var num = line.Number;
            var temp = num;
            int d = 0;
            while(temp != 0)
            {
                temp /= 10;
                ++d;
            }
            int lx = x + ((digits - d)) * CellSize.Width + CellSize.Width / 2;
            using(var brush = GetLineNumberText())
            {
                GitterApplication.TextRenderer.DrawText(
                    graphics,
                    num.ToString(CultureInfo.InvariantCulture),
                    font,
                    brush,
                    lx, y,
                    ContentFormat);
            }
            int lineX = x;
            graphics.DrawLine(Pens.Gray, lineX, y, lineX, y + CellSize.Height);
            lineX = x + (digits + 1) * CellSize.Width + 1;
            graphics.DrawLine(Pens.Gray, lineX, y, lineX, y + CellSize.Height);
            lineX = x + width - Margin * 2;
            graphics.DrawLine(Pens.Gray, lineX, y, lineX, y + CellSize.Height);
            var rcLine = new Rectangle(
                x + rcColNumbers.Width, y,
                width - 2 * Margin - rcColNumbers.Width, CellSize.Height);
            graphics.SmoothingMode = SmoothingMode.Default;
            if(hover)
            {
                backgroundBrush = selected ?
                    GetLineSelectedHoverBackground() :
                    GetLineHoverBackground();
            }
            else
            {
                backgroundBrush = selected ?
                    GetLineSelectedBackground() :
                    (alternate ?
                        new SolidBrush(Style.Colors.Alternate) :
                        new SolidBrush(Style.Colors.LineContextBackground));
            }
            using(backgroundBrush)
            {
                graphics.FillRectangle(backgroundBrush, rcLine);
            }
            lineX = x + digits * CellSize.Width + _hashColumnWidth + _autorColumnWidth + 1;
            graphics.DrawLine(Pens.Gray, lineX, y, lineX, y + CellSize.Height);
            using(var brush = new SolidBrush(Style.Colors.WindowText))
            {
                if(paintHeader)
                {
                    var rcHash   = new Rectangle(rcLine.X, rcLine.Y, _hashColumnWidth, rcLine.Height);
                    var rcAuthor = new Rectangle(rcLine.X + _hashColumnWidth, rcLine.Y, _autorColumnWidth, rcLine.Height);
                    GitterApplication.TextRenderer.DrawText(
                        graphics, hunk.Commit.Hash.ToString(7), font, brush,
                        rcHash.X + CellSize.Width / 2, rcHash.Y, ContentFormat);
                    GitterApplication.TextRenderer.DrawText(
                        graphics, hunk.Commit.Author, font, brush,
                        rcAuthor.X + CellSize.Width / 2, rcAuthor.Y, ContentFormat);
                }

                rcLine.X += _hashColumnWidth + _autorColumnWidth;
                rcLine.Width -= _hashColumnWidth + _autorColumnWidth;
                GitterApplication.TextRenderer.DrawText(
                    graphics, line.Text, font, brush,
                    rcLine.X, rcLine.Y, ContentFormat);
            }
        }
Ejemplo n.º 9
0
 public BlameLine[] GetSelectedLines()
 {
     if(_selStart == -1) return new BlameLine[0];
     int offset = 0;
     int i = 0;
     int num = _selStart;
     while(_blameFile[i].Count <= num)
     {
         int lc = _blameFile[i].Count;
         offset += lc;
         num -= lc;
         ++i;
     }
     int count = _selEnd - _selStart + 1;
     var res = new BlameLine[count];
     int id = 0;
     while(id != res.Length)
     {
         res[id++] = _blameFile[i][num++];
         if(num >= _blameFile[i].Count)
         {
             ++i;
             num = 0;
         }
     }
     return res;
 }