fpmhelp.inc 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. {
  2. This file is part of the ffff
  3. Copyright (c) 1998 by Berczi Gabor
  4. Help menu entries
  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. procedure TIDEApp.HelpContents;
  12. var FileID: word;
  13. Ctx : THelpCtx;
  14. var Found: boolean;
  15. begin
  16. CheckHelpSystem;
  17. Found:=HelpFacility^.TopicSearch('Table of contents',FileID,Ctx);
  18. if Found then
  19. Help(FileID,Ctx,false)
  20. else
  21. HelpIndex('');
  22. end;
  23. procedure TIDEApp.HelpHelpIndex;
  24. begin
  25. HelpIndex('');
  26. end;
  27. procedure TIDEApp.HelpTopicSearch;
  28. begin
  29. end;
  30. procedure TIDEApp.HelpPrevTopic;
  31. begin
  32. if HelpWindow=nil then HelpContents else
  33. with HelpWindow^ do
  34. if GetState(sfVisible) then Message(HelpWindow^.HelpView,evCommand,cmPrevTopic,nil)
  35. else begin HelpWindow^.Show; HelpWindow^.MakeFirst; end;
  36. end;
  37. procedure TIDEApp.HelpUsingHelp;
  38. begin
  39. Help(0,hcUsingHelp,false);
  40. end;
  41. type
  42. PHelpFileListBox = ^THelpFileListBox;
  43. THelpFileListBox = object(TListBox)
  44. function GetText(Item: sw_Integer; MaxLen: sw_Integer): String; virtual;
  45. end;
  46. PHelpFilesDialog = ^THelpFilesDialog;
  47. THelpFilesDialog = object(TCenterDialog)
  48. constructor Init;
  49. procedure HandleEvent(var Event: TEvent); virtual;
  50. destructor Done; virtual;
  51. private
  52. LB: PHelpFileListBox;
  53. C : PUnsortedStringCollection;
  54. end;
  55. function THelpFileListBox.GetText(Item: sw_Integer; MaxLen: sw_Integer): String;
  56. var S: string;
  57. P: integer;
  58. begin
  59. S:=inherited GetText(Item,MaxLen);
  60. P:=Pos('|',S);
  61. if P>0 then S:=copy(S,P+1,255)+' - '+copy(S,1,P-1);
  62. GetText:=copy(S,1,MaxLen);
  63. end;
  64. constructor THelpFilesDialog.Init;
  65. var R,R2: TRect;
  66. SB: PScrollBar;
  67. I: integer;
  68. begin
  69. R.Assign(0,0,round(ScreenWidth*5/8),ScreenHeight-10);
  70. inherited Init(R, dialog_helpfiles);
  71. New(C, Init(20,10));
  72. GetExtent(R); R.Grow(-2,-2); Inc(R.A.Y); R.B.X:=R.B.X-13;
  73. R2.Copy(R); R2.Move(1,0); R2.A.X:=R2.B.X-1;
  74. New(SB, Init(R2)); Insert(SB);
  75. New(LB, Init(R, 1, SB));
  76. for I:=0 to HelpFiles^.Count-1 do
  77. begin
  78. C^.Insert(NewStr(HelpFiles^.At(I)^));
  79. end;
  80. LB^.NewList(C);
  81. Insert(LB);
  82. R2.Copy(R); Dec(R2.A.Y); R2.B.Y:=R2.A.Y+1;
  83. Insert(New(PLabel, Init(R2, label_helpfiles_helpfiles, LB)));
  84. GetExtent(R); R.Grow(-2,-2); Inc(R.A.Y); R.A.X:=R.B.X-13+1; R.B.Y:=R.A.Y+2;
  85. Insert(New(PButton, Init(R, button_OK, cmOK, bfDefault)));
  86. R.Move(0,2);
  87. Insert(New(PButton, Init(R, button_New, cmAddItem, bfNormal)));
  88. R.Move(0,2);
  89. Insert(New(PButton, Init(R, button_Delete, cmDeleteItem, bfNormal)));
  90. R.Move(0,2);
  91. Insert(New(PButton, Init(R, button_Cancel, cmCancel, bfNormal)));
  92. LB^.Select;
  93. end;
  94. procedure THelpFilesDialog.HandleEvent(var Event: TEvent);
  95. var I: integer;
  96. D: PFileDialog;
  97. FileName: string;
  98. Re: word;
  99. S: string;
  100. LS: PFPHTMLFileLinkScanner;
  101. BS: PBufStream;
  102. begin
  103. case Event.What of
  104. evKeyDown :
  105. case Event.KeyCode of
  106. kbIns :
  107. begin
  108. Message(@Self,evCommand,cmAddItem,nil);
  109. ClearEvent(Event);
  110. end;
  111. kbDel :
  112. begin
  113. Message(@Self,evCommand,cmDeleteItem,nil);
  114. ClearEvent(Event);
  115. end;
  116. end;
  117. evCommand :
  118. case Event.Command of
  119. cmAddItem :
  120. begin
  121. S:='';
  122. New(D, Init(HelpFileExts,
  123. dialog_installhelpfile,
  124. label_installhelpfile_filename,
  125. fdOpenButton,hidOpenHelpFile));
  126. Re:=Desktop^.ExecView(D);
  127. if Re<>cmCancel then
  128. begin
  129. D^.GetFileName(FileName);
  130. if UpcaseStr(ExtOf(FileName))=UpcaseStr(HTMLIndexExt) then
  131. begin
  132. S:='HTML Index';
  133. end
  134. else
  135. if UpcaseStr(copy(ExtOf(FileName),1,length(HTMLExt)))=UpcaseStr(HTMLExt) then
  136. begin
  137. Re:=ConfirmBox(msg_createkeywordindexforhelpfile,nil,true);
  138. if Re<>cmCancel then
  139. if Re=cmNo then
  140. Re:=InputBox(dialog_topictitle,label_topictitle_title,S,40)
  141. else
  142. begin
  143. ShowMessage(msg_pleasewaitwhilecreatingindex);
  144. S:='HTML Index';
  145. PushStatus(FormatStrStr(msg_buildingindexfile,FileName));
  146. New(LS, Init(DirOf(FileName)));
  147. LS^.ProcessDocument(FileName,[soSubDocsOnly]);
  148. if LS^.GetDocumentCount=0 then
  149. begin
  150. ErrorBox(FormatStrStr(msg_filedoesnotcontainanylinks,FileName),nil);
  151. Re:=cmCancel;
  152. end
  153. else
  154. begin
  155. FileName:=DirAndNameOf(FileName)+HTMLIndexExt;
  156. if ExistsFile(FileName) then
  157. if ConfirmBox(FormatStrStr(msg_filealreadyexistsoverwrite,FileName),nil,true)<>cmYes then
  158. Re:=cmCancel;
  159. if Re<>cmCancel then
  160. begin
  161. PushStatus(FormatStrStr(msg_storinghtmlindexinfile,FileName));
  162. New(BS, Init(FileName, stCreate, 4096));
  163. if Assigned(BS)=false then
  164. begin
  165. ErrorBox(FormatStrStr(msg_cantcreatefile,FileName),nil);
  166. Re:=cmCancel;
  167. end
  168. else
  169. begin
  170. LS^.StoreDocuments(BS^);
  171. if BS^.Status<>stOK then
  172. begin
  173. ErrorBox(FormatStrInt(msg_errorstoringindexdata,BS^.Status),nil);
  174. Re:=cmCancel;
  175. end;
  176. Dispose(BS, Done);
  177. end;
  178. PopStatus;
  179. end;
  180. end;
  181. Dispose(LS, Done);
  182. PopStatus;
  183. HideMessage;
  184. end;
  185. end;
  186. end;
  187. if Re<>cmCancel then
  188. begin
  189. if S<>'' then FileName:=FileName+'|'+S;
  190. LB^.List^.Insert(NewStr(FileName));
  191. LB^.SetRange(LB^.List^.Count);
  192. ReDraw;
  193. end;
  194. Dispose(D, Done);
  195. ClearEvent(Event);
  196. end;
  197. cmDeleteItem :
  198. if LB^.Range>0 then
  199. begin
  200. LB^.List^.AtFree(LB^.Focused);
  201. LB^.SetRange(LB^.List^.Count);
  202. ReDraw;
  203. ClearEvent(Event);
  204. end;
  205. cmOK :
  206. begin
  207. HelpFiles^.FreeAll;
  208. for I:=0 to LB^.List^.Count-1 do
  209. HelpFiles^.Insert(NewStr(C^.At(I)^));
  210. end;
  211. end;
  212. end;
  213. inherited HandleEvent(Event);
  214. end;
  215. destructor THelpFilesDialog.Done;
  216. begin
  217. if C<>nil then
  218. begin
  219. C^.FreeAll;
  220. Dispose(C, Done);
  221. end;
  222. inherited Done;
  223. end;
  224. procedure TIDEApp.HelpFiles;
  225. var
  226. PHFD : PHelpFilesDialog;
  227. begin
  228. New(PHFD, Init);
  229. if Desktop^.ExecView(PHFD)=cmOK then
  230. begin
  231. DoneHelpSystem;
  232. Message(Application,evBroadcast,cmHelpFilesChanged,nil);
  233. InitHelpSystem;
  234. end;
  235. if assigned(PHFD) then
  236. Dispose(PHFD, Done);
  237. end;
  238. procedure TIDEApp.About;
  239. begin
  240. ExecuteDialog(New(PFPAboutDialog, Init), nil);
  241. end;