Difference between revisions of "Creating IDE Help"

From Free Pascal wiki
Jump to navigationJump to search
m (typo)
(Added categories)
 
(25 intermediate revisions by 7 users not shown)
Line 1: Line 1:
== Help for LCL units ==
+
{{LanguageBar|Creating IDE Help}}
 +
 
 +
=Overview=
 +
 
 +
The IDE can search help for various things and there are various sources in various help formats. Here is a short list to understand the complexity:
 +
 
 +
*'''FPC messages''': compiler message like ''Error: Illegal enum minimum-size specifier''. The IDE has a default built-in to search for the ''FPCSrcDir/compiler/msg/errore.msg file'', search the message there and show the corresponding comment. The comments contain Latex tags which are stripped. At the moment a simple MessageDlg is shown. Some notorious messages need more explanation and are manually connected to URLs.
 +
*'''IDE windows, dialogs and controls''':
 +
*'''Pascal sources''':
 +
*'''FPC keywords''':
 +
*'''FPC directives''':
 +
*'''IDE directives''':
 +
 
 +
=Demos and explore=
 +
 
 +
You can see the currently installed help under '''View / IDE Internals / About IDE / Help'''.
 +
 
 +
There is a test and demonstration package under '''examples/idehelp/demoidehelp.lpk'''. It contains example code how you can add help to the IDE.
 +
 
 +
To show your help in the user's browser see examples/helphtml/htmlhelp1.lpi.
 +
 
 +
To show HTML help in a LCL control see examples/htmlhelp_ipro/htmlhelpsample.lpi.
 +
 
 +
==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.
 
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 [[LazDoc]] tool.
+
The items can be edited easily via the [[FPDoc Editor]] tool.
  
 
You can see the state of the LCL documentation here: [[LCL Documentation Roadmap]].
 
You can see the state of the LCL documentation here: [[LCL Documentation Roadmap]].
  
== Help for IDE windows ==
+
==Help for IDE windows==
  
 
This feature exists since 0.9.15.
 
This feature exists since 0.9.15.
Line 12: Line 35:
 
The help for the IDE windows (i.e. 'Object Inspector' or the 'Compiler Options') are documented in this wiki.
 
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.
 
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. You can set the short cut in the editor options -> key mapping.
+
This mapping file is edited via an editor that is shown at any place in the IDE via {{keypress|Ctrl}}+{{keypress|Shift}}+{{keypress|F1}}, except for controls that catch all keys, like synedit. You can set the shortcut in the editor options -> key mapping.
  
 
The root page of the IDE window docs is [[Lazarus IDE]].
 
The root page of the IDE window docs is [[Lazarus IDE]].
  
== Help for FPC keywords ==
+
===Example===
 +
*Open the project options: Project / Project Options
 +
*Open the help editor: {{keypress|Shift}}+{{keypress|Ctrl}}+{{keypress|F1}}
 +
 
 +
[[Image:HelpEditor1.png]]
  
This feature exists since 0.9.15 and requires the FPC docs as HTML installed locally.
+
*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'''
  
This is invoked when the cursor in the source editor is above a keyword and the user pressed F1.
+
[[Image:HelpEditorProjectOptions.png]]
The IDE searches in the FPC html documentation for the ref.kwd file. This file is maintained by the FPC team and contains a list to all HTML pages.
 
At the moment no custom help is implemented.
 
  
TODO: Document, where to get/ how to create FPC Html docs.
+
*You can click the '''Test''' button and should see [[IDE_Window:_Project_Options]] in your browser.
  
== Help for Messages ==
+
===Redirect===
 +
 
 +
The TreeView in the IDE options dialog redirects the help to the help of the selected frame:
 +
 
 +
ide/ideoptionsdlg.pas
 +
 
 +
<syntaxhighlight lang="pascal">
 +
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;
 +
</syntaxhighlight>
 +
 
 +
==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.
 +
 
 +
<syntaxhighlight lang="pascal">
 +
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;
 +
</syntaxhighlight>
 +
 
 +
==Help for Messages==
  
 
This feature exists since 0.9.15 and requires the FPC sources installed locally.
 
This feature exists since 0.9.15 and requires the FPC sources installed locally.
Line 35: Line 158:
  
 
To add a wiki help page for a message, do the following:
 
To add a wiki help page for a message, do the following:
* Create a wiki page under the root [[Build messages]]
+
* Create a wiki page under [[Build messages]]
* Open ide/helpfpcmessages.pas and add a ''AddFPCMessageHelpItem'' line like:
+
* Right click on messages window / Edit help
<pre>
+
* This shows the editor for message additions.
  AddFPCMessageHelpItem('Can''t find unit',
+
 
                        'FPC_message:_Can_not_find_unit',': Can''t find unit ');
+
[[Image:AdditionalHelpForMessages.png]]
</pre>
+
 
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.
+
The items are stored in '''<lazarusdir>/docs/additionalmsghelp.xml'''.
 +
 
 +
== Adding Kylix help ==
 +
 
 +
For wow to use the Borland Help files within the IDE editor, see [[Installing_Help_in_the_IDE#Installing_Kylix_Help_in_the_Lazarus_IDE|Adding Kylix Help]].
 +
 
 +
[[Category:Lazarus]]
 +
[[Category:IDE]]
 +
[[Category:Help and Docs]]

Latest revision as of 09:10, 22 August 2020

Deutsch (de) English (en) 日本語 (ja) русский (ru)

Overview

The IDE can search help for various things and there are various sources in various help formats. Here is a short list to understand the complexity:

  • FPC messages: compiler message like Error: Illegal enum minimum-size specifier. The IDE has a default built-in to search for the FPCSrcDir/compiler/msg/errore.msg file, search the message there and show the corresponding comment. The comments contain Latex tags which are stripped. At the moment a simple MessageDlg is shown. Some notorious messages need more explanation and are manually connected to URLs.
  • IDE windows, dialogs and controls:
  • Pascal sources:
  • FPC keywords:
  • FPC directives:
  • IDE directives:

Demos and explore

You can see the currently installed help under View / IDE Internals / About IDE / Help.

There is a test and demonstration package under examples/idehelp/demoidehelp.lpk. It contains example code how you can add help to the IDE.

To show your help in the user's browser see examples/helphtml/htmlhelp1.lpi.

To show HTML help in a LCL control see examples/htmlhelp_ipro/htmlhelpsample.lpi.

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 catch all keys, like synedit. You can set the shortcut 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

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;

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.

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;

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 Build messages
  • Right click on messages window / Edit help
  • This shows the editor for message additions.

AdditionalHelpForMessages.png

The items are stored in <lazarusdir>/docs/additionalmsghelp.xml.

Adding Kylix help

For wow to use the Borland Help files within the IDE editor, see Adding Kylix Help.