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. 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+RecentFiles[AHelpCtx-hcRecentFileBase].FileName;
  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. hcRunDir : S:=hint_rundir;
  124. hcParameters : S:=hint_runparameters;
  125. hcResetDebugger : S:=hint_resetprogram;
  126. hcContToCursor : S:=hint_rununtilcursor;
  127. hcUntilReturn : S:=hint_rununtilreturn;
  128. hcUserScreen : S:=hint_userscreen;
  129. hcCompileMenu : S:=hint_compilemenu;
  130. hcCompile : S:=hint_compile;
  131. hcMake : S:=hint_make;
  132. hcBuild : S:=hint_build;
  133. hcTarget : S:=hint_target;
  134. hcPrimaryFile : S:=hint_primaryfile;
  135. hcClearPrimary : S:=hint_clearprimaryfile;
  136. hcCompilerMessages:S:=hint_showmessages;
  137. hcDebugMenu : S:=hint_debugmenu;
  138. hcToggleBreakpoint : S:=hint_togglebreakpoint;
  139. hcNewBreakpoint : S:=hint_createnewbreakpoint;
  140. hcEditBreakpoint : S:=hint_editbreakpoint;
  141. hcDeleteBreakpoint : S:=hint_deletebreakpoint;
  142. hcOpenGDBWindow : S:=hint_opengdbwindow;
  143. hcAddWatch : S:=hint_addwatch;
  144. hcWatchesWindow : S:=hint_watches;
  145. hcStackWindow : S:=hint_callstack;
  146. hcBreakpointList : S:=hint_editbreakpoints;
  147. hcToolsMenu : S:=hint_toolsmenu;
  148. hcCalculator : S:=hint_calculator;
  149. hcGrep : S:=hint_grep;
  150. hcMsgGotoSource : S:=hint_gotosource;
  151. hcRegistersWindow : S:=hint_registers;
  152. hcFPURegisters : S:=hint_FPURegisters;
  153. hcVectorRegisters : S:=hint_VectorRegisters;
  154. hcToolsMessages : S:=hint_messageswindow;
  155. hcToolsMsgNext : S:=hint_gotonextmsg;
  156. hcToolsMsgPrev : S:=hint_gotoprevmsg;
  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. hcHide : S:=hint_hide;
  196. hcClose : S:=hint_closewindow;
  197. hcWindowList : S:=hint_windowlist;
  198. hcUserScreenWindow:S:=hint_userscreenwindow;
  199. hcHelpMenu : S:=hint_helpmenu;
  200. hcHelpContents : S:=hint_helpcontents;
  201. hcHelpIndex : S:=hint_helpindex;
  202. hcHelpTopicSearch:S:=hint_helptopicsearch;
  203. hcHelpPrevTopic : S:=hint_helpprevtopic;
  204. hcHelpUsingHelp : S:=hint_helphowtouse;
  205. hcHelpFiles : S:=hint_helpfiles;
  206. hcOpenAtCursor : S:=hint_openatcursor;
  207. hcBrowseAtCursor: S:=hint_browseatcursor;
  208. hcEditorOptions : S:=hint_editoroptionscur;
  209. else S:='???';
  210. end;
  211. Hint:=S;
  212. end;
  213. procedure TFPHTMLFileLinkScanner.ProcessDoc(Doc: PHTMLLinkScanFile);
  214. begin
  215. PushStatus(FormatStrStr(msg_indexingfile,Doc^.GetDocumentURL));
  216. inherited ProcessDoc(Doc);
  217. PopStatus;
  218. end;
  219. function TFPHTMLFileLinkScanner.CheckURL(const URL: string): boolean;
  220. var OK: boolean;
  221. const HTTPPrefix = 'http:';
  222. FTPPrefix = 'ftp:';
  223. begin
  224. OK:=inherited CheckURL(URL);
  225. if OK then OK:=DirAndNameOf(URL)<>'';
  226. if OK then OK:=CompareText(copy(ExtOf(URL),1,4),'.HTM')=0;
  227. if OK then OK:=CompareText(copy(URL,1,length(HTTPPrefix)),HTTPPrefix)<>0;
  228. if OK then OK:=CompareText(copy(URL,1,length(FTPPrefix)),FTPPrefix)<>0;
  229. CheckURL:=OK;
  230. end;
  231. function TFPHTMLFileLinkScanner.CheckText(const Text: string): boolean;
  232. var OK: boolean;
  233. i : sw_integer;
  234. S: string;
  235. begin
  236. S:=Trim(Text);
  237. OK:=(S<>'') and (S[1]<>'[') and (S[1]<>',');
  238. { remove all Indexes }
  239. if s[1] in ['0'..'9'] then
  240. begin
  241. i:=1;
  242. while (i<length(s)) and (s[i] in ['0'..'9']) do
  243. inc(i);
  244. if (i<length(s)) and (s[i] in [' ',#9,'.']) then
  245. OK:=false;
  246. end;
  247. CheckText:=OK;
  248. end;
  249. procedure InitHelpSystem;
  250. procedure AddHelpFile(HelpFile,Param: string);
  251. begin
  252. {$IFDEF DEBUG}SetStatus(msg_LoadingHelpFile+' ('+SmartPath(HelpFile)+')');{$ENDIF}
  253. if HelpFacility^.AddFile(HelpFile,Param)=nil then
  254. ErrorBox(FormatStrStr(msg_failedtoloadhelpfile,HelpFile),nil);
  255. {$IFDEF DEBUG}SetStatus(msg_LoadingHelpFile);{$ENDIF}
  256. end;
  257. var I,P: sw_integer;
  258. S: string;
  259. Param: string;
  260. begin
  261. New(HelpFacility, Init);
  262. WOAHelp.RegisterHelpType;
  263. WNGHelp.RegisterHelpType;
  264. WOS2Help.RegisterHelpType;
  265. WWinHelp.RegisterHelpType;
  266. WVPHelp.RegisterHelpType;
  267. WHTMLHlp.RegisterHelpType;
  268. PushStatus(msg_LoadingHelpFiles);
  269. for I:=0 to HelpFiles^.Count-1 do
  270. begin
  271. S:=HelpFiles^.At(I)^; Param:='';
  272. P:=Pos('|',S);
  273. if P>0 then
  274. begin Param:=copy(S,P+1,High(S)); S:=copy(S,1,P-1); end;
  275. AddHelpFile(S,Param);
  276. end;
  277. PopStatus;
  278. end;
  279. procedure CheckHelpSystem;
  280. begin
  281. if HelpInited then Exit;
  282. InitHelpSystem;
  283. HelpInited:=true;
  284. end;
  285. procedure DoneHelpSystem;
  286. begin
  287. if assigned(HelpFacility) then
  288. begin
  289. Dispose(HelpFacility, Done);
  290. HelpFacility:=nil;
  291. end;
  292. HelpInited:=false;
  293. end;
  294. procedure HelpCreateWindow;
  295. var R: TRect;
  296. begin
  297. CheckHelpSystem;
  298. if HelpWindow=nil then
  299. begin
  300. Desktop^.GetExtent(R); R.Grow(-15,-3); Dec(R.A.Y);
  301. New(HelpWindow, Init(R, dialog_help, 0, 0, SearchFreeWindowNo));
  302. if HelpWindow<>nil then
  303. begin
  304. HelpWindow^.Hide;
  305. Desktop^.Insert(HelpWindow);
  306. end;
  307. end;
  308. end;
  309. procedure Help(FileID, Context: THelpCtx; Modal: boolean);
  310. begin
  311. if Modal then
  312. begin MessageBox(msg_modalhelpnotimplemented,nil,mfInformation+mfInsertInApp+mfOKButton); Exit; end;
  313. HelpCreateWindow;
  314. with HelpWindow^ do
  315. begin
  316. HelpWindow^.ShowTopic(FileID,Context);
  317. if GetState(sfVisible)=false then Show;
  318. MakeFirst;
  319. end;
  320. Message(Application,evCommand,cmUpdate,nil);
  321. end;
  322. procedure HelpTopicSearch(Editor: PEditor);
  323. var S: string;
  324. begin
  325. if Editor=nil then S:='' else
  326. S:=GetEditorCurWord(Editor,[]);
  327. HelpTopic(S);
  328. end;
  329. procedure HelpTopic(const S: string);
  330. var FileID: word;
  331. Ctx : THelpCtx;
  332. var Found: boolean;
  333. begin
  334. CheckHelpSystem;
  335. PushStatus(msg_LocatingTopic);
  336. Found:=HelpFacility^.TopicSearch(S,FileID,Ctx);
  337. PopStatus;
  338. if Found then
  339. Help(FileID,Ctx,false)
  340. else
  341. HelpIndex(S);
  342. end;
  343. procedure HelpIndex(Keyword: string);
  344. begin
  345. HelpCreateWindow;
  346. with HelpWindow^ do
  347. begin
  348. PushStatus(msg_BuildingHelpIndex);
  349. HelpWindow^.ShowIndex;
  350. if Keyword<>'' then
  351. HelpWindow^.HelpView^.Lookup(Keyword);
  352. PopStatus;
  353. if GetState(sfVisible)=false then Show;
  354. MakeFirst;
  355. end;
  356. Message(Application,evCommand,cmUpdate,nil);
  357. end;
  358. procedure PushStatus(S: string);
  359. begin
  360. if StatusLine=nil then
  361. Exit;
  362. If StatusStackPtr<=MaxStatusLevel then
  363. StatusStack[StatusStackPtr]:=PAdvancedStatusLine(StatusLine)^.GetStatusText
  364. else
  365. StatusStack[MaxStatusLevel]:=PAdvancedStatusLine(StatusLine)^.GetStatusText;
  366. SetStatus(S);
  367. Inc(StatusStackPtr);
  368. end;
  369. procedure PopStatus;
  370. begin
  371. if StatusLine=nil then
  372. Exit;
  373. Dec(StatusStackPtr);
  374. If StatusStackPtr<=MaxStatusLevel then
  375. SetStatus(StatusStack[StatusStackPtr])
  376. else
  377. SetStatus(StatusStack[MaxStatusLevel]);
  378. end;
  379. procedure SetStatus(S: string);
  380. begin
  381. if StatusLine=nil then
  382. Exit;
  383. PAdvancedStatusLine(StatusLine)^.SetStatusText(S);
  384. end;
  385. procedure ClearStatus;
  386. begin
  387. PAdvancedStatusLine(StatusLine)^.ClearStatusText;
  388. end;
  389. function FPHTMLGetSectionColor(Section: THTMLSection; var Color: byte): boolean;
  390. var OK: boolean;
  391. S: string;
  392. begin
  393. Color:=0;
  394. OK:=(ord(Section) in [1..length(CHTMLSectionAttrs)]);
  395. if OK then
  396. begin
  397. S:=#0;
  398. S:=copy(CHTMLSectionAttrs,ord(Section),1);
  399. if Assigned(Application)=false then Color:=0 else
  400. Color:=Application^.GetColor(ord(S[1]));
  401. if (Color and $0f) = ((Color and $f0) shr 4) then { same color ? }
  402. OK:=false;
  403. end;
  404. FPHTMLGetSectionColor:=OK;
  405. end;
  406. function FPNGGetAttrColor(Attr: char; var Color: byte): boolean;
  407. var OK: boolean;
  408. begin
  409. OK:=false;
  410. case Attr of
  411. 'A' : OK:=FPHTMLGetSectionColor(hsHeading1,Color);
  412. 'B' : OK:=FPHTMLGetSectionColor(hsHeading2,Color);
  413. 'b' : OK:=FPHTMLGetSectionColor(hsHeading5,Color);
  414. 'U' : OK:=FPHTMLGetSectionColor(hsHeading3,Color);
  415. 'N' : OK:=FPHTMLGetSectionColor(hsHeading4,Color);
  416. {$ifdef DEBUGMSG}
  417. else ErrorBox('Unknown attr encountered : "'+Attr+'"',nil);
  418. {$endif}
  419. end;
  420. FPNGGetAttrColor:=OK;
  421. end;
  422. function FPINFGetAttrColor(TextStyle, TextColor: byte; var Color: byte): boolean;
  423. var OK: boolean;
  424. begin
  425. OK:=false;
  426. case TextColor of
  427. 1 : OK:=FPHTMLGetSectionColor(hsHeading1,Color);
  428. 2 : OK:=FPHTMLGetSectionColor(hsHeading2,Color);
  429. 3 : OK:=FPHTMLGetSectionColor(hsHeading3,Color);
  430. end;
  431. FPINFGetAttrColor:=OK;
  432. end;
  433. procedure InitHelpFiles;
  434. begin
  435. HTMLGetSectionColor:={$ifdef FPC}@{$endif}FPHTMLGetSectionColor;
  436. NGGetAttrColor:={$ifdef FPC}@{$endif}FPNGGetAttrColor;
  437. INFGetAttrColor:={$ifdef FPC}@{$endif}FPINFGetAttrColor;
  438. New(HelpFiles, Init(10,10));
  439. end;
  440. procedure DoneHelpFiles;
  441. begin
  442. if assigned(HelpFiles) then
  443. Dispose(HelpFiles, Done);
  444. end;
  445. procedure CloseHelpWindows;
  446. procedure CloseIfHelpWindow(P: PView); {$ifndef FPC}far;{$endif}
  447. begin
  448. if P^.HelpCtx=hcHelpWindow then
  449. begin
  450. Message(P,evCommand,cmClose,nil);
  451. {Dispose(P, Done); help windows are only hidden on close so we've
  452. to destroy them manually
  453. but this was wrong as it was not correctly
  454. resetting the corresponding pointer in whelp unit PM }
  455. end;
  456. end;
  457. begin
  458. Desktop^.ForEach(@CloseIfHelpWindow);
  459. end;
  460. END.
  461. {
  462. $Log$
  463. Revision 1.12 2005-03-13 12:32:41 florian
  464. * more status line hints fixed
  465. Revision 1.11 2005/03/13 12:25:02 florian
  466. + Recent files write full name now as hint in the status line
  467. * Rundir hint in status line fixed
  468. Revision 1.10 2005/02/14 17:13:18 peter
  469. * truncate log
  470. }