Difference between revisions of "Creating IDE Help"

From Free Pascal wiki
Jump to navigationJump to search
Line 1: Line 1:
 
{{Creating IDE Help}}
 
{{Creating IDE Help}}
 +
 +
=Overview=
 +
 +
On the one hand the IDE can search help for various things and on the other there are various help sources using various help formats. Here is a short list to understand the complexity:
 +
  
 
== Help for LCL units ==
 
== Help for LCL units ==

Revision as of 13:17, 5 February 2012

Template:Creating IDE Help

Overview

On the one hand the IDE can search help for various things and on the other there are various help sources using various help formats. Here is a short list to understand the complexity:


Help for LCL units

Whenever the user presses F1 for an Object Inspector property or on an identifier in the source editor the IDE searches the declaration and invokes the HTML viewer for the fpdoc item. The items can be edited easily via the FPDoc Editor tool.

You can see the state of the LCL documentation here: LCL Documentation Roadmap.

Help for IDE windows

This feature exists since 0.9.15.

The help for the IDE windows (i.e. 'Object Inspector' or the 'Compiler Options') are documented in this wiki. The IDE has a mapping file docs/IDEWindowHelpTree.xml, which contains the paths from the various IDE forms/controls to wiki pages. This mapping file is edited via an editor that is shown at any place in the IDE via Ctrl+Shift+F1, except for controls, that catches all keys, like synedit. You can set the short cut in the editor options -> key mapping.

The root page of the IDE window docs is Lazarus IDE.

Example

  • Open the project options: Project / Project Options
  • Open the help editor: Shift+Ctrl+F1

HelpEditor1.png

  • To the left you can see all controls of the project options dialog. You can see there are also the compiler options.
  • Select the ProjectApplicationOptionsFrame
  • Click Create Help node. This will create a new item on the right.
  • Check Has Help
  • Check Is a root control. All controls on the frame should use the help on our new help page.
  • Change the path to Project_Options

HelpEditorProjectOptions.png

Redirect

The TreeView in the IDE options dialog redirects the help to the help of the selected frame:

ide/ideoptionsdlg.pas

<Delphi> procedure TIDEOptionsDialog.CategoryTreeKeyDown(Sender: TObject; var Key: Word;

 Shift: TShiftState);

var

 Command: Word;

begin

 Command := EditorOpts.KeyMap.TranslateKey(Key,Shift,nil);
 if (Command=ecContextHelp) and (PrevEditor <> nil) then begin
   Key:=VK_UNKNOWN;
   ShowContextHelpForIDE(PrevEditor);
 end;

end; </Delphi>

Help for FPC keywords

You can register a help for fpc keywords. Note: One database can handle multiple contexts, for example help for fpc keywords, help for sources and help for messages.

<Delphi> uses

 IDEHelpIntfs, HelpIntfs, LazHelpIntf, LazHelpHTML...
 { TSimpleFPCKeywordHelpDatabase }
 TSimpleFPCKeywordHelpDatabase = class(THTMLHelpDatabase) // you can use any type of database you like
 private
   FKeywordPrefixNode: THelpNode;
 public
   function GetNodesForKeyword(const HelpKeyword: string;
                       var ListOfNodes: THelpNodeQueryList; var ErrMsg: string
                       ): TShowHelpResult; override;
   function ShowHelp(Query: THelpQuery; BaseNode, NewNode: THelpNode;
                     QueryItem: THelpQueryItem;
                     var ErrMsg: string): TShowHelpResult; override;
 end;

function TSimpleFPCKeywordHelpDatabase.GetNodesForKeyword(

 const HelpKeyword: string; var ListOfNodes: THelpNodeQueryList;
 var ErrMsg: string): TShowHelpResult;

var

 KeyWord: String;

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));
   // test: testfcpkeyword
   if KeyWord='testfcpkeyword' 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
     // Note: In your own database you can create one dummy node or
     // one node per keyword or one node per group of keywords
     // or whatever you like.
     if FKeywordPrefixNode=nil then
       FKeywordPrefixNode:=THelpNode.CreateURL(Self,,);
     FKeywordPrefixNode.Title:='Pascal keyword '+KeyWord;
     CreateNodeQueryListAndAdd(FKeywordPrefixNode,nil,ListOfNodes,true);
     Result:=shrSuccess;
   end;
 end;

end;

function TSimpleFPCKeywordHelpDatabase.ShowHelp(Query: THelpQuery; BaseNode,

 NewNode: THelpNode; QueryItem: THelpQueryItem; var ErrMsg: string
 ): TShowHelpResult;

var

 KeywordQuery: THelpQueryKeyword;
 KeyWord: String;

begin

 Result:=shrHelpNotFound;
 if not (Query is THelpQueryKeyword) then exit;
 KeywordQuery:=THelpQueryKeyword(Query);
 KeyWord:=copy(KeywordQuery.Keyword,length(FPCKeyWordHelpPrefix)+1,length(KeywordQuery.Keyword));
 debugln(['TSimpleFPCKeywordHelpDatabase.ShowHelp Keyword=',Keyword]);
 // ShowURL ...

end;

procedure Register; begin

FPCKeywordsHelpDB:=HelpDatabases.CreateHelpDatabase('NameYourHelpDB',
                                           TSimpleFPCKeywordHelpDatabase,true);

end; </Delphi>

Help for Messages

This feature exists since 0.9.15 and requires the FPC sources installed locally.

This is invoked when the user presses F1 or uses the Help menu item of the message window.

Normally the IDE will search the errore.msg file in the FPC sources and show the comment for the message. But some messages like unit not found need extra help. The following describes how to do that:

To add a wiki help page for a message, do the following:

  • Create a wiki page under the root Build messages
  • Open ide/helpfpcmessages.pas and add a AddFPCMessageHelpItem line like:
  AddFPCMessageHelpItem('Can''t find unit',
                        'FPC_message:_Can_not_find_unit',': Can''t find unit ');

The first parameter is the title shown in errors. The second parameter is the wiki URL. And the third parameter is the regular expression to match the message.

Adding Kylix help

How to use the Borland Help files within the IDE editor: Adding Kylix Help