fphelp.pas 13 KB

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