mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-19 16:19:16 +02:00
* CHMHelp: code formatting/cleanup
git-svn-id: trunk@46572 -
This commit is contained in:
parent
1dfd47f490
commit
808d598c0f
@ -154,7 +154,7 @@ var
|
||||
|
||||
const
|
||||
INVALID_FILE_TYPE = 1;
|
||||
VERSION_STAMP = '2014-09-22'; //used in displaying version in about form etc
|
||||
VERSION_STAMP = '2014-10-16'; //used in displaying version in about form etc
|
||||
|
||||
implementation
|
||||
|
||||
@ -196,6 +196,7 @@ begin
|
||||
l.BorderSpacing.Around := 6;
|
||||
l.Caption := 'LHelp (CHM file viewer)' + LineEnding +
|
||||
'Version ' + VERSION_STAMP + LineEnding +
|
||||
LineEnding +
|
||||
'Copyright (C) Andrew Haines, ' + LineEnding +
|
||||
'Lazarus contributors';
|
||||
l.AutoSize := True;
|
||||
|
@ -149,22 +149,26 @@ begin
|
||||
|
||||
Result:=shrViewerError;
|
||||
ErrMsg:='';
|
||||
if (not Node.URLValid) then begin
|
||||
if (not Node.URLValid) then
|
||||
begin
|
||||
ErrMsg:='TLHelpConnector.ShowNode Node.URLValid=false';
|
||||
exit;
|
||||
end;
|
||||
if (Node.URL='') then begin
|
||||
if (Node.URL='') then
|
||||
begin
|
||||
ErrMsg:='TLHelpConnector.ShowNode Node.URL empty';
|
||||
exit;
|
||||
end;
|
||||
|
||||
SplitURL(Node.URL,URLScheme,URLPath,URLParams);
|
||||
CHMFilename:=CleanAndExpandFilename(URLPath);
|
||||
if not FileExistsUTF8(CHMFilename) then begin
|
||||
if not FileExistsUTF8(CHMFilename) then
|
||||
begin
|
||||
ErrMsg:='chm file "'+CHMFilename+'" not found';
|
||||
exit;
|
||||
end;
|
||||
if DirPathExists(CHMFilename) then begin
|
||||
if DirPathExists(CHMFilename) then
|
||||
begin
|
||||
ErrMsg:='invalid chm file "'+CHMFilename+'"';
|
||||
exit;
|
||||
end;
|
||||
@ -172,21 +176,24 @@ begin
|
||||
SubPath:='';
|
||||
if (URLParams<>'') and (URLParams[1]='?') then
|
||||
Delete(URLParams,1,1);
|
||||
if LeftStr(URLParams,length(CHMPathParam)+1)=CHMPathParam+'=' then begin
|
||||
if LeftStr(URLParams,length(CHMPathParam)+1)=CHMPathParam+'=' then
|
||||
begin
|
||||
SubPath:=URLParams;
|
||||
Delete(SubPath,1,length(CHMPathParam)+1);
|
||||
end;
|
||||
|
||||
if Connection=nil then begin
|
||||
if Connection=nil then
|
||||
begin
|
||||
// create a connection to lhelp:
|
||||
FConnection := TLHelpConnection.Create;
|
||||
Connection.ProcessWhileWaiting := @Application.ProcessMessages;
|
||||
end;
|
||||
|
||||
if Connection.ServerRunning = false then begin
|
||||
if Connection.ServerRunning = false then
|
||||
begin
|
||||
// Use '_lhlpctl_' in case application developer uses SimpleIPC
|
||||
// and also uses the exe name followed by the process ID.
|
||||
// Follow help protocol specs defined in
|
||||
// See help protocol specs defined in
|
||||
// http://wiki.lazarus.freepascal.org/Help_protocol
|
||||
// Use process id in order to avoid conflicts when multiple entries are running
|
||||
IPCFile:=LowerCase(ExtractFileName(Application.ExeName))+
|
||||
@ -207,12 +214,14 @@ begin
|
||||
Path:=Path+GetExeExt;
|
||||
|
||||
// search in Path
|
||||
if (Path<>'') and (ExtractFilePath(Path)='') then begin
|
||||
if (Path<>'') and (ExtractFilePath(Path)='') then
|
||||
begin
|
||||
s:=FindDefaultExecutablePath(Path);
|
||||
if s<>'' then Path:=s;
|
||||
end;
|
||||
|
||||
if not FileExistsUTF8(Path) then begin
|
||||
if not FileExistsUTF8(Path) then
|
||||
begin
|
||||
ErrMsg:='The chm viewer program lhelp was not found at "'+Path+'"';
|
||||
exit;
|
||||
end;
|
||||
@ -239,7 +248,8 @@ procedure TLHelpConnector.Assign(Source: TPersistent);
|
||||
var
|
||||
Src: TLHelpConnector;
|
||||
begin
|
||||
if Source is TLHelpConnector then begin
|
||||
if Source is TLHelpConnector then
|
||||
begin
|
||||
Src:=TLHelpConnector(Source);
|
||||
LHelpPath:=Src.LHelpPath;
|
||||
end;
|
||||
@ -295,9 +305,12 @@ function TCHMHelpDatabase.ShowHelp(Query: THelpQuery; BaseNode,
|
||||
begin
|
||||
ErrMsg:='';
|
||||
Result:=shrContextNotFound;
|
||||
if NewNode.URLValid then begin
|
||||
if NewNode.URLValid then
|
||||
begin
|
||||
Result:=ShowURL(NewNode.URL,NewNode.Title,ErrMsg);
|
||||
end else begin
|
||||
end
|
||||
else
|
||||
begin
|
||||
Result:=shrContextNotFound;
|
||||
ErrMsg:='TCHMHelpDatabase.ShowHelp Node.URLValid=false Node.URL="'+NewNode.URL+'"';
|
||||
end;
|
||||
@ -311,7 +324,8 @@ var
|
||||
begin
|
||||
//DebugLn('TCHMHelpDatabase.ShowURL A URL="',URL,'" Title="',Title,'"');
|
||||
|
||||
if not FileExistsUTF8(Filename) then begin
|
||||
if not FileExistsUTF8(Filename) then
|
||||
begin
|
||||
ErrMsg:='chm help file "'+Filename+'" not found';
|
||||
exit(shrDatabaseNotFound);
|
||||
end;
|
||||
@ -338,9 +352,10 @@ begin
|
||||
Result:=inherited GetNodesForKeyword(HelpKeyword, ListOfNodes, ErrMsg);
|
||||
if Result<>shrSuccess then exit;
|
||||
|
||||
if not (csDesigning in ComponentState)
|
||||
and (KeywordPrefix<>'')
|
||||
and (LeftStr(HelpKeyword,length(KeywordPrefix))=KeywordPrefix) then begin
|
||||
if not (csDesigning in ComponentState) and
|
||||
(KeywordPrefix<>'') and
|
||||
(LeftStr(HelpKeyword,length(KeywordPrefix))=KeywordPrefix) then
|
||||
begin
|
||||
// HelpKeyword starts with KeywordPrefix -> add default node
|
||||
if FHelpNode=nil then
|
||||
FHelpNode:=THelpNode.CreateURL(Self,'','');
|
||||
|
@ -211,20 +211,23 @@ begin
|
||||
|
||||
fServerOut.Active := False;
|
||||
fServerOut.ServerID := NameForServer;
|
||||
if not ServerRunning then begin
|
||||
if not ServerRunning then
|
||||
begin
|
||||
Cmd := ServerExe + ' --ipcname ' + NameForServer;
|
||||
if Hide then Cmd := Cmd + ' --hide';
|
||||
{$IFDEF darwin}
|
||||
if DirectoryExistsUTF8(ServerEXE+'.app') then
|
||||
ServerEXE+='.app';
|
||||
debugln(['TLHelpConnection.StartHelpServer ',ServerEXE]);
|
||||
if DirectoryExistsUTF8(ServerEXE) then begin
|
||||
if DirectoryExistsUTF8(ServerEXE) then
|
||||
begin
|
||||
// application bundle
|
||||
// to put lhelp into the foreground, use "open -n"
|
||||
Cmd:='/usr/bin/open -n '+ServerEXE+' --args --ipcname ' + NameForServer
|
||||
end;
|
||||
{$ENDIF}
|
||||
with TProcessUTF8.Create(nil) do begin
|
||||
with TProcessUTF8.Create(nil) do
|
||||
begin
|
||||
InheritHandles := false;
|
||||
ShowWindow:=swoShowNormal;
|
||||
CommandLine := Cmd;
|
||||
@ -233,16 +236,19 @@ begin
|
||||
Free;
|
||||
end;
|
||||
// give the server some time to get started
|
||||
for X := 0 to 40 do begin
|
||||
for X := 0 to 40 do
|
||||
begin
|
||||
// use fServerOut.ServerRunning here instead of Self.ServerRunning to avoid a race condition
|
||||
if not fServerOut.ServerRunning then Sleep(200);
|
||||
end;
|
||||
end;
|
||||
if fServerOut.ServerRunning then begin
|
||||
if fServerOut.ServerRunning then
|
||||
begin
|
||||
fServerOut.Active := True;
|
||||
Result := True;
|
||||
end
|
||||
else begin
|
||||
else
|
||||
begin
|
||||
debugln('Could not get lhelp running with command '+Cmd);
|
||||
end;
|
||||
end;
|
||||
|
@ -47,8 +47,10 @@ type
|
||||
|
||||
TChmHelpViewer = class(THelpViewer)
|
||||
private
|
||||
// Full path and filename to help executable (lhelp)
|
||||
fHelpExe: String;
|
||||
fHelpLabel: String; //ID used for SimpleIPC identification
|
||||
// ID used for SimpleIPC identification:
|
||||
fHelpLabel: String;
|
||||
fHelpConnection: TLHelpConnection;
|
||||
fCHMSearchPath: String;
|
||||
fHelpExeParams: String;
|
||||
|
Loading…
Reference in New Issue
Block a user