mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-16 23:49:28 +02:00
wiki: started search
git-svn-id: trunk@35642 -
This commit is contained in:
parent
179972fb78
commit
827eef7e1e
7
.gitattributes
vendored
7
.gitattributes
vendored
@ -2848,6 +2848,13 @@ components/wiki/lazwiki/wikiparser.pas svneol=native#text/plain
|
||||
components/wiki/myfphttpclient.pp svneol=native#text/plain
|
||||
components/wiki/parsewikipage.lpi svneol=native#text/plain
|
||||
components/wiki/parsewikipage.lpr svneol=native#text/plain
|
||||
components/wiki/test/wikihelpmanager.pas svneol=native#text/plain
|
||||
components/wiki/test/wikisearchdemo.ico -text svneol=unset#image/ico
|
||||
components/wiki/test/wikisearchdemo.lpi svneol=native#text/plain
|
||||
components/wiki/test/wikisearchdemo.lpr svneol=native#text/plain
|
||||
components/wiki/test/wikisearchdemo.res -text
|
||||
components/wiki/test/wikisearchmain.lfm svneol=native#text/plain
|
||||
components/wiki/test/wikisearchmain.pas svneol=native#text/plain
|
||||
components/wiki/wikiconvert.lpi svneol=native#text/plain
|
||||
components/wiki/wikiconvert.lpr svneol=native#text/plain
|
||||
components/wiki/wikiget.lpi svneol=native#text/plain
|
||||
|
175
components/wiki/test/wikihelpmanager.pas
Normal file
175
components/wiki/test/wikihelpmanager.pas
Normal file
@ -0,0 +1,175 @@
|
||||
unit WikiHelpManager;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, LazFileUtils, LazLogger, Wiki2HTMLConvert;
|
||||
|
||||
type
|
||||
TWikiHelp = class;
|
||||
|
||||
{ TWikiHelpThread }
|
||||
|
||||
TWikiHelpThread = class(TThread)
|
||||
protected
|
||||
fLogMsg: string;
|
||||
procedure Execute; override;
|
||||
procedure MainThreadLog;
|
||||
procedure Log(Msg: string);
|
||||
procedure OnScanComplete; // called in thread at end
|
||||
public
|
||||
Help: TWikiHelp;
|
||||
XMLDirectory: string;
|
||||
ImagesDirectory: string;
|
||||
end;
|
||||
|
||||
{ TWikiHelp }
|
||||
|
||||
TWikiHelp = class(TComponent)
|
||||
private
|
||||
FAborting: boolean;
|
||||
FImagesDirectory: string;
|
||||
FScanning: boolean;
|
||||
FXMLDirectory: string;
|
||||
FCritSec: TRTLCriticalSection;
|
||||
FScanThread: TWikiHelpThread;
|
||||
procedure SetImagesDirectory(AValue: string);
|
||||
procedure SetXMLDirectory(AValue: string);
|
||||
procedure EnterCritSect;
|
||||
procedure LeaveCritSect;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
procedure StartScan;
|
||||
procedure Abort;
|
||||
property Scanning: boolean read FScanning;
|
||||
property Aborting: boolean read FAborting;
|
||||
property XMLDirectory: string read FXMLDirectory write SetXMLDirectory; // directory where the wiki xml files are
|
||||
property ImagesDirectory: string read FImagesDirectory write SetImagesDirectory; // directory where the wiki image files are
|
||||
end;
|
||||
|
||||
var
|
||||
WikiHelp: TWikiHelp = nil;
|
||||
|
||||
implementation
|
||||
|
||||
{ TWikiHelpThread }
|
||||
|
||||
procedure TWikiHelpThread.Execute;
|
||||
begin
|
||||
try
|
||||
Log('TWikiHelpThread.Execute START XMLDirectory="'+XMLDirectory+'"');
|
||||
|
||||
Log('TWikiHelpThread.Execute SCAN complete XMLDirectory="'+XMLDirectory+'"');
|
||||
except
|
||||
on E: Exception do begin
|
||||
Log('TWikiHelpThread.Execute error: '+E.Message);
|
||||
end;
|
||||
end;
|
||||
Synchronize(@OnScanComplete);
|
||||
end;
|
||||
|
||||
procedure TWikiHelpThread.MainThreadLog;
|
||||
// called in main thread
|
||||
begin
|
||||
DebugLn(fLogMsg);
|
||||
end;
|
||||
|
||||
procedure TWikiHelpThread.Log(Msg: string);
|
||||
begin
|
||||
fLogMsg:=Msg;
|
||||
Synchronize(@MainThreadLog);
|
||||
end;
|
||||
|
||||
procedure TWikiHelpThread.OnScanComplete;
|
||||
// called in this thread
|
||||
begin
|
||||
Help.EnterCritSect;
|
||||
try
|
||||
Help.FScanThread:=nil;
|
||||
Help.FScanning:=false;
|
||||
finally
|
||||
Help.LeaveCritSect;
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TWikiHelp }
|
||||
|
||||
procedure TWikiHelp.SetImagesDirectory(AValue: string);
|
||||
var
|
||||
NewDir: String;
|
||||
begin
|
||||
NewDir:=AppendPathDelim(TrimFilename(AValue));
|
||||
if FImagesDirectory=NewDir then Exit;
|
||||
FImagesDirectory:=NewDir;
|
||||
end;
|
||||
|
||||
procedure TWikiHelp.SetXMLDirectory(AValue: string);
|
||||
var
|
||||
NewDir: String;
|
||||
begin
|
||||
NewDir:=AppendPathDelim(TrimFilename(AValue));
|
||||
if FXMLDirectory=NewDir then Exit;
|
||||
FXMLDirectory:=NewDir;
|
||||
end;
|
||||
|
||||
procedure TWikiHelp.EnterCritSect;
|
||||
begin
|
||||
EnterCriticalsection(FCritSec);
|
||||
end;
|
||||
|
||||
procedure TWikiHelp.LeaveCritSect;
|
||||
begin
|
||||
LeaveCriticalsection(FCritSec);
|
||||
end;
|
||||
|
||||
constructor TWikiHelp.Create(AOwner: TComponent);
|
||||
begin
|
||||
InitCriticalSection(FCritSec);
|
||||
inherited Create(AOwner);
|
||||
end;
|
||||
|
||||
destructor TWikiHelp.Destroy;
|
||||
begin
|
||||
Abort;
|
||||
inherited Destroy;
|
||||
DoneCriticalsection(FCritSec);
|
||||
end;
|
||||
|
||||
procedure TWikiHelp.StartScan;
|
||||
begin
|
||||
if not DirPathExists(XMLDirectory) then
|
||||
raise Exception.Create('TWikiHelp.StartScan XMLDirectory not found: '+XMLDirectory);
|
||||
if not DirPathExists(ImagesDirectory) then
|
||||
raise Exception.Create('TWikiHelp.StartScan ImagesDirectory not found: '+ImagesDirectory);
|
||||
EnterCritSect;
|
||||
try
|
||||
if Scanning then exit;
|
||||
FScanning:=true;
|
||||
FScanThread:=TWikiHelpThread.Create(true);
|
||||
FScanThread.FreeOnTerminate:=true;
|
||||
FScanThread.Help:=Self;
|
||||
FScanThread.XMLDirectory:=XMLDirectory;
|
||||
FScanThread.ImagesDirectory:=ImagesDirectory;
|
||||
{$IF FPC_FULLVERSION<=20403}
|
||||
FScanThread.Resume;
|
||||
{$ELSE}
|
||||
FScanThread.Start;
|
||||
{$ENDIF}
|
||||
finally
|
||||
LeaveCritSect;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TWikiHelp.Abort;
|
||||
begin
|
||||
FAborting:=true;
|
||||
while Scanning do
|
||||
Sleep(10);
|
||||
FAborting:=false;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
BIN
components/wiki/test/wikisearchdemo.ico
Normal file
BIN
components/wiki/test/wikisearchdemo.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 134 KiB |
103
components/wiki/test/wikisearchdemo.lpi
Normal file
103
components/wiki/test/wikisearchdemo.lpi
Normal file
@ -0,0 +1,103 @@
|
||||
<?xml version="1.0"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="9"/>
|
||||
<General>
|
||||
<SessionStorage Value="InIDEConfig"/>
|
||||
<MainUnit Value="0"/>
|
||||
<Title Value="project1"/>
|
||||
<ResourceType Value="res"/>
|
||||
<UseXPManifest Value="True"/>
|
||||
<Icon Value="0"/>
|
||||
</General>
|
||||
<i18n>
|
||||
<EnableI18N LFM="False"/>
|
||||
</i18n>
|
||||
<VersionInfo>
|
||||
<StringTable ProductVersion=""/>
|
||||
</VersionInfo>
|
||||
<BuildModes Count="1">
|
||||
<Item1 Name="Default" Default="True"/>
|
||||
</BuildModes>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
|
||||
<ExcludeFileFilter Value="*.(bak|ppu|o|so);*~;backup"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<local>
|
||||
<FormatVersion Value="1"/>
|
||||
<LaunchingApplication PathPlusParams="/usr/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
|
||||
</local>
|
||||
</RunParams>
|
||||
<RequiredPackages Count="4">
|
||||
<Item1>
|
||||
<PackageName Value="turbopoweripro"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<PackageName Value="MultiThreadProcsLaz"/>
|
||||
</Item2>
|
||||
<Item3>
|
||||
<PackageName Value="LazWiki"/>
|
||||
</Item3>
|
||||
<Item4>
|
||||
<PackageName Value="LCL"/>
|
||||
</Item4>
|
||||
</RequiredPackages>
|
||||
<Units Count="3">
|
||||
<Unit0>
|
||||
<Filename Value="wikisearchdemo.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="wikisearchdemo"/>
|
||||
</Unit0>
|
||||
<Unit1>
|
||||
<Filename Value="wikisearchmain.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<ComponentName Value="WikiSearchDemoForm"/>
|
||||
<ResourceBaseClass Value="Form"/>
|
||||
<UnitName Value="WikiSearchMain"/>
|
||||
</Unit1>
|
||||
<Unit2>
|
||||
<Filename Value="wikihelpmanager.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="WikiHelpManager"/>
|
||||
</Unit2>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<Target>
|
||||
<Filename Value="wikisearchdemo"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<Linking>
|
||||
<Options>
|
||||
<Win32>
|
||||
<GraphicApplication Value="True"/>
|
||||
</Win32>
|
||||
</Options>
|
||||
</Linking>
|
||||
<Other>
|
||||
<CompilerMessages>
|
||||
<MsgFileName Value=""/>
|
||||
</CompilerMessages>
|
||||
<CompilerPath Value="$(CompPath)"/>
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<Exceptions Count="3">
|
||||
<Item1>
|
||||
<Name Value="EAbort"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<Name Value="ECodetoolError"/>
|
||||
</Item2>
|
||||
<Item3>
|
||||
<Name Value="EFOpenError"/>
|
||||
</Item3>
|
||||
</Exceptions>
|
||||
</Debugging>
|
||||
</CONFIG>
|
22
components/wiki/test/wikisearchdemo.lpr
Normal file
22
components/wiki/test/wikisearchdemo.lpr
Normal file
@ -0,0 +1,22 @@
|
||||
program WikiSearchDemo;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses
|
||||
{$IFDEF UNIX}{$IFDEF UseCThreads}
|
||||
cthreads,
|
||||
{$ENDIF}{$ENDIF}
|
||||
Interfaces, // this includes the LCL widgetset
|
||||
Forms, WikiSearchMain, WikiHelpManager
|
||||
{ you can add units after this };
|
||||
|
||||
{$R *.res}
|
||||
|
||||
begin
|
||||
Application.Title:='WikiSearchDemo';
|
||||
RequireDerivedFormResource := True;
|
||||
Application.Initialize;
|
||||
Application.CreateForm(TWikiSearchDemoForm, WikiSearchDemoForm);
|
||||
Application.Run;
|
||||
end.
|
||||
|
BIN
components/wiki/test/wikisearchdemo.res
Normal file
BIN
components/wiki/test/wikisearchdemo.res
Normal file
Binary file not shown.
108
components/wiki/test/wikisearchmain.lfm
Normal file
108
components/wiki/test/wikisearchmain.lfm
Normal file
@ -0,0 +1,108 @@
|
||||
object WikiSearchDemoForm: TWikiSearchDemoForm
|
||||
Left = 734
|
||||
Height = 501
|
||||
Top = 312
|
||||
Width = 663
|
||||
Caption = 'WikiSearchDemoForm'
|
||||
ClientHeight = 501
|
||||
ClientWidth = 663
|
||||
OnCreate = FormCreate
|
||||
OnDestroy = FormDestroy
|
||||
Position = poScreenCenter
|
||||
LCLVersion = '0.9.31'
|
||||
object SearchLabel: TLabel
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = SearchEdit
|
||||
AnchorSideTop.Side = asrCenter
|
||||
Left = 6
|
||||
Height = 18
|
||||
Top = 10
|
||||
Width = 84
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'SearchLabel'
|
||||
ParentColor = False
|
||||
end
|
||||
object SearchEdit: TEdit
|
||||
AnchorSideLeft.Control = SearchLabel
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = Owner
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 96
|
||||
Height = 27
|
||||
Top = 6
|
||||
Width = 561
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Around = 6
|
||||
TabOrder = 0
|
||||
Text = 'SearchEdit'
|
||||
end
|
||||
object ResultsGroupBox: TGroupBox
|
||||
AnchorSideTop.Control = SearchEdit
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 6
|
||||
Height = 287
|
||||
Top = 39
|
||||
Width = 651
|
||||
Align = alBottom
|
||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'ResultsGroupBox'
|
||||
ClientHeight = 268
|
||||
ClientWidth = 647
|
||||
TabOrder = 1
|
||||
object ResultsIpHtmlPanel: TIpHtmlPanel
|
||||
Left = 0
|
||||
Height = 268
|
||||
Top = 0
|
||||
Width = 647
|
||||
Align = alClient
|
||||
FixedTypeface = 'Courier New'
|
||||
DefaultTypeFace = 'default'
|
||||
DefaultFontSize = 12
|
||||
FlagErrors = False
|
||||
PrintSettings.MarginLeft = 0.5
|
||||
PrintSettings.MarginTop = 0.5
|
||||
PrintSettings.MarginRight = 0.5
|
||||
PrintSettings.MarginBottom = 0.5
|
||||
TabOrder = 0
|
||||
end
|
||||
end
|
||||
object PageGroupBox: TGroupBox
|
||||
Left = 6
|
||||
Height = 152
|
||||
Top = 343
|
||||
Width = 651
|
||||
Align = alBottom
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'PageGroupBox'
|
||||
ClientHeight = 133
|
||||
ClientWidth = 647
|
||||
TabOrder = 2
|
||||
object PageIpHtmlPanel: TIpHtmlPanel
|
||||
Left = 0
|
||||
Height = 133
|
||||
Top = 0
|
||||
Width = 647
|
||||
Align = alClient
|
||||
FixedTypeface = 'Courier New'
|
||||
DefaultTypeFace = 'default'
|
||||
DefaultFontSize = 12
|
||||
FlagErrors = False
|
||||
PrintSettings.MarginLeft = 0.5
|
||||
PrintSettings.MarginTop = 0.5
|
||||
PrintSettings.MarginRight = 0.5
|
||||
PrintSettings.MarginBottom = 0.5
|
||||
TabOrder = 0
|
||||
end
|
||||
end
|
||||
object Splitter1: TSplitter
|
||||
Cursor = crVSplit
|
||||
Left = 0
|
||||
Height = 5
|
||||
Top = 332
|
||||
Width = 663
|
||||
Align = alBottom
|
||||
ResizeAnchor = akBottom
|
||||
end
|
||||
end
|
58
components/wiki/test/wikisearchmain.pas
Normal file
58
components/wiki/test/wikisearchmain.pas
Normal file
@ -0,0 +1,58 @@
|
||||
unit WikiSearchMain;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, FileUtil, IpHtml, Forms, Controls, Graphics, Dialogs,
|
||||
StdCtrls, ExtCtrls, WikiHelpManager;
|
||||
|
||||
type
|
||||
|
||||
{ TWikiSearchDemoForm }
|
||||
|
||||
TWikiSearchDemoForm = class(TForm)
|
||||
PageGroupBox: TGroupBox;
|
||||
PageIpHtmlPanel: TIpHtmlPanel;
|
||||
ResultsGroupBox: TGroupBox;
|
||||
ResultsIpHtmlPanel: TIpHtmlPanel;
|
||||
SearchEdit: TEdit;
|
||||
SearchLabel: TLabel;
|
||||
Splitter1: TSplitter;
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure FormDestroy(Sender: TObject);
|
||||
private
|
||||
public
|
||||
end;
|
||||
|
||||
var
|
||||
WikiSearchDemoForm: TWikiSearchDemoForm;
|
||||
|
||||
implementation
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
{ TWikiSearchDemoForm }
|
||||
|
||||
procedure TWikiSearchDemoForm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
Caption:='Search Wiki (Proof of concept)';
|
||||
SearchLabel.Caption:='Search:';
|
||||
SearchEdit.Text:='';
|
||||
ResultsGroupBox.Caption:='Result:';
|
||||
PageGroupBox.Caption:='Page:';
|
||||
|
||||
WikiHelp:=TWikiHelp.Create(nil);
|
||||
WikiHelp.XMLDirectory:=SetDirSeparators('../wikixml');
|
||||
WikiHelp.ImagesDirectory:=SetDirSeparators('../images');
|
||||
WikiHelp.StartScan;
|
||||
end;
|
||||
|
||||
procedure TWikiSearchDemoForm.FormDestroy(Sender: TObject);
|
||||
begin
|
||||
FreeAndNil(WikiHelp);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user