Пример #1
0
        public int CompareTo(DiffViewPosition Pos)
        {
            int iResult = Line - Pos.Line;

            if (iResult == 0)
            {
                iResult = Column - Pos.Column;
            }

            return iResult;
        }
Пример #2
0
        public int CompareTo(DiffViewPosition Pos)
        {
            int iResult = Line - Pos.Line;

            if (iResult == 0)
            {
                iResult = Column - Pos.Column;
            }

            return(iResult);
        }
Пример #3
0
        private void View_PositionChanged(object sender, System.EventArgs e)
        {
            DiffView         View = ActiveView;
            DiffViewPosition Pos  = View.Position;

            lblPosition.Text = String.Format("Ln {0}, Col {1}", Pos.Line + 1, Pos.Column + 1);
            UpdateButtons();

            if (View != ViewLineDiff)
            {
                UpdateLineDiff();
            }
        }
Пример #4
0
        public DiffView()
        {
            //Set some important control styles
            SetStyle(ControlStyles.Opaque, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.DoubleBuffer, true);
            SetStyle(ControlStyles.Selectable, true);
            SetStyle(ControlStyles.StandardClick, true);
            SetStyle(ControlStyles.StandardDoubleClick, true);
            SetStyle(ControlStyles.ResizeRedraw, true);

            m_Position = new DiffViewPosition(0, 0);

            UpdateTextMetrics(true);

            m_AutoScrollTimer = new Timer();
            m_AutoScrollTimer.Enabled = false;
            m_AutoScrollTimer.Interval = 100;
            m_AutoScrollTimer.Tick += new EventHandler(AutoScrollTimer_Tick);

            m_OptionsChangedHandler = new EventHandler(DiffOptionsChanged);
            DiffOptions.OptionsChanged += m_OptionsChangedHandler;

            Cursor = Cursors.IBeam;
        }
Пример #5
0
        private void UpdateAfterSetData()
        {
            //Reset the position before we start calculating things
            m_Position = new DiffViewPosition(0, 0);
            m_SelectionStart = DiffViewPosition.Empty;

            //We have to call this to recalc the gutter width
            UpdateTextMetrics(false);

            //We have to call this to setup the scroll bars
            SetupScrollBars();

            //Reset the scroll position
            VScrollPos = 0;
            HScrollPos = 0;

            //Update the caret
            UpdateCaret();

            //Force a repaint
            Invalidate();

            //Fire the LinesChanged event
            if (LinesChanged != null)
            {
                LinesChanged(this, EventArgs.Empty);
            }

            //Fire the position changed event
            if (PositionChanged != null)
            {
                PositionChanged(this, EventArgs.Empty);
            }

            FireSelectionChanged();
        }
Пример #6
0
        private void SetSelectionEnd(int iLine, int iColumn)
        {
            bool bSelectionChanged = false;
            if (!HasSelection)
            {
                m_SelectionStart = m_Position;
                bSelectionChanged = true;
            }

            //Move the Position but keep the selection start
            int iOriginalLine = m_Position.Line;
            SetPosition(iLine, iColumn, false, true);
            int iNumLines = Math.Abs(iLine - iOriginalLine);

            //Invalidate new selection
            int iFirstLine = Math.Min(iOriginalLine, iLine);
            Point Pt = GetPointFromPos(iFirstLine, 0);
            Rectangle R = new Rectangle(GutterWidth, Pt.Y, ClientSize.Width, (iNumLines + 1) * LineHeight);
            Invalidate(R);

            if (bSelectionChanged)
            {
                FireSelectionChanged();
            }
        }
Пример #7
0
        private void SetPosition(int iLine, int iColumn, bool bClearSelection, bool bScrollToCaret)
        {
            if (iLine >= LineCount) iLine = LineCount - 1;
            if (iLine < 0) iLine = 0;

            int iLength = GetLineLength(iLine);
            if (iColumn > iLength) iColumn = iLength;
            if (iColumn < 0) iColumn = 0;

            if (bClearSelection)
            {
                ClearSelection();
            }

            bool bLineNumberChanged = m_Position.Line != iLine;
            bool bColumnNumberChanged = m_Position.Column != iColumn;

            if (bLineNumberChanged || bColumnNumberChanged)
            {
                //Invalidate the old gutter line.
                if (bLineNumberChanged) InvalidateCaretGutter();

                m_Position = new DiffViewPosition(iLine, iColumn);

                //Invalidate the new gutter line.
                if (bLineNumberChanged) InvalidateCaretGutter();

                UpdateCaret();

                //If the selection range is now empty, then clear the selection.
                if (m_Position == m_SelectionStart)
                {
                    ClearSelection();
                    //Set the flag so we don't refire the SelectionChanged event below.
                    bClearSelection = true;
                }

                if (m_Lines != null)
                {
                    if (PositionChanged != null)
                    {
                        PositionChanged(this, EventArgs.Empty);
                    }

                    //If we cleared the selection earlier, then that
                    //fire a SelectionChanged event.  If not, then we
                    //need to fire it now because we've changed the
                    //selection end point.
                    if (!bClearSelection)
                    {
                        FireSelectionChanged();
                    }
                }
            }

            if (bScrollToCaret)
            {
                ScrollToCaret();
            }
        }
Пример #8
0
        private bool InSelection(DiffViewPosition Pos)
        {
            bool bResult = false;

            if (HasSelection)
            {
                DiffViewPosition StartSel, EndSel;
                GetForwardOrderSelection(out StartSel, out EndSel);
                bResult = (Pos >= StartSel && Pos <= EndSel);
            }

            return bResult;
        }
Пример #9
0
 private void GetForwardOrderSelection(out DiffViewPosition StartSel, out DiffViewPosition EndSel)
 {
     //Determine the selection positions in forward order.
     //Get them in order in case we have a reverse selection.
     StartSel = m_SelectionStart;
     EndSel = m_Position;
     if (StartSel.Line > EndSel.Line || (StartSel.Line == EndSel.Line && StartSel.Column > EndSel.Column))
     {
         StartSel = m_Position;
         EndSel = m_SelectionStart;
     }
 }
Пример #10
0
 private void ClearSelection()
 {
     if (HasSelection)
     {
         InvalidateSelection();
         m_SelectionStart = DiffViewPosition.Empty;
         FireSelectionChanged();
     }
 }