2
0

fphelp.pas 15 KB

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