Ejemplo n.º 1
0
 private IEnumerable <BlameHunk> GetBlame(string path)
 {
     if (!getBlameResultCache.TryGetValue(path, out IEnumerable <BlameHunk> result))
     {
         try
         {
             if (path.StartsWith(Root, StringComparison.Ordinal))
             {
                 var relativePath = MakeRelativeToRepository(path);
                 if (!Repository.Ignore.IsPathIgnored(relativePath))
                 {
                     result = Repository.Blame(relativePath);
                 }
             }
             else
             {
                 result = new BlameHunk[0];
             }
         }
         catch (Exception ex)
         {
             Logger.Info("Couldn't blame " + path, ex);
             result = new BlameHunk[0];
         }
         getBlameResultCache.Add(path, result);
     }
     return(result);
 }
Ejemplo n.º 2
0
        private IEnumerable <BlameHunk> GetBlame(string path)
        {
            IEnumerable <BlameHunk> result;

            if (!getBlameResultCache.TryGetValue(path, out result))
            {
                try
                {
                    if (path.StartsWith(Root))
                    {
                        result = Repository.Blame(MakeRelativeToRepository(path));
                    }
                    else
                    {
                        result = new BlameHunk[0];
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error("Couldn't blame " + path, ex);
                    result = new BlameHunk[0];
                }
                getBlameResultCache.Add(path, result);
            }
            return(result);
        }
Ejemplo n.º 3
0
        private int GetLinesToContainingHunk(int lineIndex, out BlameHunk blameHunk)
        {
            int res = 0;

            for (int i = 0; i < BlameFile.Count; ++i)
            {
                if (res + BlameFile[i].Count > lineIndex)
                {
                    blameHunk = BlameFile[i];
                    return(res);
                }
                res += BlameFile[i].Count;
            }
            blameHunk = null;
            return(res);
        }
Ejemplo n.º 4
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.º 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
 private int GetLinesToContainingHunk(int lineIndex, out BlameHunk blameHunk)
 {
     int res = 0;
     for(int i = 0; i < _blameFile.Count; ++i)
     {
         if(res + _blameFile[i].Count > lineIndex)
         {
             blameHunk = _blameFile[i];
             return res;
         }
         res += _blameFile[i].Count;
     }
     blameHunk = null;
     return res;
 }