|
| 1 | +unit DelphiAIDev.IDE.NTAEditViewNotifier; |
| 2 | + |
| 3 | +interface |
| 4 | + |
| 5 | +uses |
| 6 | + System.SysUtils, |
| 7 | + System.Classes, |
| 8 | + System.Generics.Collections, |
| 9 | + System.Types, |
| 10 | + System.SyncObjs, |
| 11 | + System.RegularExpressions, |
| 12 | + Vcl.Dialogs, |
| 13 | + Vcl.Graphics, |
| 14 | + Vcl.Imaging.pngimage, |
| 15 | + DelphiAIDev.Utils, |
| 16 | + DelphiAIDev.Utils.OTA, |
| 17 | + DelphiAIDev.Consts, |
| 18 | + DelphiAIDev.CodeCompletion.Vars, |
| 19 | + ToolsAPI; |
| 20 | + |
| 21 | +type |
| 22 | + TDelphiAIDevIDENTAEditViewNotifier = class(TInterfacedObject, IOTANotifier, INTAEditViewNotifier) |
| 23 | + protected |
| 24 | + FIOTAEditView: IOTAEditView; |
| 25 | + FIndex: Integer; |
| 26 | + procedure RemoveNotifier; |
| 27 | + public |
| 28 | + constructor Create(FileName: string; AEditView: IOTAEditView); |
| 29 | + destructor Destroy; override; |
| 30 | + |
| 31 | + { INTAEditViewNotifier } |
| 32 | + ///<summary>EditorIdle é chamado após alguma ação ter ocorrido na visualização |
| 33 | + ///(edição, movimento do cursor, etc.) e um período de tempo ter passado sem que outra |
| 34 | + ///ação acontecesse. Isso é aproximadamente equivalente ao momento em que o Code |
| 35 | + ///Insight é acionado (e está vinculado à configuração de atraso do Code Insight)</summary> |
| 36 | + procedure EditorIdle(const View: IOTAEditView); |
| 37 | + procedure BeginPaint(const View: IOTAEditView; var FullRepaint: Boolean); |
| 38 | + procedure PaintLine(const View: IOTAEditView; LineNumber: Integer; |
| 39 | + const LineText: PAnsiChar; const TextWidth: Word; const LineAttributes: TOTAAttributeArray; |
| 40 | + const Canvas: TCanvas; const TextRect: TRect; const LineRect: TRect; const CellSize: TSize); |
| 41 | + ///<summary>EndPaint é chamado depois que todas as linhas foram repintadas. |
| 42 | + ///Use isso para limpar quaisquer estruturas de dados que foram mantidas |
| 43 | + ///ao longo da pintura das linhas</summary> |
| 44 | + procedure EndPaint(const View: IOTAEditView); |
| 45 | + |
| 46 | + //IOTANotifier |
| 47 | + procedure AfterSave; |
| 48 | + procedure BeforeSave; |
| 49 | + procedure Modified; |
| 50 | + procedure Destroyed; |
| 51 | + end; |
| 52 | + |
| 53 | +implementation |
| 54 | + |
| 55 | +constructor TDelphiAIDevIDENTAEditViewNotifier.Create(FileName: string; AEditView: IOTAEditView); |
| 56 | +begin |
| 57 | + inherited Create; |
| 58 | + FIOTAEditView := AEditView; |
| 59 | + FIndex := FIOTAEditView.AddNotifier(Self); |
| 60 | +end; |
| 61 | + |
| 62 | +destructor TDelphiAIDevIDENTAEditViewNotifier.Destroy; |
| 63 | +begin |
| 64 | + RemoveNotifier; |
| 65 | + inherited; |
| 66 | +end; |
| 67 | + |
| 68 | +procedure TDelphiAIDevIDENTAEditViewNotifier.Destroyed; |
| 69 | +begin |
| 70 | + RemoveNotifier; |
| 71 | +end; |
| 72 | + |
| 73 | +procedure TDelphiAIDevIDENTAEditViewNotifier.AfterSave; |
| 74 | +begin |
| 75 | + |
| 76 | +end; |
| 77 | + |
| 78 | +procedure TDelphiAIDevIDENTAEditViewNotifier.BeforeSave; |
| 79 | +begin |
| 80 | + |
| 81 | +end; |
| 82 | + |
| 83 | +procedure TDelphiAIDevIDENTAEditViewNotifier.BeginPaint(const View: IOTAEditView; var FullRepaint: Boolean); |
| 84 | +begin |
| 85 | + FullRepaint := True; |
| 86 | +end; |
| 87 | + |
| 88 | +procedure TDelphiAIDevIDENTAEditViewNotifier.EditorIdle(const View: IOTAEditView); |
| 89 | +var |
| 90 | + LRow: Integer; |
| 91 | + LColumn: Integer; |
| 92 | +begin |
| 93 | + TUtilsOTA.GetCursorPosition(LRow, LColumn); |
| 94 | + |
| 95 | +// TUtils.AddLog(Format('EditorIdle - %d (%d) - %d (%d) - %s ', |
| 96 | +// [TDelphiAIDevCodeCompletionVars.GetInstance.Row, LRow, TDelphiAIDevCodeCompletionVars.GetInstance.Column, LColumn, DateTimeToStr(Now)])); |
| 97 | + |
| 98 | + if (LRow <> TDelphiAIDevCodeCompletionVars.GetInstance.Row) or (LColumn <> TDelphiAIDevCodeCompletionVars.GetInstance.Column) then |
| 99 | + begin |
| 100 | + TDelphiAIDevCodeCompletionVars.GetInstance.LineIni := 0; |
| 101 | + TDelphiAIDevCodeCompletionVars.GetInstance.Clear; |
| 102 | + end; |
| 103 | + |
| 104 | + //TUtils.AddLog('EditorIdle ' + BoolToStr(TDelphiAIDevCodeCompletionVars.GetInstance.ClearNext, True)); |
| 105 | + |
| 106 | +// if TDelphiAIDevCodeCompletionVars.GetInstance.ClearNext then |
| 107 | +// begin |
| 108 | +// TDelphiAIDevCodeCompletionVars.GetInstance.Clear; |
| 109 | +// end |
| 110 | +// else |
| 111 | +// TDelphiAIDevCodeCompletionVars.GetInstance.ClearNext := True; |
| 112 | + |
| 113 | + //View.AddNotifier() |
| 114 | + //View.GetEditWindow.Form.Repaint; |
| 115 | +end; |
| 116 | + |
| 117 | +procedure TDelphiAIDevIDENTAEditViewNotifier.EndPaint(const View: IOTAEditView); |
| 118 | +begin |
| 119 | + //TUtils.AddLog('EndPaint'); |
| 120 | +end; |
| 121 | + |
| 122 | +procedure TDelphiAIDevIDENTAEditViewNotifier.Modified; |
| 123 | +begin |
| 124 | + |
| 125 | +end; |
| 126 | + |
| 127 | + |
| 128 | +procedure TDelphiAIDevIDENTAEditViewNotifier.PaintLine(const View: IOTAEditView; LineNumber: Integer; |
| 129 | + const LineText: PAnsiChar; const TextWidth: Word; const LineAttributes: TOTAAttributeArray; |
| 130 | + const Canvas: TCanvas; const TextRect: TRect; const LineRect: TRect; const CellSize: TSize); |
| 131 | +var |
| 132 | + LLineText: string; |
| 133 | +begin |
| 134 | + if LineNumber < 1 then |
| 135 | + Exit; |
| 136 | + |
| 137 | + LLineText := string(LineText); |
| 138 | + |
| 139 | + if not LLineText.Trim.IsEmpty then |
| 140 | + Exit; |
| 141 | + |
| 142 | + //if LineNumber <> View.CursorPos.Line then |
| 143 | + // Exit; |
| 144 | + |
| 145 | + if (LineNumber >= TDelphiAIDevCodeCompletionVars.GetInstance.LineIni)and(LineNumber <= TDelphiAIDevCodeCompletionVars.GetInstance.LineEnd) then |
| 146 | + begin |
| 147 | + Canvas.Brush.Style := bsClear; |
| 148 | + Canvas.Font.Color := $777777; //$666666; |
| 149 | + |
| 150 | + try |
| 151 | + LLineText := TDelphiAIDevCodeCompletionVars.GetInstance.Contents[LineNumber - TDelphiAIDevCodeCompletionVars.GetInstance.LineIni]; |
| 152 | + Canvas.TextOut(TextRect.Left, TextRect.Top, LLineText.TrimRight); |
| 153 | + except on E: Exception do |
| 154 | + TUtils.AddLog(E.Message); |
| 155 | + end; |
| 156 | + end; |
| 157 | +end; |
| 158 | + |
| 159 | +procedure TDelphiAIDevIDENTAEditViewNotifier.RemoveNotifier; |
| 160 | +begin |
| 161 | + if Assigned(FIOTAEditView) and (FIndex >= 0) then |
| 162 | + begin |
| 163 | + FIOTAEditView.RemoveNotifier(FIndex); |
| 164 | + FIndex := -1; |
| 165 | + FIOTAEditView := nil; |
| 166 | + end; |
| 167 | +end; |
| 168 | + |
| 169 | +end. |
0 commit comments