chmhelp: ability to use different chm viewers

git-svn-id: trunk@32295 -
This commit is contained in:
mattias 2011-09-11 20:51:04 +00:00
parent ccd95aed3e
commit 36dc00ab92
2 changed files with 44 additions and 6 deletions

View File

@ -95,9 +95,13 @@
<CompilerOptions> <CompilerOptions>
<Version Value="10"/> <Version Value="10"/>
<PathDelim Value="\"/> <PathDelim Value="\"/>
<Target>
<Filename Value="lhelp"/>
</Target>
<SearchPaths> <SearchPaths>
<Libraries Value="\emul\linux\x86\lib\;\emul\linux\x86\usr\lib32\"/> <Libraries Value="\emul\linux\x86\lib\;\emul\linux\x86\usr\lib32\"/>
<OtherUnitFiles Value="..\..\..\..\fpc\packages\chm\src"/> <OtherUnitFiles Value="..\..\..\..\fpc\packages\chm\src"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
<SrcPath Value="$(LazarusDir)\lcl;$(LazarusDir)\lcl\interfaces\$(LCLWidgetType)"/> <SrcPath Value="$(LazarusDir)\lcl;$(LazarusDir)\lcl\interfaces\$(LCLWidgetType)"/>
</SearchPaths> </SearchPaths>
<Parsing> <Parsing>

View File

