• R/O
  • SSH
  • HTTPS

dzlargetextview: Commit


Commit MetaInfo

Revision274 (tree)
Time2018-05-10 19:39:50
Authordummzeuch

Log Message

(empty log message)

Change Summary

Incremental Difference

--- tags/1.0.2/src/dzLargeTextViewer_version.ini (nonexistent)
+++ tags/1.0.2/src/dzLargeTextViewer_version.ini (revision 274)
@@ -0,0 +1,21 @@
1+[Version Info]
2+AutoIncBuild=0
3+Build=219
4+MajorVer=1
5+MinorVer=0
6+Release=2
7+Revision=0
8+
9+[Version Info Keys]
10+FileVersion=1.0.2.219
11+ProductVersion={today}
12+FileDescription=Viewer for large text files
13+OriginalFilename=dzLargeTextViewer.exe
14+Comments=
15+CompanyName=dummzeuch.de
16+InternalName=dzLargeTextViewer
17+LegalCopyright=Thomas Mueller, 2013-{ThisYear}
18+LegalTrademarks=T. Mueller
19+ProductName=dzLargeTextViewer
20+BuildDateTime={today}
21+
--- tags/1.0.2/src/dzLargeTextViewer.dpr (nonexistent)
+++ tags/1.0.2/src/dzLargeTextViewer.dpr (revision 274)
@@ -0,0 +1,22 @@
1+program dzLargeTextViewer;
2+
3+uses
4+ Forms,
5+ w_LargeTextViewer in 'w_LargeTextViewer.pas' {f_LargeTextViewer},
6+ u_TextFileIndexer in 'u_TextFileIndexer.pas',
7+ w_GotoLine in 'w_GotoLine.pas' {f_GotoLine},
8+ w_BMSearchTest in 'w_BMSearchTest.pas' {f_BMSearchTest},
9+ JclUnicode in '..\libs\jcl\source\common\JclUnicode.pas',
10+ u_LargeTextAccess in 'u_LargeTextAccess.pas',
11+ u_Int64ListFile in 'u_Int64ListFile.pas',
12+ w_Search in 'w_Search.pas' {f_Search};
13+
14+{$R *_version.res}
15+{$R *_icon.res}
16+
17+begin
18+ Application.Initialize;
19+ Application.MainFormOnTaskbar := True;
20+ Application.CreateForm(Tf_LargeTextViewer, f_LargeTextViewer);
21+ Application.Run;
22+end.
--- tags/1.0.2/src/dzLargeTextViewer.dproj (nonexistent)
+++ tags/1.0.2/src/dzLargeTextViewer.dproj (revision 274)
@@ -0,0 +1,304 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+ <PropertyGroup>
4+ <ProjectGuid>{b6113310-a312-491b-823e-3a1e137966ec}</ProjectGuid>
5+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+ <DCC_DCCCompiler>DCC32</DCC_DCCCompiler>
8+ <DCC_DependencyCheckOutputName>..\dzLargeTextViewer.exe</DCC_DependencyCheckOutputName>
9+ <MainSource>dzLargeTextViewer.dpr</MainSource>
10+ </PropertyGroup>
11+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
12+ <Version>7.0</Version>
13+ <DCC_DebugInformation>False</DCC_DebugInformation>
14+ <DCC_LocalDebugSymbols>False</DCC_LocalDebugSymbols>
15+ <DCC_SymbolReferenceInfo>0</DCC_SymbolReferenceInfo>
16+ <DCC_Define>RELEASE</DCC_Define>
17+ </PropertyGroup>
18+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
19+ <Version>7.0</Version>
20+ <DCC_Optimize>False</DCC_Optimize>
21+ <DCC_ExeOutput>..</DCC_ExeOutput>
22+ <DCC_DcuOutput>..\dcu</DCC_DcuOutput>
23+ <DCC_ObjOutput>..\dcu</DCC_ObjOutput>
24+ <DCC_HppOutput>..\dcu</DCC_HppOutput>
25+ <DCC_UnitSearchPath>$(BDS)\lib\Debug;..\libs\dzlib\src;..\libs\dzlib\components;..\libs\dzlib\jedi_inc;..\libs\dzlib\templates;..\libs\jcl\source\common;..\libs\jcl\source\include;..\libs\jcl\source\include\jedi;..\libs\jcl\source\windows</DCC_UnitSearchPath>
26+ <DCC_ResourcePath>$(BDS)\lib\Debug;..\libs\dzlib\src;..\libs\dzlib\components;..\libs\dzlib\jedi_inc;..\libs\dzlib\templates;..\libs\jcl\source\common;..\libs\jcl\source\include;..\libs\jcl\source\include\jedi;..\libs\jcl\source\windows</DCC_ResourcePath>
27+ <DCC_ObjPath>$(BDS)\lib\Debug;..\libs\dzlib\src;..\libs\dzlib\components;..\libs\dzlib\jedi_inc;..\libs\dzlib\templates;..\libs\jcl\source\common;..\libs\jcl\source\include;..\libs\jcl\source\include\jedi;..\libs\jcl\source\windows</DCC_ObjPath>
28+ <DCC_IncludePath>$(BDS)\lib\Debug;..\libs\dzlib\src;..\libs\dzlib\components;..\libs\dzlib\jedi_inc;..\libs\dzlib\templates;..\libs\jcl\source\common;..\libs\jcl\source\include;..\libs\jcl\source\include\jedi;..\libs\jcl\source\windows</DCC_IncludePath>
29+ <DCC_Define>DEBUG;NO_TRANSLATION;no_jvcl</DCC_Define>
30+ <DCC_SYMBOL_PLATFORM>False</DCC_SYMBOL_PLATFORM>
31+ <DCC_UNIT_PLATFORM>False</DCC_UNIT_PLATFORM>
32+ </PropertyGroup>
33+ <ProjectExtensions>
34+ <Borland.Personality>Delphi.Personality</Borland.Personality>
35+ <Borland.ProjectType />
36+ <BorlandProject>
37+<BorlandProject><Delphi.Personality><Parameters><Parameters Name="UseLauncher">False</Parameters><Parameters Name="LoadAllSymbols">True</Parameters><Parameters Name="LoadUnspecifiedSymbols">False</Parameters></Parameters><VersionInfo><VersionInfo Name="IncludeVerInfo">False</VersionInfo><VersionInfo Name="AutoIncBuild">False</VersionInfo><VersionInfo Name="MajorVer">1</VersionInfo><VersionInfo Name="MinorVer">0</VersionInfo><VersionInfo Name="Release">0</VersionInfo><VersionInfo Name="Build">0</VersionInfo><VersionInfo Name="Debug">False</VersionInfo><VersionInfo Name="PreRelease">False</VersionInfo><VersionInfo Name="Special">False</VersionInfo><VersionInfo Name="Private">False</VersionInfo><VersionInfo Name="DLL">False</VersionInfo><VersionInfo Name="Locale">2057</VersionInfo><VersionInfo Name="CodePage">1252</VersionInfo></VersionInfo><VersionInfoKeys><VersionInfoKeys Name="CompanyName"></VersionInfoKeys><VersionInfoKeys Name="FileDescription"></VersionInfoKeys><VersionInfoKeys Name="FileVersion">1.0.0.0</VersionInfoKeys><VersionInfoKeys Name="InternalName"></VersionInfoKeys><VersionInfoKeys Name="LegalCopyright"></VersionInfoKeys><VersionInfoKeys Name="LegalTrademarks"></VersionInfoKeys><VersionInfoKeys Name="OriginalFilename"></VersionInfoKeys><VersionInfoKeys Name="ProductName"></VersionInfoKeys><VersionInfoKeys Name="ProductVersion">1.0.0.0</VersionInfoKeys><VersionInfoKeys Name="Comments"></VersionInfoKeys></VersionInfoKeys><Excluded_Packages>
38+
39+
40+
41+
42+
43+
44+
45+
46+
47+
48+
49+
50+
51+
52+
53+
54+
55+
56+
57+
58+
59+
60+
61+
62+
63+
64+
65+
66+
67+
68+
69+
70+
71+
72+
73+
74+
75+
76+
77+
78+
79+
80+
81+
82+
83+
84+
85+
86+
87+
88+
89+
90+
91+
92+
93+
94+
95+
96+
97+
98+
99+
100+
101+
102+
103+
104+
105+
106+
107+
108+
109+
110+
111+
112+
113+
114+
115+
116+
117+
118+
119+
120+
121+
122+
123+
124+
125+
126+
127+
128+
129+
130+
131+
132+
133+
134+
135+
136+
137+
138+
139+
140+
141+
142+
143+
144+
145+
146+
147+
148+
149+
150+
151+
152+
153+
154+
155+
156+
157+
158+
159+
160+
161+
162+
163+
164+
165+
166+
167+
168+
169+
170+
171+
172+
173+
174+
175+
176+
177+
178+
179+
180+
181+
182+
183+
184+
185+
186+
187+
188+
189+
190+
191+
192+
193+
194+
195+
196+
197+
198+
199+
200+
201+
202+
203+
204+
205+
206+
207+
208+
209+
210+
211+
212+
213+
214+
215+
216+
217+
218+
219+
220+
221+
222+
223+
224+
225+
226+
227+
228+
229+
230+
231+
232+
233+
234+
235+
236+
237+
238+
239+
240+
241+
242+
243+
244+
245+
246+
247+
248+
249+
250+
251+
252+
253+
254+
255+
256+
257+
258+
259+ <Excluded_Packages Name="$(BDS)\bin\dcloffice2k100.bpl">Microsoft Office 2000 Sample Automation Server Wrapper Components</Excluded_Packages>
260+ <Excluded_Packages Name="$(BDS)\bin\dclofficexp100.bpl">Microsoft Office XP Sample Automation Server Wrapper Components</Excluded_Packages>
261+ <Excluded_Packages Name="$(BDS)\bin\bcbie100.bpl">File c:\program files (x86)\codegear\rad studio\5.0\bin\bcbie100.bpl not found</Excluded_Packages>
262+ <Excluded_Packages Name="$(BDS)\bin\dclbcbsmp100.bpl">File c:\program files (x86)\codegear\rad studio\5.0\bin\dclbcbsmp100.bpl not found</Excluded_Packages>
263+ <Excluded_Packages Name="$(BDS)\Bin\dclib100.bpl">File c:\program files (x86)\codegear\rad studio\5.0\Bin\dclib100.bpl not found</Excluded_Packages>
264+ <Excluded_Packages Name="$(BDS)\bin\dcldbx4100.bpl">File c:\program files (x86)\codegear\rad studio\5.0\bin\dcldbx4100.bpl not found</Excluded_Packages>
265+ <Excluded_Packages Name="$(BDS)\bin\dcldbxcds4100.bpl">File c:\program files (x86)\codegear\rad studio\5.0\bin\dcldbxcds4100.bpl not found</Excluded_Packages>
266+ <Excluded_Packages Name="C:\Users\Public\Documents\RAD Studio\5.0\Bpl\dclfsIBX11.bpl">FastScript 1.9 IBX Components</Excluded_Packages>
267+ <Excluded_Packages Name="C:\Users\Public\Documents\RAD Studio\5.0\Bpl\JclDebugExpert110.bpl">JCL Debug IDE extension</Excluded_Packages>
268+ <Excluded_Packages Name="C:\Users\Public\Documents\RAD Studio\5.0\Bpl\JclBaseExpert110.bpl">JCL Package containing common units for JCL Experts</Excluded_Packages>
269+ <Excluded_Packages Name="C:\Users\Public\Documents\RAD Studio\5.0\Bpl\JclFavoriteFoldersExpert110.bpl">JCL Open and Save IDE dialogs with favorite folders</Excluded_Packages>
270+ <Excluded_Packages Name="C:\Users\Public\Documents\RAD Studio\5.0\Bpl\JclProjectAnalysisExpert110.bpl">JCL Project Analyzer</Excluded_Packages>
271+ <Excluded_Packages Name="C:\Users\Public\Documents\RAD Studio\5.0\Bpl\JclStackTraceViewerExpert110.bpl">JCL Stack Trace Viewer</Excluded_Packages>
272+ <Excluded_Packages Name="C:\Users\Public\Documents\RAD Studio\5.0\Bpl\DclArgVideoComponents100.bpl">Schniering ArgVideo components</Excluded_Packages>
273+ <Excluded_Packages Name="C:\Users\Public\Documents\RAD Studio\5.0\Bpl\dclfsTee11.bpl">FastScript 1.9 Tee Components</Excluded_Packages>
274+ <Excluded_Packages Name="$(BDS)\bin\bcboffice2k100.bpl">File c:\program files (x86)\codegear\rad studio\5.0\bin\bcboffice2k100.bpl not found</Excluded_Packages>
275+ <Excluded_Packages Name="$(BDS)\bin\bcbofficexp100.bpl">File c:\program files (x86)\codegear\rad studio\5.0\bin\bcbofficexp100.bpl not found</Excluded_Packages>
276+ </Excluded_Packages><Source><Source Name="MainSource">dzLargeTextViewer.dpr</Source></Source></Delphi.Personality></BorlandProject></BorlandProject>
277+ </ProjectExtensions>
278+ <Import Project="$(MSBuildBinPath)\Borland.Delphi.Targets" />
279+ <PropertyGroup>
280+ <PreBuildEvent>..\buildtools\prebuild.cmd $(PROJECTPATH)</PreBuildEvent>
281+ <PostBuildEvent>..\buildtools\postbuild.cmd $(OUTPUTDIR)$(OUTPUTNAME)</PostBuildEvent>
282+ </PropertyGroup>
283+ <ItemGroup>
284+ <DelphiCompile Include="dzLargeTextViewer.dpr">
285+ <MainSource>MainSource</MainSource>
286+ </DelphiCompile>
287+ <DCCReference Include="..\libs\jcl\source\common\JclUnicode.pas" />
288+ <DCCReference Include="u_Int64ListFile.pas" />
289+ <DCCReference Include="u_LargeTextAccess.pas" />
290+ <DCCReference Include="u_TextFileIndexer.pas" />
291+ <DCCReference Include="w_BMSearchTest.pas">
292+ <Form>f_BMSearchTest</Form>
293+ </DCCReference>
294+ <DCCReference Include="w_GotoLine.pas">
295+ <Form>f_GotoLine</Form>
296+ </DCCReference>
297+ <DCCReference Include="w_LargeTextViewer.pas">
298+ <Form>f_LargeTextViewer</Form>
299+ </DCCReference>
300+ <DCCReference Include="w_Search.pas">
301+ <Form>f_Search</Form>
302+ </DCCReference>
303+ </ItemGroup>
304+</Project>
\ No newline at end of file
--- tags/1.0.2/src/w_BMSearchTest.pas (nonexistent)
+++ tags/1.0.2/src/w_BMSearchTest.pas (revision 274)
@@ -0,0 +1,214 @@
1+unit w_BMSearchTest;
2+
3+interface
4+
5+uses
6+ Windows,
7+ Messages,
8+ SysUtils,
9+ Variants,
10+ Classes,
11+ Graphics,
12+ Controls,
13+ Forms,
14+ StdCtrls,
15+ u_dzTranslator;
16+
17+type
18+ TOnSearchEvent = procedure(_Sender: TObject; const _Pattern: string) of object;
19+
20+type
21+ Tf_BMSearchTest = class(TForm)
22+ ed_Pattern: TEdit;
23+ l_Pattern: TLabel;
24+ m_Text: TMemo;
25+ b_Find: TButton;
26+ procedure b_FindClick(Sender: TObject);
27+ private
28+ FCallback: TOnSearchEvent;
29+ procedure SetData(const _Pattern: string; _Callback: TOnSearchEvent);
30+ public
31+ class procedure Execute(_Owner: TWinControl; const _Pattern: string; _Callback: TOnSearchEvent); static;
32+ constructor Create(_Owner: TComponent); override;
33+ end;
34+
35+implementation
36+
37+{$R *.dfm}
38+
39+uses
40+ StrUtils,
41+ u_dzVclUtils;
42+
43+type
44+ ITextBuffer = interface ['{8B4A019A-99CA-4E86-864D-D1E9E6020648}']
45+ function GetChar(_Idx: Int64): Char;
46+ function GetString(_Idx: Int64; _Len: integer): string;
47+ function GetLength: Int64;
48+ end;
49+
50+//type
51+// TTextBuffer = class
52+// private
53+// function GetChar(_Idx: Int64): char;
54+// function GetLength: Int64;
55+// public
56+// constructor Create(const _fn: string);
57+// destructor Destroy;
58+// end;
59+
60+type
61+ TStringBuffer = class(TInterfacedObject, ITextBuffer)
62+ private
63+ FText: string;
64+ function GetChar(_Idx: Int64): Char;
65+ function GetString(_Idx: Int64; _Len: integer): string;
66+ function GetLength: Int64;
67+ public
68+ constructor Create(const _Text: string);
69+ end;
70+
71+{ TStringBuffer }
72+
73+constructor TStringBuffer.Create(const _Text: string);
74+begin
75+ inherited Create;
76+ FText := _Text;
77+end;
78+
79+function TStringBuffer.GetChar(_Idx: Int64): Char;
80+begin
81+ Result := FText[_Idx];
82+end;
83+
84+function TStringBuffer.GetLength: Int64;
85+begin
86+ Result := Length(FText);
87+end;
88+
89+function TStringBuffer.GetString(_Idx: Int64; _Len: integer): string;
90+begin
91+ Result := Copy(FText, _Idx, _Len);
92+end;
93+
94+type
95+ TBMSearch = class
96+ private
97+ FSkip: array of integer;
98+ FPatternLen: integer;
99+ FPattern: string;
100+ public
101+ constructor Create(const _Pattern: string);
102+ function Find(_Text: ITextBuffer; var _Offset: Int64): Boolean;
103+ end;
104+
105+{ TBMSearch }
106+
107+constructor TBMSearch.Create(const _Pattern: string);
108+var
109+ i: integer;
110+begin
111+ FPattern := _Pattern;
112+ FPatternLen := Length(_Pattern);
113+ if FPatternLen = 0 then
114+ Exit;
115+
116+ SetLength(FSkip, integer(High(Char)) + 1);
117+ for i := Low(FSkip) to High(FSkip) do
118+ FSkip[i] := FPatternLen;
119+ for i := 1 to FPatternLen - 1 do
120+ FSkip[integer(_Pattern[i])] := FPatternLen - i;
121+end;
122+
123+function TBMSearch.Find(_Text: ITextBuffer; var _Offset: Int64): Boolean;
124+var
125+ i: Int64;
126+ TextLen: Int64;
127+ TextIdx: Int64;
128+ PatternIdx: integer;
129+ s: string;
130+begin
131+ Result := False;
132+ if FPatternLen = 0 then
133+ Exit;
134+
135+ i := FPatternLen + (_Offset);
136+ TextLen := _Text.GetLength;
137+ while (not Result) and (i <= TextLen) do begin
138+ TextIdx := i;
139+ PatternIdx := FPatternLen;
140+ while (PatternIdx >= 1) do begin
141+ if _Text.GetChar(TextIdx) = FPattern[PatternIdx] then begin
142+ PatternIdx := PatternIdx - 1;
143+ TextIdx := TextIdx - 1;
144+ end else
145+ PatternIdx := -1;
146+ if PatternIdx = 0 then begin
147+ _Offset := TextIdx;
148+ s := _Text.GetString(_Offset, FPatternLen);
149+ Result := True;
150+ Exit;
151+ end;
152+ i := i + FSkip[integer(_Text.GetChar(i))];
153+ end;
154+ end;
155+end;
156+
157+var
158+ frm: Tf_BMSearchTest;
159+
160+{ Tf_BMSearchTest }
161+
162+class procedure Tf_BMSearchTest.Execute(_Owner: TWinControl; const _Pattern: string;
163+ _Callback: TOnSearchEvent);
164+begin
165+ if not Assigned(frm) then begin
166+ frm := Tf_BMSearchTest.Create(_Owner);
167+ TForm_CenterOn(frm, _Owner);
168+ end;
169+ frm.SetData(_Pattern, _Callback);
170+ frm.Show;
171+end;
172+
173+constructor Tf_BMSearchTest.Create(_Owner: TComponent);
174+begin
175+ inherited;
176+
177+ TranslateComponent(Self);
178+
179+ m_Text.SelStart := 0;
180+ m_Text.SelLength := 0;
181+end;
182+
183+procedure Tf_BMSearchTest.SetData(const _Pattern: string; _Callback: TOnSearchEvent);
184+begin
185+ ed_Pattern.Text := _Pattern;
186+ FCallback := _Callback;
187+end;
188+
189+procedure Tf_BMSearchTest.b_FindClick(Sender: TObject);
190+var
191+ Pattern: string;
192+ Search: TBMSearch;
193+ Offset: Int64;
194+ Text: ITextBuffer;
195+begin
196+ Pattern := ed_Pattern.Text;
197+ Search := TBMSearch.Create(Pattern);
198+ try
199+ Offset := m_Text.SelStart + m_Text.SelLength + 1;
200+ Text := TStringBuffer.Create(m_Text.Lines.Text);
201+ if Search.Find(Text, Offset) then begin
202+ m_Text.SelStart := Offset;
203+ m_Text.SelLength := Length(Pattern);
204+ end;
205+ finally
206+ FreeAndNil(Search);
207+ end;
208+ m_Text.SetFocus;
209+ Exit;
210+
211+ FCallback(Self, ed_Pattern.Text);
212+end;
213+
214+end.
--- tags/1.0.2/src/w_LargeTextViewer.pas (nonexistent)
+++ tags/1.0.2/src/w_LargeTextViewer.pas (revision 274)
@@ -0,0 +1,254 @@
1+unit w_LargeTextViewer;
2+
3+interface
4+
5+uses
6+ Windows,
7+ Messages,
8+ SysUtils,
9+ Variants,
10+ Classes,
11+ Graphics,
12+ Controls,
13+ Forms,
14+ Dialogs,
15+ Grids,
16+ ExtCtrls,
17+ ComCtrls,
18+ Menus,
19+ ActnList,
20+ c_dzVirtualStringGrid,
21+ u_dzTranslator,
22+ u_TextFileIndexer,
23+ u_dzNamedThread,
24+ u_dzFileStreams;
25+
26+type
27+ TIndexerThread = class(TNamedThread)
28+ private
29+ FIndexer: TTextFileIndexer;
30+ protected
31+ constructor Create(_Indexer: TTextFileIndexer);
32+ procedure Execute; override;
33+ end;
34+
35+type
36+ Tf_LargeTextViewer = class(TForm)
37+ sg_Display: TdzVirtualStringGrid;
38+ tim_Update: TTimer;
39+ TheStatusBar: TStatusBar;
40+ TheMainMenu: TMainMenu;
41+ mi_File: TMenuItem;
42+ mi_Open: TMenuItem;
43+ mi_Exit: TMenuItem;
44+ TheOpenDialog: TOpenDialog;
45+ pm_Grid: TPopupMenu;
46+ mi_Copy: TMenuItem;
47+ TheActionList: TActionList;
48+ act_LineCopy: TAction;
49+ act_FileOpen: TAction;
50+ act_FileExit: TAction;
51+ Line1: TMenuItem;
52+ mi_LineCopy: TMenuItem;
53+ act_LineGoto: TAction;
54+ mi_LineGoto: TMenuItem;
55+ act_LineFind: TAction;
56+ mi_LineFind: TMenuItem;
57+ procedure sg_DisplayGetNonfixedCellData(_Sender: TObject; _DataCol, _DataRow: Integer;
58+ _State: TGridDrawState; var _Text: string; var _HAlign: TAlignment;
59+ var _VAlign: TdzCellVertAlign; _Font: TFont; var _Color: TColor);
60+ procedure sg_DisplayResize(Sender: TObject);
61+ procedure tim_UpdateTimer(Sender: TObject);
62+ procedure act_FileOpenExecute(Sender: TObject);
63+ procedure act_FileExitExecute(Sender: TObject);
64+ procedure sg_DisplayGetRowHead(_Sender: TObject; _Row: Integer; _State: TGridDrawState;
65+ var _Text: string; var _HAlign: TAlignment; var _VAlign: TdzCellVertAlign; _Font: TFont;
66+ var _Color: TColor);
67+ procedure act_LineCopyExecute(Sender: TObject);
68+ procedure sg_DisplaySelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean);
69+ procedure act_LineGotoExecute(Sender: TObject);
70+ procedure act_LineFindExecute(Sender: TObject);
71+ private
72+ FIndexer: TTextFileIndexer;
73+ FIndexThread: TIndexerThread;
74+ FFile: TdzFile;
75+ procedure OpenFile;
76+ procedure UpdateCurrentLineNo;
77+ procedure OnFind(_Sender: TObject; const _Pattern: string);
78+ public
79+ constructor Create(_Owner: TComponent); override;
80+ destructor Destroy; override;
81+ procedure LoadFile(const _Filename: string);
82+ end;
83+
84+var
85+ f_LargeTextViewer: Tf_LargeTextViewer;
86+
87+implementation
88+
89+{$R *.dfm}
90+
91+uses
92+ ClipBrd,
93+ u_dzClassUtils,
94+ w_GotoLine,
95+ w_BMSearchTest;
96+
97+{ TIndexerThread }
98+
99+constructor TIndexerThread.Create(_Indexer: TTextFileIndexer);
100+begin
101+ FIndexer := _Indexer;
102+ inherited Create(False);
103+end;
104+
105+procedure TIndexerThread.Execute;
106+begin
107+ inherited;
108+ try
109+ FIndexer.Execute;
110+ except
111+ on EAbort do
112+ // ignore;
113+ else
114+ raise;
115+ end;
116+end;
117+
118+constructor Tf_LargeTextViewer.Create(_Owner: TComponent);
119+begin
120+ inherited;
121+ OpenFile;
122+end;
123+
124+destructor Tf_LargeTextViewer.Destroy;
125+begin
126+ FreeAndNil(FFile);
127+ if Assigned(FIndexer) then
128+ FIndexer.Abort;
129+ FreeAndNil(FIndexThread);
130+ FreeAndNil(FIndexer);
131+ inherited;
132+end;
133+
134+procedure Tf_LargeTextViewer.LoadFile(const _Filename: string);
135+begin
136+ FIndexer := TTextFileIndexer.Create(_Filename);
137+ FIndexThread := TIndexerThread.Create(FIndexer);
138+ // the indexer now runs in the background
139+ tim_Update.Enabled := True;
140+ // open the file a second time, so it can be used in sg_DisplayGetNonfixedCellData
141+ FFile := TdzFile.Create(_Filename);
142+ FFile.OpenReadonly;
143+ UpdateCurrentLineNo;
144+end;
145+
146+procedure Tf_LargeTextViewer.UpdateCurrentLineNo;
147+begin
148+ TheStatusBar.Panels[1].Text := Format(_('Current line: %s'), [FormatFloat('#,###,###,###,###,##0', sg_Display.Row + sg_Display.FixedRows + 1)]);
149+end;
150+
151+procedure Tf_LargeTextViewer.act_LineCopyExecute(Sender: TObject);
152+var
153+ i: Integer;
154+ sl: TStringList;
155+begin
156+ sl := TStringList.Create;
157+ try
158+ for i := sg_Display.Selection.Top to sg_Display.Selection.Bottom do begin
159+ sl.Add(sg_Display.GetCellText(sg_Display.FixedCols, i));
160+ end;
161+ Clipboard.AsText := sl.Text;
162+ finally
163+ FreeAndNil(sl);
164+ end;
165+end;
166+
167+procedure Tf_LargeTextViewer.act_LineFindExecute(Sender: TObject);
168+begin
169+ Tf_BMSearchTest.Execute(Self, 'while', OnFind);
170+end;
171+
172+procedure Tf_LargeTextViewer.OnFind(_Sender: TObject; const _Pattern: string);
173+begin
174+//
175+end;
176+
177+procedure Tf_LargeTextViewer.act_LineGotoExecute(Sender: TObject);
178+var
179+ LineNo: Integer;
180+begin
181+ LineNo := sg_Display.Row + sg_Display.FixedRows + 1;
182+ if not Tf_GotoLine.Execute(Self, FIndexer.LineIndexCount, LineNo) then
183+ Exit;
184+ sg_Display.Row := sg_Display.FixedRows + LineNo - 1;
185+ UpdateCurrentLineNo;
186+end;
187+
188+procedure Tf_LargeTextViewer.act_FileExitExecute(Sender: TObject);
189+begin
190+ Close;
191+end;
192+
193+procedure Tf_LargeTextViewer.OpenFile;
194+begin
195+ TheOpenDialog.Filter := 'all files (*.*)|*.*';
196+ if not TheOpenDialog.Execute then
197+ Exit;
198+ LoadFile(TheOpenDialog.Filename);
199+end;
200+
201+procedure Tf_LargeTextViewer.act_FileOpenExecute(Sender: TObject);
202+begin
203+ OpenFile;
204+end;
205+
206+procedure Tf_LargeTextViewer.sg_DisplayGetNonfixedCellData(_Sender: TObject; _DataCol, _DataRow: Integer;
207+ _State: TGridDrawState; var _Text: string; var _HAlign: TAlignment; var _VAlign: TdzCellVertAlign;
208+ _Font: TFont; var _Color: TColor);
209+var
210+ SeekIdx: Int64;
211+ s: string;
212+begin
213+ if not Assigned(FIndexer) or (FIndexer.LineIndexCount <= _DataRow) then
214+ Exit;
215+ SeekIdx := FIndexer.LineIndex[_DataRow];
216+ FFile.Position := SeekIdx;
217+ TStream_ReadStringLn(FFile, s);
218+ _Text := s;
219+end;
220+
221+procedure Tf_LargeTextViewer.sg_DisplayGetRowHead(_Sender: TObject; _Row: Integer;
222+ _State: TGridDrawState; var _Text: string; var _HAlign: TAlignment; var _VAlign: TdzCellVertAlign;
223+ _Font: TFont; var _Color: TColor);
224+begin
225+ _Text := FormatFloat('#,###,###,###,###,##0', _Row - (_Sender as TdzVirtualStringGrid).FixedRows + 1);
226+ _HAlign := taRightJustify;
227+end;
228+
229+procedure Tf_LargeTextViewer.sg_DisplayResize(Sender: TObject);
230+begin
231+ sg_Display.ColWidths[1] := sg_Display.ClientWidth - sg_Display.ColWidths[0];
232+end;
233+
234+procedure Tf_LargeTextViewer.sg_DisplaySelectCell(Sender: TObject; ACol, ARow: Integer;
235+ var CanSelect: Boolean);
236+begin
237+ UpdateCurrentLineNo;
238+end;
239+
240+procedure Tf_LargeTextViewer.tim_UpdateTimer(Sender: TObject);
241+var
242+ LineCount: Integer;
243+begin
244+ LineCount := FIndexer.LineIndexCount;
245+ sg_Display.RowCount := LineCount;
246+ if FIndexer.isDone then begin
247+ tim_Update.Enabled := False;
248+ TheStatusBar.Panels[0].Text := Format(_('Total lines: %s'), [FormatFloat('#,###,###,###,###,##0', LineCount)]);
249+ end else
250+ TheStatusBar.Panels[0].Text := Format(_('Indexing (%s lines)'), [FormatFloat('#,###,###,###,###,##0', LineCount)]);
251+end;
252+
253+end.
254+
--- tags/1.0.2/src/u_TextFileIndexer.pas (nonexistent)
+++ tags/1.0.2/src/u_TextFileIndexer.pas (revision 274)
@@ -0,0 +1,145 @@
1+unit u_TextFileIndexer;
2+
3+interface
4+
5+uses
6+ SysUtils,
7+ Classes,
8+ u_Int64ListFile,
9+ u_dzCriticalSection,
10+ u_LargeTextAccess;
11+
12+type
13+ TTextFileIndexer = class
14+ private
15+ type
16+ TLineIndexes = class(TInt64ListFile)
17+ private
18+ procedure InitCount;
19+ end;
20+ private
21+ FCritSect: TdzCriticalSection;
22+ FLineIndexes: TLineIndexes;
23+ FIsDone: boolean;
24+ FFilename: string;
25+ FAbortRequested: boolean;
26+ function GetLineIndex(_Idx: integer): Int64;
27+ function GetLineIndexCount: integer;
28+ public
29+ constructor Create(const _Filename: string);
30+ destructor Destroy; override;
31+ procedure Execute;
32+ procedure Abort;
33+ property LineIndex[_Idx: integer]: Int64 read GetLineIndex;
34+ property LineIndexCount: integer read GetLineIndexCount;
35+ property isDone: boolean read FIsDone;
36+ end;
37+
38+implementation
39+
40+uses
41+ u_dzConvertUtils,
42+ u_dzFileStreams;
43+
44+{ TTextFileIndexer }
45+
46+constructor TTextFileIndexer.Create(const _Filename: string);
47+begin
48+ inherited Create;
49+ FFilename := _Filename;
50+ FLineIndexes := TLineIndexes.Create(FFilename + '.LineIndex');
51+ FLineIndexes.InitCount;
52+ FCritSect := TdzCriticalSection.Create;
53+end;
54+
55+destructor TTextFileIndexer.Destroy;
56+begin
57+ FreeAndNil(FCritSect);
58+ FreeAndNil(FLineIndexes);
59+ inherited;
60+end;
61+
62+procedure TTextFileIndexer.Execute;
63+
64+ procedure AddIdx(_Idx: Int64);
65+ begin
66+ FCritSect.Enter;
67+ try
68+ FLineIndexes.Add(_Idx);
69+ finally
70+ FCritSect.Leave;
71+ end;
72+ end;
73+
74+var
75+ i: Int64;
76+ lta: TLargeTextAccess;
77+begin
78+ FAbortRequested := False;
79+ if FLineIndexes.Count > 0 then begin
80+ FIsDone := True;
81+ Exit;
82+ end;
83+ FIsDone := False;
84+ lta := TLargeTextAccess.Create(FFilename, ofForward);
85+ try
86+ AddIdx(0);
87+ i := 0;
88+ while i < lta.GetLength do begin
89+ if lta.GetChar(i) = #10 then begin
90+ AddIdx(i + 1);
91+ end;
92+ Inc(i);
93+ if FAbortRequested then
94+ SysUtils.Abort;
95+ end;
96+ finally
97+ FreeAndNil(lta);
98+ end;
99+ FIsDone := True;
100+end;
101+
102+function TTextFileIndexer.GetLineIndex(_Idx: integer): Int64;
103+begin
104+ FCritSect.Enter;
105+ try
106+ Result := FLineIndexes.Items[_Idx];
107+ finally
108+ FCritSect.Leave;
109+ end;
110+end;
111+
112+function TTextFileIndexer.GetLineIndexCount: integer;
113+begin
114+ FCritSect.Enter;
115+ try
116+ Result := FLineIndexes.Count;
117+ finally
118+ FCritSect.Leave;
119+ end;
120+end;
121+
122+procedure TTextFileIndexer.Abort;
123+begin
124+ FAbortRequested := True;
125+end;
126+
127+{ TTextFileIndexer.TLineIndexes }
128+
129+procedure TTextFileIndexer.TLineIndexes.InitCount;
130+var
131+ Size: Int64;
132+ Idx: Int64;
133+begin
134+ Size := FTempFile.Size;
135+ if (FCount = 0) and (Size > 0) and (Size mod SizeOf(FBuffer) = 0) then begin
136+ FCount := Size div SizeOf(FCount);
137+ Idx := FCount - 1;
138+ while Items[Idx] = 0 do begin
139+ Dec(Idx);
140+ end;
141+ FCount := Idx + 1;
142+ end;
143+end;
144+
145+end.
--- tags/1.0.2/src/u_Int64ListFile.pas (nonexistent)
+++ tags/1.0.2/src/u_Int64ListFile.pas (revision 274)
@@ -0,0 +1,140 @@
1+unit u_Int64ListFile;
2+
3+interface
4+
5+uses
6+ Windows,
7+ SysUtils,
8+ Classes,
9+ u_dzTranslator,
10+ u_dzFileStreams,
11+ u_dzFileUtils;
12+
13+type
14+ ///<summary>
15+ /// A list of Int64 items backed by a file. It can grow beyond memory size
16+ /// theoretically up to MaxInt64/SizeOf(Int64) items
17+ /// (tested up to 790 million entries). </summary>
18+ TInt64ListFile = class
19+ protected
20+ FTempDir: IUniqueTempDir;
21+ FBuffer: array[0..1023] of Int64;
22+ FOffset: Int64;
23+ FCount: Int64;
24+ FTempFile: TdzFile;
25+ function GetItems(_Idx: Int64): Int64;
26+ procedure SetItems(_Idx: Int64; const _Value: Int64);
27+ procedure AssureBufferFor(_Idx: integer);
28+ procedure WriteBufferToFile;
29+ procedure ReadBufferFromFile;
30+ public
31+ constructor Create(const _fn: string); overload;
32+ constructor Create; overload;
33+ destructor Destroy; override;
34+ function Add(_Value: Int64): Int64;
35+ property Items[_Idx: Int64]: Int64 read GetItems write SetItems;
36+ property Count: Int64 read FCount;
37+ end;
38+
39+implementation
40+
41+uses
42+ RTLConsts;
43+
44+{ TInt64ListFile }
45+
46+constructor TInt64ListFile.Create(const _fn: string);
47+var
48+ Size: Int64;
49+begin
50+ inherited Create;
51+ FTempFile := TdzFile.Create(_fn);
52+ FTempFile.AccessMode := faReadWrite;
53+ FTempFile.ShareMode := fsNoSharing;
54+ FTempFile.CreateDisposition := fcOpenCreateIfNotExists;
55+ FTempFile.Open;
56+ FOffset := 0;
57+ Size := FTempFile.Size;
58+ if (Size > 0) and (Size mod SizeOf(FBuffer) = SizeOf(FCount)) then begin
59+ FTempFile.Seek(-SizeOf(FCount), soEnd);
60+ FTempFile.ReadBuffer(FCount, SizeOf(FCount));
61+ Assert(Size div SizeOf(Int64) - 1 >= FCount);
62+ end;
63+ ReadBufferFromFile;
64+end;
65+
66+constructor TInt64ListFile.Create;
67+begin
68+ FTempDir := TFileSystem.CreateUniqueTempDir();
69+ Create(FTempDir.PathBS + 'temp' + '.In64');
70+end;
71+
72+destructor TInt64ListFile.Destroy;
73+var
74+ SizeMod: Int64;
75+begin
76+ if Assigned(FTempFile) then begin
77+ if FCount > 0 then
78+ WriteBufferToFile;
79+ SizeMod := FTempFile.Size mod SizeOf(FBuffer);
80+ if SizeMod = SizeOf(FCount) then
81+ FTempFile.Seek(-SizeOf(FCount), soEnd)
82+ else if SizeMod = SizeOf(FCount) then
83+ FTempFile.Seek(0, soEnd);
84+ FTempFile.WriteBuffer(FCount, SizeOf(FCount));
85+ FreeAndNil(FTempFile);
86+ end;
87+ inherited;
88+end;
89+
90+function TInt64ListFile.Add(_Value: Int64): Int64;
91+begin
92+ Result := FCount;
93+ AssureBufferFor(Result);
94+ FBuffer[Result - FOffset] := _Value;
95+ Inc(FCount);
96+end;
97+
98+procedure TInt64ListFile.ReadBufferFromFile;
99+begin
100+ if FOffset * SizeOf(Int64) + SizeOf(FBuffer) <= FTempFile.Size then begin
101+ FTempFile.Position := FOffset * SizeOf(Int64);
102+ FTempFile.ReadBuffer(FBuffer, SizeOf(FBuffer));
103+ end else
104+ ZeroMemory(@FBuffer, SizeOf(FBuffer));
105+end;
106+
107+procedure TInt64ListFile.WriteBufferToFile;
108+begin
109+ if FOffset >= 0 then begin
110+ FTempFile.Position := FOffset * SizeOf(Int64);
111+ FTempFile.WriteBuffer(FBuffer, SizeOf(FBuffer));
112+ end;
113+end;
114+
115+procedure TInt64ListFile.AssureBufferFor(_Idx: integer);
116+begin
117+ if (_Idx < FOffset) or (_Idx >= FOffset + Length(FBuffer)) then begin
118+ WriteBufferToFile;
119+ FOffset := (_Idx div Length(FBuffer)) * Length(FBuffer);
120+ ReadBufferFromFile;
121+ end;
122+end;
123+
124+function TInt64ListFile.GetItems(_Idx: Int64): Int64;
125+begin
126+ if (_Idx < 0) or (_Idx >= FCount) then
127+ raise Exception.CreateFmt(_('List index out of bounds (%d) (Count=%d)'), [_Idx, FCount]);
128+ AssureBufferFor(_Idx);
129+ Result := FBuffer[_Idx - FOffset];
130+end;
131+
132+procedure TInt64ListFile.SetItems(_Idx: Int64; const _Value: Int64);
133+begin
134+ if (_Idx < 0) or (_Idx >= FCount) then
135+ raise Exception.CreateFmt(_('List index out of bounds (%d) (Count=%d)'), [_Idx, FCount]);
136+ AssureBufferFor(_Idx);
137+ FBuffer[_Idx - FOffset] := _Value;
138+end;
139+
140+end.
--- tags/1.0.2/src/dzLargeTextViewer.manifest.in (nonexistent)
+++ tags/1.0.2/src/dzLargeTextViewer.manifest.in (revision 274)
@@ -0,0 +1,52 @@
1+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+<!--
3+ This manifest tells Windows Vista (and Windows 7/8) not to virtualize any file
4+ or registry access. Also, it disables themes support.
5+ -->
6+ <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
7+ <assemblyIdentity version="1.0.0.0"
8+ processorArchitecture="*"
9+ name="template from dzlib build tools"
10+ type="win32"/>
11+<!-- We do not want themes support
12+ <dependency>
13+ <dependentassembly>
14+ <assemblyidentity type="win32"
15+ name="Microsoft.Windows.Common-Controls"
16+ version="6.0.0.0"
17+ publickeytoken="6595b64144ccf1df"
18+ language="*" processorarchitecture="*">
19+ </assemblyidentity>
20+ </dependentassembly>
21+ <dependency>
22+ -->
23+ <description>This application was built using buildtools from dzlib</description>
24+ <!-- COMPATIBILITY SECTION SPECIFIES IF APP IS COMPLIANT
25+ DISABLES PCA IF SPECIFIED -->
26+ <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
27+ <application>
28+ <!-- We support Windows Vista -->
29+ <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
30+ <!-- We support Windows 7 -->
31+ <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
32+ <!-- We support Windows 8 -->
33+ <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
34+ <!-- We support Windows 8.1 -->
35+ <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
36+ <!-- We support Windows 10 -->
37+ <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
38+ </application>
39+ </compatibility>
40+
41+ <!-- TRUSTINFO SECTION SPECIFIES REQUESTED PERMISSIONS AND
42+ UIPI DISABLEMENT (SPECIAL CONDITIONS APPLY TO UIPI DISABLEMENT)-->
43+ <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
44+ <security>
45+ <requestedPrivileges>
46+ <requestedExecutionLevel
47+ level="asInvoker"
48+ uiAccess="false"/>
49+ </requestedPrivileges>
50+ </security>
51+ </trustInfo>
52+</assembly>
\ No newline at end of file
--- tags/1.0.2/src/u_LargeTextAccess.pas (nonexistent)
+++ tags/1.0.2/src/u_LargeTextAccess.pas (revision 274)
@@ -0,0 +1,82 @@
1+unit u_LargeTextAccess;
2+
3+interface
4+
5+uses
6+ SysUtils,
7+ Classes,
8+ u_dzFileStreams;
9+
10+type
11+ TLargeTextAccess = class
12+ public
13+ type
14+ TOptimizeForEnum = (ofForward, ofBackward, ofBoth);
15+ private
16+ const
17+ BUFFER_SIZE = 1024 * 128;
18+ var
19+ FOptimizeFor: TOptimizeForEnum;
20+ FFilename: string;
21+ FStream: TdzFile;
22+ FLength: Int64;
23+ FOffset: Int64;
24+ FBuffer: array[0..BUFFER_SIZE - 1] of char;
25+ public
26+ constructor Create(const _fn: string; _OptimizeFor: TOptimizeForEnum = ofBoth);
27+ destructor Destroy; override;
28+ function GetChar(_Idx: Int64): char;
29+ function GetLength: Int64;
30+ end;
31+
32+implementation
33+
34+{ TLargeTextAccess }
35+
36+constructor TLargeTextAccess.Create(const _fn: string; _OptimizeFor: TOptimizeForEnum = ofBoth);
37+begin
38+ inherited Create;
39+ FFilename := _fn;
40+ FOptimizeFor := _OptimizeFor;
41+ FStream := TdzFile.Create(FFilename);
42+ FStream.OpenReadonly;
43+ FLength := FStream.Size;
44+ FOffset := -BUFFER_SIZE;
45+end;
46+
47+destructor TLargeTextAccess.Destroy;
48+begin
49+ FreeAndNil(FStream);
50+ inherited;
51+end;
52+
53+function TLargeTextAccess.GetChar(_Idx: Int64): char;
54+begin
55+ if (_Idx < 0) or (_Idx >= FLength) then
56+ raise Exception.CreateFmt('Index %d out of range.', [_Idx]);
57+
58+ if (_Idx < FOffset) or (_Idx >= FOffset + BUFFER_SIZE) then begin
59+ case FOptimizeFor of
60+ ofForward:
61+ FOffset := _Idx;
62+ ofBackward:
63+ FOffset := _Idx - BUFFER_SIZE + 1;
64+ else // ofBoth
65+ FOffset := _Idx - BUFFER_SIZE div 2 + 1;
66+ end;
67+ if FOffset < 0 then
68+ FOffset := 0;
69+ if FOffset >= FLength then
70+ FOffset := FLength - 1;
71+ FStream.Position := FOffset;
72+ FStream.Read(FBuffer, BUFFER_SIZE);
73+ end;
74+ Result := FBuffer[_Idx - FOffset]
75+end;
76+
77+function TLargeTextAccess.GetLength: Int64;
78+begin
79+ Result := FLength;
80+end;
81+
82+end.
--- tags/1.0.2/src/w_Search.pas (nonexistent)
+++ tags/1.0.2/src/w_Search.pas (revision 274)
@@ -0,0 +1,214 @@
1+unit w_Search;
2+
3+interface
4+
5+uses
6+ Windows,
7+ Messages,
8+ SysUtils,
9+ Variants,
10+ Classes,
11+ Graphics,
12+ Controls,
13+ Forms,
14+ StdCtrls,
15+ u_dzTranslator;
16+
17+type
18+ TOnSearchEvent = procedure(_Sender: TObject; const _Pattern: string) of object;
19+
20+type
21+ Tf_Search = class(TForm)
22+ ed_Pattern: TEdit;
23+ l_Pattern: TLabel;
24+ m_Text: TMemo;
25+ b_Find: TButton;
26+ procedure b_FindClick(Sender: TObject);
27+ private
28+ FCallback: TOnSearchEvent;
29+ procedure SetData(const _Pattern: string; _Callback: TOnSearchEvent);
30+ public
31+ class procedure Execute(_Owner: TWinControl; const _Pattern: string; _Callback: TOnSearchEvent); static;
32+ constructor Create(_Owner: TComponent); override;
33+ end;
34+
35+implementation
36+
37+{$R *.dfm}
38+
39+uses
40+ StrUtils,
41+ u_dzVclUtils;
42+
43+type
44+ ITextBuffer = interface ['{8B4A019A-99CA-4E86-864D-D1E9E6020648}']
45+ function GetChar(_Idx: Int64): Char;
46+ function GetString(_Idx: Int64; _Len: integer): string;
47+ function GetLength: Int64;
48+ end;
49+
50+//type
51+// TTextBuffer = class
52+// private
53+// function GetChar(_Idx: Int64): char;
54+// function GetLength: Int64;
55+// public
56+// constructor Create(const _fn: string);
57+// destructor Destroy;
58+// end;
59+
60+type
61+ TStringBuffer = class(TInterfacedObject, ITextBuffer)
62+ private
63+ FText: string;
64+ function GetChar(_Idx: Int64): Char;
65+ function GetString(_Idx: Int64; _Len: integer): string;
66+ function GetLength: Int64;
67+ public
68+ constructor Create(const _Text: string);
69+ end;
70+
71+{ TStringBuffer }
72+
73+constructor TStringBuffer.Create(const _Text: string);
74+begin
75+ inherited Create;
76+ FText := _Text;
77+end;
78+
79+function TStringBuffer.GetChar(_Idx: Int64): Char;
80+begin
81+ Result := FText[_Idx];
82+end;
83+
84+function TStringBuffer.GetLength: Int64;
85+begin
86+ Result := Length(FText);
87+end;
88+
89+function TStringBuffer.GetString(_Idx: Int64; _Len: integer): string;
90+begin
91+ Result := Copy(FText, _Idx, _Len);
92+end;
93+
94+type
95+ TBMSearch = class
96+ private
97+ FSkip: array of integer;
98+ FPatternLen: integer;
99+ FPattern: string;
100+ public
101+ constructor Create(const _Pattern: string);
102+ function Find(_Text: ITextBuffer; var _Offset: Int64): Boolean;
103+ end;
104+
105+{ TBMSearch }
106+
107+constructor TBMSearch.Create(const _Pattern: string);
108+var
109+ i: integer;
110+begin
111+ FPattern := _Pattern;
112+ FPatternLen := Length(_Pattern);
113+ if FPatternLen = 0 then
114+ Exit;
115+
116+ SetLength(FSkip, integer(High(Char)) + 1);
117+ for i := Low(FSkip) to High(FSkip) do
118+ FSkip[i] := FPatternLen;
119+ for i := 1 to FPatternLen - 1 do
120+ FSkip[integer(_Pattern[i])] := FPatternLen - i;
121+end;
122+
123+function TBMSearch.Find(_Text: ITextBuffer; var _Offset: Int64): Boolean;
124+var
125+ i: Int64;
126+ TextLen: Int64;
127+ TextIdx: Int64;
128+ PatternIdx: integer;
129+ s: string;
130+begin
131+ Result := False;
132+ if FPatternLen = 0 then
133+ Exit;
134+
135+ i := FPatternLen + (_Offset);
136+ TextLen := _Text.GetLength;
137+ while (not Result) and (i <= TextLen) do begin
138+ TextIdx := i;
139+ PatternIdx := FPatternLen;
140+ while (PatternIdx >= 1) do begin
141+ if _Text.GetChar(TextIdx) = FPattern[PatternIdx] then begin
142+ PatternIdx := PatternIdx - 1;
143+ TextIdx := TextIdx - 1;
144+ end else
145+ PatternIdx := -1;
146+ if PatternIdx = 0 then begin
147+ _Offset := TextIdx;
148+ s := _Text.GetString(_Offset, FPatternLen);
149+ Result := True;
150+ Exit;
151+ end;
152+ i := i + FSkip[integer(_Text.GetChar(i))];
153+ end;
154+ end;
155+end;
156+
157+var
158+ frm: Tf_Search;
159+
160+{ Tf_Search }
161+
162+class procedure Tf_Search.Execute(_Owner: TWinControl; const _Pattern: string;
163+ _Callback: TOnSearchEvent);
164+begin
165+ if not Assigned(frm) then begin
166+ frm := Tf_Search.Create(_Owner);
167+ TForm_CenterOn(frm, _Owner);
168+ end;
169+ frm.SetData(_Pattern, _Callback);
170+ frm.Show;
171+end;
172+
173+constructor Tf_Search.Create(_Owner: TComponent);
174+begin
175+ inherited;
176+
177+ TranslateComponent(Self);
178+
179+ m_Text.SelStart := 0;
180+ m_Text.SelLength := 0;
181+end;
182+
183+procedure Tf_Search.SetData(const _Pattern: string; _Callback: TOnSearchEvent);
184+begin
185+ ed_Pattern.Text := _Pattern;
186+ FCallback := _Callback;
187+end;
188+
189+procedure Tf_Search.b_FindClick(Sender: TObject);
190+var
191+ Pattern: string;
192+ Search: TBMSearch;
193+ Offset: Int64;
194+ Text: ITextBuffer;
195+begin
196+ Pattern := ed_Pattern.Text;
197+ Search := TBMSearch.Create(Pattern);
198+ try
199+ Offset := m_Text.SelStart + m_Text.SelLength + 1;
200+ Text := TStringBuffer.Create(m_Text.Lines.Text);
201+ if Search.Find(Text, Offset) then begin
202+ m_Text.SelStart := Offset;
203+ m_Text.SelLength := Length(Pattern);
204+ end;
205+ finally
206+ FreeAndNil(Search);
207+ end;
208+ m_Text.SetFocus;
209+ Exit;
210+
211+ FCallback(Self, ed_Pattern.Text);
212+end;
213+
214+end.
--- tags/1.0.2/src/w_GotoLine.pas (nonexistent)
+++ tags/1.0.2/src/w_GotoLine.pas (revision 274)
@@ -0,0 +1,95 @@
1+unit w_GotoLine;
2+
3+interface
4+
5+uses
6+ Windows,
7+ Messages,
8+ SysUtils,
9+ Variants,
10+ Classes,
11+ Graphics,
12+ Controls,
13+ Forms,
14+ Dialogs,
15+ StdCtrls,
16+ u_dzTranslator,
17+ u_dzVclUtils,
18+ u_dzInputValidator;
19+
20+type
21+ Tf_GotoLine = class(TForm)
22+ ed_LineNumber: TEdit;
23+ l_LineNumber: TLabel;
24+ b_Ok: TButton;
25+ b_Cancel: TButton;
26+ procedure ed_LineNumberChange(Sender: TObject);
27+ private
28+ FInputValidator: IdzInputValidator;
29+ FMaxLineNo: Integer;
30+ procedure SetData(_MaxLineNo: Integer; _LineNo: Integer);
31+ procedure GetData(out _LineNo: Integer);
32+ procedure CheckInput;
33+ public
34+ class function Execute(_Owner: TWinControl; _MaxLineNo: Integer; var _LineNo: Integer): Boolean; static;
35+ constructor Create(_Owner: TComponent); override;
36+ end;
37+
38+implementation
39+
40+{$R *.dfm}
41+
42+
43+{ Tf_GotoLine }
44+
45+class function Tf_GotoLine.Execute(_Owner: TWinControl; _MaxLineNo: Integer; var _LineNo: Integer): Boolean;
46+var
47+ frm: Tf_GotoLine;
48+begin
49+ frm := Tf_GotoLine.Create(_Owner);
50+ try
51+ TForm_CenterOn(frm, _Owner);
52+ frm.SetData(_MaxLineNo, _LineNo);
53+ Result := (frm.ShowModal = mrok);
54+ if Result then
55+ frm.GetData(_LineNo);
56+ finally
57+ FreeAndNil(frm);
58+ end;
59+end;
60+
61+constructor Tf_GotoLine.Create(_Owner: TComponent);
62+begin
63+ inherited;
64+ TranslateComponent(Self);
65+end;
66+
67+procedure Tf_GotoLine.GetData(out _LineNo: Integer);
68+begin
69+ _LineNo := StrToInt(ed_LineNumber.Text);
70+end;
71+
72+procedure Tf_GotoLine.SetData(_MaxLineNo: Integer; _LineNo: Integer);
73+begin
74+ FMaxLineNo := _MaxLineNo;
75+ ed_LineNumber.Text := IntToStr(_LineNo)
76+end;
77+
78+procedure Tf_GotoLine.CheckInput;
79+begin
80+ if not Assigned(FInputValidator) then begin
81+ FInputValidator := InputValidator();
82+ FInputValidator.EnableMessages(True);
83+ end;
84+ FInputValidator.Reset;
85+ FInputValidator.Check(ed_LineNumber).AsInteger.IsBetween(1, FMaxLineNo);
86+ b_Ok.Enabled := FInputValidator.GetResult;
87+end;
88+
89+procedure Tf_GotoLine.ed_LineNumberChange(Sender: TObject);
90+begin
91+ CheckInput;
92+end;
93+
94+end.
95+
Show on old repository browser