Ejemplo n.º 1
0
        static void MessageFunc(Gtk.TreeViewColumn tree_column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
        {
            string filter = GetCurrentFilter(model);

            CellRendererText renderer = (CellRendererText)cell;
            var rev = (Revision)model.GetValue(iter, 0);

            if (string.IsNullOrEmpty(rev.Message))
            {
                renderer.Text = GettextCatalog.GetString("(No message)");
            }
            else
            {
                string message = Revision.FormatMessage(rev.Message);
                int    idx     = message.IndexOf('\n');
                if (idx > 0)
                {
                    message = message.Substring(0, idx);
                }
                if (string.IsNullOrEmpty(filter))
                {
                    renderer.Text = message;
                }
                else
                {
                    renderer.Markup = EscapeWithFilterMarker(message, filter);
                }
            }
        }
Ejemplo n.º 2
0
            protected override bool OnExposeEvent(Gdk.EventExpose e)
            {
                using (Cairo.Context cr = Gdk.CairoHelper.Create(e.Window)) {
                    cr.LineWidth = Math.Max(1.0, widget.Editor.Options.Zoom);

                    cr.Rectangle(leftSpacer, 0, Allocation.Width, Allocation.Height);
                    cr.SetSourceRGB(0.95, 0.95, 0.95);
                    cr.Fill();

                    int    startLine = widget.Editor.YToLine((int)widget.Editor.VAdjustment.Value);
                    double startY    = widget.Editor.LineToY(startLine);
                    while (startLine > 1 && startLine < annotations.Count && annotations[startLine - 1] != null && annotations[startLine] != null && annotations[startLine - 1].Revision == annotations[startLine].Revision)
                    {
                        startLine--;
                        startY -= widget.Editor.GetLineHeight(widget.Editor.Document.GetLine(startLine));
                    }
                    double curY = startY - widget.Editor.VAdjustment.Value;
                    int    line = startLine;
                    while (curY < Allocation.Bottom && line <= widget.Editor.LineCount)
                    {
                        double curStart = curY;
//						widget.JumpOverFoldings (ref line);
                        int        lineStart = line;
                        int        authorWidth = 0, revisionWidth = 0, dateWidth = 0, h = 16;
                        Annotation ann = line <= annotations.Count ? annotations[line - 1] : null;
                        if (ann != null)
                        {
                            do
                            {
                                widget.JumpOverFoldings(ref line);
                                line++;
                            } while (line <= annotations.Count && annotations[line - 1] != null && annotations[line - 1].Revision == ann.Revision);

                            double nextY = widget.editor.LineToY(line) - widget.editor.VAdjustment.Value;
                            if (highlightAnnotation != null && highlightAnnotation.Revision == ann.Revision && curStart <= highlightPositon && highlightPositon < nextY)
                            {
                                cr.Rectangle(leftSpacer, curStart + cr.LineWidth, Allocation.Width - leftSpacer, nextY - curStart - cr.LineWidth);
                                cr.SetSourceRGB(1, 1, 1);
                                cr.Fill();
                            }

                            // use a fixed size revision to get a approx. revision width
                            layout.SetText("88888888");
                            layout.GetPixelSize(out revisionWidth, out h);
                            layout.SetText(TruncRevision(ann.Revision));
                            e.Window.DrawLayout(Style.BlackGC, Allocation.Width - revisionWidth - margin, (int)(curY + (widget.Editor.LineHeight - h) / 2), layout);

                            const int dateRevisionSpacing = 16;
                            if (ann.HasDate)
                            {
                                string dateTime = ann.Date.ToShortDateString();
                                // use a fixed size date to get a approx. date width
                                layout.SetText(new DateTime(1999, 10, 10).ToShortDateString());
                                layout.GetPixelSize(out dateWidth, out h);
                                layout.SetText(dateTime);
                                e.Window.DrawLayout(Style.BlackGC, Allocation.Width - revisionWidth - margin - revisionWidth - dateRevisionSpacing, (int)(curY + (widget.Editor.LineHeight - h) / 2), layout);
                            }

                            using (var authorLayout = PangoUtil.CreateLayout(this)) {
                                var description = Pango.FontDescription.FromString("Tahoma " + (int)(10 * widget.Editor.Options.Zoom));
                                authorLayout.FontDescription = description;
                                authorLayout.SetText(ann.Author);
                                authorLayout.GetPixelSize(out authorWidth, out h);

                                var maxWidth = Allocation.Width - revisionWidth - margin - revisionWidth - dateRevisionSpacing;

                                /*				if (authorWidth > maxWidth) {
                                 *                                      int idx = ann.Author.IndexOf ('<');
                                 *                                      if (idx > 0)
                                 *                                              authorLayout.SetText (ann.Author.Substring (0, idx) + Environment.NewLine + ann.Author.Substring (idx));
                                 *                                      authorLayout.GetPixelSize (out authorWidth, out h);
                                 *                              }*/

                                cr.Save();
                                cr.Rectangle(0, 0, maxWidth, Allocation.Height);
                                cr.Clip();
                                cr.Translate(leftSpacer + margin, (int)(curY + (widget.Editor.LineHeight - h) / 2));
                                cr.SetSourceRGB(0, 0, 0);
                                cr.ShowLayout(authorLayout);
                                cr.ResetClip();
                                cr.Restore();
                            }

                            curY = nextY;
                        }
                        else
                        {
                            curY += widget.Editor.GetLineHeight(line);
                            line++;
                            widget.JumpOverFoldings(ref line);
                        }

                        if (ann != null && line - lineStart > 1)
                        {
                            string msg = GetCommitMessage(lineStart, false);
                            if (!string.IsNullOrEmpty(msg))
                            {
                                msg = Revision.FormatMessage(msg);

                                layout.SetText(msg);
                                layout.Width = (int)(Allocation.Width * Pango.Scale.PangoScale);
                                using (var gc = new Gdk.GC(e.Window)) {
                                    gc.RgbFgColor    = Style.Dark(State);
                                    gc.ClipRectangle = new Rectangle(0, (int)curStart, Allocation.Width, (int)(curY - curStart));
                                    e.Window.DrawLayout(gc, (int)(leftSpacer + margin), (int)(curStart + h), layout);
                                }
                            }
                        }

                        cr.Rectangle(0, curStart, leftSpacer, curY - curStart);

                        if (ann != null && ann != locallyModified && !string.IsNullOrEmpty(ann.Author))
                        {
                            double a;

                            if (ann != null && (maxDate - minDate).TotalHours > 0)
                            {
                                a = 1 - (ann.Date - minDate).TotalHours / (maxDate - minDate).TotalHours;
                            }
                            else
                            {
                                a = 1;
                            }
                            HslColor color = new Cairo.Color(0.90, 0.90, 1);
                            color.L = 0.4 + a / 2;
                            color.S = 1 - a / 2;
                            cr.SetSourceColor(color);
                        }
                        else
                        {
                            cr.SetSourceColor(ann != null ? new Cairo.Color(1, 1, 0) : new Cairo.Color(0.95, 0.95, 0.95));
                        }
                        cr.Fill();

                        if (ann != null)
                        {
                            cr.MoveTo(0, curY + 0.5);
                            cr.LineTo(Allocation.Width, curY + 0.5);
                            cr.SetSourceRGB(0.6, 0.6, 0.6);
                            cr.Stroke();
                        }
                    }
                }
                return(true);
            }