@ -36,6 +36,7 @@ type
fHelpLabel: String; fHelpLabel: String;
fHelpConnection: TLHelpConnection; fHelpConnection: TLHelpConnection;
fChmsFilePath: String; fChmsFilePath: String;
fHelpExeParams: String;
function GetHelpEXE: String; function GetHelpEXE: String;
function DBFindViewer({%H-}HelpDB: THelpDatabase; {%H-}const MimeType: string; function DBFindViewer({%H-}HelpDB: THelpDatabase; {%H-}const MimeType: string;
var {%H-}ErrMsg: string; out Viewer: THelpViewer): TShowHelpResult; var {%H-}ErrMsg: string; out Viewer: THelpViewer): TShowHelpResult;
@ -52,7 +53,7 @@ type
constructor Create(TheOwner: TComponent); override; constructor Create(TheOwner: TComponent); override;
destructor Destroy; override; destructor Destroy; override;
function SupportsTableOfContents: boolean; override; function SupportsTableOfContents: boolean; override;
procedure ShowTableOfContents(Node: THelpNode); override; procedure ShowTableOfContents({%H-}Node: THelpNode); override;
function SupportsMimeType(const AMimeType: string): boolean; override; function SupportsMimeType(const AMimeType: string): boolean; override;
function ShowNode(Node: THelpNode; var ErrMsg: string): TShowHelpResult; override; function ShowNode(Node: THelpNode; var ErrMsg: string): TShowHelpResult; override;
//procedure Hide; virtual; //procedure Hide; virtual;
@ -64,11 +65,13 @@ type
property HelpEXE: String read GetHelpEXE write SetHelpEXE; property HelpEXE: String read GetHelpEXE write SetHelpEXE;
property HelpLabel: String read GetHelpLabel write SetHelpLabel; property HelpLabel: String read GetHelpLabel write SetHelpLabel;
property HelpFilesPath: String read fChmsFilePath write SetChmsFilePath; property HelpFilesPath: String read fChmsFilePath write SetChmsFilePath;
property HelpExeParams: String read fHelpExeParams write fHelpExeParams;
end; end;
procedure Register; procedure Register;
implementation implementation
uses Process, MacroIntf, InterfaceBase, Forms, Dialogs, HelpFPDoc, IDEMsgIntf; uses Process, MacroIntf, InterfaceBase, Forms, Dialogs, HelpFPDoc, IDEMsgIntf;
function FixSlash(AStr: String): String; function FixSlash(AStr: String): String;
@ -187,14 +190,16 @@ begin
then then
Exit; Exit;
WS := ' --ws='+LCLPlatformDirNames[WidgetSet.LCLPlatform]+' '; WS := '--ws='+LCLPlatformDirNames[WidgetSet.LCLPlatform];
//Result := MessageDlg('The help viewer is not compiled yet. Try to compile it now?', mtConfirmation, mbYesNo ,0); //Result := MessageDlg('The help viewer is not compiled yet. Try to compile it now?', mtConfirmation, mbYesNo ,0);
//if Result <> mrYes then //if Result <> mrYes then
// Exit; // Exit;
Proc := TProcess.Create(nil); Proc := TProcess.Create(nil);
Proc.CommandLine := Lazbuild + WS + LHelpProject; Proc.Executable := Utf8ToSys(Lazbuild);
Proc.Parameters.Add(WS);
Proc.Parameters.Add(Utf8ToSys(LHelpProject));
Proc.Options := [poUsePipes, poStderrToOutPut]; Proc.Options := [poUsePipes, poStderrToOutPut];
Proc.Execute; Proc.Execute;
@ -338,6 +343,7 @@ var
Url: String; Url: String;
Res: TLHelpResponse; Res: TLHelpResponse;
DocsDir: String; DocsDir: String;
Proc: TProcess;
begin begin
if Pos('file://', Node.URL) = 1 then if Pos('file://', Node.URL) = 1 then
begin begin
@ -345,7 +351,7 @@ begin
Exit; Exit;
end; end;
Result:=shrNone; Result:=shrNone;
if CheckBuildLHelp <> mrOK then begin if (ExtractFileNameOnly(HelpEXE) = 'lhelp') and (CheckBuildLHelp <> mrOK) then begin
ErrMsg := 'The program "' + HelpEXE + '" doesn''t seem to exist'+LineEnding+ ErrMsg := 'The program "' + HelpEXE + '" doesn''t seem to exist'+LineEnding+
'or could not be built!'; 'or could not be built!';
Exit(shrViewerNotFound); Exit(shrViewerNotFound);
@ -376,8 +382,34 @@ begin
FileName := IncludeTrailingPathDelimiter(DocsDir)+FileName; FileName := IncludeTrailingPathDelimiter(DocsDir)+FileName;
fHelpConnection.StartHelpServer(HelpLabel, HelpExe); if ExtractFileNameOnly(HelpExe) = 'lhelp' then begin
Res := fHelpConnection.OpenURL(FileName, Url); fHelpConnection.StartHelpServer(HelpLabel, HelpExe);
Res := fHelpConnection.OpenURL(FileName, Url);
end else begin
if Trim(fHelpExeParams) = '' then
begin
Result := shrViewerError;
ErrMsg := 'If you do not use "lhelp" as viewer you have to setup '
+ 'HelpExeParams correctly in' + sLineBreak
+ 'Environment Options -> Help -> Help Options -> '
+ 'under HelpViewers - CHM Help Viewer' + sLineBreak
+ 'e.g. for HH.EXE (HTML Help in Windows) it must be' + sLineBreak
+ ' "%s::%s"' + sLineBreak
+ 'where first %s will be replaced by CHM file name' + sLineBreak
+ 'and the second one will be replaced by URL';
Exit;
end;
Proc := TProcess.Create(nil);
try
Proc.Executable := Utf8ToSys(fHelpExe);
Proc.Parameters.Add(Utf8ToSys(Format(fHelpExeParams, [FileName, Url])));
Proc.Execute;
Res := srSuccess;
except
Res := srUnknown;
end;
Proc.Free;
end;
case Res of case Res of
srSuccess: Result := shrSuccess; srSuccess: Result := shrSuccess;
@ -406,6 +438,7 @@ end;
procedure TChmHelpViewer.Load(Storage: TConfigStorage); procedure TChmHelpViewer.Load(Storage: TConfigStorage);
begin begin
HelpEXE:=Storage.GetValue('CHMHelp/Exe',''); HelpEXE:=Storage.GetValue('CHMHelp/Exe','');
HelpExeParams := Storage.GetValue('CHMHelp/ExeParams','');
HelpLabel:=Storage.GetValue('CHMHelp/Name','lazhelp'); HelpLabel:=Storage.GetValue('CHMHelp/Name','lazhelp');
HelpFilesPath := Storage.GetValue('CHMHelp/FilesPath',''); HelpFilesPath := Storage.GetValue('CHMHelp/FilesPath','');
end; end;
@ -413,6 +446,7 @@ end;
procedure TChmHelpViewer.Save(Storage: TConfigStorage); procedure TChmHelpViewer.Save(Storage: TConfigStorage);
begin begin
Storage.SetDeleteValue('CHMHelp/Exe',HelpEXE,''); Storage.SetDeleteValue('CHMHelp/Exe',HelpEXE,'');
Storage.SetDeleteValue('CHMHelp/ExeParams',HelpExeParams,'');
Storage.SetDeleteValue('CHMHelp/Name',HelpLabel,'lazhelp'); Storage.SetDeleteValue('CHMHelp/Name',HelpLabel,'lazhelp');
Storage.SetDeleteValue('CHMHelp/FilesPath',HelpFilesPath,''); Storage.SetDeleteValue('CHMHelp/FilesPath',HelpFilesPath,'');
end; end;