fphelp.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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,
  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,
  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. hcUserScreen : S:='Switch to the full-screen user output';
  108. hcCompileMenu : S:='Compile, build & make';
  109. hcCompile : S:='Compile the current source file';
  110. hcMake : S:='Rebuild soruce file and all other files that have been modified';
  111. hcBuild : S:='Rebuild program and all available source files';
  112. hcTarget : S:='Select target platform to compile for';
  113. hcPrimaryFile : S:='Define then file that is the focus of Make and Build';
  114. hcClearPrimary : S:='Clear the file previously set to Primary';
  115. hcInformation : S:='Show compiler messages and program information';
  116. hcDebugMenu : S:='';
  117. hcToggleBreakpoint : S:='Toggles Breakpoint';
  118. hcToolsMenu : S:='User installed tools';
  119. hcCalculator : S:='Show calculator';
  120. hcGrep : S:='Run grep';
  121. hcToolsBase..
  122. hcToolsBase+MaxToolCount
  123. : S:='User installed tool';
  124. hcOptionsMenu : S:='Setting for compiler, editor, mouse, etc.';
  125. hcSwitchesMode : S:='Select settings for normal, debug or release version';
  126. hcCompiler : S:='Set default compiler directives and conditional defines';
  127. hcMemorySizes : S:='Set default stack and heap sizes for generated programs';
  128. hcLinker : S:='Set linker options';
  129. hcDebugger : S:='Set debug information options';
  130. hcDirectories : S:='Set paths for units, include, object and generated files';
  131. hcTools : S:='Create or change tools';
  132. hcEnvironmentMenu:S:='Specify environment settins';
  133. hcPreferences : S:='Specify desktop settings';
  134. hcEditor : S:='Specify default editor settings';
  135. hcMouse : S:='Specify mouse settings';
  136. hcStartup : S:='Permanently change default startup options';
  137. hcColors : S:='Customize IDE colors for windows, menus, editors, etc.';
  138. hcOpenINI : S:='Load a previously saved options file';
  139. hcSaveINI : S:='Save all the changes made in the options menu';
  140. hcSaveAsINI : S:='Save all the changes made under a different name';
  141. hcWindowMenu : S:='Windows managment commands';
  142. hcTile : S:='Arrange windows on desktop by tiling';
  143. hcCascade : S:='Arrange windows on desktop by cascading';
  144. hcCloseAll : S:='Close all windows on the desktop';
  145. hcResize : S:='Change the size/postion of the active window';
  146. hcZoom : S:='Enlarge or restore the size of the active window';
  147. hcNext : S:='Make the next window active';
  148. hcPrev : S:='Make the previous window active';
  149. hcClose : S:='Close the active window';
  150. hcWindowList : S:='Show a list of all open windows';
  151. hcUserScreenWindow:S:='Show contents of user screen in a window';
  152. hcHelpMenu : S:='Get online help';
  153. hcHelpContents : S:='Show table of contents for Online Help';
  154. hcHelpIndex : S:='Show index for Online Help';
  155. hcHelpTopicSearch:S:='Display help on the word at cursor';
  156. hcHelpPrevTopic : S:='Redisplay the last-viewed Online Help screen';
  157. hcHelpUsingHelp : S:='How to use Online Help';
  158. hcHelpFiles : S:='Install or remove installed help files';
  159. hcOpenAtCursor : S:='Attempt to open the file indicated by the word at cursor';
  160. hcBrowseAtCursor: S:='Attempt to browse the symbol at cursor';
  161. hcEditorOptions : S:='Specify editor settings';
  162. else S:='???';
  163. end;
  164. Hint:=S;
  165. end;
  166. procedure InitHelpSystem;
  167. procedure AddFile(HelpFile: string);
  168. begin
  169. {$IFDEF DEBUG}SetStatus(strLoadingHelp+' ('+SmartPath(HelpFile)+')');{$ENDIF}
  170. HelpFacility^.AddHelpFile(HelpFile);
  171. {$IFDEF DEBUG}SetStatus(strLoadingHelp);{$ENDIF}
  172. end;
  173. var I: integer;
  174. begin
  175. New(HelpFacility, Init);
  176. PushStatus(strLoadingHelp);
  177. for I:=0 to HelpFiles^.Count-1 do
  178. AddFile(HelpFiles^.At(I)^);
  179. PopStatus;
  180. end;
  181. procedure CheckHelpSystem;
  182. begin
  183. if HelpInited then Exit;
  184. InitHelpSystem;
  185. HelpInited:=true;
  186. end;
  187. procedure DoneHelpSystem;
  188. begin
  189. if HelpFacility<>nil then Dispose(HelpFacility, Done); HelpFacility:=nil;
  190. HelpInited:=false;
  191. end;
  192. procedure HelpCreateWindow;
  193. var R: TRect;
  194. begin
  195. CheckHelpSystem;
  196. if HelpWindow=nil then
  197. begin
  198. Desktop^.GetExtent(R); R.Grow(-15,-3); Dec(R.A.Y);
  199. New(HelpWindow, Init(R, 'Help', 0, 0, wnNoNumber));
  200. if HelpWindow<>nil then
  201. begin
  202. HelpWindow^.HelpCtx:=hcHelpWindow;
  203. HelpWindow^.HideOnClose:=true;
  204. HelpWindow^.Hide;
  205. Desktop^.Insert(HelpWindow);
  206. end;
  207. end;
  208. end;
  209. procedure Help(FileID, Context: word; Modal: boolean);
  210. begin
  211. if Modal then
  212. begin MessageBox('Sorry, modal help not yet implemented.',nil,mfInformation+mfInsertInApp+mfOKButton); Exit; end;
  213. HelpCreateWindow;
  214. with HelpWindow^ do
  215. begin
  216. HelpWindow^.ShowTopic(0,Context);
  217. if GetState(sfVisible)=false then Show;
  218. MakeFirst;
  219. end;
  220. Message(Application,evCommand,cmUpdate,nil);
  221. end;
  222. procedure HelpTopicSearch(Editor: PEditor);
  223. var S: string;
  224. begin
  225. if Editor=nil then S:='' else
  226. S:=GetEditorCurWord(Editor);
  227. HelpTopic(S);
  228. end;
  229. procedure HelpTopic(S: string);
  230. var FileID, Ctx: word;
  231. var Found: boolean;
  232. begin
  233. CheckHelpSystem;
  234. PushStatus(strLocatingTopic);
  235. Found:=HelpFacility^.TopicSearch(S,FileID,Ctx);
  236. PopStatus;
  237. if Found then
  238. Help(FileID,Ctx,false) else
  239. HelpIndex(S);
  240. end;
  241. procedure HelpIndex(Keyword: string);
  242. begin
  243. HelpCreateWindow;
  244. with HelpWindow^ do
  245. begin
  246. PushStatus(strBuildingHelpIndex);
  247. HelpWindow^.ShowIndex;
  248. if Keyword<>'' then
  249. HelpWindow^.HelpView^.Lookup(Keyword);
  250. PopStatus;
  251. if GetState(sfVisible)=false then Show;
  252. MakeFirst;
  253. end;
  254. Message(Application,evCommand,cmUpdate,nil);
  255. end;
  256. procedure PushStatus(S: string);
  257. begin
  258. if StatusLine=nil then Exit;
  259. If StatusStackPtr<=MaxStatusLevel then
  260. StatusStack[StatusStackPtr]:=PAdvancedStatusLine(StatusLine)^.GetStatusText
  261. else
  262. StatusStack[MaxStatusLevel]:=PAdvancedStatusLine(StatusLine)^.GetStatusText;
  263. SetStatus(S);
  264. Inc(StatusStackPtr);
  265. end;
  266. procedure PopStatus;
  267. begin
  268. if StatusLine=nil then Exit;
  269. Dec(StatusStackPtr);
  270. If StatusStackPtr<=MaxStatusLevel then
  271. SetStatus(StatusStack[StatusStackPtr])
  272. else
  273. SetStatus(StatusStack[MaxStatusLevel]);
  274. end;
  275. procedure SetStatus(S: string);
  276. begin
  277. if StatusLine=nil then Exit;
  278. PAdvancedStatusLine(StatusLine)^.SetStatusText(S);
  279. end;
  280. procedure ClearStatus;
  281. begin
  282. PAdvancedStatusLine(StatusLine)^.ClearStatusText;
  283. end;
  284. procedure InitHelpFiles;
  285. begin
  286. New(HelpFiles, Init(10,10));
  287. end;
  288. procedure DoneHelpFiles;
  289. begin
  290. if HelpFiles<>nil then Dispose(HelpFiles, Done);
  291. end;
  292. END.
  293. {
  294. $Log$
  295. Revision 1.5 1999-02-04 12:23:44 pierre
  296. + cmResetDebugger and cmGrep
  297. * Avoid StatusStack overflow
  298. Revision 1.4 1999/01/21 11:54:13 peter
  299. + tools menu
  300. + speedsearch in symbolbrowser
  301. * working run command
  302. Revision 1.3 1999/01/04 11:49:44 peter
  303. * 'Use tab characters' now works correctly
  304. + Syntax highlight now acts on File|Save As...
  305. + Added a new class to syntax highlight: 'hex numbers'.
  306. * There was something very wrong with the palette managment. Now fixed.
  307. + Added output directory (-FE<xxx>) support to 'Directories' dialog...
  308. * Fixed some possible bugs in Running/Compiling, and the compilation/run
  309. process revised
  310. Revision 1.2 1998/12/28 15:47:44 peter
  311. + Added user screen support, display & window
  312. + Implemented Editor,Mouse Options dialog
  313. + Added location of .INI and .CFG file
  314. + Option (INI) file managment implemented (see bottom of Options Menu)
  315. + Switches updated
  316. + Run program
  317. Revision 1.3 1998/12/22 10:39:42 peter
  318. + options are now written/read
  319. + find and replace routines
  320. }