fphelp.pas 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  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,
  16. FVConsts,
  17. WHelp,WHlpView,WHTML,
  18. WEditor,WCEdit,
  19. WViews,WHTMLScn,
  20. FPViews;
  21. type
  22. PIDEStatusLine = ^TIDEStatusLine;
  23. TIDEStatusLine = object(TAdvancedStatusLine)
  24. function Hint(AHelpCtx: Word): String; virtual;
  25. procedure HandleEvent(var Event: TEvent); virtual;
  26. end;
  27. PFPHTMLFileLinkScanner = ^TFPHTMLFileLinkScanner;
  28. TFPHTMLFileLinkScanner = object(THTMLFileLinkScanner)
  29. function CheckURL(const URL: string): boolean; virtual;
  30. function CheckText(const Text: string): boolean; virtual;
  31. procedure ProcessDoc(Doc: PHTMLLinkScanFile); virtual;
  32. end;
  33. procedure Help(FileID, Context: THelpCtx; Modal: boolean);
  34. procedure HelpIndex(Keyword: string);
  35. procedure HelpTopicSearch(Editor: PEditor);
  36. procedure HelpTopic(const S: string);
  37. procedure CloseHelpWindows;
  38. procedure InitHelpSystem;
  39. procedure DoneHelpSystem;
  40. procedure InitHelpFiles;
  41. procedure DoneHelpFiles;
  42. procedure CheckHelpSystem;
  43. procedure PushStatus(S: string);
  44. procedure SetStatus(S: string);
  45. procedure ClearStatus;
  46. procedure PopStatus;
  47. const
  48. HelpWindow : PFPHelpWindow = nil;
  49. HelpInited : boolean = false;
  50. implementation
  51. uses Objects,Views,App,MsgBox,
  52. WUtils,WOAHelp,WHTMLHlp,WNGHelp,WOS2Help,WVPHelp,WWinHelp,
  53. FPString,FPConst,FPVars,FPUtils;
  54. const
  55. MaxStatusLevel = {$ifdef FPC}10{$else}1{$endif};
  56. var StatusStack : array[0..MaxStatusLevel] of string[MaxViewWidth];
  57. const
  58. StatusStackPtr : integer = 0;
  59. procedure TIDEStatusLine.HandleEvent(var Event: TEvent);
  60. begin
  61. case Event.What of
  62. evBroadcast :
  63. case Event.Command of
  64. cmUpdate : Update;
  65. end;
  66. end;
  67. inherited HandleEvent(Event);
  68. end;
  69. function TIDEStatusLine.Hint(AHelpCtx: Word): String;
  70. var S: string;
  71. begin
  72. case AHelpCtx of
  73. hcNoContext : S:='';
  74. hcDragging : S:='';
  75. hcSourceWindow : S:='';
  76. hcHelpWindow : S:='';
  77. hcCalcWindow : S:='';
  78. hcInfoWindow : S:='';
  79. hcClipboardWindow:S:='';
  80. hcBrowserWindow : S:='';
  81. hcMessagesWindow: S:='';
  82. hcCompilerMessagesWindow: S:='';
  83. hcASCIITableWindow: S:='';
  84. hcGDBWindow : S:=hint_rawgdbwindow;
  85. hcDisassemblyWindow : S:=hint_disassemblywindow;
  86. hcBreakpointListWindow : S:=hint_allbreakpoints;
  87. hcSystemMenu : S:=hint_systemmenu;
  88. hcUpdate : S:=hint_update;
  89. hcAbout : S:=hint_about;
  90. hcFileMenu : S:=hint_filemenu;
  91. hcNew : S:=hint_filenew;
  92. hcNewFromTemplate:S:=hint_filenewfromtemplate;
  93. hcOpen : S:=hint_fileopen;
  94. hcSave : S:=hint_filesave;
  95. hcSaveAs : S:=hint_filesaveas;
  96. hcSaveAll : S:=hint_filesaveall;
  97. hcChangeDir : S:=hint_changedir;
  98. hcDOSShell : S:=hint_dosshell;
  99. hcQuit : S:=hint_exit;
  100. hcRecentFileBase..hcRecentFileBase+10
  101. : S:=hint_openrecentfile;
  102. hcEditMenu : S:=hint_editmenu;
  103. hcUndo : S:=hint_editundo;
  104. hcRedo : S:=hint_editredo;
  105. hcCut : S:=hint_editcut;
  106. hcCopy : S:=hint_editcopy;
  107. hcPaste : S:=hint_editpaste;
  108. hcCopyWin : S:=hint_editcopywin;
  109. hcPasteWin : S:=hint_editpastewin;
  110. hcClear : S:=hint_editclear;
  111. hcShowClipboard : S:=hint_showclipboard;
  112. hcSearchMenu : S:=hint_searchmenu;
  113. hcFind : S:=hint_searchfind;
  114. hcReplace : S:=hint_searchreplace;
  115. hcSearchAgain : S:=hint_searchagain;
  116. hcGotoLine : S:=hint_gotoline;
  117. hcObjects : S:=hint_objects;
  118. hcModules : S:=hint_modules;
  119. hcGlobals : S:=hint_globals;
  120. hcSymbol : S:=hint_symbol;
  121. hcRunMenu : S:=hint_runmenu;
  122. hcRun : S:=hint_run;
  123. hcParameters : S:=hint_runparameters;
  124. hcResetDebugger : S:=hint_resetprogram;
  125. hcContToCursor : S:=hint_rununtilcursor;
  126. hcUntilReturn : S:=hint_rununtilreturn;
  127. hcUserScreen : S:=hint_userscreen;
  128. hcCompileMenu : S:=hint_compilemenu;
  129. hcCompile : S:=hint_compile;
  130. hcMake : S:=hint_make;
  131. hcBuild : S:=hint_build;
  132. hcTarget : S:=hint_target;
  133. hcPrimaryFile : S:=hint_primaryfile;
  134. hcClearPrimary : S:=hint_clearprimaryfile;
  135. hcCompilerMessages:S:=hint_showmessages;
  136. hcDebugMenu : S:=hint_debugmenu;
  137. hcToggleBreakpoint : S:=hint_togglebreakpoint;
  138. hcNewBreakpoint : S:=hint_createnewbreakpoint;
  139. hcEditBreakpoint : S:=hint_editbreakpoint;
  140. hcDeleteBreakpoint : S:=hint_deletebreakpoint;
  141. hcOpenGDBWindow : S:=hint_opengdbwindow;
  142. hcAddWatch : S:=hint_addwatch;
  143. hcWatchesWindow : S:=hint_watches;
  144. hcStackWindow : S:=hint_callstack;
  145. hcBreakpointList : S:=hint_editbreakpoints;
  146. hcToolsMenu : S:=hint_toolsmenu;
  147. hcCalculator : S:=hint_calculator;
  148. hcGrep : S:=hint_grep;
  149. hcMsgGotoSource : S:=hint_gotosource;
  150. hcRegistersWindow : S:=hint_registers;
  151. hcToolsMessages : S:=hint_messageswindow;
  152. hcToolsBase..
  153. hcToolsBase+MaxToolCount
  154. : S:=hint_usertool;
  155. hcASCIITable : S:=hint_asciitable;
  156. hcOptionsMenu : S:=hint_optionsmenu;
  157. hcSwitchesMode : S:=hint_switchesmode;
  158. hcCompiler,
  159. hcCompilerNoAltX : S:=hint_compiler;
  160. hcMemorySizes : S:=hint_memorysizes;
  161. hcLinker : S:=hint_linkeroptions;
  162. hcDebugger : S:=hint_debugoptions;
  163. hcDirectories : S:=hint_directories;
  164. hcBrowser,
  165. hcBrowserOptions: S:=hint_browser;
  166. hcTools : S:=hint_tools;
  167. hcRemoteDialog : S:=hint_remotedialog;
  168. hcTransferRemote: S:=hint_transferremote;
  169. hcDoReload : S:=hint_reloadmodifiedfile;
  170. hcEnvironmentMenu:S:=hint_environmentmenu;
  171. hcPreferences : S:=hint_preferences;
  172. hcEditor : S:=hint_editoroptions;
  173. hcCodeCompleteOptions:S:=hint_codecomplete;
  174. hcCodeTemplateOptions:S:=hint_codetemplates;
  175. hcMouse : S:=hint_mouseoptions;
  176. hcDesktopOptions: S:=hint_desktopoptions;
  177. hcStartup : S:=hint_startup;
  178. hcColors : S:=hint_colors;
  179. hcOpenINI : S:=hint_openini;
  180. hcSaveINI : S:=hint_saveini;
  181. hcSaveAsINI : S:=hint_saveasini;
  182. hcWindowMenu : S:=hint_windowmenu;
  183. hcTile : S:=hint_tile;
  184. hcCascade : S:=hint_cascade;
  185. hcCloseAll : S:=hint_closeall;
  186. hcResize : S:=hint_resize;
  187. hcZoom : S:=hint_zoom;
  188. hcNext : S:=hint_next;
  189. hcPrev : S:=hint_prev;
  190. hcClose : S:=hint_closewindow;
  191. hcWindowList : S:=hint_windowlist;
  192. hcUserScreenWindow:S:=hint_userscreenwindow;
  193. hcHelpMenu : S:=hint_helpmenu;
  194. hcHelpContents : S:=hint_helpcontents;
  195. hcHelpIndex : S:=hint_helpindex;
  196. hcHelpTopicSearch:S:=hint_helptopicsearch;
  197. hcHelpPrevTopic : S:=hint_helpprevtopic;
  198. hcHelpUsingHelp : S:=hint_helphowtouse;
  199. hcHelpFiles : S:=hint_helpfiles;
  200. hcOpenAtCursor : S:=hint_openatcursor;
  201. hcBrowseAtCursor: S:=hint_browseatcursor;
  202. hcEditorOptions : S:=hint_editoroptionscur;
  203. else S:='???';
  204. end;
  205. Hint:=S;
  206. end;
  207. procedure TFPHTMLFileLinkScanner.ProcessDoc(Doc: PHTMLLinkScanFile);
  208. begin
  209. PushStatus(FormatStrStr(msg_indexingfile,Doc^.GetDocumentURL));
  210. inherited ProcessDoc(Doc);
  211. PopStatus;
  212. end;
  213. function TFPHTMLFileLinkScanner.CheckURL(const URL: string): boolean;
  214. var OK: boolean;
  215. const HTTPPrefix = 'http:';
  216. FTPPrefix = 'ftp:';
  217. begin
  218. OK:=inherited CheckURL(URL);
  219. if OK then OK:=DirAndNameOf(URL)<>'';
  220. if OK then OK:=CompareText(copy(ExtOf(URL),1,4),'.HTM')=0;
  221. if OK then OK:=CompareText(copy(URL,1,length(HTTPPrefix)),HTTPPrefix)<>0;
  222. if OK then OK:=CompareText(copy(URL,1,length(FTPPrefix)),FTPPrefix)<>0;
  223. CheckURL:=OK;
  224. end;
  225. function TFPHTMLFileLinkScanner.CheckText(const Text: string): boolean;
  226. var OK: boolean;
  227. i : sw_integer;
  228. S: string;
  229. begin
  230. S:=Trim(Text);
  231. OK:=(S<>'') and (S[1]<>'[') and (S[1]<>',');
  232. { remove all Indexes }
  233. if s[1] in ['0'..'9'] then
  234. begin
  235. i:=1;
  236. while (i<length(s)) and (s[i] in ['0'..'9']) do
  237. inc(i);
  238. if (i<length(s)) and (s[i] in [' ',#9,'.']) then
  239. OK:=false;
  240. end;
  241. CheckText:=OK;
  242. end;
  243. procedure InitHelpSystem;
  244. procedure AddHelpFile(HelpFile,Param: string);
  245. begin
  246. {$IFDEF DEBUG}SetStatus(msg_LoadingHelpFile+' ('+SmartPath(HelpFile)+')');{$ENDIF}
  247. if HelpFacility^.AddFile(HelpFile,Param)=nil then
  248. ErrorBox(FormatStrStr(msg_failedtoloadhelpfile,HelpFile),nil);
  249. {$IFDEF DEBUG}SetStatus(msg_LoadingHelpFile);{$ENDIF}
  250. end;
  251. var I,P: sw_integer;
  252. S: string;
  253. Param: string;
  254. begin
  255. New(HelpFacility, Init);
  256. WOAHelp.RegisterHelpType;
  257. WNGHelp.RegisterHelpType;
  258. WOS2Help.RegisterHelpType;
  259. WWinHelp.RegisterHelpType;
  260. WVPHelp.RegisterHelpType;
  261. WHTMLHlp.RegisterHelpType;
  262. PushStatus(msg_LoadingHelpFiles);
  263. for I:=0 to HelpFiles^.Count-1 do
  264. begin
  265. S:=HelpFiles^.At(I)^; Param:='';
  266. P:=Pos('|',S);
  267. if P>0 then
  268. begin Param:=copy(S,P+1,High(S)); S:=copy(S,1,P-1); end;
  269. AddHelpFile(S,Param);
  270. end;
  271. PopStatus;
  272. end;
  273. procedure CheckHelpSystem;
  274. begin
  275. if HelpInited then Exit;
  276. InitHelpSystem;
  277. HelpInited:=true;
  278. end;
  279. procedure DoneHelpSystem;
  280. begin
  281. if assigned(HelpFacility) then
  282. begin
  283. Dispose(HelpFacility, Done);
  284. HelpFacility:=nil;
  285. end;
  286. HelpInited:=false;
  287. end;
  288. procedure HelpCreateWindow;
  289. var R: TRect;
  290. begin
  291. CheckHelpSystem;
  292. if HelpWindow=nil then
  293. begin
  294. Desktop^.GetExtent(R); R.Grow(-15,-3); Dec(R.A.Y);
  295. New(HelpWindow, Init(R, dialog_help, 0, 0, SearchFreeWindowNo));
  296. if HelpWindow<>nil then
  297. begin
  298. HelpWindow^.Hide;
  299. Desktop^.Insert(HelpWindow);
  300. end;
  301. end;
  302. end;
  303. procedure Help(FileID, Context: THelpCtx; Modal: boolean);
  304. begin
  305. if Modal then
  306. begin MessageBox(msg_modalhelpnotimplemented,nil,mfInformation+mfInsertInApp+mfOKButton); Exit; end;
  307. HelpCreateWindow;
  308. with HelpWindow^ do
  309. begin
  310. HelpWindow^.ShowTopic(FileID,Context);
  311. if GetState(sfVisible)=false then Show;
  312. MakeFirst;
  313. end;
  314. Message(Application,evCommand,cmUpdate,nil);
  315. end;
  316. procedure HelpTopicSearch(Editor: PEditor);
  317. var S: string;
  318. begin
  319. if Editor=nil then S:='' else
  320. S:=GetEditorCurWord(Editor,[]);
  321. HelpTopic(S);
  322. end;
  323. procedure HelpTopic(const S: string);
  324. var FileID: word;
  325. Ctx : THelpCtx;
  326. var Found: boolean;
  327. begin
  328. CheckHelpSystem;
  329. PushStatus(msg_LocatingTopic);
  330. Found:=HelpFacility^.TopicSearch(S,FileID,Ctx);
  331. PopStatus;
  332. if Found then
  333. Help(FileID,Ctx,false)
  334. else
  335. HelpIndex(S);
  336. end;
  337. procedure HelpIndex(Keyword: string);
  338. begin
  339. HelpCreateWindow;
  340. with HelpWindow^ do
  341. begin
  342. PushStatus(msg_BuildingHelpIndex);
  343. HelpWindow^.ShowIndex;
  344. if Keyword<>'' then
  345. HelpWindow^.HelpView^.Lookup(Keyword);
  346. PopStatus;
  347. if GetState(sfVisible)=false then Show;
  348. MakeFirst;
  349. end;
  350. Message(Application,evCommand,cmUpdate,nil);
  351. end;
  352. procedure PushStatus(S: string);
  353. begin
  354. if StatusLine=nil then
  355. Exit;
  356. If StatusStackPtr<=MaxStatusLevel then
  357. StatusStack[StatusStackPtr]:=PAdvancedStatusLine(StatusLine)^.GetStatusText
  358. else
  359. StatusStack[MaxStatusLevel]:=PAdvancedStatusLine(StatusLine)^.GetStatusText;
  360. SetStatus(S);
  361. Inc(StatusStackPtr);
  362. end;
  363. procedure PopStatus;
  364. begin
  365. if StatusLine=nil then
  366. Exit;
  367. Dec(StatusStackPtr);
  368. If StatusStackPtr<=MaxStatusLevel then
  369. SetStatus(StatusStack[StatusStackPtr])
  370. else
  371. SetStatus(StatusStack[MaxStatusLevel]);
  372. end;
  373. procedure SetStatus(S: string);
  374. begin
  375. if StatusLine=nil then
  376. Exit;
  377. PAdvancedStatusLine(StatusLine)^.SetStatusText(S);
  378. end;
  379. procedure ClearStatus;
  380. begin
  381. PAdvancedStatusLine(StatusLine)^.ClearStatusText;
  382. end;
  383. function FPHTMLGetSectionColor(Section: THTMLSection; var Color: byte): boolean;
  384. var OK: boolean;
  385. S: string;
  386. begin
  387. Color:=0;
  388. OK:=(ord(Section) in [1..length(CHTMLSectionAttrs)]);
  389. if OK then
  390. begin
  391. S:=#0;
  392. S:=copy(CHTMLSectionAttrs,ord(Section),1);
  393. if Assigned(Application)=false then Color:=0 else
  394. Color:=Application^.GetColor(ord(S[1]));
  395. if (Color and $0f) = ((Color and $f0) shr 4) then { same color ? }
  396. OK:=false;
  397. end;
  398. FPHTMLGetSectionColor:=OK;
  399. end;
  400. function FPNGGetAttrColor(Attr: char; var Color: byte): boolean;
  401. var OK: boolean;
  402. begin
  403. OK:=false;
  404. case Attr of
  405. 'A' : OK:=FPHTMLGetSectionColor(hsHeading1,Color);
  406. 'B' : OK:=FPHTMLGetSectionColor(hsHeading2,Color);
  407. 'b' : OK:=FPHTMLGetSectionColor(hsHeading5,Color);
  408. 'U' : OK:=FPHTMLGetSectionColor(hsHeading3,Color);
  409. 'N' : OK:=FPHTMLGetSectionColor(hsHeading4,Color);
  410. {$ifdef DEBUGMSG}
  411. else ErrorBox('Unknown attr encountered : "'+Attr+'"',nil);
  412. {$endif}
  413. end;
  414. FPNGGetAttrColor:=OK;
  415. end;
  416. function FPINFGetAttrColor(TextStyle, TextColor: byte; var Color: byte): boolean;
  417. var OK: boolean;
  418. begin
  419. OK:=false;
  420. case TextColor of
  421. 1 : OK:=FPHTMLGetSectionColor(hsHeading1,Color);
  422. 2 : OK:=FPHTMLGetSectionColor(hsHeading2,Color);
  423. 3 : OK:=FPHTMLGetSectionColor(hsHeading3,Color);
  424. end;
  425. FPINFGetAttrColor:=OK;
  426. end;
  427. procedure InitHelpFiles;
  428. begin
  429. HTMLGetSectionColor:={$ifdef FPC}@{$endif}FPHTMLGetSectionColor;
  430. NGGetAttrColor:={$ifdef FPC}@{$endif}FPNGGetAttrColor;
  431. INFGetAttrColor:={$ifdef FPC}@{$endif}FPINFGetAttrColor;
  432. New(HelpFiles, Init(10,10));
  433. end;
  434. procedure DoneHelpFiles;
  435. begin
  436. if assigned(HelpFiles) then
  437. Dispose(HelpFiles, Done);
  438. end;
  439. procedure CloseHelpWindows;
  440. procedure CloseIfHelpWindow(P: PView); {$ifndef FPC}far;{$endif}
  441. begin
  442. if P^.HelpCtx=hcHelpWindow then
  443. begin
  444. Message(P,evCommand,cmClose,nil);
  445. {Dispose(P, Done); help windows are only hidden on close so we've
  446. to destroy them manually
  447. but this was wrong as it was not correctly
  448. resetting the corresponding pointer in whelp unit PM }
  449. end;
  450. end;
  451. begin
  452. Desktop^.ForEach(@CloseIfHelpWindow);
  453. end;
  454. END.
  455. {
  456. $Log$
  457. Revision 1.9 2004-11-08 20:28:26 peter
  458. * Breakpoints are now deleted when removed from source, disabling is
  459. still possible from the breakpoint list
  460. * COMPILER_1_0, FVISION, GABOR defines removed, only support new
  461. FV and 1.9.x compilers
  462. * Run directory added to Run menu
  463. * Useless programinfo window removed
  464. Revision 1.8 2003/01/22 00:27:58 pierre
  465. * implement reloadfile if changed
  466. Revision 1.7 2002/11/28 12:57:42 pierre
  467. * new hints for remote addition
  468. Revision 1.6 2002/09/07 15:40:43 peter
  469. * old logs removed and tabs fixed
  470. Revision 1.5 2002/01/24 09:21:41 pierre
  471. * only disable Alt-X in Options|Compiler dialog
  472. }