fphelp.pas 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  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 CloseHelpWindows;
  34. procedure InitHelpSystem;
  35. procedure DoneHelpSystem;
  36. procedure InitHelpFiles;
  37. procedure DoneHelpFiles;
  38. procedure PushStatus(S: string);
  39. procedure SetStatus(S: string);
  40. procedure ClearStatus;
  41. procedure PopStatus;
  42. const
  43. HelpWindow : PFPHelpWindow = nil;
  44. HelpInited : boolean = false;
  45. implementation
  46. uses Objects,Views,App,MsgBox,Commands,
  47. WHTMLHlp,
  48. FPConst,FPVars,FPUtils;
  49. const
  50. MaxStatusLevel = {$ifdef FPC}10{$else}1{$endif};
  51. var StatusStack : array[0..MaxStatusLevel] of string[MaxViewWidth];
  52. const
  53. StatusStackPtr : integer = 0;
  54. procedure TIDEStatusLine.HandleEvent(var Event: TEvent);
  55. begin
  56. case Event.What of
  57. evBroadcast :
  58. case Event.Command of
  59. cmUpdate : Update;
  60. end;
  61. end;
  62. inherited HandleEvent(Event);
  63. end;
  64. function TIDEStatusLine.Hint(AHelpCtx: Word): String;
  65. var S: string;
  66. begin
  67. case AHelpCtx of
  68. hcNoContext : S:='';
  69. hcSourceWindow : S:='';
  70. hcHelpWindow : S:='';
  71. hcCalcWindow : S:='';
  72. hcInfoWindow : S:='';
  73. hcClipboardWindow:S:='';
  74. hcBrowserWindow : S:='';
  75. hcMessagesWindow: S:='';
  76. hcGDBWindow : S:='Raw GDB communication window';
  77. hcBreakpointListWindow : S:='All current breakpoints';
  78. hcSystemMenu : S:='System menu';
  79. hcUpdate : S:='Refresh and redraw display';
  80. hcAbout : S:='Show version and copyright information';
  81. hcFileMenu : S:='File managment commands (Open, New, Save, etc.)';
  82. hcNew : S:='Create a new file in a new edit window';
  83. hcNewFromTemplate:S:='Create a new file using a code template';
  84. hcOpen : S:='Locate and open a file in an edit window';
  85. hcSave : S:='Save the file in the active edit window';
  86. hcSaveAs : S:='Save the current file under a different name, directory or drive';
  87. hcSaveAll : S:='Save all modified files';
  88. hcChangeDir : S:='Choose a new default directory';
  89. hcDOSShell : S:='Temporarily exit to DOS';
  90. hcQuit : S:='Exit the IDE';
  91. hcRecentFileBase..hcRecentFileBase+10
  92. : S:='Open indicated file in a new editor window';
  93. hcEditMenu : S:='Clipboard editing commands';
  94. hcUndo : S:='Undo the previous editor operation';
  95. hcRedo : S:='Redo the previously undone editor operation';
  96. hcCut : S:='Remove the selected text and put it in the clipboard';
  97. hcCopy : S:='Copy the selected text in the clipboard';
  98. hcPaste : S:='Insert selected text from the clipboard at the cursor position';
  99. hcCopyWin : S:='Copy the selected text in windows clipboard';
  100. hcPasteWin : S:='Insert selected text from windows clipboard at the cursor position';
  101. hcClear : S:='Delete the selected text';
  102. hcShowClipboard : S:='Open then clipboard window';
  103. hcSearchMenu : S:='Text and symbols search commands';
  104. hcFind : S:='Search for text';
  105. hcReplace : S:='Search for text and replace it with new text';
  106. hcSearchAgain : S:='Repeat the last Search or Replace command';
  107. hcGotoLine : S:='Move the cursor to a specified line number';
  108. hcObjects : S:='Open a browser displaying all objects in the program';
  109. hcModules : S:='Open a browser displaying all modules of the program';
  110. hcGlobals : S:='Open a browser displaying all global symbols in the program';
  111. hcSymbol : S:='Open a browser a current word (not yet scope sensitive)';
  112. hcRunMenu : S:='Execution and parameters';
  113. hcRun : S:='Run the current program';
  114. hcParameters : S:='Set command-line parameters passed to program at execution';
  115. hcResetDebugger : S:='Reset Program';
  116. hcContToCursor : S:='Go on until Cursor position';
  117. hcUntilReturn : S:='Go on until end of current function';
  118. hcUserScreen : S:='Switch to the full-screen user output';
  119. hcCompileMenu : S:='Compile, build & make';
  120. hcCompile : S:='Compile the current source file';
  121. hcMake : S:='Rebuild soruce file and all other files that have been modified';
  122. hcBuild : S:='Rebuild program and all available source files';
  123. hcTarget : S:='Select target platform to compile for';
  124. hcPrimaryFile : S:='Define then file that is the focus of Make and Build';
  125. hcClearPrimary : S:='Clear the file previously set to Primary';
  126. hcInformation : S:='Show compiler messages and program information';
  127. hcCompilerMessages:S:='Show compiler messages window';
  128. hcDebugMenu : S:='Debug Program';
  129. hcToggleBreakpoint : S:='Toggles Breakpoint';
  130. hcNewBreakpoint : S:='Create a new breakpoint';
  131. hcEditBreakpoint : S:='Edit focused breakpoint';
  132. hcDeleteBreakpoint : S:='Delete focused breakpoint';
  133. hcOpenGDBWindow : S:='Open direct window to GDB';
  134. hcAddWatch : S:='Add a new expression to watch';
  135. hcWatches : S:='Open the Watches Window';
  136. hcStack : S:='Show call stack';
  137. hcBreakpointList : S:='Edit breakpoints';
  138. hcToolsMenu : S:='User installed tools';
  139. hcCalculator : S:='Show calculator';
  140. hcGrep : S:='Run grep';
  141. hcMsgGotoSource : S:='Edit source';
  142. hcToolsMessages : S:='Open the message window';
  143. hcToolsBase..
  144. hcToolsBase+MaxToolCount
  145. : S:='User installed tool';
  146. hcASCIITable : S:='Show ASCII table';
  147. hcOptionsMenu : S:='Setting for compiler, editor, mouse, etc.';
  148. hcSwitchesMode : S:='Select settings for normal, debug or release version';
  149. hcCompiler : S:='Set default compiler directives and conditional defines';
  150. hcMemorySizes : S:='Set default stack and heap sizes for generated programs';
  151. hcLinker : S:='Set linker options';
  152. hcDebugger : S:='Set debug information options';
  153. hcDirectories : S:='Set paths for units, include, object and generated files';
  154. hcBrowser : S:='Specify global browser settings';
  155. hcTools : S:='Create or change tools';
  156. hcEnvironmentMenu:S:='Specify environment settins';
  157. hcPreferences : S:='Specify desktop settings';
  158. hcEditor : S:='Specify default editor settings';
  159. hcMouse : S:='Specify mouse settings';
  160. hcDesktopOptions: S:='Specify desktop settings';
  161. hcStartup : S:='Permanently change default startup options';
  162. hcColors : S:='Customize IDE colors for windows, menus, editors, etc.';
  163. hcOpenINI : S:='Load a previously saved options file';
  164. hcSaveINI : S:='Save all the changes made in the options menu';
  165. hcSaveAsINI : S:='Save all the changes made under a different name';
  166. hcWindowMenu : S:='Windows managment commands';
  167. hcTile : S:='Arrange windows on desktop by tiling';
  168. hcCascade : S:='Arrange windows on desktop by cascading';
  169. hcCloseAll : S:='Close all windows on the desktop';
  170. hcResize : S:='Change the size/postion of the active window';
  171. hcZoom : S:='Enlarge or restore the size of the active window';
  172. hcNext : S:='Make the next window active';
  173. hcPrev : S:='Make the previous window active';
  174. hcClose : S:='Close the active window';
  175. hcWindowList : S:='Show a list of all open windows';
  176. hcUserScreenWindow:S:='Show contents of user screen in a window';
  177. hcHelpMenu : S:='Get online help';
  178. hcHelpContents : S:='Show table of contents for Online Help';
  179. hcHelpIndex : S:='Show index for Online Help';
  180. hcHelpTopicSearch:S:='Display help on the word at cursor';
  181. hcHelpPrevTopic : S:='Redisplay the last-viewed Online Help screen';
  182. hcHelpUsingHelp : S:='How to use Online Help';
  183. hcHelpFiles : S:='Install or remove installed help files';
  184. hcOpenAtCursor : S:='Attempt to open the file indicated by the word at cursor';
  185. hcBrowseAtCursor: S:='Attempt to browse the symbol at cursor';
  186. hcEditorOptions : S:='Specify editor settings';
  187. else S:='???';
  188. end;
  189. Hint:=S;
  190. end;
  191. procedure InitHelpSystem;
  192. procedure AddOAFile(HelpFile: string);
  193. begin
  194. {$IFDEF DEBUG}SetStatus(strLoadingHelp+' ('+SmartPath(HelpFile)+')');{$ENDIF}
  195. HelpFacility^.AddOAHelpFile(HelpFile);
  196. {$IFDEF DEBUG}SetStatus(strLoadingHelp);{$ENDIF}
  197. end;
  198. procedure AddHTMLFile(TOCEntry,HelpFile: string);
  199. begin
  200. {$IFDEF DEBUG}SetStatus(strLoadingHelp+' ('+SmartPath(HelpFile)+')');{$ENDIF}
  201. HelpFacility^.AddHTMLHelpFile(HelpFile, TOCEntry);
  202. {$IFDEF DEBUG}SetStatus(strLoadingHelp);{$ENDIF}
  203. end;
  204. var I,P: sw_integer;
  205. S: string;
  206. TopicTitle: string;
  207. begin
  208. New(HelpFacility, Init);
  209. PushStatus(strLoadingHelp);
  210. { AddHTMLFile('User''s guide','C:\FP\USER\USER.HTM');}
  211. for I:=0 to HelpFiles^.Count-1 do
  212. begin
  213. S:=HelpFiles^.At(I)^; TopicTitle:='';
  214. P:=Pos('|',S);
  215. if P>0 then
  216. begin TopicTitle:=copy(S,P+1,255); S:=copy(S,1,P-1); end;
  217. if TopicTitle='' then TopicTitle:=S;
  218. if copy(UpcaseStr(ExtOf(S)),1,4)='.HTM' then { this recognizes both .htm and .html }
  219. AddHTMLFile(TopicTitle,S)
  220. else
  221. AddOAFile(S);
  222. end;
  223. PopStatus;
  224. end;
  225. procedure CheckHelpSystem;
  226. begin
  227. if HelpInited then Exit;
  228. InitHelpSystem;
  229. HelpInited:=true;
  230. end;
  231. procedure DoneHelpSystem;
  232. begin
  233. if assigned(HelpFacility) then
  234. begin
  235. Dispose(HelpFacility, Done);
  236. HelpFacility:=nil;
  237. end;
  238. HelpInited:=false;
  239. end;
  240. procedure HelpCreateWindow;
  241. var R: TRect;
  242. begin
  243. CheckHelpSystem;
  244. if HelpWindow=nil then
  245. begin
  246. Desktop^.GetExtent(R); R.Grow(-15,-3); Dec(R.A.Y);
  247. New(HelpWindow, Init(R, 'Help', 0, 0, SearchFreeWindowNo));
  248. if HelpWindow<>nil then
  249. begin
  250. HelpWindow^.Hide;
  251. Desktop^.Insert(HelpWindow);
  252. end;
  253. end;
  254. end;
  255. procedure Help(FileID, Context: THelpCtx; Modal: boolean);
  256. begin
  257. if Modal then
  258. begin MessageBox('Sorry, modal help not yet implemented.',nil,mfInformation+mfInsertInApp+mfOKButton); Exit; end;
  259. HelpCreateWindow;
  260. with HelpWindow^ do
  261. begin
  262. HelpWindow^.ShowTopic(0,Context);
  263. if GetState(sfVisible)=false then Show;
  264. MakeFirst;
  265. end;
  266. Message(Application,evCommand,cmUpdate,nil);
  267. end;
  268. procedure HelpTopicSearch(Editor: PEditor);
  269. var S: string;
  270. begin
  271. if Editor=nil then S:='' else
  272. S:=GetEditorCurWord(Editor);
  273. HelpTopic(S);
  274. end;
  275. procedure HelpTopic(const S: string);
  276. var FileID: word;
  277. Ctx : THelpCtx;
  278. var Found: boolean;
  279. begin
  280. CheckHelpSystem;
  281. PushStatus(strLocatingTopic);
  282. Found:=HelpFacility^.TopicSearch(S,FileID,Ctx);
  283. PopStatus;
  284. if Found then
  285. Help(FileID,Ctx,false)
  286. else
  287. HelpIndex(S);
  288. end;
  289. procedure HelpIndex(Keyword: string);
  290. begin
  291. HelpCreateWindow;
  292. with HelpWindow^ do
  293. begin
  294. PushStatus(strBuildingHelpIndex);
  295. HelpWindow^.ShowIndex;
  296. if Keyword<>'' then
  297. HelpWindow^.HelpView^.Lookup(Keyword);
  298. PopStatus;
  299. if GetState(sfVisible)=false then Show;
  300. MakeFirst;
  301. end;
  302. Message(Application,evCommand,cmUpdate,nil);
  303. end;
  304. procedure PushStatus(S: string);
  305. begin
  306. if StatusLine=nil then
  307. Exit;
  308. If StatusStackPtr<=MaxStatusLevel then
  309. StatusStack[StatusStackPtr]:=PAdvancedStatusLine(StatusLine)^.GetStatusText
  310. else
  311. StatusStack[MaxStatusLevel]:=PAdvancedStatusLine(StatusLine)^.GetStatusText;
  312. SetStatus(S);
  313. Inc(StatusStackPtr);
  314. end;
  315. procedure PopStatus;
  316. begin
  317. if StatusLine=nil then
  318. Exit;
  319. Dec(StatusStackPtr);
  320. If StatusStackPtr<=MaxStatusLevel then
  321. SetStatus(StatusStack[StatusStackPtr])
  322. else
  323. SetStatus(StatusStack[MaxStatusLevel]);
  324. end;
  325. procedure SetStatus(S: string);
  326. begin
  327. if StatusLine=nil then
  328. Exit;
  329. PAdvancedStatusLine(StatusLine)^.SetStatusText(S);
  330. end;
  331. procedure ClearStatus;
  332. begin
  333. PAdvancedStatusLine(StatusLine)^.ClearStatusText;
  334. end;
  335. procedure InitHelpFiles;
  336. begin
  337. New(HelpFiles, Init(10,10));
  338. end;
  339. procedure DoneHelpFiles;
  340. begin
  341. if assigned(HelpFiles) then
  342. Dispose(HelpFiles, Done);
  343. end;
  344. procedure CloseHelpWindows;
  345. procedure CloseIfHelpWindow(P: PView); {$ifndef FPC}far;{$endif}
  346. begin
  347. if P^.HelpCtx=hcHelpWindow then
  348. begin
  349. Message(P,evCommand,cmClose,nil);
  350. Dispose(P, Done); { help windows are only hidden on close so we've
  351. to destroy them manually }
  352. end;
  353. end;
  354. begin
  355. Desktop^.ForEach(@CloseIfHelpWindow);
  356. end;
  357. END.
  358. {
  359. $Log$
  360. Revision 1.23 1999-09-09 16:31:45 pierre
  361. * some breakpoint related fixes and Help contexts
  362. Revision 1.22 1999/09/09 14:15:27 pierre
  363. + cmCopyWin,cmPasteWin
  364. Revision 1.21 1999/08/16 18:25:17 peter
  365. * Adjusting the selection when the editor didn't contain any line.
  366. * Reserved word recognition redesigned, but this didn't affect the overall
  367. syntax highlight speed remarkably (at least not on my Amd-K6/350).
  368. The syntax scanner loop is a bit slow but the main problem is the
  369. recognition of special symbols. Switching off symbol processing boosts
  370. the performance up to ca. 200%...
  371. * The editor didn't allow copying (for ex to clipboard) of a single character
  372. * 'File|Save as' caused permanently run-time error 3. Not any more now...
  373. * Compiler Messages window (actually the whole desktop) did not act on any
  374. keypress when compilation failed and thus the window remained visible
  375. + Message windows are now closed upon pressing Esc
  376. + At 'Run' the IDE checks whether any sources are modified, and recompiles
  377. only when neccessary
  378. + BlockRead and BlockWrite (Ctrl+K+R/W) implemented in TCodeEditor
  379. + LineSelect (Ctrl+K+L) implemented
  380. * The IDE had problems closing help windows before saving the desktop
  381. Revision 1.20 1999/08/03 20:22:31 peter
  382. + TTab acts now on Ctrl+Tab and Ctrl+Shift+Tab...
  383. + Desktop saving should work now
  384. - History saved
  385. - Clipboard content saved
  386. - Desktop saved
  387. - Symbol info saved
  388. * syntax-highlight bug fixed, which compared special keywords case sensitive
  389. (for ex. 'asm' caused asm-highlighting, while 'ASM' didn't)
  390. * with 'whole words only' set, the editor didn't found occourences of the
  391. searched text, if the text appeared previously in the same line, but didn't
  392. satisfied the 'whole-word' condition
  393. * ^QB jumped to (SelStart.X,SelEnd.X) instead of (SelStart.X,SelStart.Y)
  394. (ie. the beginning of the selection)
  395. * when started typing in a new line, but not at the start (X=0) of it,
  396. the editor inserted the text one character more to left as it should...
  397. * TCodeEditor.HideSelection (Ctrl-K+H) didn't update the screen
  398. * Shift shouldn't cause so much trouble in TCodeEditor now...
  399. * Syntax highlight had problems recognizing a special symbol if it was
  400. prefixed by another symbol character in the source text
  401. * Auto-save also occours at Dos shell, Tool execution, etc. now...
  402. Revision 1.19 1999/07/12 13:14:17 pierre
  403. * LineEnd bug corrected, now goes end of text even if selected
  404. + Until Return for debugger
  405. + Code for Quit inside GDB Window
  406. Revision 1.18 1999/07/10 01:24:16 pierre
  407. + First implementation of watches window
  408. Revision 1.17 1999/06/30 23:58:14 pierre
  409. + BreakpointsList Window implemented
  410. with Edit/New/Delete functions
  411. + Individual breakpoint dialog with support for all types
  412. ignorecount and conditions
  413. (commands are not yet implemented, don't know if this wolud be useful)
  414. awatch and rwatch have problems because GDB does not annotate them
  415. I fixed v4.16 for this
  416. Revision 1.16 1999/06/28 19:32:19 peter
  417. * fixes from gabor
  418. Revision 1.15 1999/06/25 00:39:58 pierre
  419. help for cmSymbol,cmAddWatch,cmStack and cmBreakpoint list
  420. Revision 1.14 1999/04/07 21:55:46 peter
  421. + object support for browser
  422. * html help fixes
  423. * more desktop saving things
  424. * NODEBUG directive to exclude debugger
  425. Revision 1.13 1999/03/23 15:11:28 peter
  426. * desktop saving things
  427. * vesa mode
  428. * preferences dialog
  429. Revision 1.12 1999/03/16 12:38:09 peter
  430. * tools macro fixes
  431. + tph writer
  432. + first things for resource files
  433. Revision 1.11 1999/03/01 15:41:53 peter
  434. + Added dummy entries for functions not yet implemented
  435. * MenuBar didn't update itself automatically on command-set changes
  436. * Fixed Debugging/Profiling options dialog
  437. * TCodeEditor converts spaces to tabs at save only if efUseTabChars is set
  438. * efBackSpaceUnindents works correctly
  439. + 'Messages' window implemented
  440. + Added '$CAP MSG()' and '$CAP EDIT' to available tool-macros
  441. + Added TP message-filter support (for ex. you can call GREP thru
  442. GREP2MSG and view the result in the messages window - just like in TP)
  443. * A 'var' was missing from the param-list of THelpFacility.TopicSearch,
  444. so topic search didn't work...
  445. * In FPHELP.PAS there were still context-variables defined as word instead
  446. of THelpCtx
  447. * StdStatusKeys() was missing from the statusdef for help windows
  448. + Topic-title for index-table can be specified when adding a HTML-files
  449. Revision 1.10 1999/02/22 11:51:35 peter
  450. * browser updates from gabor
  451. Revision 1.9 1999/02/19 18:43:45 peter
  452. + open dialog supports mask list
  453. Revision 1.8 1999/02/11 19:07:21 pierre
  454. * GDBWindow redesigned :
  455. normal editor apart from
  456. that any kbEnter will send the line (for begin to cursor)
  457. to GDB command !
  458. GDBWindow opened in Debugger Menu
  459. still buggy :
  460. -echo should not be present if at end of text
  461. -GDBWindow becomes First after each step (I don't know why !)
  462. Revision 1.7 1999/02/08 17:40:01 pierre
  463. + cmContToCursor added
  464. Revision 1.6 1999/02/08 10:37:43 peter
  465. + html helpviewer
  466. Revision 1.5 1999/02/04 12:23:44 pierre
  467. + cmResetDebugger and cmGrep
  468. * Avoid StatusStack overflow
  469. Revision 1.4 1999/01/21 11:54:13 peter
  470. + tools menu
  471. + speedsearch in symbolbrowser
  472. * working run command
  473. Revision 1.3 1999/01/04 11:49:44 peter
  474. * 'Use tab characters' now works correctly
  475. + Syntax highlight now acts on File|Save As...
  476. + Added a new class to syntax highlight: 'hex numbers'.
  477. * There was something very wrong with the palette managment. Now fixed.
  478. + Added output directory (-FE<xxx>) support to 'Directories' dialog...
  479. * Fixed some possible bugs in Running/Compiling, and the compilation/run
  480. process revised
  481. Revision 1.2 1998/12/28 15:47:44 peter
  482. + Added user screen support, display & window
  483. + Implemented Editor,Mouse Options dialog
  484. + Added location of .INI and .CFG file
  485. + Option (INI) file managment implemented (see bottom of Options Menu)
  486. + Switches updated
  487. + Run program
  488. Revision 1.3 1998/12/22 10:39:42 peter
  489. + options are now written/read
  490. + find and replace routines
  491. }