example: idehelp: fpc keywords

git-svn-id: trunk@35026 -
This commit is contained in:
mattias 2012-01-29 20:40:39 +00:00
parent 139a3f1c56
commit 5e7cd09324
5 changed files with 183 additions and 0 deletions

4
.gitattributes vendored
View File

@ -3804,6 +3804,10 @@ examples/icons/project1.lpr svneol=native#text/plain
examples/icons/project1.res -text
examples/icons/unit1.lfm svneol=native#text/plain
examples/icons/unit1.pas svneol=native#text/pascal
examples/idehelp/demoidehelp.lpk svneol=native#text/plain
examples/idehelp/demoidehelp.pas svneol=native#text/plain
examples/idehelp/myidehelp.lfm svneol=native#text/plain
examples/idehelp/myidehelp.pas svneol=native#text/plain
examples/idequickfix/quickfixdemo1.pas svneol=native#text/plain
examples/idequickfix/quickfixexample.lpk svneol=native#text/plain
examples/idequickfix/quickfixexample.pas svneol=native#text/plain

View File

@ -0,0 +1,37 @@
<?xml version="1.0"?>
<CONFIG>
<Package Version="4">
<Name Value="DemoIDEHelp"/>
<CompilerOptions>
<Version Value="11"/>
<SearchPaths>
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Other>
<CompilerMessages>
<MsgFileName Value=""/>
</CompilerMessages>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
<Files Count="1">
<Item1>
<Filename Value="myidehelp.pas"/>
<HasRegisterProc Value="True"/>
<UnitName Value="myidehelp"/>
</Item1>
</Files>
<Type Value="RunAndDesignTime"/>
<RequiredPkgs Count="1">
<Item1>
<PackageName Value="IDEIntf"/>
</Item1>
</RequiredPkgs>
<UsageOptions>
<UnitPath Value="$(PkgOutDir)"/>
</UsageOptions>
<PublishOptions>
<Version Value="2"/>
</PublishOptions>
</Package>
</CONFIG>

View File

@ -0,0 +1,21 @@
{ This file was automatically created by Lazarus. Do not edit!
This source is only used to compile and install the package.
}
unit DemoIDEHelp;
interface
uses
myidehelp, LazarusPackageIntf;
implementation
procedure Register;
begin
RegisterUnit('myidehelp', @myidehelp.Register);
end;
initialization
RegisterPackage('DemoIDEHelp', @Register);
end.

View File

@ -0,0 +1,8 @@
object MyHelpSetupDialog: TMyHelpSetupDialog
Left = 250
Height = 466
Top = 250
Width = 557
Caption = 'MyHelpSetupDialog'
LCLVersion = '0.9.31'
end

View File

@ -0,0 +1,113 @@
unit myidehelp;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, LazHelpHTML,
LazHelpIntf, HelpIntfs, IDEHelpIntf, IDEDialogs;
type
{ TMyFPCKeywordHelpDatabase
Help for FPC keywords. }
TMyFPCKeywordHelpDatabase = class(THTMLHelpDatabase)
private
FKeywordPrefixNode: THelpNode;
public
KeywordToText: TStrings; // every line has the format: Keyword=Text
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
function GetNodesForKeyword(const HelpKeyword: string;
var ListOfNodes: THelpNodeQueryList; var {%H-}ErrMsg: string
): TShowHelpResult; override;
function ShowHelp(Query: THelpQuery; {%H-}BaseNode, {%H-}NewNode: THelpNode;
{%H-}QueryItem: THelpQueryItem;
var {%H-}ErrMsg: string): TShowHelpResult; override;
end;
TMyHelpSetupDialog = class(TForm)
private
public
end;
var
MyHelpSetupDialog: TMyHelpSetupDialog;
procedure Register;
implementation
procedure Register;
begin
HelpDatabases.CreateHelpDatabase('MyFPCKeyWordHelpDB',TMyFPCKeywordHelpDatabase,true);
end;
{ TMyFPCKeywordHelpDatabase }
constructor TMyFPCKeywordHelpDatabase.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
KeywordToText:=TStringList.Create;
KeywordToText.Add('procedure=Named code block');
end;
destructor TMyFPCKeywordHelpDatabase.Destroy;
begin
FreeAndNil(KeywordToText);
inherited Destroy;
end;
function TMyFPCKeywordHelpDatabase.GetNodesForKeyword(
const HelpKeyword: string; var ListOfNodes: THelpNodeQueryList;
var ErrMsg: string): TShowHelpResult;
var
KeyWord: String;
i: Integer;
begin
Result:=shrHelpNotFound;
if (csDesigning in ComponentState) then exit;
if (FPCKeyWordHelpPrefix<>'')
and (LeftStr(HelpKeyword,length(FPCKeyWordHelpPrefix))=FPCKeyWordHelpPrefix) then begin
// HelpKeyword starts with KeywordPrefix
KeyWord:=copy(HelpKeyword,length(FPCKeyWordHelpPrefix)+1,length(HelpKeyword));
i:=KeywordToText.IndexOfName(lowercase(KeyWord));
if i>=0 then begin
// this help database knows this keyword
// => add a node, so that if there are several possibilities the IDE can
// show the user a dialog to choose
if FKeywordPrefixNode=nil then
FKeywordPrefixNode:=THelpNode.CreateURL(Self,'','');
FKeywordPrefixNode.Title:='Pascal keyword '+KeyWord;
CreateNodeQueryListAndAdd(FKeywordPrefixNode,nil,ListOfNodes,true);
Result:=shrSuccess;
end;
end;
end;
function TMyFPCKeywordHelpDatabase.ShowHelp(Query: THelpQuery; BaseNode,
NewNode: THelpNode; QueryItem: THelpQueryItem; var ErrMsg: string
): TShowHelpResult;
var
KeywordQuery: THelpQueryKeyword;
KeyWord: String;
Txt: String;
begin
Result:=shrHelpNotFound;
if not (Query is THelpQueryKeyword) then exit;
KeywordQuery:=THelpQueryKeyword(Query);
KeyWord:=copy(KeywordQuery.Keyword,length(FPCKeyWordHelpPrefix)+1,length(KeywordQuery.Keyword));
Txt:=KeywordToText.Values[lowercase(KeyWord)];
IDEMessageDialog('My fpc keyword key',
'The keyword "'+KeyWord+'":'#13#13
+Txt,mtInformation,[mbOk]);
Result:=shrSuccess;
end;
{$R *.lfm}
end.