fphelp.pas 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  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. hcSymbol : S:='Open a browser a current word (not yet scope sensitive)';
  107. hcRunMenu : S:='Execution and parameters';
  108. hcRun : S:='Run the current program';
  109. hcParameters : S:='Set command-line parameters passed to program at execution';
  110. hcResetDebugger : S:='Reset Program';
  111. hcContToCursor : S:='Go on until Cursor position';
  112. hcUserScreen : S:='Switch to the full-screen user output';
  113. hcCompileMenu : S:='Compile, build & make';
  114. hcCompile : S:='Compile the current source file';
  115. hcMake : S:='Rebuild soruce file and all other files that have been modified';
  116. hcBuild : S:='Rebuild program and all available source files';
  117. hcTarget : S:='Select target platform to compile for';
  118. hcPrimaryFile : S:='Define then file that is the focus of Make and Build';
  119. hcClearPrimary : S:='Clear the file previously set to Primary';
  120. hcInformation : S:='Show compiler messages and program information';
  121. hcDebugMenu : S:='Debug Program';
  122. hcToggleBreakpoint : S:='Toggles Breakpoint';
  123. hcOpenGDBWindow : S:='Open direct window to GDB';
  124. hcAddWatch : S:='Add a new watch';
  125. hcStack : S:='Show calling stack';
  126. hcBreakpointList : S:='Edit breakpoints';
  127. hcToolsMenu : S:='User installed tools';
  128. hcCalculator : S:='Show calculator';
  129. { hcGrep : S:='Run grep';}
  130. hcToolsMessages : S:='Open the message window';
  131. hcToolsBase..
  132. hcToolsBase+MaxToolCount
  133. : S:='User installed tool';
  134. hcASCIITable : S:='Show ASCII table';
  135. hcOptionsMenu : S:='Setting for compiler, editor, mouse, etc.';
  136. hcSwitchesMode : S:='Select settings for normal, debug or release version';
  137. hcCompiler : S:='Set default compiler directives and conditional defines';
  138. hcMemorySizes : S:='Set default stack and heap sizes for generated programs';
  139. hcLinker : S:='Set linker options';
  140. hcDebugger : S:='Set debug information options';
  141. hcDirectories : S:='Set paths for units, include, object and generated files';
  142. hcBrowser : S:='Specify global browser settings';
  143. hcTools : S:='Create or change tools';
  144. hcEnvironmentMenu:S:='Specify environment settins';
  145. hcPreferences : S:='Specify desktop settings';
  146. hcEditor : S:='Specify default editor settings';
  147. hcMouse : S:='Specify mouse settings';
  148. hcDesktopOptions: S:='Specify desktop settings';
  149. hcStartup : S:='Permanently change default startup options';
  150. hcColors : S:='Customize IDE colors for windows, menus, editors, etc.';
  151. hcOpenINI : S:='Load a previously saved options file';
  152. hcSaveINI : S:='Save all the changes made in the options menu';
  153. hcSaveAsINI : S:='Save all the changes made under a different name';
  154. hcWindowMenu : S:='Windows managment commands';
  155. hcTile : S:='Arrange windows on desktop by tiling';
  156. hcCascade : S:='Arrange windows on desktop by cascading';
  157. hcCloseAll : S:='Close all windows on the desktop';
  158. hcResize : S:='Change the size/postion of the active window';
  159. hcZoom : S:='Enlarge or restore the size of the active window';
  160. hcNext : S:='Make the next window active';
  161. hcPrev : S:='Make the previous window active';
  162. hcClose : S:='Close the active window';
  163. hcWindowList : S:='Show a list of all open windows';
  164. hcUserScreenWindow:S:='Show contents of user screen in a window';
  165. hcHelpMenu : S:='Get online help';
  166. hcHelpContents : S:='Show table of contents for Online Help';
  167. hcHelpIndex : S:='Show index for Online Help';
  168. hcHelpTopicSearch:S:='Display help on the word at cursor';
  169. hcHelpPrevTopic : S:='Redisplay the last-viewed Online Help screen';
  170. hcHelpUsingHelp : S:='How to use Online Help';
  171. hcHelpFiles : S:='Install or remove installed help files';
  172. hcOpenAtCursor : S:='Attempt to open the file indicated by the word at cursor';
  173. hcBrowseAtCursor: S:='Attempt to browse the symbol at cursor';
  174. hcEditorOptions : S:='Specify editor settings';
  175. else S:='???';
  176. end;
  177. Hint:=S;
  178. end;
  179. procedure InitHelpSystem;
  180. procedure AddOAFile(HelpFile: string);
  181. begin
  182. {$IFDEF DEBUG}SetStatus(strLoadingHelp+' ('+SmartPath(HelpFile)+')');{$ENDIF}
  183. HelpFacility^.AddOAHelpFile(HelpFile);
  184. {$IFDEF DEBUG}SetStatus(strLoadingHelp);{$ENDIF}
  185. end;
  186. procedure AddHTMLFile(TOCEntry,HelpFile: string);
  187. begin
  188. {$IFDEF DEBUG}SetStatus(strLoadingHelp+' ('+SmartPath(HelpFile)+')');{$ENDIF}
  189. HelpFacility^.AddHTMLHelpFile(HelpFile, TOCEntry);
  190. {$IFDEF DEBUG}SetStatus(strLoadingHelp);{$ENDIF}
  191. end;
  192. var I,P: sw_integer;
  193. S: string;
  194. TopicTitle: string;
  195. begin
  196. New(HelpFacility, Init);
  197. PushStatus(strLoadingHelp);
  198. { AddHTMLFile('User''s guide','C:\FP\USER\USER.HTM');}
  199. for I:=0 to HelpFiles^.Count-1 do
  200. begin
  201. S:=HelpFiles^.At(I)^; TopicTitle:='';
  202. P:=Pos('|',S);
  203. if P>0 then
  204. begin TopicTitle:=copy(S,P+1,255); S:=copy(S,1,P-1); end;
  205. if TopicTitle='' then TopicTitle:=S;
  206. if copy(UpcaseStr(ExtOf(S)),1,4)='.HTM' then { this recognizes both .htm and .html }
  207. AddHTMLFile(TopicTitle,S)
  208. else
  209. AddOAFile(S);
  210. end;
  211. PopStatus;
  212. end;
  213. procedure CheckHelpSystem;
  214. begin
  215. if HelpInited then Exit;
  216. InitHelpSystem;
  217. HelpInited:=true;
  218. end;
  219. procedure DoneHelpSystem;
  220. begin
  221. if assigned(HelpFacility) then
  222. begin
  223. Dispose(HelpFacility, Done);
  224. HelpFacility:=nil;
  225. end;
  226. HelpInited:=false;
  227. end;
  228. procedure HelpCreateWindow;
  229. var R: TRect;
  230. begin
  231. CheckHelpSystem;
  232. if HelpWindow=nil then
  233. begin
  234. Desktop^.GetExtent(R); R.Grow(-15,-3); Dec(R.A.Y);
  235. New(HelpWindow, Init(R, 'Help', 0, 0, SearchFreeWindowNo));
  236. if HelpWindow<>nil then
  237. begin
  238. HelpWindow^.Hide;
  239. Desktop^.Insert(HelpWindow);
  240. end;
  241. end;
  242. end;
  243. procedure Help(FileID, Context: THelpCtx; Modal: boolean);
  244. begin
  245. if Modal then
  246. begin MessageBox('Sorry, modal help not yet implemented.',nil,mfInformation+mfInsertInApp+mfOKButton); Exit; end;
  247. HelpCreateWindow;
  248. with HelpWindow^ do
  249. begin
  250. HelpWindow^.ShowTopic(0,Context);
  251. if GetState(sfVisible)=false then Show;
  252. MakeFirst;
  253. end;
  254. Message(Application,evCommand,cmUpdate,nil);
  255. end;
  256. procedure HelpTopicSearch(Editor: PEditor);
  257. var S: string;
  258. begin
  259. if Editor=nil then S:='' else
  260. S:=GetEditorCurWord(Editor);
  261. HelpTopic(S);
  262. end;
  263. procedure HelpTopic(const S: string);
  264. var FileID: word;
  265. Ctx : THelpCtx;
  266. var Found: boolean;
  267. begin
  268. CheckHelpSystem;
  269. PushStatus(strLocatingTopic);
  270. Found:=HelpFacility^.TopicSearch(S,FileID,Ctx);
  271. PopStatus;
  272. if Found then
  273. Help(FileID,Ctx,false)
  274. else
  275. HelpIndex(S);
  276. end;
  277. procedure HelpIndex(Keyword: string);
  278. begin
  279. HelpCreateWindow;
  280. with HelpWindow^ do
  281. begin
  282. PushStatus(strBuildingHelpIndex);
  283. HelpWindow^.ShowIndex;
  284. if Keyword<>'' then
  285. HelpWindow^.HelpView^.Lookup(Keyword);
  286. PopStatus;
  287. if GetState(sfVisible)=false then Show;
  288. MakeFirst;
  289. end;
  290. Message(Application,evCommand,cmUpdate,nil);
  291. end;
  292. procedure PushStatus(S: string);
  293. begin
  294. if StatusLine=nil then
  295. Exit;
  296. If StatusStackPtr<=MaxStatusLevel then
  297. StatusStack[StatusStackPtr]:=PAdvancedStatusLine(StatusLine)^.GetStatusText
  298. else
  299. StatusStack[MaxStatusLevel]:=PAdvancedStatusLine(StatusLine)^.GetStatusText;
  300. SetStatus(S);
  301. Inc(StatusStackPtr);
  302. end;
  303. procedure PopStatus;
  304. begin
  305. if StatusLine=nil then
  306. Exit;
  307. Dec(StatusStackPtr);
  308. If StatusStackPtr<=MaxStatusLevel then
  309. SetStatus(StatusStack[StatusStackPtr])
  310. else
  311. SetStatus(StatusStack[MaxStatusLevel]);
  312. end;
  313. procedure SetStatus(S: string);
  314. begin
  315. if StatusLine=nil then
  316. Exit;
  317. PAdvancedStatusLine(StatusLine)^.SetStatusText(S);
  318. end;
  319. procedure ClearStatus;
  320. begin
  321. PAdvancedStatusLine(StatusLine)^.ClearStatusText;
  322. end;
  323. procedure InitHelpFiles;
  324. begin
  325. New(HelpFiles, Init(10,10));
  326. end;
  327. procedure DoneHelpFiles;
  328. begin
  329. if assigned(HelpFiles) then
  330. Dispose(HelpFiles, Done);
  331. end;
  332. END.
  333. {
  334. $Log$
  335. Revision 1.15 1999-06-25 00:39:58 pierre
  336. help for cmSymbol,cmAddWatch,cmStack and cmBreakpoint list
  337. Revision 1.14 1999/04/07 21:55:46 peter
  338. + object support for browser
  339. * html help fixes
  340. * more desktop saving things
  341. * NODEBUG directive to exclude debugger
  342. Revision 1.13 1999/03/23 15:11:28 peter
  343. * desktop saving things
  344. * vesa mode
  345. * preferences dialog
  346. Revision 1.12 1999/03/16 12:38:09 peter
  347. * tools macro fixes
  348. + tph writer
  349. + first things for resource files
  350. Revision 1.11 1999/03/01 15:41:53 peter
  351. + Added dummy entries for functions not yet implemented
  352. * MenuBar didn't update itself automatically on command-set changes
  353. * Fixed Debugging/Profiling options dialog
  354. * TCodeEditor converts spaces to tabs at save only if efUseTabChars is set
  355. * efBackSpaceUnindents works correctly
  356. + 'Messages' window implemented
  357. + Added '$CAP MSG()' and '$CAP EDIT' to available tool-macros
  358. + Added TP message-filter support (for ex. you can call GREP thru
  359. GREP2MSG and view the result in the messages window - just like in TP)
  360. * A 'var' was missing from the param-list of THelpFacility.TopicSearch,
  361. so topic search didn't work...
  362. * In FPHELP.PAS there were still context-variables defined as word instead
  363. of THelpCtx
  364. * StdStatusKeys() was missing from the statusdef for help windows
  365. + Topic-title for index-table can be specified when adding a HTML-files
  366. Revision 1.10 1999/02/22 11:51:35 peter
  367. * browser updates from gabor
  368. Revision 1.9 1999/02/19 18:43:45 peter
  369. + open dialog supports mask list
  370. Revision 1.8 1999/02/11 19:07:21 pierre
  371. * GDBWindow redesigned :
  372. normal editor apart from
  373. that any kbEnter will send the line (for begin to cursor)
  374. to GDB command !
  375. GDBWindow opened in Debugger Menu
  376. still buggy :
  377. -echo should not be present if at end of text
  378. -GDBWindow becomes First after each step (I don't know why !)
  379. Revision 1.7 1999/02/08 17:40:01 pierre
  380. + cmContToCursor added
  381. Revision 1.6 1999/02/08 10:37:43 peter
  382. + html helpviewer
  383. Revision 1.5 1999/02/04 12:23:44 pierre
  384. + cmResetDebugger and cmGrep
  385. * Avoid StatusStack overflow
  386. Revision 1.4 1999/01/21 11:54:13 peter
  387. + tools menu
  388. + speedsearch in symbolbrowser
  389. * working run command
  390. Revision 1.3 1999/01/04 11:49:44 peter
  391. * 'Use tab characters' now works correctly
  392. + Syntax highlight now acts on File|Save As...
  393. + Added a new class to syntax highlight: 'hex numbers'.
  394. * There was something very wrong with the palette managment. Now fixed.
  395. + Added output directory (-FE<xxx>) support to 'Directories' dialog...
  396. * Fixed some possible bugs in Running/Compiling, and the compilation/run
  397. process revised
  398. Revision 1.2 1998/12/28 15:47:44 peter
  399. + Added user screen support, display & window
  400. + Implemented Editor,Mouse Options dialog
  401. + Added location of .INI and .CFG file
  402. + Option (INI) file managment implemented (see bottom of Options Menu)
  403. + Switches updated
  404. + Run program
  405. Revision 1.3 1998/12/22 10:39:42 peter
  406. + options are now written/read
  407. + find and replace routines
  408. }