Ejemplo n.º 1
0
 private void IncPos(Hunk h, ref int pos)
 {
     if (sidebyside)
     {
         pos += h.MaxLines();
     }
     else if (h.Same)
     {
         pos += h.Original().Count;
     }
     else
     {
         pos += h.Original().Count;
         for (int i = 0; i < h.ChangedLists; i++)
         {
             pos += h.Changes(i).Count;
         }
     }
 }
			private void IncPos(Hunk h, ref int pos) {
				if (sidebyside)
					pos += h.MaxLines();
				else if (h.Same)
					pos += h.Original().Count;
				else {
					pos += h.Original().Count;
					for (int i = 0; i < h.ChangedLists; i++)
						pos += h.Changes(i).Count;
				}
			}
Ejemplo n.º 3
0
        private DiffWidget(Hunk[] hunks, Options options) : base(false, 0)
        {
            if (hunks == null || hunks.Length == 0 || options == null)
            {
                throw new ArgumentException();
            }

            if (options.SideBySide && options.LeftName != null && options.RightName != null)
            {
                HBox filetitles = new HBox(true, 2);
                PackStart(filetitles, false, false, 2);
                Label leftlabel  = new Label(options.LeftName);
                Label rightlabel = new Label(options.RightName);
                filetitles.PackStart(leftlabel);
                filetitles.PackStart(rightlabel);
            }

            HBox centerpanel = new HBox(false, 0);

            PackStart(centerpanel);

            scroller = new ScrolledWindow();

            centerpanel.PackStart(new OverviewRenderer(this, scroller, hunks, options.SideBySide), false, false, 0);

            Viewport textviewport = new Viewport();

            centerpanel.PackStart(scroller);
            scroller.Add(textviewport);

            int nRows = 0;

            foreach (Hunk hunk in hunks)
            {
                if (options.SideBySide)
                {
                    nRows += hunk.MaxLines();
                }
                else
                {
                    if (hunk.Same)
                    {
                        nRows += hunk.Original().Count;
                    }
                    else
                    {
                        for (int i = 0; i < hunk.ChangedLists; i++)
                        {
                            nRows += hunk.Changes(i).Count;
                        }
                    }
                }
            }

            uint nCols = 1 + (uint)hunks[0].ChangedLists;

            if (options.SideBySide)
            {
                nCols += 2;
            }
            if (options.LineNumbers)
            {
                nCols++;
            }

            VBox tablecontainer = new VBox(false, 0);

            textviewport.Add(tablecontainer);

            difftable = new Table((uint)nRows, (uint)nCols, false);

            tablecontainer.PackStart(difftable, false, false, 0);

            uint row = 0;

            if (options.Font != null)
            {
                font = Pango.FontDescription.FromString(options.Font);
            }

            Hunk lastHunk = hunks.Length > 0 ? hunks[hunks.Length - 1] : null;

            foreach (Hunk hunk in hunks)
            {
                char leftmode = hunk.Same ? ' ' : (hunk.ChangedLists == 1 && hunk.Changes(0).Count == 0) ? '-' : 'C';
                uint inc      = 0;

                if (options.SideBySide)
                {
                    ComposeLines(hunk.Original(), leftmode, -1, difftable, row, false, 0, options.LineWrap, font, options.LineNumbers, lastHunk.Original());
                    inc = (uint)hunk.Original().Count;
                }
                else
                {
                    if (leftmode == 'C')
                    {
                        leftmode = '-';
                    }
                    int altlines = -1;
                    if (hunk.ChangedLists == 1 && hunk.Same)
                    {
                        altlines = hunk.Changes(0).Start;
                    }
                    ComposeLines(hunk.Original(), leftmode, altlines, difftable, row, true, 0, options.LineWrap, font, options.LineNumbers, lastHunk.Original());
                    row += (uint)hunk.Original().Count;
                }

                for (int i = 0; i < hunk.ChangedLists; i++)
                {
                    char rightmode = hunk.Same ? ' ' : hunk.Original().Count == 0 ? '+' : 'C';

                    if (options.SideBySide)
                    {
                        int colsper = 1 + (options.LineNumbers ? 1 : 0);
                        ComposeLines(hunk.Changes(i), rightmode, -1, difftable, row, false, (uint)((i + 1) * colsper), options.LineWrap, font, options.LineNumbers, lastHunk.Original());
                        if (hunk.Changes(i).Count > inc)
                        {
                            inc = (uint)hunk.Changes(i).Count;
                        }
                    }
                    else
                    {
                        if (rightmode == 'C')
                        {
                            rightmode = '+';
                        }

                        if (!hunk.Same)
                        {
                            ComposeLines(hunk.Changes(i), rightmode, -1, difftable, row, true, 0, options.LineWrap, font, options.LineNumbers, lastHunk.Original());
                        }

                        if (!hunk.Same)
                        {
                            row += (uint)hunk.Changes(i).Count;
                        }
                    }
                }

                if (options.SideBySide)
                {
                    row += inc;
                }
            }
        }