mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-15 15:09:28 +02:00
Help for FPC keywords: implemented
git-svn-id: trunk@9186 -
This commit is contained in:
parent
34412e24ab
commit
d05b7c6e0e
@ -211,18 +211,14 @@ begin
|
||||
if sl=nil then
|
||||
sl:=TStringList.Create;
|
||||
try
|
||||
try
|
||||
sl.LoadFromFile(Filename);
|
||||
Result:=mrOk;
|
||||
except
|
||||
on E: Exception do begin
|
||||
MessageDlg('Error','Error loading '+ListTitle+' from'#13
|
||||
+Filename+#13#13
|
||||
+E.Message,mtError,[mbOk],0);
|
||||
end;
|
||||
sl.LoadFromFile(Filename);
|
||||
Result:=mrOk;
|
||||
except
|
||||
on E: Exception do begin
|
||||
MessageDlg('Error','Error loading '+ListTitle+' from'#13
|
||||
+Filename+#13#13
|
||||
+E.Message,mtError,[mbOk],0);
|
||||
end;
|
||||
finally
|
||||
sl.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -449,7 +449,8 @@ end;
|
||||
function THelpManager.ShowHelpForSourcePosition(const Filename: string;
|
||||
const CodePos: TPoint; var ErrMsg: string): TShowHelpResult;
|
||||
|
||||
procedure FindHelpForFPCKeyWord(const KeyWord: string);
|
||||
function ShowHelpForFPCKeyWord(const KeyWord: string): TShowHelpResult;
|
||||
// true: help found
|
||||
var
|
||||
RefFilename: String;
|
||||
i: Integer;
|
||||
@ -459,6 +460,7 @@ function THelpManager.ShowHelpForSourcePosition(const Filename: string;
|
||||
FileEndPos: LongInt;
|
||||
HTMLFilename: String;
|
||||
begin
|
||||
Result:=shrHelpNotFound;
|
||||
if Keyword='' then exit;
|
||||
RefFilename:=HelpOpts.FPCDocsHTMLDirectory;
|
||||
if (RefFilename='') then exit;
|
||||
@ -482,7 +484,9 @@ function THelpManager.ShowHelpForSourcePosition(const Filename: string;
|
||||
HTMLFilename:=copy(Line,FileStartPos,FileEndPos-FileStartPos);
|
||||
HTMLFilename:=AppendPathDelim(HelpOpts.FPCDocsHTMLDirectory)+'ref'
|
||||
+PathDelim+HTMLFilename;
|
||||
|
||||
Result:=ShowHelpFileOrError(HTMLFilename,
|
||||
'FPC help for keyword "'+KeyWord+'"',
|
||||
'text/html');
|
||||
break;
|
||||
end;
|
||||
end;
|
||||
@ -491,19 +495,21 @@ function THelpManager.ShowHelpForSourcePosition(const Filename: string;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure CollectKeyWords(CodeBuffer: TCodeBuffer);
|
||||
function CollectKeyWords(CodeBuffer: TCodeBuffer): TShowHelpResult;
|
||||
// true: help found
|
||||
var
|
||||
p: Integer;
|
||||
IdentStart, IdentEnd: integer;
|
||||
KeyWord: String;
|
||||
begin
|
||||
Result:=shrHelpNotFound;
|
||||
p:=0;
|
||||
CodeBuffer.LineColToPosition(CodePos.Y,CodePos.X,p);
|
||||
if p<1 then exit;
|
||||
GetIdentStartEndAtPosition(CodeBuffer.Source,p,IdentStart,IdentEnd);
|
||||
if IdentEnd<=IdentStart then exit;
|
||||
KeyWord:=copy(CodeBuffer.Source,IdentStart,IdentEnd-IdentStart);
|
||||
FindHelpForFPCKeyWord(KeyWord);
|
||||
Result:=ShowHelpForFPCKeyWord(KeyWord);
|
||||
end;
|
||||
|
||||
function ConvertCodePosToPascalHelpContext(ACodePos: PCodeXYPosition
|
||||
@ -656,7 +662,8 @@ begin
|
||||
if mrOk<>LoadCodeBuffer(CodeBuffer,FileName,[lbfCheckIfText]) then
|
||||
exit;
|
||||
|
||||
CollectKeyWords(CodeBuffer);
|
||||
Result:=CollectKeyWords(CodeBuffer);
|
||||
if Result=shrSuccess then exit;
|
||||
CollectDeclarations(CodeBuffer);
|
||||
end;
|
||||
|
||||
|
@ -557,6 +557,8 @@ type
|
||||
procedure ShowError(ShowResult: TShowHelpResult; const ErrMsg: string); virtual; abstract;
|
||||
function GetBaseURLForBasePathObject(BasePathObject: TObject): string; virtual;
|
||||
function GetBaseDirectoryForBasePathObject(BasePathObject: TObject): string; virtual;
|
||||
function FindViewer(const MimeType: string; var ErrMsg: string;
|
||||
var Viewer: THelpViewer): TShowHelpResult; virtual;
|
||||
public
|
||||
// show help for ...
|
||||
function ShowHelpForNodes(Query: THelpQuery; Nodes: THelpNodeQueryList;
|
||||
@ -575,6 +577,8 @@ type
|
||||
var ErrMsg: string): TShowHelpResult; virtual;
|
||||
function ShowHelpForClass(Query: THelpQueryClass;
|
||||
var ErrMsg: string): TShowHelpResult; virtual;
|
||||
function ShowHelp(const Filename, Title, MimeType: string;
|
||||
var ErrMsg: string): TShowHelpResult; virtual;
|
||||
// search registered items in all databases
|
||||
function GetNodesForKeyword(const HelpKeyword: string;
|
||||
var ListOfNodes: THelpNodeQueryList;
|
||||
@ -749,6 +753,12 @@ function ShowHelpForMessageLine(const MessageLine: string;
|
||||
MessageParts: TStrings; var ErrMsg: string): TShowHelpResult;
|
||||
function ShowHelpOrErrorForMessageLine(const MessageLine: string;
|
||||
MessageParts: TStrings): TShowHelpResult;
|
||||
|
||||
// view help
|
||||
function ShowHelpFile(const Filename, Title, MimeType: string;
|
||||
var ErrMsg: string): TShowHelpResult;
|
||||
function ShowHelpFileOrError(const Filename, Title, MimeType: string
|
||||
): TShowHelpResult;
|
||||
|
||||
// URL functions
|
||||
function FilenameToURL(const Filename: string): string;
|
||||
@ -875,6 +885,22 @@ begin
|
||||
HelpDatabases.ShowError(Result,ErrMsg);
|
||||
end;
|
||||
|
||||
function ShowHelpFile(const Filename, Title, MimeType: string;
|
||||
var ErrMsg: string): TShowHelpResult;
|
||||
begin
|
||||
Result:=HelpDatabases.ShowHelp(Filename,Title,MimeType,ErrMsg);
|
||||
end;
|
||||
|
||||
function ShowHelpFileOrError(const Filename, Title, MimeType: string
|
||||
): TShowHelpResult;
|
||||
var
|
||||
ErrMsg: String;
|
||||
begin
|
||||
ErrMsg:='';
|
||||
Result:=ShowHelpFile(Filename,Title,MimeType,ErrMsg);
|
||||
HelpDatabases.ShowError(Result,ErrMsg);
|
||||
end;
|
||||
|
||||
function FilenameToURL(const Filename: string): string;
|
||||
var
|
||||
i: Integer;
|
||||
@ -1523,6 +1549,26 @@ begin
|
||||
Result:=AppendPathDelim(Result);
|
||||
end;
|
||||
|
||||
function THelpDatabases.FindViewer(const MimeType: string; var ErrMsg: string;
|
||||
var Viewer: THelpViewer): TShowHelpResult;
|
||||
var
|
||||
Viewers: TList;
|
||||
begin
|
||||
Viewer:=nil;
|
||||
Viewers:=HelpViewers.GetViewersSupportingMimeType(MimeType);
|
||||
try
|
||||
if (Viewers=nil) or (Viewers.Count=0) then begin
|
||||
ErrMsg:='Did not find a viewer for help type "'+MimeType+'"';
|
||||
Result:=shrViewerNotFound;
|
||||
end else begin
|
||||
Viewer:=THelpViewer(Viewers[0]);
|
||||
Result:=shrSuccess;
|
||||
end;
|
||||
finally
|
||||
Viewers.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
function THelpDatabases.ShowHelpForNodes(Query: THelpQuery;
|
||||
Nodes: THelpNodeQueryList; var ErrMsg: string): TShowHelpResult;
|
||||
var
|
||||
@ -1751,6 +1797,27 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function THelpDatabases.ShowHelp(const Filename, Title, MimeType: string;
|
||||
var ErrMsg: string): TShowHelpResult;
|
||||
var
|
||||
Viewer: THelpViewer;
|
||||
Node: THelpNode;
|
||||
begin
|
||||
ErrMsg:='';
|
||||
// get a viewer for this file
|
||||
Result:=FindViewer(MimeType,ErrMsg,Viewer);
|
||||
if Result<>shrSuccess then exit;
|
||||
|
||||
// call viewer
|
||||
Node:=nil;
|
||||
try
|
||||
Node:=THelpNode.CreateURL(nil,Title,FilenameToURL(Filename));
|
||||
Result:=Viewer.ShowNode(Node,ErrMsg);
|
||||
finally
|
||||
Node.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
function THelpDatabases.GetNodesForKeyword(const HelpKeyword: string;
|
||||
var ListOfNodes: THelpNodeQueryList; var ErrMsg: string): TShowHelpResult;
|
||||
// if ListOfNodes<>nil then new nodes will be appended
|
||||
|
Loading…
Reference in New Issue
Block a user