2
0

fphelp.pas 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. {
  2. This file is part of the Free Pascal Integrated Development Environment
  3. Copyright (c) 1998 by Berczi Gabor
  4. Help routines for the IDE
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. unit FPHelp;
  12. {$ifdef cpullvm}
  13. {$modeswitch nestedprocvars}
  14. {$endif}
  15. {$H-}
  16. interface
  17. uses
  18. Drivers,
  19. FVConsts,
  20. WHelp,WHlpView,WHTML,
  21. WEditor,WCEdit,
  22. WViews,WHTMLScn,
  23. FPViews;
  24. type
  25. PIDEStatusLine = ^TIDEStatusLine;
  26. TIDEStatusLine = object(TAdvancedStatusLine)
  27. function Hint(AHelpCtx: Word): String; virtual;
  28. procedure HandleEvent(var Event: TEvent); virtual;
  29. end;
  30. PFPHTMLFileLinkScanner = ^TFPHTMLFileLinkScanner;
  31. TFPHTMLFileLinkScanner = object(THTMLFileLinkScanner)
  32. function CheckURL(const URL: string): boolean; virtual;
  33. function CheckText(const Text: string): boolean; virtual;
  34. procedure ProcessDoc(Doc: PHTMLLinkScanFile); virtual;
  35. end;
  36. procedure Help(FileID, Context: THelpCtx; Modal: boolean);
  37. procedure HelpIndex(Keyword: string);
  38. procedure HelpTopicSearch(Editor: PEditor);
  39. procedure HelpTopic(const S: string);
  40. procedure CloseHelpWindows;
  41. procedure HelpDebugInfos;
  42. procedure InitHelpSystem;
  43. procedure DoneHelpSystem;
  44. procedure InitHelpFiles;
  45. procedure DoneHelpFiles;
  46. procedure CheckHelpSystem;
  47. procedure PushStatus(S: string);
  48. procedure SetStatus(S: string);
  49. procedure ClearStatus;
  50. procedure PopStatus;
  51. const
  52. HelpWindow : PFPHelpWindow = nil;
  53. HelpInited : boolean = false;
  54. implementation
  55. uses Objects,Views,App,MsgBox,
  56. WUtils,WOAHelp,WHTMLHlp,WNGHelp,WOS2Help,WVPHelp,WWinHelp,
  57. FPConst,FPVars,FPUtils;
  58. const
  59. MaxStatusLevel = 10;
  60. {$if MaxViewWidth < 256}
  61. var StatusStack : array[0..MaxStatusLevel] of string[MaxViewWidth];
  62. {$else}
  63. var StatusStack : array[0..MaxStatusLevel] of string[255{MaxViewWidth}];
  64. {$endif}
  65. const
  66. StatusStackPtr : integer = 0;
  67. {$ifdef useresstrings}
  68. resourcestring
  69. {$else}
  70. const
  71. {$endif}
  72. dialog_help = 'Help';
  73. msg_modalhelpnotimplemented = 'Sorry, modal help not yet implemented.';
  74. { Help messages }
  75. msg_indexingfile = 'Indexing file %s';
  76. msg_loadinghelpfiles = 'Loading help files...';
  77. msg_loadinghelpfile = 'Loading help file...';
  78. msg_buildinghelpindex = 'Building Help Index...';
  79. msg_locatingtopic = 'Locating topic...';
  80. msg_failedtoloadhelpfile = 'Failed to load help file %s';
  81. { Menu hints }
  82. hint_systemmenu = 'System menu';
  83. hint_update = 'Refresh and redraw display';
  84. hint_about = 'Show version and copyright information';
  85. hint_filemenu = 'File management commands (Open, New, Save, etc.)';
  86. hint_filenew = 'Create a new file in a new edit window';
  87. hint_filenewfromtemplate='Create a new file using a code template';
  88. hint_fileopen = 'Locate and open a file in an edit window';
  89. hint_filesave = 'Save the file in the active edit window';
  90. hint_filesaveas = 'Save the current file under a different name, directory or drive';
  91. hint_filesaveall = 'Save all modified files';
  92. hint_print = 'Print current file';
  93. hint_printersetup = 'Setup printer output device';
  94. hint_changedir = 'Choose a new default directory';
  95. hint_dosshell = 'Temporarily exit to shell';
  96. hint_exit = 'Exit the IDE';
  97. hint_openrecentfile = 'Open ';
  98. hint_editmenu = 'Clipboard editing commands';
  99. hint_editundo = 'Undo the previous editor operation';
  100. hint_editredo = 'Redo the previously undone editor operation';
  101. hint_editcut = 'Remove the selected text and put it in the clipboard';
  102. hint_editcopy = 'Copy the selected text in the clipboard';
  103. hint_editpaste = 'Insert selected text from the clipboard at the cursor position';
  104. {$ifdef HASAMIGA}
  105. {$ifdef AROS}
  106. hint_editcopywin = 'Copy the selected text in AROS clipboard';
  107. hint_editpastewin = 'Insert selected text from AROS clipboard at the cursor position';
  108. {$else}
  109. hint_editcopywin = 'Copy the selected text to the system clipboard';
  110. hint_editpastewin = 'Insert selected text from the system clipboard at the cursor position';
  111. {$endif}
  112. {$else}
  113. hint_editcopywin = 'Copy the selected text in windows clipboard';
  114. hint_editpastewin = 'Insert selected text from windows clipboard at the cursor position';
  115. {$endif}
  116. hint_editclear = 'Delete the selected text';
  117. hint_editselectall = 'Select the whole text';
  118. hint_editunselect = 'Unselect everything';
  119. hint_showclipboard = 'Open then clipboard window';
  120. hint_searchmenu = 'Text and symbols search commands';
  121. hint_searchfind = 'Search for text';
  122. hint_searchreplace = 'Search for text and replace it with new text';
  123. hint_replaceagain = 'Repeat the last Replace command (%s with %s)';
  124. hint_searchagain = 'Repeat the last Search command (%s)';
  125. hint_gotoline = 'Move the cursor to a specified line number';
  126. hint_objects = 'Open a browser displaying all objects in the program';
  127. hint_modules = 'Open a browser displaying all modules of the program';
  128. hint_globals = 'Open a browser displaying all global symbols in the program';
  129. hint_symbol = 'Open a browser a current word (not yet scope sensitive)';
  130. hint_runmenu = 'Execution and parameters';
  131. hint_run = 'Run the current program';
  132. hint_rundir = 'Set directory that will be used as current working directory at execution';
  133. hint_runparameters = 'Set command-line parameters passed to program at execution';
  134. hint_resetprogram = 'Reset Program';
  135. hint_rununtilcursor = 'Go on until Cursor position';
  136. hint_rununtilreturn = 'Go on until end of current function';
  137. hint_userscreen = 'Switch to the full-screen user output';
  138. hint_compilemenu = 'Compile, build & make';
  139. hint_compile = 'Compile the current source file';
  140. hint_make = 'Rebuild source file and all other files that have been modified';
  141. hint_build = 'Rebuild program and all available source files';
  142. hint_target = 'Select target platform to compile for';
  143. hint_primaryfile = 'Define the file that is the focus of Make and Build';
  144. hint_clearprimaryfile = 'Clear the file previously set to Primary';
  145. hint_information = 'Show compiler messages and program information';
  146. hint_showmessages = 'Show compiler messages window';
  147. hint_debugmenu = 'Debug Program';
  148. hint_togglebreakpoint = 'Toggles Breakpoint';
  149. hint_createnewbreakpoint = 'Create a new breakpoint';
  150. hint_editbreakpoint = 'Edit focused breakpoint';
  151. hint_deletebreakpoint = 'Delete focused breakpoint';
  152. hint_opengdbwindow = 'Open direct window to GDB';
  153. hint_addwatch = 'Add a new expression to watch';
  154. hint_watches = 'Open the Watches Window';
  155. hint_callstack = 'Show call stack';
  156. hint_editbreakpoints = 'Edit breakpoints';
  157. hint_toolsmenu = 'User installed tools';
  158. hint_calculator = 'Show calculator';
  159. hint_grep = 'Run grep';
  160. hint_gotosource = 'Edit source';
  161. hint_registers = 'Open the Registers Window';
  162. hint_fpuregisters = 'Open the FPU Registers Window';
  163. hint_vectorregisters = 'Open the Vector Registers Window';
  164. hint_messageswindow = 'Open the message window';
  165. hint_gotonextmsg = 'Jumps to the next message in the Message Window';
  166. hint_gotoprevmsg = 'Jumps to the previous message in the Message Window';
  167. hint_usertool = 'User installed tool';
  168. hint_asciitable = 'Show ASCII table';
  169. hint_optionsmenu = 'Setting for compiler, editor, mouse, etc.';
  170. hint_switchesmode = 'Select settings for normal, debug or release version';
  171. hint_compiler = 'Set default compiler directives and conditional defines';
  172. hint_memorysizes = 'Set default stack and heap sizes for generated programs';
  173. hint_linkeroptions = 'Set linker options';
  174. hint_debugoptions = 'Set debug information options';
  175. hint_remotedialog = 'Set remote protocol parameters';
  176. hint_transferremote = 'Transfer executable to remote target';
  177. hint_directories = 'Set paths for units, include, object and generated files';
  178. hint_browser = 'Specify global browser settings';
  179. hint_reloadmodifiedfile= 'Reload file modified on disk';
  180. hint_tools = 'Create or change tools';
  181. hint_environmentmenu = 'Specify environment settins';
  182. hint_preferences = 'Specify preferences settings';
  183. hint_editoroptions = 'Specify default editor settings';
  184. hint_codecomplete = 'Specify CodeComplete keywords';
  185. hint_codetemplates = 'Specify CodeTemplates';
  186. hint_mouseoptions = 'Specify mouse settings';
  187. hint_desktopoptions = 'Specify desktop settings';
  188. hint_startup = 'Permanently change default startup options';
  189. hint_colors = 'Customize IDE colors for windows, menus, editors, etc.';
  190. hint_openini = 'Load a previously saved options file';
  191. hint_saveini = 'Save all the changes made in the options menu';
  192. hint_saveasini = 'Save all the changes made under a different name';
  193. hint_windowmenu = 'Windows management commands';
  194. hint_tile = 'Arrange windows on desktop by tiling';
  195. hint_cascade = 'Arrange windows on desktop by cascading';
  196. hint_closeall = 'Close all windows on the desktop';
  197. hint_resize = 'Change the size/postion of the active window';
  198. hint_zoom = 'Enlarge or restore the size of the active window';
  199. hint_next = 'Make the next window active';
  200. hint_prev = 'Make the previous window active';
  201. hint_hide = 'Hide the current window';
  202. hint_closewindow = 'Close the active window';
  203. hint_windowlist = 'Show a list of all open windows';
  204. hint_userscreenwindow = 'Show contents of user screen in a window';
  205. hint_helpmenu = 'Get online help';
  206. hint_helpcontents = 'Show table of contents for Online Help';
  207. hint_helpindex = 'Show index for Online Help';
  208. hint_helptopicsearch = 'Display help on the word at cursor';
  209. hint_helpprevtopic = 'Redisplay the last-viewed Online Help screen';
  210. hint_helphowtouse = 'How to use Online Help';
  211. hint_helpfiles = 'Install or remove installed help files';
  212. hint_openatcursor = 'Attempt to open the file indicated by the word at cursor';
  213. hint_browseatcursor = 'Attempt to browse the symbol at cursor';
  214. hint_editoroptionscur = 'Specify editor settings';
  215. hint_rawgdbwindow = 'Raw GDB communication window';
  216. hint_disassemblywindow = 'Show mixed Assembly/Source window';
  217. hint_allbreakpoints = 'All current breakpoints';
  218. procedure TIDEStatusLine.HandleEvent(var Event: TEvent);
  219. begin
  220. case Event.What of
  221. evBroadcast :
  222. case Event.Command of
  223. cmUpdate : Update;
  224. end;
  225. end;
  226. inherited HandleEvent(Event);
  227. end;
  228. function TIDEStatusLine.Hint(AHelpCtx: Word): String;
  229. var S: string;
  230. begin
  231. case AHelpCtx of
  232. hcNoContext : S:='';
  233. hcDragging : S:='';
  234. hcSourceWindow : S:='';
  235. hcHelpWindow : S:='';
  236. hcCalcWindow : S:='';
  237. hcInfoWindow : S:='';
  238. hcClipboardWindow:S:='';
  239. hcBrowserWindow : S:='';
  240. hcMessagesWindow: S:='';
  241. hcCompilerMessagesWindow: S:='';
  242. hcASCIITableWindow: S:='';
  243. hcGDBWindow : S:=hint_rawgdbwindow;
  244. hcDisassemblyWindow : S:=hint_disassemblywindow;
  245. hcBreakpointListWindow : S:=hint_allbreakpoints;
  246. hcSystemMenu : S:=hint_systemmenu;
  247. hcUpdate : S:=hint_update;
  248. hcAbout : S:=hint_about;
  249. hcFileMenu : S:=hint_filemenu;
  250. hcNew : S:=hint_filenew;
  251. hcNewFromTemplate:S:=hint_filenewfromtemplate;
  252. hcOpen : S:=hint_fileopen;
  253. hcSave : S:=hint_filesave;
  254. hcSaveAs : S:=hint_filesaveas;
  255. hcSaveAll : S:=hint_filesaveall;
  256. hcPrint : S:=hint_print;
  257. hcPrinterSetup : S:=hint_printersetup;
  258. hcChangeDir : S:=hint_changedir;
  259. hcDOSShell : S:=hint_dosshell;
  260. hcQuit : S:=hint_exit;
  261. hcRecentFileBase..hcRecentFileBase+10
  262. : S:=hint_openrecentfile+RecentFiles[AHelpCtx-hcRecentFileBase].FileName;
  263. hcEditMenu : S:=hint_editmenu;
  264. hcUndo : S:=hint_editundo;
  265. hcRedo : S:=hint_editredo;
  266. hcCut : S:=hint_editcut;
  267. hcCopy : S:=hint_editcopy;
  268. hcPaste : S:=hint_editpaste;
  269. hcSelectAll : S:=hint_editselectall;
  270. hcUnselect : S:=hint_editunselect;
  271. hcCopyWin : S:=hint_editcopywin;
  272. hcPasteWin : S:=hint_editpastewin;
  273. hcClear : S:=hint_editclear;
  274. hcShowClipboard : S:=hint_showclipboard;
  275. hcSearchMenu : S:=hint_searchmenu;
  276. hcFind : S:=hint_searchfind;
  277. hcReplace : S:=hint_searchreplace;
  278. hcSearchAgain : begin
  279. if (FindFlags and ffDoReplace)<>0 then
  280. s:=formatstrstr2(hint_replaceagain,findstr,WEditor.replacestr)
  281. else
  282. s:=formatstrstr(hint_searchagain,findstr);
  283. end;
  284. hcGotoLine : S:=hint_gotoline;
  285. hcObjects : S:=hint_objects;
  286. hcModules : S:=hint_modules;
  287. hcGlobals : S:=hint_globals;
  288. hcSymbol : S:=hint_symbol;
  289. hcRunMenu : S:=hint_runmenu;
  290. hcRun : S:=hint_run;
  291. hcRunDir : S:=hint_rundir;
  292. hcParameters : S:=hint_runparameters;
  293. hcResetDebugger : S:=hint_resetprogram;
  294. hcContToCursor : S:=hint_rununtilcursor;
  295. hcUntilReturn : S:=hint_rununtilreturn;
  296. hcUserScreen : S:=hint_userscreen;
  297. hcCompileMenu : S:=hint_compilemenu;
  298. hcCompile : S:=hint_compile;
  299. hcMake : S:=hint_make;
  300. hcBuild : S:=hint_build;
  301. hcTarget : S:=hint_target;
  302. hcPrimaryFile : S:=hint_primaryfile;
  303. hcClearPrimary : S:=hint_clearprimaryfile;
  304. hcCompilerMessages:S:=hint_showmessages;
  305. hcDebugMenu : S:=hint_debugmenu;
  306. hcToggleBreakpoint : S:=hint_togglebreakpoint;
  307. hcNewBreakpoint : S:=hint_createnewbreakpoint;
  308. hcEditBreakpoint : S:=hint_editbreakpoint;
  309. hcDeleteBreakpoint : S:=hint_deletebreakpoint;
  310. hcOpenGDBWindow : S:=hint_opengdbwindow;
  311. hcAddWatch : S:=hint_addwatch;
  312. hcWatchesWindow : S:=hint_watches;
  313. hcStackWindow : S:=hint_callstack;
  314. hcBreakpointList : S:=hint_editbreakpoints;
  315. hcToolsMenu : S:=hint_toolsmenu;
  316. hcCalculator : S:=hint_calculator;
  317. hcGrep : S:=hint_grep;
  318. hcMsgGotoSource : S:=hint_gotosource;
  319. hcRegistersWindow : S:=hint_registers;
  320. hcFPURegisters : S:=hint_FPURegisters;
  321. hcVectorRegisters : S:=hint_VectorRegisters;
  322. hcToolsMessages : S:=hint_messageswindow;
  323. hcToolsMsgNext : S:=hint_gotonextmsg;
  324. hcToolsMsgPrev : S:=hint_gotoprevmsg;
  325. hcToolsBase..
  326. hcToolsBase+MaxToolCount
  327. : S:=hint_usertool;
  328. hcASCIITable : S:=hint_asciitable;
  329. hcOptionsMenu : S:=hint_optionsmenu;
  330. hcSwitchesMode : S:=hint_switchesmode;
  331. hcCompiler,
  332. hcCompilerNoAltX : S:=hint_compiler;
  333. hcMemorySizes : S:=hint_memorysizes;
  334. hcLinker : S:=hint_linkeroptions;
  335. hcDebugger : S:=hint_debugoptions;
  336. hcDirectories : S:=hint_directories;
  337. hcBrowser,
  338. hcBrowserOptions: S:=hint_browser;
  339. hcTools : S:=hint_tools;
  340. hcRemoteDialog : S:=hint_remotedialog;
  341. hcTransferRemote: S:=hint_transferremote;
  342. hcDoReload : S:=hint_reloadmodifiedfile;
  343. hcEnvironmentMenu:S:=hint_environmentmenu;
  344. hcPreferences : S:=hint_preferences;
  345. hcEditor : S:=hint_editoroptions;
  346. hcCodeCompleteOptions:S:=hint_codecomplete;
  347. hcCodeTemplateOptions:S:=hint_codetemplates;
  348. hcMouse : S:=hint_mouseoptions;
  349. hcDesktopOptions: S:=hint_desktopoptions;
  350. hcStartup : S:=hint_startup;
  351. hcColors : S:=hint_colors;
  352. hcOpenINI : S:=hint_openini;
  353. hcSaveINI : S:=hint_saveini;
  354. hcSaveAsINI : S:=hint_saveasini;
  355. hcWindowMenu : S:=hint_windowmenu;
  356. hcTile : S:=hint_tile;
  357. hcCascade : S:=hint_cascade;
  358. hcCloseAll : S:=hint_closeall;
  359. hcResize : S:=hint_resize;
  360. hcZoom : S:=hint_zoom;
  361. hcNext : S:=hint_next;
  362. hcPrev : S:=hint_prev;
  363. hcHide : S:=hint_hide;
  364. hcClose : S:=hint_closewindow;
  365. hcWindowList : S:=hint_windowlist;
  366. hcUserScreenWindow:S:=hint_userscreenwindow;
  367. hcHelpMenu : S:=hint_helpmenu;
  368. hcHelpContents : S:=hint_helpcontents;
  369. hcHelpIndex : S:=hint_helpindex;
  370. hcHelpTopicSearch:S:=hint_helptopicsearch;
  371. hcHelpPrevTopic : S:=hint_helpprevtopic;
  372. hcHelpUsingHelp : S:=hint_helphowtouse;
  373. hcHelpFiles : S:=hint_helpfiles;
  374. hcOpenAtCursor : S:=hint_openatcursor;
  375. hcBrowseAtCursor: S:=hint_browseatcursor;
  376. hcEditorOptions : S:=hint_editoroptionscur;
  377. else S:='???';
  378. end;
  379. Hint:=S;
  380. end;
  381. procedure TFPHTMLFileLinkScanner.ProcessDoc(Doc: PHTMLLinkScanFile);
  382. begin
  383. PushStatus(FormatStrStr(msg_indexingfile,Doc^.GetDocumentURL));
  384. inherited ProcessDoc(Doc);
  385. PopStatus;
  386. end;
  387. function TFPHTMLFileLinkScanner.CheckURL(const URL: string): boolean;
  388. var OK: boolean;
  389. const HTTPPrefix = 'http:';
  390. FTPPrefix = 'ftp:';
  391. begin
  392. OK:=inherited CheckURL(URL);
  393. if OK then OK:=DirAndNameOf(URL)<>'';
  394. if OK then OK:=CompareText(copy(ExtOf(URL),1,4),'.HTM')=0;
  395. if OK then OK:=CompareText(copy(URL,1,length(HTTPPrefix)),HTTPPrefix)<>0;
  396. if OK then OK:=CompareText(copy(URL,1,length(FTPPrefix)),FTPPrefix)<>0;
  397. CheckURL:=OK;
  398. end;
  399. function TFPHTMLFileLinkScanner.CheckText(const Text: string): boolean;
  400. var OK: boolean;
  401. i : sw_integer;
  402. S: string;
  403. begin
  404. S:=Trim(Text);
  405. OK:=(S<>'') and (S[1]<>'[') and (S[1]<>',');
  406. { remove all Indexes }
  407. if s[1] in ['0'..'9'] then
  408. begin
  409. i:=1;
  410. while (i<length(s)) and (s[i] in ['0'..'9']) do
  411. inc(i);
  412. if (i<length(s)) and (s[i] in [' ',#9,'.']) then
  413. OK:=false;
  414. end;
  415. CheckText:=OK;
  416. end;
  417. procedure InitHelpSystem;
  418. procedure AddHelpFile(HelpFile,Param: string);
  419. begin
  420. {$IFDEF DEBUG}SetStatus(msg_LoadingHelpFile+' ('+SmartPath(HelpFile)+')');{$ENDIF}
  421. if HelpFacility^.AddFile(HelpFile,Param)=nil then
  422. ErrorBox(FormatStrStr(msg_failedtoloadhelpfile,HelpFile),nil);
  423. {$IFDEF DEBUG}SetStatus(msg_LoadingHelpFile);{$ENDIF}
  424. end;
  425. var I,P: sw_integer;
  426. S: string;
  427. Param: string;
  428. begin
  429. New(HelpFacility, Init);
  430. WOAHelp.RegisterHelpType;
  431. WNGHelp.RegisterHelpType;
  432. WOS2Help.RegisterHelpType;
  433. WWinHelp.RegisterHelpType;
  434. WVPHelp.RegisterHelpType;
  435. WHTMLHlp.RegisterHelpType; // Also registers chm and html index (.htx)
  436. PushStatus(msg_LoadingHelpFiles);
  437. for I:=0 to HelpFiles^.Count-1 do
  438. begin
  439. S:=HelpFiles^.At(I)^; Param:='';
  440. P:=Pos('|',S);
  441. if P>0 then
  442. begin Param:=copy(S,P+1,High(S)); S:=copy(S,1,P-1); end;
  443. AddHelpFile(S,Param);
  444. end;
  445. PopStatus;
  446. end;
  447. procedure CheckHelpSystem;
  448. begin
  449. if HelpInited then Exit;
  450. InitHelpSystem;
  451. HelpInited:=true;
  452. end;
  453. procedure DoneHelpSystem;
  454. begin
  455. if assigned(HelpFacility) then
  456. begin
  457. Dispose(HelpFacility, Done);
  458. HelpFacility:=nil;
  459. end;
  460. HelpInited:=false;
  461. end;
  462. procedure HelpCreateWindow;
  463. var R: TRect;
  464. begin
  465. CheckHelpSystem;
  466. if HelpWindow=nil then
  467. begin
  468. Desktop^.GetExtent(R); R.Grow(-15,-3); Dec(R.A.Y);
  469. New(HelpWindow, Init(R, dialog_help, 0, 0, SearchFreeWindowNo));
  470. if HelpWindow<>nil then
  471. begin
  472. HelpWindow^.Hide;
  473. Desktop^.Insert(HelpWindow);
  474. end;
  475. end;
  476. end;
  477. procedure Help(FileID, Context: THelpCtx; Modal: boolean);
  478. begin
  479. if Modal then
  480. begin MessageBox(msg_modalhelpnotimplemented,nil,mfInformation+mfInsertInApp+mfOKButton); Exit; end;
  481. HelpCreateWindow;
  482. with HelpWindow^ do
  483. begin
  484. HelpWindow^.ShowTopic(FileID,Context);
  485. if GetState(sfVisible)=false then Show;
  486. MakeFirst;
  487. end;
  488. Message(Application,evCommand,cmUpdate,nil);
  489. end;
  490. procedure HelpTopicSearch(Editor: PEditor);
  491. var S: string;
  492. begin
  493. if Editor=nil then S:='' else
  494. S:=GetEditorCurWord(Editor,[]);
  495. HelpTopic(S);
  496. end;
  497. procedure HelpTopic(const S: string);
  498. var FileID: word;
  499. Ctx : THelpCtx;
  500. var Found: boolean;
  501. begin
  502. CheckHelpSystem;
  503. PushStatus(msg_LocatingTopic);
  504. Found:=HelpFacility^.TopicSearch(S,FileID,Ctx);
  505. PopStatus;
  506. if Found then
  507. Help(FileID,Ctx,false)
  508. else
  509. HelpIndex(S);
  510. end;
  511. procedure HelpIndex(Keyword: string);
  512. begin
  513. HelpCreateWindow;
  514. with HelpWindow^ do
  515. begin
  516. PushStatus(msg_BuildingHelpIndex);
  517. HelpWindow^.ShowIndex;
  518. if Keyword<>'' then
  519. HelpWindow^.HelpView^.Lookup(Keyword);
  520. PopStatus;
  521. if GetState(sfVisible)=false then Show;
  522. MakeFirst;
  523. end;
  524. Message(Application,evCommand,cmUpdate,nil);
  525. end;
  526. procedure HelpDebugInfos;
  527. begin
  528. HelpCreateWindow;
  529. HelpWindow^.ShowDebugInfos;
  530. end;
  531. procedure PushStatus(S: string);
  532. begin
  533. if StatusLine=nil then
  534. Exit;
  535. If StatusStackPtr<=MaxStatusLevel then
  536. StatusStack[StatusStackPtr]:=PAdvancedStatusLine(StatusLine)^.GetStatusText
  537. else
  538. StatusStack[MaxStatusLevel]:=PAdvancedStatusLine(StatusLine)^.GetStatusText;
  539. SetStatus(S);
  540. Inc(StatusStackPtr);
  541. end;
  542. procedure PopStatus;
  543. begin
  544. if StatusLine=nil then
  545. Exit;
  546. Dec(StatusStackPtr);
  547. If StatusStackPtr<=MaxStatusLevel then
  548. SetStatus(StatusStack[StatusStackPtr])
  549. else
  550. SetStatus(StatusStack[MaxStatusLevel]);
  551. end;
  552. procedure SetStatus(S: string);
  553. begin
  554. if StatusLine=nil then
  555. Exit;
  556. PAdvancedStatusLine(StatusLine)^.SetStatusText(S);
  557. end;
  558. procedure ClearStatus;
  559. begin
  560. PAdvancedStatusLine(StatusLine)^.ClearStatusText;
  561. end;
  562. function FPHTMLGetSectionColor(Section: THTMLSection; var Color: byte): boolean;
  563. var OK: boolean;
  564. S: string;
  565. begin
  566. Color:=0;
  567. OK:=(ord(Section) in [1..length(CHTMLSectionAttrs)]);
  568. if OK then
  569. begin
  570. S:=#0;
  571. S:=copy(CHTMLSectionAttrs,ord(Section),1);
  572. if Assigned(Application)=false then Color:=0 else
  573. Color:=Application^.GetColor(ord(S[1]));
  574. if (Color and $0f) = ((Color and $f0) shr 4) then { same color ? }
  575. OK:=false;
  576. end;
  577. FPHTMLGetSectionColor:=OK;
  578. end;
  579. function FPNGGetAttrColor(Attr: AnsiChar; var Color: byte): boolean;
  580. var OK: boolean;
  581. begin
  582. OK:=false;
  583. case Attr of
  584. 'A' : OK:=FPHTMLGetSectionColor(hsHeading1,Color);
  585. 'B' : OK:=FPHTMLGetSectionColor(hsHeading2,Color);
  586. 'b' : OK:=FPHTMLGetSectionColor(hsHeading5,Color);
  587. 'U' : OK:=FPHTMLGetSectionColor(hsHeading3,Color);
  588. 'N' : OK:=FPHTMLGetSectionColor(hsHeading4,Color);
  589. {$ifdef DEBUGMSG}
  590. else ErrorBox('Unknown attr encountered : "'+Attr+'"',nil);
  591. {$endif}
  592. end;
  593. FPNGGetAttrColor:=OK;
  594. end;
  595. function FPINFGetAttrColor(TextStyle, TextColor: byte; var Color: byte): boolean;
  596. var OK: boolean;
  597. begin
  598. OK:=false;
  599. case TextColor of
  600. 1 : OK:=FPHTMLGetSectionColor(hsHeading1,Color);
  601. 2 : OK:=FPHTMLGetSectionColor(hsHeading2,Color);
  602. 3 : OK:=FPHTMLGetSectionColor(hsHeading3,Color);
  603. end;
  604. FPINFGetAttrColor:=OK;
  605. end;
  606. procedure InitHelpFiles;
  607. begin
  608. HTMLGetSectionColor:={$ifdef FPC}@{$endif}FPHTMLGetSectionColor;
  609. NGGetAttrColor:={$ifdef FPC}@{$endif}FPNGGetAttrColor;
  610. INFGetAttrColor:={$ifdef FPC}@{$endif}FPINFGetAttrColor;
  611. New(HelpFiles, Init(10,10));
  612. end;
  613. procedure DoneHelpFiles;
  614. begin
  615. if assigned(HelpFiles) then
  616. Dispose(HelpFiles, Done);
  617. end;
  618. procedure CloseHelpWindows;
  619. procedure CloseIfHelpWindow(P: PView);
  620. begin
  621. if P^.HelpCtx=hcHelpWindow then
  622. begin
  623. Message(P,evCommand,cmClose,nil);
  624. {Dispose(P, Done); help windows are only hidden on close so we've
  625. to destroy them manually
  626. but this was wrong as it was not correctly
  627. resetting the corresponding pointer in whelp unit PM }
  628. end;
  629. end;
  630. begin
  631. Desktop^.ForEach(TCallbackProcParam(@CloseIfHelpWindow));
  632. end;
  633. END.