fphelp.pas 14 KB

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