fpmhelp.inc 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. function StoreHtmlIndexFile(const FileName: string; LS: PFPHTMLFileLinkScanner;var Re: Word; SilentFails: Boolean): Boolean;
  115. var
  116. BS: PBufStream;
  117. begin
  118. if ExistsFile(FileName) then
  119. if ConfirmBox(FormatStrStr(msg_filealreadyexistsoverwrite,FileName),nil,true)<>cmYes then
  120. Re:=cmCancel;
  121. if Re<>cmCancel then
  122. begin
  123. PushStatus(FormatStrStr(msg_storinghtmlindexinfile,FileName));
  124. New(BS, Init(FileName, stCreate, 4096));
  125. if Assigned(BS)=false then
  126. begin
  127. if not SilentFails then
  128. begin
  129. ErrorBox(FormatStrStr(msg_cantcreatefile,FileName),nil);
  130. end;
  131. Re:=cmCancel;
  132. end
  133. else
  134. begin
  135. LS^.StoreDocuments(BS^);
  136. if BS^.Status<>stOK then
  137. begin
  138. if not SilentFails then
  139. begin
  140. ErrorBox(FormatStrInt(msg_errorstoringindexdata,BS^.Status),nil);
  141. end;
  142. Re:=cmCancel;
  143. end;
  144. Dispose(BS, Done);
  145. end;
  146. PopStatus;
  147. end;
  148. StoreHtmlIndexFile := Re <> cmCancel;
  149. end;
  150. var I: integer;
  151. D: PFileDialog;
  152. FileName: string;
  153. Re: word;
  154. S: string;
  155. LS: PFPHTMLFileLinkScanner;
  156. begin
  157. case Event.What of
  158. evKeyDown :
  159. case Event.KeyCode of
  160. kbIns :
  161. begin
  162. Message(@Self,evCommand,cmAddItem,nil);
  163. ClearEvent(Event);
  164. end;
  165. kbDel :
  166. begin
  167. Message(@Self,evCommand,cmDeleteItem,nil);
  168. ClearEvent(Event);
  169. end;
  170. end;
  171. evCommand :
  172. case Event.Command of
  173. cmAddItem :
  174. begin
  175. S:='';
  176. New(D, Init(HelpFileExts,
  177. dialog_installhelpfile,
  178. label_installhelpfile_filename,
  179. fdOpenButton,hidOpenHelpFile));
  180. Re:=Desktop^.ExecView(D);
  181. if Re<>cmCancel then
  182. begin
  183. D^.GetFileName(FileName);
  184. if UpcaseStr(ExtOf(FileName))=UpcaseStr(HTMLIndexExt) then
  185. begin
  186. S:='HTML Index';
  187. end
  188. else
  189. if UpcaseStr(copy(ExtOf(FileName),1,length(HTMLExt)))=UpcaseStr(HTMLExt) then
  190. begin
  191. Re:=ConfirmBox(msg_createkeywordindexforhelpfile,nil,true);
  192. if Re<>cmCancel then
  193. if Re=cmNo then
  194. Re:=InputBox(dialog_topictitle,label_topictitle_title,S,40)
  195. else
  196. begin
  197. ShowMessage(msg_pleasewaitwhilecreatingindex);
  198. S:='HTML Index';
  199. PushStatus(FormatStrStr(msg_buildingindexfile,FileName));
  200. New(LS, Init(DirOf(FileName)));
  201. LS^.ProcessDocument(FileName,[soSubDocsOnly]);
  202. if LS^.GetDocumentCount=0 then
  203. begin
  204. ErrorBox(FormatStrStr(msg_filedoesnotcontainanylinks,FileName),nil);
  205. Re:=cmCancel;
  206. end
  207. else
  208. begin
  209. FileName:=DirAndNameOf(FileName)+HTMLIndexExt;
  210. if not StoreHtmlIndexFile(FileName, LS, Re, True) then
  211. begin
  212. Re:=ConfirmBox(FormatStrStr('Could not create "%s", try creating it in local dir?', FileName),nil,true);
  213. FileName := GetCurDir + NameAndExtOf(FileName);
  214. if Re = cmYes then
  215. begin
  216. StoreHtmlIndexFile(FileName, LS, Re, False);
  217. end;
  218. end
  219. end;
  220. Dispose(LS, Done);
  221. PopStatus;
  222. HideMessage;
  223. end;
  224. end;
  225. end;
  226. if Re<>cmCancel then
  227. begin
  228. if S<>'' then FileName:=FileName+'|'+S;
  229. LB^.List^.Insert(NewStr(FileName));
  230. LB^.SetRange(LB^.List^.Count);
  231. ReDraw;
  232. end;
  233. Dispose(D, Done);
  234. ClearEvent(Event);
  235. end;
  236. cmDeleteItem :
  237. if LB^.Range>0 then
  238. begin
  239. LB^.List^.AtFree(LB^.Focused);
  240. LB^.SetRange(LB^.List^.Count);
  241. ReDraw;
  242. ClearEvent(Event);
  243. end;
  244. cmOK :
  245. begin
  246. HelpFiles^.FreeAll;
  247. for I:=0 to LB^.List^.Count-1 do
  248. HelpFiles^.Insert(NewStr(C^.At(I)^));
  249. end;
  250. end;
  251. end;
  252. inherited HandleEvent(Event);
  253. end;
  254. destructor THelpFilesDialog.Done;
  255. begin
  256. if C<>nil then
  257. begin
  258. C^.FreeAll;
  259. Dispose(C, Done);
  260. end;
  261. inherited Done;
  262. end;
  263. procedure TIDEApp.HelpFiles;
  264. var
  265. PHFD : PHelpFilesDialog;
  266. begin
  267. New(PHFD, Init);
  268. if Desktop^.ExecView(PHFD)=cmOK then
  269. begin
  270. DoneHelpSystem;
  271. Message(Application,evBroadcast,cmHelpFilesChanged,nil);
  272. InitHelpSystem;
  273. end;
  274. if assigned(PHFD) then
  275. Dispose(PHFD, Done);
  276. end;
  277. procedure TIDEApp.About;
  278. begin
  279. ExecuteDialog(New(PFPAboutDialog, Init), nil);
  280. end;