Пример #1
0
			protected override bool OnLeaveNotifyEvent (EventCrossing evnt)
			{
				selectedHunk = null;
				TooltipText = null;
				QueueDraw ();
				return base.OnLeaveNotifyEvent (evnt);
			}
Пример #2
0
			void IncPos(Hunk h, ref int pos)
			{
				pos += h.MaxLines();
/*				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;
				}*/
			}
Пример #3
0
			protected override bool OnMotionNotifyEvent (EventMotion evnt)
			{
				bool hideButton = widget.OriginalEditor.Document.ReadOnly || !widget.DiffEditor.Document.ReadOnly;
				Diff.Hunk selectedHunk = null;
				if (!hideButton) {
					int delta = widget.OriginalEditor.Allocation.Y - Allocation.Y;
					foreach (Diff.Hunk hunk in widget.Diff) {
						if (!hunk.Same) {
							int y1 = delta + widget.OriginalEditor.LineToVisualY (hunk.Right.Start) - (int)widget.OriginalEditor.VAdjustment.Value;
							int y2 = delta + widget.OriginalEditor.LineToVisualY (hunk.Right.Start + hunk.Right.Count) - (int)widget.OriginalEditor.VAdjustment.Value;
							if (y1 == y2)
								y2 = y1 + 1;
							
							int z1 = delta + widget.DiffEditor.LineToVisualY (hunk.Left.Start) - (int)widget.DiffEditor.VAdjustment.Value;
							int z2 = delta + widget.DiffEditor.LineToVisualY (hunk.Left.Start + hunk.Left.Count) - (int)widget.DiffEditor.VAdjustment.Value;
							
							if (z1 == z2)
								z2 = z1 + 1;
							
							int x, y, r;
							GetButtonPosition (hunk, z1, z2, y1, y2, out x, out y, out r);
							
							if (evnt.X >= x && evnt.X - x < r && evnt.Y >= y && evnt.Y - y < r) {
								selectedHunk = hunk;
								TooltipText = GettextCatalog.GetString ("Revert this change");
								break;
							}
						}
					}
				} else {
					selectedHunk = null;
				}
				if (selectedHunk == null)
					TooltipText = null;
				if (this.selectedHunk != selectedHunk) {
					this.selectedHunk = selectedHunk;
					QueueDraw ();
				}
				
				return base.OnMotionNotifyEvent (evnt);
			}
		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;
			}
		}
			public OverviewRenderer2(DiffWidget widget, ScrolledWindow scroller, Hunk[] hunks, bool sidebyside) {
				this.widget = widget;
				this.hunks = hunks;
				this.scroller = scroller;
				this.sidebyside = sidebyside;
				scroller.ExposeEvent += OnScroll;
				WidthRequest = 50;
			}
			public OverviewRenderer(DiffWidget widget, ScrolledWindow scroller, Hunk[] hunks, bool sidebyside)
			{
				this.scroller = scroller;
				this.ButtonPressEvent += ButtonPressHandler;
				Add (new OverviewRenderer2 (widget, scroller, hunks, sidebyside));
			}
		internal Patch(Hunk[] hunks) {
			this.hunks = hunks;
		}
Пример #8
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;
                }
            }
        }