fpmhelp.inc 8.0 KB

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