From 5e7cd09324d6b75573f3145a78acb3e7ede80fbe Mon Sep 17 00:00:00 2001 From: mattias Date: Sun, 29 Jan 2012 20:40:39 +0000 Subject: [PATCH] example: idehelp: fpc keywords git-svn-id: trunk@35026 - --- .gitattributes | 4 ++ examples/idehelp/demoidehelp.lpk | 37 ++++++++++ examples/idehelp/demoidehelp.pas | 21 ++++++ examples/idehelp/myidehelp.lfm | 8 +++ examples/idehelp/myidehelp.pas | 113 +++++++++++++++++++++++++++++++ 5 files changed, 183 insertions(+) create mode 100644 examples/idehelp/demoidehelp.lpk create mode 100644 examples/idehelp/demoidehelp.pas create mode 100644 examples/idehelp/myidehelp.lfm create mode 100644 examples/idehelp/myidehelp.pas diff --git a/.gitattributes b/.gitattributes index 63ec09c844..eebe462d34 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/examples/idehelp/demoidehelp.lpk b/examples/idehelp/demoidehelp.lpk new file mode 100644 index 0000000000..25ffbbc4fc --- /dev/null +++ b/examples/idehelp/demoidehelp.lpk @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/idehelp/demoidehelp.pas b/examples/idehelp/demoidehelp.pas new file mode 100644 index 0000000000..6462e91c5f --- /dev/null +++ b/examples/idehelp/demoidehelp.pas @@ -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. diff --git a/examples/idehelp/myidehelp.lfm b/examples/idehelp/myidehelp.lfm new file mode 100644 index 0000000000..83c8455597 --- /dev/null +++ b/examples/idehelp/myidehelp.lfm @@ -0,0 +1,8 @@ +object MyHelpSetupDialog: TMyHelpSetupDialog + Left = 250 + Height = 466 + Top = 250 + Width = 557 + Caption = 'MyHelpSetupDialog' + LCLVersion = '0.9.31' +end diff --git a/examples/idehelp/myidehelp.pas b/examples/idehelp/myidehelp.pas new file mode 100644 index 0000000000..290dbaa960 --- /dev/null +++ b/examples/idehelp/myidehelp.pas @@ -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. +