From cb86aa9add5a242fac0f34b3304dadf315f830af Mon Sep 17 00:00:00 2001 From: gambas Date: Wed, 7 Mar 2018 01:09:44 +0100 Subject: [PATCH] TextEditor: Don't store breakpoints and bookmarks in each line, but in global collections. [GB.FORM.EDITOR] * NEW: TextEditor: Don't store breakpoints and bookmarks in each line, but in global collections. --- comp/src/gb.form.editor/.src/CDocument.class | 149 ++++++++++++++---- comp/src/gb.form.editor/.src/CLineInfo.class | 40 +---- comp/src/gb.form.editor/.src/TextEditor.class | 87 +++++----- .../.src/_TextEditor_Line.class | 12 +- 4 files changed, 170 insertions(+), 118 deletions(-) diff --git a/comp/src/gb.form.editor/.src/CDocument.class b/comp/src/gb.form.editor/.src/CDocument.class index 1c00e120f..9db3d3be9 100644 --- a/comp/src/gb.form.editor/.src/CDocument.class +++ b/comp/src/gb.form.editor/.src/CDocument.class @@ -42,6 +42,9 @@ Private $bCloseBraces As Boolean Private $iEndOfLine As Integer = gb.Unix Private $sEndOfLine As String = "\n" +Private $cBreakpoint As New Collection +Private $cBookmark As New Collection + Public Sub _new() _Mode = New TextEditorMode @@ -210,6 +213,62 @@ Public Sub Refresh(Optional Y As Integer = -1) End +Private Sub RemoveCollection(cCol As Collection, Y As Integer, N As Integer) As Collection + + Dim cNew As Collection + Dim bValue As Boolean + Dim iLine As Integer + + If cCol.Count = 0 Then Return cCol + + cNew = New Collection + For Each bValue In cCol + iLine = CInt(cCol.Key) + If iLine < Y Then + Else If iLine >= (Y + N) Then + iLine -= N + Else + Continue + Endif + cNew[iLine] = bValue + Next + + Return cNew + +End + + +Private Sub RemoveLines(Y As Integer, N As Integer) + + Lines.Remove(Y, N) + LinesInfo.Remove(Y, N) + LineLength.Remove(Y, N) + + $cBookmark = RemoveCollection($cBookmark, Y, N) + $cBreakpoint = RemoveCollection($cBreakpoint, Y, N) + +End + +Private Sub InsertCollection(cCol As Collection, Y As Integer) As Collection + + Dim bValue As Boolean + Dim iLine As Integer + Dim cNew As Collection + + If cCol.Count = 0 Then Return cCol + + cNew = New Collection + For Each bValue In cCol + iLine = CInt(cCol.Key) + If iLine >= Y Then Inc iLine + cNew[iLine] = bValue + Next + + Return cNew + +End + + Private Sub InsertLine(Y As Integer) Lines.Add("", Y) @@ -217,6 +276,9 @@ Private Sub InsertLine(Y As Integer) LinesInfo.Add(CLineInfo(), Y) LinesInfo[Y].Modified = True + $cBookmark = InsertCollection($cBookmark, Y) + $cBreakpoint = InsertCollection($cBreakpoint, Y) + End ' void GDocument::insertLine(int y) @@ -515,9 +577,7 @@ Public Sub Remove(X1 As Integer, Y1 As Integer, X2 As Integer, Y2 As Integer) SetLine(Y1, String.Left(Lines[Y1], X1) & String.Mid$(Lines[Y2], X2 + 1), True) - Lines.Remove(Y1 + 1, Y2 - Y1) - LinesInfo.Remove(Y1 + 1, Y2 - Y1) - LineLength.Remove(Y1 + 1, Y2 - Y1) + RemoveLines(Y1 + 1, Y2 - Y1) For Each hView In GetAllViews() hView._RaiseChange @@ -983,16 +1043,34 @@ Private Function Keywords_Read() As String[] End +Public Sub HasBreakpoint(iLine As Integer) As Boolean + + Return $cBreakpoint.Exist(iLine) + +End + +Public Sub IsBreakpointDisabled(iLine As Integer) As Boolean + + If $cBreakpoint.Exist(iLine) Then Return Not CBool($cBreakpoint[iLine]) + +End + +Public Sub SetBreakpoint(iLine As Integer, bOn As Boolean, Optional bDisable As Boolean) + + If bOn Then + $cBreakpoint[iLine] = Not bDisable + Else + $cBreakpoint.Remove(iLine) + Endif + +End + Private Function Breakpoints_Read() As Integer[] - Dim Y As Integer - Dim aRes As Integer[] + Dim aRes As New Integer[] - aRes = New Integer[] - For Y = 0 To Lines.Max - If Info(Y).Breakpoint Then - aRes.Add(Y) - Endif + For Each $cBreakpoint + aRes.Add(CInt($cBreakpoint.Key)) Next Return aRes @@ -1002,31 +1080,43 @@ End Private Sub Breakpoints_Write(Value As Integer[]) Dim Y As Integer - - For Y = 0 To Lines.Max - If Info(Y).Breakpoint Then SetInfo(Y).Breakpoint = False - Next + $cBreakpoint.Clear + If Value Then For Each Y In Value - SetInfo(Y).Breakpoint = True + $cBreakpoint[Y] = True Next Endif + + Refresh End +Public Sub HasBookmark(iLine As Integer) As Boolean + + Return $cBookmark.Exist(iLine) + +End + +Public Sub SetBookmark(iLine As Integer, bOn As Boolean) + + If bOn Then + $cBookmark[iLine] = True + Else + $cBookmark.Remove(iLine) + Endif + +End + Private Function Bookmarks_Read() As Integer[] - Dim Y As Integer - Dim aRes As Integer[] - - aRes = New Integer[] - For Y = 0 To Lines.Max - If Info(Y).Bookmark Then - aRes.Add(Y) - Endif - Next + Dim aRes As New Integer[] + For Each $cBookmark + aRes.Add(CInt($cBookmark.Key)) + Next + aRes.Sort Return aRes End @@ -1034,16 +1124,16 @@ End Private Sub Bookmarks_Write(Value As Integer[]) Dim Y As Integer - - For Y = 0 To Lines.Max - If Info(Y).Bookmark Then SetInfo(Y).Bookmark = False - Next + $cBookmark.Clear + If Value Then For Each Y In Value - SetInfo(Y).Bookmark = True + $cBookmark[Y] = True Next Endif + + Refresh End @@ -1406,4 +1496,3 @@ Public Sub GetIndentText(iStart As Integer, iEnd As Integer) As String Return sResult End - diff --git a/comp/src/gb.form.editor/.src/CLineInfo.class b/comp/src/gb.form.editor/.src/CLineInfo.class index ab4890be2..af4682d14 100644 --- a/comp/src/gb.form.editor/.src/CLineInfo.class +++ b/comp/src/gb.form.editor/.src/CLineInfo.class @@ -4,12 +4,9 @@ Property Modified As Boolean Property Saved As Boolean Property Alternate As Boolean Property Limit As Boolean -Property Breakpoint As Boolean -Property Disabled As Boolean -Property Bookmark As Boolean Property Comment As Boolean -Private Enum FLAG_MODIFIED, FLAG_SAVED, FLAG_ALTERNATE, FLAG_LIMIT, FLAG_BREAKPOINT, FLAG_DISABLED, FLAG_BOOKMARK, FLAG_COMMENT +Private Enum FLAG_MODIFIED, FLAG_SAVED, FLAG_ALTERNATE, FLAG_LIMIT, FLAG_COMMENT Public Colors As Byte[] Public Tag As Short @@ -95,30 +92,6 @@ Private Sub Limit_Write(Value As Boolean) End -Private Function Breakpoint_Read() As Boolean - - Return BTst($iFlag, FLAG_BREAKPOINT) - -End - -Private Sub Breakpoint_Write(Value As Boolean) - - SetFlag(FLAG_BREAKPOINT, Value) - -End - -Private Function Bookmark_Read() As Boolean - - Return BTst($iFlag, FLAG_BOOKMARK) - -End - -Private Sub Bookmark_Write(Value As Boolean) - - SetFlag(FLAG_BOOKMARK, Value) - -End - Private Function Comment_Read() As Boolean Return BTst($iFlag, FLAG_COMMENT) @@ -131,14 +104,3 @@ Private Sub Comment_Write(Value As Boolean) End -Private Function Disabled_Read() As Boolean - - Return BTst($iFlag, FLAG_DISABLED) - -End - -Private Sub Disabled_Write(Value As Boolean) - - SetFlag(FLAG_DISABLED, Value) - -End diff --git a/comp/src/gb.form.editor/.src/TextEditor.class b/comp/src/gb.form.editor/.src/TextEditor.class index a88e2928b..fd587d189 100644 --- a/comp/src/gb.form.editor/.src/TextEditor.class +++ b/comp/src/gb.form.editor/.src/TextEditor.class @@ -1014,48 +1014,29 @@ Private Sub DrawMargin(X As Integer, Y As Integer, Width As Integer, Height As I 'Paint.FillRect(X, Y, $MW, Height, $iBackground) - If $bShowModified Then - If hInfo.Modified Or If hInfo.Saved Then - If hInfo.Modified Then - iCol = Color.Merge($iBackground, Color.Red, 0.2) - Else If hInfo.Saved Then - iCol = Color.Merge($iBackground, Color.Green, 0.2) - Endif - Paint.FillRect(X + $MW - 5, Y, 4, Height, iCol) - Endif - Endif - - If YL < 0 Or If YL = Y Then - If $bShowLineNumber Then - If (Row + 1) Mod 10 = 0 Then - iCol = $iForeground - Else - iCol = $iLimitColor - Endif - Paint.Background = iCol - sStr = CStr(Row + 1 + $iLineNumberOffset) - Paint.DrawText(sStr, X, Y, $iWidthLineNumber - 4, H, Align.Right) - ' If Row = $Y Then - ' Paint.Background = Color.SetAlpha(iCol, 128) - ' Paint.DrawText(sStr, X + 1, Y, $iWidthLineNumber - 4, H, Align.Right) - ' Endif - Endif - Endif - - If YL >= 0 Then Paint.FillRect(X, YL, Width, 1, $iLimitColor) - If $bShowIcon Or If $bShowExpand Then - If hInfo.Breakpoint Or If hInfo.Bookmark Or If hInfo.Limit Then + If $hDoc.HasBreakpoint(Row) Or If $hDoc.HasBookmark(Row) Or If hInfo.Limit Then + + If $hDoc.HasBookmark(Row) Then + ' SS = S / 3 + ' Paint.MoveTo(0, SS) + ' Paint.RelLineTo(SS, SS) + ' Paint.RelLineTo(2 * SS, - SS * 2) + ' Paint.LineWidth = SS / 2 + ' Paint.Background = $hStyles[Highlight.Current].Color + ' Paint.Stroke + Paint.FillRect(X, Y, $MW, Height, $hStyles[Highlight.Selection].Color) + Endif Paint.Save Paint.Translate(X + $iPosIcon + H / 4, Y + H / 4) S = H / 2 Paint.LineWidth = S / 6 - If hInfo.Breakpoint Then + If $hDoc.HasBreakpoint(Row) Then Paint.Ellipse(0, 0, S, S) - If hInfo.Disabled Then + If $hDoc.IsBreakpointDisabled(Row) Then Paint.Background = Color.SetAlpha($hStyles[Highlight.Normal].Color, 228) Else Paint.Background = Color.SetAlpha($hStyles[Highlight.Breakpoint].Color, 128) @@ -1064,16 +1045,6 @@ Private Sub DrawMargin(X As Integer, Y As Integer, Width As Integer, Height As I Paint.Stroke Endif - If hInfo.Bookmark Then - SS = S / 3 - Paint.MoveTo(0, SS) - Paint.RelLineTo(SS, SS) - Paint.RelLineTo(2 * SS, - SS * 2) - Paint.LineWidth = SS / 2 - Paint.Background = $hStyles[Highlight.Current].Color - Paint.Stroke - Endif - If $bShowExpand Then If hInfo.Limit Then SS = S / 2 @@ -1097,6 +1068,36 @@ Private Sub DrawMargin(X As Integer, Y As Integer, Width As Integer, Height As I Endif + If $bShowModified Then + If hInfo.Modified Or If hInfo.Saved Then + If hInfo.Modified Then + iCol = Color.Merge($iBackground, Color.Red, 0.2) + Else If hInfo.Saved Then + iCol = Color.Merge($iBackground, Color.Green, 0.2) + Endif + Paint.FillRect(X + $MW - 5, Y, 4, Height, iCol) + Endif + Endif + + If YL >= 0 Then Paint.FillRect(X, YL, Width, 1, $iLimitColor) + + If YL < 0 Or If YL = Y Then + If $bShowLineNumber Then + If (Row + 1) Mod 10 = 0 Then + iCol = $iForeground + Else + iCol = $iLimitColor + Endif + Paint.Background = iCol + sStr = CStr(Row + 1 + $iLineNumberOffset) + Paint.DrawText(sStr, X, Y, $iWidthLineNumber - 4, H, Align.Right) + ' If Row = $Y Then + ' Paint.Background = Color.SetAlpha(iCol, 128) + ' Paint.DrawText(sStr, X + 1, Y, $iWidthLineNumber - 4, H, Align.Right) + ' Endif + Endif + Endif + End Fast Private Sub TextWidth(sText As String, iStart As Integer, iLength As Integer) As Integer diff --git a/comp/src/gb.form.editor/.src/_TextEditor_Line.class b/comp/src/gb.form.editor/.src/_TextEditor_Line.class index 6ffd29189..a7e228510 100644 --- a/comp/src/gb.form.editor/.src/_TextEditor_Line.class +++ b/comp/src/gb.form.editor/.src/_TextEditor_Line.class @@ -75,26 +75,26 @@ End Private Function Breakpoint_Read() As Boolean - Return GetDoc().Info(_Line).Breakpoint + Return GetDoc().HasBreakpoint(_Line) End Private Sub Breakpoint_Write(Value As Boolean) - GetDoc().SetInfo(_Line).Breakpoint = Value + GetDoc().SetBreakpoint(_Line, Value, GetDoc().IsBreakpointDisabled(_Line)) Refresh End Private Function Bookmark_Read() As Boolean - Return GetDoc().Info(_Line).Bookmark + Return GetDoc().HasBookmark(_Line) End Private Sub Bookmark_Write(Value As Boolean) - GetDoc().SetInfo(_Line).Bookmark = Value + GetDoc().SetBookmark(_Line, Value) Refresh End @@ -173,13 +173,13 @@ End Private Function Disabled_Read() As Boolean - Return GetDoc().Info(_Line).Disabled + Return GetDoc().IsBreakpointDisabled(_Line) End Private Sub Disabled_Write(Value As Boolean) - GetDoc().SetInfo(_Line).Disabled = Value + GetDoc().SetBreakpoint(_Line, GetDoc().HasBreakpoint(_Line), Value) Refresh End