fphelp.pas 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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(Keyword: string);
  30. procedure HelpTopicSearch(Editor: PEditor);
  31. procedure HelpTopic(S: string);
  32. procedure InitHelpSystem;
  33. procedure DoneHelpSystem;
  34. procedure InitHelpFiles;
  35. procedure DoneHelpFiles;
  36. procedure PushStatus(S: string);
  37. procedure SetStatus(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. hcTools : S:='Create or change tools';
  134. hcEnvironmentMenu:S:='Specify environment settins';
  135. hcPreferences : S:='Specify desktop settings';
  136. hcEditor : S:='Specify default editor settings';
  137. hcMouse : S:='Specify mouse settings';
  138. hcStartup : S:='Permanently change default startup options';
  139. hcColors : S:='Customize IDE colors for windows, menus, editors, etc.';
  140. hcOpenINI : S:='Load a previously saved options file';
  141. hcSaveINI : S:='Save all the changes made in the options menu';
  142. hcSaveAsINI : S:='Save all the changes made under a different name';
  143. hcWindowMenu : S:='Windows managment commands';
  144. hcTile : S:='Arrange windows on desktop by tiling';
  145. hcCascade : S:='Arrange windows on desktop by cascading';
  146. hcCloseAll : S:='Close all windows on the desktop';
  147. hcResize : S:='Change the size/postion of the active window';
  148. hcZoom : S:='Enlarge or restore the size of the active window';
  149. hcNext : S:='Make the next window active';
  150. hcPrev : S:='Make the previous window active';
  151. hcClose : S:='Close the active window';
  152. hcWindowList : S:='Show a list of all open windows';
  153. hcUserScreenWindow:S:='Show contents of user screen in a window';
  154. hcHelpMenu : S:='Get online help';
  155. hcHelpContents : S:='Show table of contents for Online Help';
  156. hcHelpIndex : S:='Show index for Online Help';
  157. hcHelpTopicSearch:S:='Display help on the word at cursor';
  158. hcHelpPrevTopic : S:='Redisplay the last-viewed Online Help screen';
  159. hcHelpUsingHelp : S:='How to use Online Help';
  160. hcHelpFiles : S:='Install or remove installed help files';
  161. hcOpenAtCursor : S:='Attempt to open the file indicated by the word at cursor';
  162. hcBrowseAtCursor: S:='Attempt to browse the symbol at cursor';
  163. hcEditorOptions : S:='Specify editor settings';
  164. else S:='???';
  165. end;
  166. Hint:=S;
  167. end;
  168. procedure InitHelpSystem;
  169. procedure AddOAFile(HelpFile: string);
  170. begin
  171. {$IFDEF DEBUG}SetStatus(strLoadingHelp+' ('+SmartPath(HelpFile)+')');{$ENDIF}
  172. HelpFacility^.AddOAHelpFile(HelpFile);
  173. {$IFDEF DEBUG}SetStatus(strLoadingHelp);{$ENDIF}
  174. end;
  175. procedure AddHTMLFile(TOCEntry,HelpFile: string);
  176. begin
  177. {$IFDEF DEBUG}SetStatus(strLoadingHelp+' ('+SmartPath(HelpFile)+')');{$ENDIF}
  178. HelpFacility^.AddHTMLHelpFile(HelpFile, TOCEntry);
  179. {$IFDEF DEBUG}SetStatus(strLoadingHelp);{$ENDIF}
  180. end;
  181. var I: integer;
  182. S: string;
  183. begin
  184. New(HelpFacility, Init);
  185. PushStatus(strLoadingHelp);
  186. { AddHTMLFile('User''s guide','C:\FP\USER\USER.HTM');}
  187. for I:=0 to HelpFiles^.Count-1 do
  188. begin
  189. S:=HelpFiles^.At(I)^;
  190. if copy(UpcaseStr(ExtOf(S)),1,4)='.HTM' then
  191. AddHTMLFile(S,S)
  192. else
  193. AddOAFile(S);
  194. end;
  195. PopStatus;
  196. end;
  197. procedure CheckHelpSystem;
  198. begin
  199. if HelpInited then Exit;
  200. InitHelpSystem;
  201. HelpInited:=true;
  202. end;
  203. procedure DoneHelpSystem;
  204. begin
  205. if HelpFacility<>nil then Dispose(HelpFacility, Done); HelpFacility:=nil;
  206. HelpInited:=false;
  207. end;
  208. procedure HelpCreateWindow;
  209. var R: TRect;
  210. begin
  211. CheckHelpSystem;
  212. if HelpWindow=nil then
  213. begin
  214. Desktop^.GetExtent(R); R.Grow(-15,-3); Dec(R.A.Y);
  215. New(HelpWindow, Init(R, 'Help', 0, 0, wnNoNumber));
  216. if HelpWindow<>nil then
  217. begin
  218. HelpWindow^.HelpCtx:=hcHelpWindow;
  219. HelpWindow^.HideOnClose:=true;
  220. HelpWindow^.Hide;
  221. Desktop^.Insert(HelpWindow);
  222. end;
  223. end;
  224. end;
  225. procedure Help(FileID, Context: word; Modal: boolean);
  226. begin
  227. if Modal then
  228. begin MessageBox('Sorry, modal help not yet implemented.',nil,mfInformation+mfInsertInApp+mfOKButton); Exit; end;
  229. HelpCreateWindow;
  230. with HelpWindow^ do
  231. begin
  232. HelpWindow^.ShowTopic(0,Context);
  233. if GetState(sfVisible)=false then Show;
  234. MakeFirst;
  235. end;
  236. Message(Application,evCommand,cmUpdate,nil);
  237. end;
  238. procedure HelpTopicSearch(Editor: PEditor);
  239. var S: string;
  240. begin
  241. if Editor=nil then S:='' else
  242. S:=GetEditorCurWord(Editor);
  243. HelpTopic(S);
  244. end;
  245. procedure HelpTopic(S: string);
  246. var FileID, Ctx: word;
  247. var Found: boolean;
  248. begin
  249. CheckHelpSystem;
  250. PushStatus(strLocatingTopic);
  251. Found:=HelpFacility^.TopicSearch(S,FileID,Ctx);
  252. PopStatus;
  253. if Found then
  254. Help(FileID,Ctx,false) else
  255. HelpIndex(S);
  256. end;
  257. procedure HelpIndex(Keyword: string);
  258. begin
  259. HelpCreateWindow;
  260. with HelpWindow^ do
  261. begin
  262. PushStatus(strBuildingHelpIndex);
  263. HelpWindow^.ShowIndex;
  264. if Keyword<>'' then
  265. HelpWindow^.HelpView^.Lookup(Keyword);
  266. PopStatus;
  267. if GetState(sfVisible)=false then Show;
  268. MakeFirst;
  269. end;
  270. Message(Application,evCommand,cmUpdate,nil);
  271. end;
  272. procedure PushStatus(S: string);
  273. begin
  274. if StatusLine=nil then Exit;
  275. If StatusStackPtr<=MaxStatusLevel then
  276. StatusStack[StatusStackPtr]:=PAdvancedStatusLine(StatusLine)^.GetStatusText
  277. else
  278. StatusStack[MaxStatusLevel]:=PAdvancedStatusLine(StatusLine)^.GetStatusText;
  279. SetStatus(S);
  280. Inc(StatusStackPtr);
  281. end;
  282. procedure PopStatus;
  283. begin
  284. if StatusLine=nil then Exit;
  285. Dec(StatusStackPtr);
  286. If StatusStackPtr<=MaxStatusLevel then
  287. SetStatus(StatusStack[StatusStackPtr])
  288. else
  289. SetStatus(StatusStack[MaxStatusLevel]);
  290. end;
  291. procedure SetStatus(S: string);
  292. begin
  293. if StatusLine=nil then Exit;
  294. PAdvancedStatusLine(StatusLine)^.SetStatusText(S);
  295. end;
  296. procedure ClearStatus;
  297. begin
  298. PAdvancedStatusLine(StatusLine)^.ClearStatusText;
  299. end;
  300. procedure InitHelpFiles;
  301. begin
  302. New(HelpFiles, Init(10,10));
  303. end;
  304. procedure DoneHelpFiles;
  305. begin
  306. if HelpFiles<>nil then Dispose(HelpFiles, Done);
  307. end;
  308. END.
  309. {
  310. $Log$
  311. Revision 1.8 1999-02-11 19:07:21 pierre
  312. * GDBWindow redesigned :
  313. normal editor apart from
  314. that any kbEnter will send the line (for begin to cursor)
  315. to GDB command !
  316. GDBWindow opened in Debugger Menu
  317. still buggy :
  318. -echo should not be present if at end of text
  319. -GDBWindow becomes First after each step (I don't know why !)
  320. Revision 1.7 1999/02/08 17:40:01 pierre
  321. + cmContToCursor added
  322. Revision 1.6 1999/02/08 10:37:43 peter
  323. + html helpviewer
  324. Revision 1.5 1999/02/04 12:23:44 pierre
  325. + cmResetDebugger and cmGrep
  326. * Avoid StatusStack overflow
  327. Revision 1.4 1999/01/21 11:54:13 peter
  328. + tools menu
  329. + speedsearch in symbolbrowser
  330. * working run command
  331. Revision 1.3 1999/01/04 11:49:44 peter
  332. * 'Use tab characters' now works correctly
  333. + Syntax highlight now acts on File|Save As...
  334. + Added a new class to syntax highlight: 'hex numbers'.
  335. * There was something very wrong with the palette managment. Now fixed.
  336. + Added output directory (-FE<xxx>) support to 'Directories' dialog...
  337. * Fixed some possible bugs in Running/Compiling, and the compilation/run
  338. process revised
  339. Revision 1.2 1998/12/28 15:47:44 peter
  340. + Added user screen support, display & window
  341. + Implemented Editor,Mouse Options dialog
  342. + Added location of .INI and .CFG file
  343. + Option (INI) file managment implemented (see bottom of Options Menu)
  344. + Switches updated
  345. + Run program
  346. Revision 1.3 1998/12/22 10:39:42 peter
  347. + options are now written/read
  348. + find and replace routines
  349. }