/ideintf/idehelpintf.pas

http://github.com/graemeg/lazarus · Pascal · 193 lines · 118 code · 31 blank · 44 comment · 5 complexity · 4c5b6172fda0ebcbbb9aeb0d3b3f7b78 MD5 · raw file

  1. { $Id: helpintf.pas 9271 2006-05-13 12:00:43Z mattias $ }
  2. {
  3. *****************************************************************************
  4. * *
  5. * See the file COPYING.modifiedLGPL.txt, included in this distribution, *
  6. * for details about the copyright. *
  7. * *
  8. * This program is distributed in the hope that it will be useful, *
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
  11. * *
  12. *****************************************************************************
  13. Author: Mattias Gaertner
  14. Abstract:
  15. This unit defines various base classes for the Help System used by the IDE.
  16. }
  17. unit IDEHelpIntf;
  18. {$mode objfpc}{$H+}
  19. interface
  20. uses
  21. Classes, SysUtils, LCLProc, Forms, Controls, HelpIntfs, LazHelpIntf,
  22. TextTools;
  23. type
  24. { THelpDBIRegExprMessage
  25. Help registration item for matching a message (e.g. a fpc warning) with
  26. a regular expression.
  27. For example a line like
  28. "/usr/share/lazarus/components/synedit/syneditkeycmds.pp(532,10) Warning: Function result does not seem to be set"
  29. could be matched with
  30. Expression=') Warning: Function result does not seem to be set'
  31. }
  32. THelpDBIRegExprMessage = class(THelpDBIMessage)
  33. private
  34. FExpression: string;
  35. FModifierStr: string;
  36. public
  37. constructor Create(TheNode: THelpNode; const RegularExpression,
  38. TheModifierStr: string);
  39. function MessageMatches(const TheMessage: string; MessageParts: TStrings
  40. ): boolean; override;
  41. property Expression: string read FExpression write FExpression;
  42. property ModifierStr: string read FModifierStr write FModifierStr;
  43. end;
  44. { TBaseHelpManager }
  45. TBaseHelpManager = class(TComponent)
  46. public
  47. procedure ConnectMainBarEvents; virtual; abstract;
  48. procedure LoadHelpOptions; virtual; abstract;
  49. procedure SaveHelpOptions; virtual; abstract;
  50. function ShowHelpForSourcePosition(const Filename: string;
  51. const CodePos: TPoint;
  52. var ErrMsg: string): TShowHelpResult; virtual; abstract;
  53. procedure ShowHelpForMessage(Line: integer); virtual; abstract;
  54. procedure ShowHelpForObjectInspector(Sender: TObject); virtual; abstract;
  55. function CreateHint(aHintWindow: THintWindow; ScreenPos: TPoint;
  56. const BaseURL: string; var TheHint: string;
  57. out HintWinRect: TRect): boolean; virtual; abstract;
  58. function ConvertSourcePosToPascalHelpContext(const CaretPos: TPoint;
  59. const Filename: string): TPascalHelpContextList; virtual; abstract;
  60. end;
  61. var
  62. LazarusHelp: TBaseHelpManager; // initialized by the IDE
  63. type
  64. { TIDEHTMLControlIntf }
  65. TIDEHTMLControlIntf = interface
  66. function GetURL: string;
  67. procedure SetURL(const AValue: string);
  68. property URL: string read GetURL write SetURL;
  69. procedure SetHTMLContent(Stream: TStream);
  70. procedure GetPreferredControlSize(out AWidth, AHeight: integer);
  71. end;
  72. { TAbstractIDEHTMLProvider
  73. An instance of this class connects 3 parts:
  74. 1. IDE html files (via implementation)
  75. 2. a html viewer control (via ControlIntf)
  76. 3. IDE or designtime package code
  77. All three can communicate. }
  78. TAbstractIDEHTMLProvider = class(TComponent)
  79. protected
  80. FBaseURL: string;
  81. FControlIntf: TIDEHTMLControlIntf;
  82. procedure SetBaseURL(const AValue: string); virtual;
  83. procedure SetControlIntf(const AValue: TIDEHTMLControlIntf); virtual;
  84. public
  85. constructor Create(TheOwner: TComponent); override;
  86. destructor Destroy; override;
  87. function GetStream(const URL: string
  88. ): TStream; virtual; abstract; { provider assumes ownership of returned TStream
  89. and increases internal reference count.
  90. If not found it raises an exception. }
  91. procedure ReleaseStream(const URL: string); virtual; abstract;
  92. property BaseURL: string read FBaseURL write SetBaseURL;// fallback for relative URLs
  93. function BuildURL(const CurBaseURL, CurURL: string): string; virtual;
  94. property ControlIntf: TIDEHTMLControlIntf read FControlIntf write SetControlIntf;
  95. end;
  96. TCreateIDEHTMLControlEvent =
  97. function(Owner: TComponent; var Provider: TAbstractIDEHTMLProvider): TControl;
  98. TCreateIDEHTMLProviderEvent =
  99. function(Owner: TComponent): TAbstractIDEHTMLProvider;
  100. var
  101. CreateIDEHTMLControl: TCreateIDEHTMLControlEvent = nil;// will be set by the IDE
  102. // and overidden by a package like turbopoweriprodsgn.lpk
  103. CreateIDEHTMLProvider: TCreateIDEHTMLProviderEvent = nil;// will be set by the IDE
  104. implementation
  105. { THelpDBIRegExprMessage }
  106. constructor THelpDBIRegExprMessage.Create(TheNode: THelpNode;
  107. const RegularExpression, TheModifierStr: string);
  108. begin
  109. Node:=TheNode;
  110. FExpression:=RegularExpression;
  111. FModifierStr:=TheModifierStr;
  112. end;
  113. function THelpDBIRegExprMessage.MessageMatches(const TheMessage: string;
  114. MessageParts: TStrings): boolean;
  115. begin
  116. Result:=REMatches(TheMessage,Expression,ModifierStr);
  117. //writeln('THelpDBIRegExprMessage.MessageMatches TheMessage="',TheMessage,'" Expression="',Expression,'" Result=',Result);
  118. end;
  119. { TAbstractIDEHTMLProvider }
  120. procedure TAbstractIDEHTMLProvider.SetBaseURL(const AValue: string);
  121. begin
  122. if FBaseURL=AValue then exit;
  123. FBaseURL:=AValue;
  124. end;
  125. procedure TAbstractIDEHTMLProvider.SetControlIntf(
  126. const AValue: TIDEHTMLControlIntf);
  127. begin
  128. if FControlIntf=AValue then exit;
  129. FControlIntf:=AValue;
  130. end;
  131. constructor TAbstractIDEHTMLProvider.Create(TheOwner: TComponent);
  132. begin
  133. inherited Create(TheOwner);
  134. end;
  135. destructor TAbstractIDEHTMLProvider.Destroy;
  136. begin
  137. FControlIntf:=nil; // decrease reference count
  138. inherited Destroy;
  139. end;
  140. function TAbstractIDEHTMLProvider.BuildURL(const CurBaseURL, CurURL: string
  141. ): string;
  142. var
  143. URLType: string;
  144. URLPath: string;
  145. URLParams: string;
  146. begin
  147. Result:=CurURL;
  148. SplitURL(CurURL,URLType,URLPath,URLParams);
  149. //DebugLn(['TAbstractIDEHTMLProvider.BuildURL CurURL=',CurURL,' URLType=',URLType,' URLPath=',URLPath,' URLParams=',URLParams]);
  150. if URLType='' then begin
  151. // no URLType => use CurURL as URLPath
  152. Result:=CurURL;
  153. //DebugLn(['TAbstractIDEHTMLProvider.BuildURL AAA1 ',Result]);
  154. if not URLFilenameIsAbsolute(Result) then
  155. Result:=CurBaseURL+Result;
  156. end else begin
  157. Result:=CurURL;
  158. end;
  159. end;
  160. end.