mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-10 09:59:17 +02:00
wiki test: started options
git-svn-id: trunk@35792 -
This commit is contained in:
parent
6fdd286ea2
commit
46191839c5
@ -682,7 +682,7 @@ begin
|
||||
Page:=TW2XHTMLPage(Pages[i]);
|
||||
Page.Filename:=PageToFilename(Page,false);
|
||||
if Page.WikiPage<>nil then
|
||||
Page.WikiPage.LanguageTags:=LanguageTags;
|
||||
Page.WikiPage.LanguageTags:=CodeTags;
|
||||
ShortFilenameToPage[Page.Filename]:=Page;
|
||||
end;
|
||||
end;
|
||||
|
@ -52,7 +52,7 @@ type
|
||||
|
||||
TWiki2FormatConverter = class
|
||||
private
|
||||
FLanguageTags: TKeyWordFunctionList;
|
||||
FCodeTags: TKeyWordFunctionList;
|
||||
FNoWarnBaseURLs: TStringToStringTree;
|
||||
FOnLog: TWikiOnLog;
|
||||
FTitle: string;
|
||||
@ -86,7 +86,8 @@ type
|
||||
property Title: string read FTitle write SetTitle;
|
||||
property WarnMissingPageLinks: boolean read FWarnMissingPageLinks write FWarnMissingPageLinks; // warn if an internal link links to non existing page
|
||||
property NoWarnBaseURLs: TStringToStringTree read FNoWarnBaseURLs;
|
||||
property LanguageTags: TKeyWordFunctionList read FLanguageTags write FLanguageTags;
|
||||
property CodeTags: TKeyWordFunctionList read FCodeTags write FCodeTags;
|
||||
function CollectAllLangCodes(Delimiter: char = ','): string;
|
||||
end;
|
||||
|
||||
function WikiPageToFilename(Page: string; IsInternalLink, AppendCaseID: boolean): string;
|
||||
@ -94,7 +95,7 @@ function WikiFilenameToPage(Filename: string): string;
|
||||
function WikiImageToFilename(Image: string; IsInternalLink, InsertCaseID: boolean;
|
||||
KeepScheme: boolean = false): string;
|
||||
function WikiHeaderToLink(Header: string): string;
|
||||
function WikiCreateCommonLanguageList(AddLazWikiLangs: boolean): TKeyWordFunctionList;
|
||||
function WikiCreateCommonCodeTagList(AddLazWikiLangs: boolean): TKeyWordFunctionList;
|
||||
function GetWikiPageLanguage(const Page: string): string;
|
||||
function WikiPageHasLanguage(const Page, Languages: string): boolean;
|
||||
|
||||
@ -222,7 +223,7 @@ begin
|
||||
// load wiki pages
|
||||
for i:=0 to Count-1 do begin
|
||||
Page:=Pages[i];
|
||||
Page.WikiPage.LanguageTags:=LanguageTags;
|
||||
Page.WikiPage.LanguageTags:=CodeTags;
|
||||
Page.ParseWikiDoc(false);
|
||||
end;
|
||||
end;
|
||||
@ -240,6 +241,29 @@ begin
|
||||
Result:=fPages.Count;
|
||||
end;
|
||||
|
||||
function TWiki2FormatConverter.CollectAllLangCodes(Delimiter: char): string;
|
||||
var
|
||||
i: Integer;
|
||||
Page: TW2FormatPage;
|
||||
Lang: String;
|
||||
Langs: TStringToStringTree;
|
||||
begin
|
||||
Result:='';
|
||||
Langs:=TStringToStringTree.Create(false);
|
||||
try
|
||||
for i:=0 to Count-1 do begin
|
||||
Page:=Pages[i];
|
||||
Lang:=GetWikiPageLanguage(Page.WikiDocumentName);
|
||||
if Lang='' then continue;
|
||||
if Langs.Contains(Lang) then continue;
|
||||
Langs[Lang]:='1';
|
||||
Result+=Delimiter+Lang;
|
||||
end;
|
||||
finally
|
||||
Langs.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TW2FormatPage }
|
||||
|
||||
constructor TW2FormatPage.Create(TheConverter: TWiki2FormatConverter);
|
||||
@ -404,7 +428,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function WikiCreateCommonLanguageList(AddLazWikiLangs: boolean): TKeyWordFunctionList;
|
||||
function WikiCreateCommonCodeTagList(AddLazWikiLangs: boolean): TKeyWordFunctionList;
|
||||
begin
|
||||
Result:=TKeyWordFunctionList.Create('LanguageTags');
|
||||
with Result do begin
|
||||
|
@ -233,6 +233,11 @@ type
|
||||
property Aborting: boolean read FAborting;
|
||||
function LoadComplete: boolean;
|
||||
|
||||
// languages
|
||||
function CollectAllLanguages(AsCaption: boolean): TStrings;
|
||||
function LangCodeToCaption(LangCode: string): string;
|
||||
function LangCaptionToCode(Caption: string): string;
|
||||
|
||||
// search
|
||||
procedure Search(const Term: string; const Languages: string = '');
|
||||
procedure Search(aQuery: TWikiHelpQuery);
|
||||
@ -1426,7 +1431,7 @@ begin
|
||||
InitCriticalSection(FCritSec);
|
||||
inherited Create(AOwner);
|
||||
FConverter:=TWiki2HelpConverter.Create;
|
||||
FConverter.LanguageTags:=WikiCreateCommonLanguageList(true);
|
||||
FConverter.CodeTags:=WikiCreateCommonCodeTagList(true);
|
||||
FConverter.FHelp:=Self;
|
||||
FScoring:=TWHScoring.Create;
|
||||
FScoring.Phrases[whfcPageTitle,whfsWholeWord]:=128;
|
||||
@ -1444,7 +1449,7 @@ end;
|
||||
destructor TWikiHelp.Destroy;
|
||||
begin
|
||||
AbortLoading(true);
|
||||
FConverter.LanguageTags.Free;
|
||||
FConverter.CodeTags.Free;
|
||||
FreeAndNil(FConverter);
|
||||
FreeAndNil(FScoring);
|
||||
FreeAndNil(FQuery);
|
||||
@ -1508,6 +1513,45 @@ begin
|
||||
Result:=(fProgressStep>=whpsWikiLoadComplete);
|
||||
end;
|
||||
|
||||
function TWikiHelp.CollectAllLanguages(AsCaption: boolean): TStrings;
|
||||
|
||||
procedure Add(Code: string);
|
||||
begin
|
||||
if AsCaption then
|
||||
Code:=LangCodeToCaption(Code);
|
||||
CollectAllLanguages.Add(Code);
|
||||
end;
|
||||
|
||||
var
|
||||
Codes: String;
|
||||
p: SizeInt;
|
||||
Code: String;
|
||||
begin
|
||||
Result:=TStringList.Create;
|
||||
Add('');
|
||||
if LoadComplete then begin
|
||||
Codes:=Converter.CollectAllLangCodes(';')+';';
|
||||
repeat
|
||||
p:=Pos(';',Codes);
|
||||
if p<1 then p:=length(Codes)+1;
|
||||
Code:=LeftStr(Codes,p-1);
|
||||
Delete(Codes,1,p);
|
||||
if Code<>'' then
|
||||
Add(Code);
|
||||
until Codes='';
|
||||
end;
|
||||
end;
|
||||
|
||||
function TWikiHelp.LangCodeToCaption(LangCode: string): string;
|
||||
begin
|
||||
Result:=LangCode;
|
||||
end;
|
||||
|
||||
function TWikiHelp.LangCaptionToCode(Caption: string): string;
|
||||
begin
|
||||
Result:=Caption;
|
||||
end;
|
||||
|
||||
function TWikiHelp.GetProgressCaption: string;
|
||||
begin
|
||||
EnterCritSect;
|
||||
|
@ -44,7 +44,7 @@
|
||||
<PackageName Value="LCL"/>
|
||||
</Item4>
|
||||
</RequiredPackages>
|
||||
<Units Count="3">
|
||||
<Units Count="4">
|
||||
<Unit0>
|
||||
<Filename Value="wikisearchdemo.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
@ -62,6 +62,13 @@
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="WikiHelpManager"/>
|
||||
</Unit2>
|
||||
<Unit3>
|
||||
<Filename Value="wikisearchoptions.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<ComponentName Value="WikiSearchOptsWnd"/>
|
||||
<ResourceBaseClass Value="Form"/>
|
||||
<UnitName Value="WikiSearchOptions"/>
|
||||
</Unit3>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
|
@ -7,7 +7,7 @@ uses
|
||||
cthreads,
|
||||
{$ENDIF}
|
||||
Interfaces, // this includes the LCL widgetset
|
||||
Forms, WikiSearchMain, WikiHelpManager
|
||||
Forms, WikiSearchMain, WikiHelpManager, WikiSearchOptions
|
||||
{ you can add units after this };
|
||||
|
||||
{$R *.res}
|
||||
@ -17,6 +17,7 @@ begin
|
||||
RequireDerivedFormResource := True;
|
||||
Application.Initialize;
|
||||
Application.CreateForm(TWikiSearchDemoForm, WikiSearchDemoForm);
|
||||
Application.CreateForm(TWikiSearchOptsWnd, WikiSearchOptsWnd);
|
||||
Application.Run;
|
||||
end.
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
object WikiSearchDemoForm: TWikiSearchDemoForm
|
||||
Left = 717
|
||||
Left = 635
|
||||
Height = 501
|
||||
Top = 218
|
||||
Top = 222
|
||||
Width = 663
|
||||
Caption = 'WikiSearchDemoForm'
|
||||
ClientHeight = 501
|
||||
@ -75,11 +75,11 @@ object WikiSearchDemoForm: TWikiSearchDemoForm
|
||||
ClientWidth = 320
|
||||
TabOrder = 2
|
||||
object ResultsIpHtmlPanel: TIpHtmlPanel
|
||||
AnchorSideTop.Control = ProgressLabel
|
||||
AnchorSideTop.Control = OptionsButton
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 1
|
||||
Height = 412
|
||||
Top = 88
|
||||
Height = 431
|
||||
Top = 69
|
||||
Width = 318
|
||||
Align = alBottom
|
||||
FixedTypeface = 'Courier New'
|
||||
@ -123,42 +123,14 @@ object WikiSearchDemoForm: TWikiSearchDemoForm
|
||||
Caption = 'SearchLabel'
|
||||
ParentColor = False
|
||||
end
|
||||
object LanguagesEdit: TEdit
|
||||
AnchorSideLeft.Control = LanguagesLabel
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = SearchEdit
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 105
|
||||
Height = 24
|
||||
Top = 37
|
||||
Width = 80
|
||||
BorderSpacing.Around = 6
|
||||
OnChange = LanguagesEditChange
|
||||
ParentShowHint = False
|
||||
ShowHint = True
|
||||
TabOrder = 2
|
||||
Text = 'LanguagesEdit'
|
||||
end
|
||||
object LanguagesLabel: TLabel
|
||||
AnchorSideLeft.Control = SearchPanel
|
||||
AnchorSideTop.Control = LanguagesEdit
|
||||
AnchorSideTop.Side = asrCenter
|
||||
Left = 7
|
||||
Height = 15
|
||||
Top = 42
|
||||
Width = 92
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'LanguagesLabel'
|
||||
ParentColor = False
|
||||
end
|
||||
object ProgressLabel: TLabel
|
||||
AnchorSideLeft.Control = SearchPanel
|
||||
AnchorSideTop.Control = LanguagesEdit
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideTop.Control = OptionsButton
|
||||
AnchorSideTop.Side = asrCenter
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 7
|
||||
Height = 15
|
||||
Top = 67
|
||||
Top = 43
|
||||
Width = 79
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'ProgressLabel'
|
||||
@ -178,6 +150,21 @@ object WikiSearchDemoForm: TWikiSearchDemoForm
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'HideSearchButton'
|
||||
OnClick = HideSearchButtonClick
|
||||
TabOrder = 2
|
||||
end
|
||||
object OptionsButton: TButton
|
||||
AnchorSideLeft.Control = SearchPanel
|
||||
AnchorSideRight.Control = SearchPanel
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 222
|
||||
Height = 26
|
||||
Top = 37
|
||||
Width = 91
|
||||
Anchors = [akTop, akRight]
|
||||
AutoSize = True
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'OptionsButton'
|
||||
OnClick = OptionsButtonClick
|
||||
TabOrder = 3
|
||||
end
|
||||
end
|
||||
|
@ -1,3 +1,23 @@
|
||||
{ Browse and search form for offline wiki
|
||||
|
||||
Copyright (C) 2012 Mattias Gaertner mattias@freepascal.org
|
||||
|
||||
This source is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
This code is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
details.
|
||||
|
||||
A copy of the GNU General Public License is available on the World Wide Web
|
||||
at <http://www.gnu.org/copyleft/gpl.html>. You can also obtain it by writing
|
||||
to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
MA 02111-1307, USA.
|
||||
|
||||
}
|
||||
unit WikiSearchMain;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
@ -6,8 +26,10 @@ interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, math, FileUtil, LazLogger, LazUTF8, LazFileUtils, laz2_DOM,
|
||||
IpHtml, Ipfilebroker, IpMsg, CodeToolManager, CodeCache, Forms, Controls,
|
||||
Graphics, Dialogs, StdCtrls, ExtCtrls, ComCtrls, WikiHelpManager;
|
||||
Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls, ComCtrls,
|
||||
IpHtml, Ipfilebroker, IpMsg,
|
||||
CodeToolManager, CodeCache,
|
||||
WikiHelpManager, WikiSearchOptions;
|
||||
|
||||
type
|
||||
|
||||
@ -24,8 +46,7 @@ type
|
||||
|
||||
TWikiSearchDemoForm = class(TForm)
|
||||
HideSearchButton: TButton;
|
||||
LanguagesEdit: TEdit;
|
||||
LanguagesLabel: TLabel;
|
||||
OptionsButton: TButton;
|
||||
PagePanel: TPanel;
|
||||
PageIpHtmlPanel: TIpHtmlPanel;
|
||||
PageToolBar: TToolBar;
|
||||
@ -44,13 +65,11 @@ type
|
||||
procedure FormDestroy(Sender: TObject);
|
||||
procedure HideSearchButtonClick(Sender: TObject);
|
||||
procedure LanguagesEditChange(Sender: TObject);
|
||||
procedure OnIdle(Sender: TObject; var {%H-}Done: Boolean);
|
||||
procedure IpHtmlPanelHotClick(Sender: TObject);
|
||||
procedure OptionsButtonClick(Sender: TObject);
|
||||
procedure SearchEditChange(Sender: TObject);
|
||||
procedure ShowSearchToolButtonClick(Sender: TObject);
|
||||
procedure Timer1Timer(Sender: TObject);
|
||||
procedure WikiHelpScanned(Sender: TObject);
|
||||
procedure WikiHelpSearched(Sender: TObject);
|
||||
private
|
||||
fLastSearchText: string;
|
||||
fLastLanguages: string;
|
||||
@ -61,12 +80,17 @@ type
|
||||
procedure UpdateProgress;
|
||||
procedure LoadHTML(Target: TIpHtmlPanel; HTML: string); overload;
|
||||
procedure LoadHTML(Target: TIpHtmlPanel; aStream: TStream); overload;
|
||||
procedure ShowOptions;
|
||||
procedure WikiHelpScanned(Sender: TObject);
|
||||
procedure WikiHelpSearched(Sender: TObject);
|
||||
procedure OnIdle(Sender: TObject; var {%H-}Done: Boolean);
|
||||
function GetLanguages: string;
|
||||
public
|
||||
property IdleConnected: boolean read FIdleConnected write SetIdleConnected;
|
||||
end;
|
||||
|
||||
var
|
||||
WikiSearchDemoForm: TWikiSearchDemoForm;
|
||||
WikiSearchDemoForm: TWikiSearchDemoForm = nil;
|
||||
|
||||
implementation
|
||||
|
||||
@ -101,10 +125,8 @@ begin
|
||||
SearchLabel.Caption:='Search:';
|
||||
SearchEdit.Text:='Documentation';
|
||||
SearchEdit.Hint:='Type one or more words separated by space, use " for phrases with spaces';
|
||||
LanguagesLabel.Caption:='Languages:';
|
||||
LanguagesEdit.Text:='';
|
||||
LanguagesEdit.Hint:='Empty for only original/untranslated pages, "de" to include german pages, "-,de" for german pages only';
|
||||
HideSearchButton.Caption:='Hide';
|
||||
OptionsButton.Caption:='Options';
|
||||
|
||||
// page panel
|
||||
ShowSearchToolButton.Caption:='Search';
|
||||
@ -200,6 +222,14 @@ begin
|
||||
IdleConnected:=false;
|
||||
end;
|
||||
|
||||
function TWikiSearchDemoForm.GetLanguages: string;
|
||||
begin
|
||||
if WikiSearchOptsWnd<>nil then
|
||||
Result:=WikiSearchOptsWnd.Languages
|
||||
else
|
||||
Result:='';
|
||||
end;
|
||||
|
||||
procedure TWikiSearchDemoForm.IpHtmlPanelHotClick(Sender: TObject);
|
||||
var
|
||||
HotNode: TIpHtmlNode;
|
||||
@ -244,6 +274,11 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TWikiSearchDemoForm.OptionsButtonClick(Sender: TObject);
|
||||
begin
|
||||
ShowOptions;
|
||||
end;
|
||||
|
||||
procedure TWikiSearchDemoForm.SearchEditChange(Sender: TObject);
|
||||
begin
|
||||
IdleConnected:=true;
|
||||
@ -273,6 +308,8 @@ end;
|
||||
procedure TWikiSearchDemoForm.WikiHelpScanned(Sender: TObject);
|
||||
begin
|
||||
UpdateProgress;
|
||||
if WikiSearchOptsWnd<>nil then
|
||||
WikiSearchOptsWnd.UpdateAvailableLanguages;
|
||||
end;
|
||||
|
||||
procedure TWikiSearchDemoForm.WikiHelpSearched(Sender: TObject);
|
||||
@ -292,7 +329,7 @@ var
|
||||
NewLanguages: String;
|
||||
begin
|
||||
NewSearchText:=UTF8Trim(SearchEdit.Text);
|
||||
NewLanguages:=UTF8Trim(LanguagesEdit.Text);
|
||||
NewLanguages:=GetLanguages;
|
||||
if (NewSearchText=fLastSearchText) and (NewLanguages=fLastLanguages) then
|
||||
exit;
|
||||
fLastSearchText:=NewSearchText;
|
||||
@ -355,5 +392,13 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TWikiSearchDemoForm.ShowOptions;
|
||||
begin
|
||||
if WikiSearchOptsWnd=nil then
|
||||
WikiSearchOptsWnd:=TWikiSearchOptsWnd.Create(Self);
|
||||
WikiSearchOptsWnd.UpdateAvailableLanguages;
|
||||
WikiSearchOptsWnd.ShowOnTop;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
@ -257,15 +257,15 @@ constructor TWiki2FPDocApplication.Create(TheOwner: TComponent);
|
||||
begin
|
||||
inherited Create(TheOwner);
|
||||
StopOnException:=True;
|
||||
FLanguageTags:=WikiCreateCommonLanguageList(true);
|
||||
FLanguageTags:=WikiCreateCommonCodeTagList(true);
|
||||
FFPDocConverter:=TWiki2FPDocConverter.Create;
|
||||
FPDocConverter.LanguageTags:=LanguageTags;
|
||||
FPDocConverter.CodeTags:=LanguageTags;
|
||||
FXHTMLConverter:=TWiki2XHTMLConverter.Create;
|
||||
XHTMLConverter.LanguageTags:=LanguageTags;
|
||||
XHTMLConverter.CodeTags:=LanguageTags;
|
||||
FHTMLConverter:=TWiki2HTMLConverter.Create;
|
||||
HTMLConverter.LanguageTags:=LanguageTags;
|
||||
HTMLConverter.CodeTags:=LanguageTags;
|
||||
FCHMConverter:=TWiki2CHMConverter.Create;
|
||||
CHMConverter.LanguageTags:=LanguageTags;
|
||||
CHMConverter.CodeTags:=LanguageTags;
|
||||
FConverter:=FHTMLConverter;
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user