fphelp.pas 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Integrated Development Environment
  4. Copyright (c) 1998 by Berczi Gabor
  5. Help routines for the IDE
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  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. unit FPHelp;
  13. interface
  14. uses
  15. Drivers,HelpCtx,
  16. WHelp,WHlpView,WHTML,
  17. {$ifdef EDITORS}
  18. Editors,
  19. {$else}
  20. WEditor,
  21. {$endif}
  22. WViews,FPViews;
  23. type
  24. PIDEStatusLine = ^TIDEStatusLine;
  25. TIDEStatusLine = object(TAdvancedStatusLine)
  26. function Hint(AHelpCtx: Word): String; virtual;
  27. procedure HandleEvent(var Event: TEvent); virtual;
  28. end;
  29. procedure Help(FileID, Context: THelpCtx; Modal: boolean);
  30. procedure HelpIndex(Keyword: string);
  31. procedure HelpTopicSearch(Editor: PEditor);
  32. procedure HelpTopic(const S: string);
  33. procedure InitHelpSystem;
  34. procedure DoneHelpSystem;
  35. procedure InitHelpFiles;
  36. procedure DoneHelpFiles;
  37. procedure PushStatus(S: string);
  38. procedure SetStatus(S: string);
  39. procedure ClearStatus;
  40. procedure PopStatus;
  41. const
  42. HelpWindow : PFPHelpWindow = nil;
  43. HelpInited : boolean = false;
  44. implementation
  45. uses Objects,Views,App,MsgBox,
  46. WHTMLHlp,
  47. FPConst,FPVars,FPUtils;
  48. const
  49. MaxStatusLevel = {$ifdef FPC}10{$else}1{$endif};
  50. var StatusStack : array[0..MaxStatusLevel] of string[MaxViewWidth];
  51. const
  52. StatusStackPtr : integer = 0;
  53. procedure TIDEStatusLine.HandleEvent(var Event: TEvent);
  54. begin
  55. case Event.What of
  56. evBroadcast :
  57. case Event.Command of
  58. cmUpdate : Update;
  59. end;
  60. end;
  61. inherited HandleEvent(Event);
  62. end;
  63. function TIDEStatusLine.Hint(AHelpCtx: Word): String;
  64. var S: string;
  65. begin
  66. case AHelpCtx of
  67. hcNoContext : S:='';
  68. hcSourceWindow : S:='';
  69. hcHelpWindow : S:='';
  70. hcCalcWindow : S:='';
  71. hcInfoWindow : S:='';
  72. hcClipboardWindow:S:='';
  73. hcBrowserWindow : S:='';
  74. hcMessagesWindow: S:='';
  75. hcSystemMenu : S:='System menu';
  76. hcUpdate : S:='Refresh and redraw display';
  77. hcAbout : S:='Show version and copyright information';
  78. hcFileMenu : S:='File managment commands (Open, New, Save, etc.)';
  79. hcNew : S:='Create a new file in a new edit window';
  80. hcNewFromTemplate:S:='Create a new file using a code template';
  81. hcOpen : S:='Locate and open a file in an edit window';
  82. hcSave : S:='Save the file in the active edit window';
  83. hcSaveAs : S:='Save the current file under a different name, directory or drive';
  84. hcSaveAll : S:='Save all modified files';
  85. hcChangeDir : S:='Choose a new default directory';
  86. hcDOSShell : S:='Temporarily exit to DOS';
  87. hcQuit : S:='Exit the IDE';
  88. hcRecentFileBase..hcRecentFileBase+10
  89. : S:='Open indicated file in a new editor window';
  90. hcEditMenu : S:='Clipboard editing commands';
  91. hcUndo : S:='Undo the previous editor operation';
  92. hcRedo : S:='Redo the previously undone editor operation';
  93. hcCut : S:='Remove the selected text and put it in the clipboard';
  94. hcCopy : S:='Copy the selected text in the clipboard';
  95. hcPaste : S:='Insert selected text from the clipboard at the cursor position';
  96. hcClear : S:='Delete the selected text';
  97. hcShowClipboard : S:='Open then clipboard window';
  98. hcSearchMenu : S:='Text and symbols search commands';
  99. hcFind : S:='Search for text';
  100. hcReplace : S:='Search for text and replace it with new text';
  101. hcSearchAgain : S:='Repeat the last Search or Replace command';
  102. hcGotoLine : S:='Move the cursor to a specified line number';
  103. hcObjects : S:='Open a browser displaying all objects in the program';
  104. hcModules : S:='Open a browser displaying all modules of the program';
  105. hcGlobals : S:='Open a browser displaying all global symbols in the program';
  106. hcRunMenu : S:='Execution and parameters';
  107. hcRun : S:='Run the current program';
  108. hcParameters : S:='Set command-line parameters passed to program at execution';
  109. hcResetDebugger : S:='Reset Program';
  110. hcContToCursor : S:='Go on until Cursor position';
  111. hcUserScreen : S:='Switch to the full-screen user output';
  112. hcCompileMenu : S:='Compile, build & make';
  113. hcCompile : S:='Compile the current source file';
  114. hcMake : S:='Rebuild soruce file and all other files that have been modified';
  115. hcBuild : S:='Rebuild program and all available source files';
  116. hcTarget : S:='Select target platform to compile for';
  117. hcPrimaryFile : S:='Define then file that is the focus of Make and Build';
  118. hcClearPrimary : S:='Clear the file previously set to Primary';
  119. hcInformation : S:='Show compiler messages and program information';
  120. hcDebugMenu : S:='Debug Program';
  121. hcToggleBreakpoint : S:='Toggles Breakpoint';
  122. hcOpenGDBWindow : S:='Open direct window to GDB';
  123. hcToolsMenu : S:='User installed tools';
  124. hcCalculator : S:='Show calculator';
  125. { hcGrep : S:='Run grep';}
  126. hcToolsMessages : S:='Open the message window';
  127. hcToolsBase..
  128. hcToolsBase+MaxToolCount
  129. : S:='User installed tool';
  130. hcASCIITable : S:='Show ASCII table';
  131. hcOptionsMenu : S:='Setting for compiler, editor, mouse, etc.';
  132. hcSwitchesMode : S:='Select settings for normal, debug or release version';
  133. hcCompiler : S:='Set default compiler directives and conditional defines';
  134. hcMemorySizes : S:='Set default stack and heap sizes for generated programs';
  135. hcLinker : S:='Set linker options';
  136. hcDebugger : S:='Set debug information options';
  137. hcDirectories : S:='Set paths for units, include, object and generated files';
  138. hcBrowser : S:='Specify global browser settings';
  139. hcTools : S:='Create or change tools';
  140. hcEnvironmentMenu:S:='Specify environment settins';
  141. hcPreferences : S:='Specify desktop settings';
  142. hcEditor : S:='Specify default editor settings';
  143. hcMouse : S:='Specify mouse settings';
  144. hcDesktopOptions: S:='Specify desktop settings';
  145. hcStartup : S:='Permanently change default startup options';
  146. hcColors : S:='Customize IDE colors for windows, menus, editors, etc.';
  147. hcOpenINI : S:='Load a previously saved options file';
  148. hcSaveINI : S:='Save all the changes made in the options menu';
  149. hcSaveAsINI : S:='Save all the changes made under a different name';
  150. hcWindowMenu : S:='Windows managment commands';
  151. hcTile : S:='Arrange windows on desktop by tiling';
  152. hcCascade : S:='Arrange windows on desktop by cascading';
  153. hcCloseAll : S:='Close all windows on the desktop';
  154. hcResize : S:='Change the size/postion of the active window';
  155. hcZoom : S:='Enlarge or restore the size of the active window';
  156. hcNext : S:='Make the next window active';
  157. hcPrev : S:='Make the previous window active';
  158. hcClose : S:='Close the active window';
  159. hcWindowList : S:='Show a list of all open windows';
  160. hcUserScreenWindow:S:='Show contents of user screen in a window';
  161. hcHelpMenu : S:='Get online help';
  162. hcHelpContents : S:='Show table of contents for Online Help';
  163. hcHelpIndex : S:='Show index for Online Help';
  164. hcHelpTopicSearch:S:='Display help on the word at cursor';
  165. hcHelpPrevTopic : S:='Redisplay the last-viewed Online Help screen';
  166. hcHelpUsingHelp : S:='How to use Online Help';
  167. hcHelpFiles : S:='Install or remove installed help files';
  168. hcOpenAtCursor : S:='Attempt to open the file indicated by the word at cursor';
  169. hcBrowseAtCursor: S:='Attempt to browse the symbol at cursor';
  170. hcEditorOptions : S:='Specify editor settings';
  171. else S:='???';
  172. end;
  173. Hint:=S;
  174. end;
  175. procedure InitHelpSystem;
  176. procedure AddOAFile(HelpFile: string);
  177. begin
  178. {$IFDEF DEBUG}SetStatus(strLoadingHelp+' ('+SmartPath(HelpFile)+')');{$ENDIF}
  179. HelpFacility^.AddOAHelpFile(HelpFile);
  180. {$IFDEF DEBUG}SetStatus(strLoadingHelp);{$ENDIF}
  181. end;
  182. procedure AddHTMLFile(TOCEntry,HelpFile: string);
  183. begin
  184. {$IFDEF DEBUG}SetStatus(strLoadingHelp+' ('+SmartPath(HelpFile)+')');{$ENDIF}
  185. HelpFacility^.AddHTMLHelpFile(HelpFile, TOCEntry);
  186. {$IFDEF DEBUG}SetStatus(strLoadingHelp);{$ENDIF}
  187. end;
  188. var I,P: sw_integer;
  189. S: string;
  190. TopicTitle: string;
  191. begin
  192. New(HelpFacility, Init);
  193. PushStatus(strLoadingHelp);
  194. { AddHTMLFile('User''s guide','C:\FP\USER\USER.HTM');}
  195. for I:=0 to HelpFiles^.Count-1 do
  196. begin
  197. S:=HelpFiles^.At(I)^; TopicTitle:='';
  198. P:=Pos('|',S);
  199. if P>0 then
  200. begin TopicTitle:=copy(S,P+1,255); S:=copy(S,1,P-1); end;
  201. if TopicTitle='' then TopicTitle:=S;
  202. if copy(UpcaseStr(ExtOf(S)),1,4)='.HTM' then { this recognizes both .htm and .html }
  203. AddHTMLFile(TopicTitle,S)
  204. else
  205. AddOAFile(S);
  206. end;
  207. PopStatus;
  208. end;
  209. procedure CheckHelpSystem;
  210. begin
  211. if HelpInited then Exit;
  212. InitHelpSystem;
  213. HelpInited:=true;
  214. end;
  215. procedure DoneHelpSystem;
  216. begin
  217. if assigned(HelpFacility) then
  218. begin
  219. Dispose(HelpFacility, Done);
  220. HelpFacility:=nil;
  221. end;
  222. HelpInited:=false;
  223. end;
  224. procedure HelpCreateWindow;
  225. var R: TRect;
  226. begin
  227. CheckHelpSystem;
  228. if HelpWindow=nil then
  229. begin
  230. Desktop^.GetExtent(R); R.Grow(-15,-3); Dec(R.A.Y);
  231. New(HelpWindow, Init(R, 'Help', 0, 0, SearchFreeWindowNo));
  232. if HelpWindow<>nil then
  233. begin
  234. HelpWindow^.Hide;
  235. Desktop^.Insert(HelpWindow);
  236. end;
  237. end;
  238. end;
  239. procedure Help(FileID, Context: THelpCtx; Modal: boolean);
  240. begin
  241. if Modal then
  242. begin MessageBox('Sorry, modal help not yet implemented.',nil,mfInformation+mfInsertInApp+mfOKButton); Exit; end;
  243. HelpCreateWindow;
  244. with HelpWindow^ do
  245. begin
  246. HelpWindow^.ShowTopic(0,Context);
  247. if GetState(sfVisible)=false then Show;
  248. MakeFirst;
  249. end;
  250. Message(Application,evCommand,cmUpdate,nil);
  251. end;
  252. procedure HelpTopicSearch(Editor: PEditor);
  253. var S: string;
  254. begin
  255. if Editor=nil then S:='' else
  256. S:=GetEditorCurWord(Editor);
  257. HelpTopic(S);
  258. end;
  259. procedure HelpTopic(const S: string);
  260. var FileID: word;
  261. Ctx : THelpCtx;
  262. var Found: boolean;
  263. begin
  264. CheckHelpSystem;
  265. PushStatus(strLocatingTopic);
  266. Found:=HelpFacility^.TopicSearch(S,FileID,Ctx);
  267. PopStatus;
  268. if Found then
  269. Help(FileID,Ctx,false)
  270. else
  271. HelpIndex(S);
  272. end;
  273. procedure HelpIndex(Keyword: string);
  274. begin
  275. HelpCreateWindow;
  276. with HelpWindow^ do
  277. begin
  278. PushStatus(strBuildingHelpIndex);
  279. HelpWindow^.ShowIndex;
  280. if Keyword<>'' then
  281. HelpWindow^.HelpView^.Lookup(Keyword);
  282. PopStatus;
  283. if GetState(sfVisible)=false then Show;
  284. MakeFirst;
  285. end;
  286. Message(Application,evCommand,cmUpdate,nil);
  287. end;
  288. procedure PushStatus(S: string);
  289. begin
  290. if StatusLine=nil then
  291. Exit;
  292. If StatusStackPtr<=MaxStatusLevel then
  293. StatusStack[StatusStackPtr]:=PAdvancedStatusLine(StatusLine)^.GetStatusText
  294. else
  295. StatusStack[MaxStatusLevel]:=PAdvancedStatusLine(StatusLine)^.GetStatusText;
  296. SetStatus(S);
  297. Inc(StatusStackPtr);
  298. end;
  299. procedure PopStatus;
  300. begin
  301. if StatusLine=nil then
  302. Exit;
  303. Dec(StatusStackPtr);
  304. If StatusStackPtr<=MaxStatusLevel then
  305. SetStatus(StatusStack[StatusStackPtr])
  306. else
  307. SetStatus(StatusStack[MaxStatusLevel]);
  308. end;
  309. procedure SetStatus(S: string);
  310. begin
  311. if StatusLine=nil then
  312. Exit;
  313. PAdvancedStatusLine(StatusLine)^.SetStatusText(S);
  314. end;
  315. procedure ClearStatus;
  316. begin
  317. PAdvancedStatusLine(StatusLine)^.ClearStatusText;
  318. end;
  319. procedure InitHelpFiles;
  320. begin
  321. New(HelpFiles, Init(10,10));
  322. end;
  323. procedure DoneHelpFiles;
  324. begin
  325. if assigned(HelpFiles) then
  326. Dispose(HelpFiles, Done);
  327. end;
  328. END.
  329. {
  330. $Log$
  331. Revision 1.14 1999-04-07 21:55:46 peter
  332. + object support for browser
  333. * html help fixes
  334. * more desktop saving things
  335. * NODEBUG directive to exclude debugger
  336. Revision 1.13 1999/03/23 15:11:28 peter
  337. * desktop saving things
  338. * vesa mode
  339. * preferences dialog
  340. Revision 1.12 1999/03/16 12:38:09 peter
  341. * tools macro fixes
  342. + tph writer
  343. + first things for resource files
  344. Revision 1.11 1999/03/01 15:41:53 peter
  345. + Added dummy entries for functions not yet implemented
  346. * MenuBar didn't update itself automatically on command-set changes
  347. * Fixed Debugging/Profiling options dialog
  348. * TCodeEditor converts spaces to tabs at save only if efUseTabChars is set
  349. * efBackSpaceUnindents works correctly
  350. + 'Messages' window implemented
  351. + Added '$CAP MSG()' and '$CAP EDIT' to available tool-macros
  352. + Added TP message-filter support (for ex. you can call GREP thru
  353. GREP2MSG and view the result in the messages window - just like in TP)
  354. * A 'var' was missing from the param-list of THelpFacility.TopicSearch,
  355. so topic search didn't work...
  356. * In FPHELP.PAS there were still context-variables defined as word instead
  357. of THelpCtx
  358. * StdStatusKeys() was missing from the statusdef for help windows
  359. + Topic-title for index-table can be specified when adding a HTML-files
  360. Revision 1.10 1999/02/22 11:51:35 peter
  361. * browser updates from gabor
  362. Revision 1.9 1999/02/19 18:43:45 peter
  363. + open dialog supports mask list
  364. Revision 1.8 1999/02/11 19:07:21 pierre
  365. * GDBWindow redesigned :
  366. normal editor apart from
  367. that any kbEnter will send the line (for begin to cursor)
  368. to GDB command !
  369. GDBWindow opened in Debugger Menu
  370. still buggy :
  371. -echo should not be present if at end of text
  372. -GDBWindow becomes First after each step (I don't know why !)
  373. Revision 1.7 1999/02/08 17:40:01 pierre
  374. + cmContToCursor added
  375. Revision 1.6 1999/02/08 10:37:43 peter
  376. + html helpviewer
  377. Revision 1.5 1999/02/04 12:23:44 pierre
  378. + cmResetDebugger and cmGrep
  379. * Avoid StatusStack overflow
  380. Revision 1.4 1999/01/21 11:54:13 peter
  381. + tools menu
  382. + speedsearch in symbolbrowser
  383. * working run command
  384. Revision 1.3 1999/01/04 11:49:44 peter
  385. * 'Use tab characters' now works correctly
  386. + Syntax highlight now acts on File|Save As...
  387. + Added a new class to syntax highlight: 'hex numbers'.
  388. * There was something very wrong with the palette managment. Now fixed.
  389. + Added output directory (-FE<xxx>) support to 'Directories' dialog...
  390. * Fixed some possible bugs in Running/Compiling, and the compilation/run
  391. process revised
  392. Revision 1.2 1998/12/28 15:47:44 peter
  393. + Added user screen support, display & window
  394. + Implemented Editor,Mouse Options dialog
  395. + Added location of .INI and .CFG file
  396. + Option (INI) file managment implemented (see bottom of Options Menu)
  397. + Switches updated
  398. + Run program
  399. Revision 1.3 1998/12/22 10:39:42 peter
  400. + options are now written/read
  401. + find and replace routines
  402. }