Beispiel #1
0
		internal Patch(Hunk[] hunks) {
			this.hunks = hunks;
		}
Beispiel #2
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;
			}
		}
Beispiel #3
0
		public OverviewRenderer(ScrolledWindow scroller, Hunk[] hunks, bool sidebyside) {
			this.scroller = scroller;
			this.ButtonPressEvent += ButtonPressHandler;
			Add(new OverviewRenderer2(scroller, hunks, sidebyside));
		}
Beispiel #4
0
		public OverviewRenderer2(ScrolledWindow scroller, Hunk[] hunks, bool sidebyside) {
			this.hunks = hunks;
			this.scroller = scroller;
			this.sidebyside = sidebyside;
			this.ExposeEvent += OnExposed;
			scroller.ExposeEvent += OnScroll;
			WidthRequest = 50;
		}
Beispiel #5
0
	private DiffWidget(Hunk[] hunks, Options options) : base(false, 0) {
		if (hunks == null || hunks.Length == 0 || options == null)
			throw new ArgumentException();
		
		if (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);

		ScrolledWindow scroller = new ScrolledWindow();
		
		centerpanel.PackStart(new OverviewRenderer(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++;
		
		Table difftable = new Table((uint)nRows, (uint)nCols, false);
		textviewport.Add(difftable);	
		
		uint row = 0;
		
		Pango.FontDescription font = null;
		if (options.Font != null)
			font = Pango.FontDescription.FromString(options.Font);
		
		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);
				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);
				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);
					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);
					
					if (!hunk.Same) row += (uint)hunk.Changes(i).Count;
				}
			}
			
			if (options.SideBySide)
				row += inc;
		}
	}