frmmain.pp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888
  1. {$mode objfpc}
  2. {$h+}
  3. unit frmmain;
  4. interface
  5. uses
  6. gtk,gdk,fpgtk,fpgtkext,pgEditor,frmlink,sysutils,classes,fpdeopts;
  7. Const
  8. DefaultTooltips = True;
  9. DefaultToolBarStyle = GTK_TOOLBAR_ICONS;
  10. DefaultToolbarRelief = GTK_RELIEF_NONE;
  11. SFileTemplate = 'template.xml';
  12. Type
  13. TNodeType = (ntfile,ntPackage,ntModule,ntElement);
  14. TMainForm = Class(TFPGtkWindow)
  15. Private
  16. FRecent : TStrings;
  17. FPages : TFPGtkNoteBook;
  18. FVBox : TFPGTKVBox;
  19. FMenu : TFpGTKMenuBar;
  20. FNewImage,
  21. FOpenImage,
  22. FSaveImage,
  23. FSaveAsImage,
  24. FNewPackageImage,
  25. FNewModuleImage,
  26. FNewElementImage,
  27. FBoldImage,
  28. FUnderlineImage,
  29. FItalicsImage,
  30. FParagraphImage,
  31. FVarImage,
  32. FLinkImage,
  33. FRemarkImage,
  34. FTableImage : TFPGtkPixmap;
  35. FHelpMenu,
  36. FExtraMenu,
  37. FInsertMenu,
  38. FFormatMenu,
  39. FFileMenu : TFPGtkMenuItem;
  40. FToolbarFrame : TFPGtkFrame;
  41. FFormatToolBar,
  42. FToolsToolBar,
  43. FMainToolBar : TFPGtkToolbar;
  44. FFileOpen,
  45. FFileNew,
  46. FFileNewFromFile,
  47. FFileSave,
  48. FFileSaveAs,
  49. FFileRecent,
  50. FFileClose,
  51. FFileExit,
  52. FInsertPackage,
  53. FInsertModule,
  54. FInsertElement,
  55. FInsertLink,
  56. FInsertTable,
  57. FFormatParagraph,
  58. FFormatBold,
  59. FFormatItalic,
  60. FFormatUnderline,
  61. FFormatRemark,
  62. FFormatVariable,
  63. FFormatCode,
  64. FFormatFile,
  65. FExtraoptions,
  66. FHelpAbout : TFPGtkMenuItem;
  67. // Utility functions
  68. Function FormatMenuItem(ACaption : String; tt : TTagType) : TFPgtkMenuItem;
  69. Function FormatMenuItem(ACaption : String; tt : TTagType; Accel : PAccelKeyDef) : TFPgtkMenuItem;
  70. // Editor functions.
  71. procedure BuildReopenList;
  72. Procedure AddTorecent(FN : String);
  73. Procedure OpenFile(FN : String);
  74. Procedure SaveEditorAs(E : TEditorPage);
  75. Procedure SaveEditor(E : TEditorPage);
  76. Function CloseEditor(E : TEditorPage) : Boolean;
  77. Procedure LoadRecent;
  78. Procedure SaveRecent;
  79. Procedure CreateForm;
  80. Function CreatePage : TEditorPage;
  81. Function Currenteditor : TEditorPage;
  82. Function AllowClose : Boolean;
  83. // Callbacks
  84. Procedure TagClick(Sender : TFPGtkObject; Data : Pointer);
  85. Procedure FileReopen(Sender: TFPGTKObject;data : Pointer);
  86. Procedure FileOpenClick(Sender : TFPGtkObject; Data : Pointer);
  87. Procedure FileNewClick(Sender : TFPGtkObject; Data : Pointer);
  88. Procedure FileNewFromFileClick(Sender : TFPGtkObject; Data : Pointer);
  89. Procedure FileSaveAsClick(Sender : TFPGtkObject; Data : Pointer);
  90. Procedure FileSaveClick(Sender : TFPGtkObject; Data : Pointer);
  91. Procedure FileExitClick(Sender : TFPGtkObject; Data : Pointer);
  92. Procedure FileCloseClick(Sender : TFPGtkObject; Data : Pointer);
  93. Procedure OptionsClick(Sender : TFPGtkObject; Data : Pointer);
  94. Procedure HelpAboutClick(Sender : TFPGtkObject; Data : Pointer);
  95. Procedure InsertNodeClick(Sender : TFPGtkObject; Data : Pointer);
  96. Procedure LinkClick(Sender : TFPGtkObject; Data : Pointer);
  97. Procedure TableClick(Sender : TFPGtkObject; Data : Pointer);
  98. Procedure GetLinkData(Sender : TFPGtkWindow;Data : Pointer; Action : Integer;Initiator : TFPGtkObject);
  99. Procedure GetTableData(Sender : TFPGtkWindow;Data : Pointer; Action : Integer;Initiator : TFPGtkObject);
  100. Procedure GetNodeData(Sender : TFPGtkWindow;Data : Pointer; Action : Integer;Initiator : TFPGtkObject);
  101. Procedure GetSkeletonData(Sender : TFPGtkWindow;Data : Pointer; Action : Integer;Initiator : TFPGtkObject);
  102. Procedure DialogSetFilename(Sender : TFPGtkWindow;Data : Pointer; Action : Integer;Initiator : TFPGtkObject);
  103. Function OnDeleteEvent(Sender:TFPgtkWidget; Event:PGdkEvent; data:pointer): boolean;
  104. Public
  105. Constructor create;
  106. Destructor Destroy; override;
  107. end;
  108. Const
  109. NodeNames : Array[TNodeType] of String
  110. = ('file','package','module','element');
  111. implementation
  112. uses fpdemsg,frmnewnode,frmtable,frmmakeskel,process,frmOptions,frmAbout,inifiles,xpms;
  113. Function TMainForm.CreatePage : TEditorPage;
  114. begin
  115. Result:=TEditorPage.Create;
  116. Result.FileNameLabel:=TFPgtkLabel.Create(SNewDocument);
  117. FPages.AppendPage(Result, REsult.FileNameLabel);
  118. FPages.Page:=Result;
  119. end;
  120. Function PixmapFromFile (FN : String; Const ImgArray : Array of string) :TFPGtkPixmap;
  121. begin
  122. Result:=TFPGtkPixmap.CReate;
  123. {$ifdef debug}
  124. writeln('loading ','bitmaps'+directoryseparator+FN);
  125. {$endif}
  126. If FileExists('bitmaps'+directoryseparator+FN) then
  127. Result.LoadFromFile('bitmaps'+directoryseparator+FN)
  128. else
  129. Result.loadFromArray(ImgArray);
  130. end;
  131. Function TMainForm.FormatMenuItem(ACaption : String; tt : TTagType) : TFPgtkMenuItem;
  132. begin
  133. Result:=NewMenuItem(ACaption,FormatHint(ACaption),'',@TagClick,Pointer(tt));
  134. end;
  135. Function TMainForm.FormatMenuItem(ACaption : String; tt : TTagType; Accel : PAccelKeyDef) : TFPgtkMenuItem;
  136. begin
  137. Result:=NewMenuItem(ACaption,FormatHint(ACaption),'',Accel,@TagClick,Pointer(tt));
  138. end;
  139. Procedure TMainForm.CreateForm;
  140. Var
  141. V : TFPGtkHBox;
  142. FAccelGroup: Integer;
  143. begin
  144. Title:=SFPDE;
  145. FAccelGroup:=AccelGroupNew;
  146. { File menu }
  147. {$ifdef debug}
  148. Writeln('Menu');
  149. {$endif}
  150. //anAG : integer; aKey : guint; aMods
  151. FFileOpen:=NewMenuItem(SMenuOpen,'','',MakeAccelKeyDef(Self,FaccelGroup,GDK_O,[amcontrol]),@FileOpenClick,Nil);
  152. FFileNew:=NewMenuItem(SMenuNew,'','',MakeAccelKeyDef(Self,FaccelGroup,GDK_N,[amcontrol]),@FileNewClick,Nil);
  153. FFileNewFromFile:=NewMenuItem(SMenuNewFromSource,'','',@FileNewFromFileClick,Nil);
  154. FFileSave:=NewMenuItem(SMenuSave,'','',MakeAccelKeyDef(Self,FaccelGroup,GDK_S,[amcontrol]),@FileSaveClick,Nil);
  155. FFileSaveAs:=NewMenuItem(SMenuSaveAs,'','',@FileSaveAsClick,Nil);
  156. FFileRecent:=NewSubMenu(SMenuRecent,'','',[]);
  157. FFileClose:=NewMenuItem(SMenuClose,'','',MakeAccelKeyDef(Self,FaccelGroup,GDK_W,[amcontrol]),@FileCLoseClick,Nil);
  158. FFileExit:=NewMenuItem(SMenuExit,'','',MakeAccelKeyDef(Self,FaccelGroup,GDK_Q,[amcontrol]),@FileExitClick,Nil);
  159. FFileMenu:=NewSubMenu(SMenuFile,'','',[FFileNew,FFileNewFromFile,FFileOpen,FFileRecent,FFileSave,FFileSaveAs,FFileClose,NewLine,FFileExit]);
  160. { Insert menu }
  161. FInsertPackage:=NewMenuItem(SMenuInsertPackage,SHintInsertPackage,'',MakeAccelKeyDef(Self,FaccelGroup,GDK_P,[amcontrol]),@InsertNodeClick,Pointer(ntpackage));
  162. FInsertModule:=NewMenuItem(SMenuInsertModule,SHintInsertModule,'',MakeAccelKeyDef(Self,FaccelGroup,GDK_M,[amcontrol]),@InsertNodeClick,Pointer(ntmodule));
  163. FInsertElement:=NewMenuItem(SMenuInsertElement,SHintInsertElement,'',MakeAccelKeyDef(Self,FaccelGroup,GDK_E,[amcontrol]),@InsertNodeClick,Pointer(ntElement));
  164. FinsertLink:=NewMenuItem(SMenuInsertLink,SHintInsertLink,'',MakeAccelKeyDef(Self,FaccelGroup,GDK_L,[amcontrol]),@LinkClick,Nil);
  165. FinsertTable:=NewMenuItem(SMenuInsertTable,SHintInsertTable,'',MakeAccelKeyDef(Self,FaccelGroup,GDK_T,[amcontrol]),@TableClick,Nil);
  166. FInsertMenu:=NewSubMenu(SMenuInsert,'','',[FInsertPackage,FInsertModule,FInsertElement,NewLine,FInsertLink,FinsertTable]);
  167. { Format menu }
  168. FFormatBold:=FormatMenuItem(SMenuFormatBold,ttBold,MakeAccelKeyDef(Self,FaccelGroup,GDK_B,[amcontrol]));
  169. FFormatItalic:=FormatMenuItem(SMenuFormatItalics,ttItalic,MakeAccelKeyDef(Self,FaccelGroup,GDK_I,[amcontrol]));
  170. FFormatUnderline:=FormatMenuItem(SMenuFormatUnderline,ttUnderline,MakeAccelKeyDef(Self,FaccelGroup,GDK_U,[amcontrol]));
  171. FFormatVariable:=FormatMenuItem(SMenuFormatVariable,ttVariable);
  172. FFormatFile:=FormatMenuItem(SMenuFormatFile,ttFile);
  173. FFormatParagraph:=FormatMenuItem(SMenuFormatParagraph,ttParagraph);
  174. FFormatRemark:=FormatMenuItem(SMenuFormatRemark,ttRemark);
  175. FFormatCode:=FormatMenuItem(SMenuFormatCode,ttCode);
  176. FFormatMenu:=NewSubMenu(SMenuFormat,'','',[FFormatBold,FFormatItalic,FFormatUnderline,FFormatVariable,FFormatFile,
  177. NewLine,FFormatParagraph,FFormatRemark,FFormatCode]);
  178. { Extra menu }
  179. FExtraOptions:=NewMenuItem(SMenuExtraOptions,SHMenuExtraOptions,'',@OptionsClick,Nil);
  180. FExtraMenu:=NewSubMenu(SMenuExtra,'','',[FExtraOptions]);
  181. { Help menu }
  182. FHelpAbout:=NewMenuItem(SMenuHelpAbout,SHMenuHelpAbout,'',@HelpAboutClick,Nil);
  183. FHelpMenu:=NewSubMenu(SMenuHelp,'','',[FHelpAbout]);
  184. FMenu:=NewMenuBar([FFileMenu,FInsertMenu,FFormatMenu,FExtraMenu,FHelpMenu]);
  185. {$ifdef debug}
  186. Writeln('Toolbar pixmaps');
  187. {$endif}
  188. { Tool bar bitmaps }
  189. FNewImage:=PixMapFromFile('new.xpm',ImgNew);
  190. FOpenImage:=PixmapFromFile('open.xpm',ImgOpen);
  191. FSaveImage:=PixmapFromFile('save.xpm',ImgSave);
  192. FSaveAsImage:=PixMapFromFile('saveas.xpm',ImgSaveAs);
  193. FNewPackageImage:=PixMapFromFile('newpackage.xpm',ImgNewPackage);
  194. FNewModuleImage:=PixMapFromFile('newmodule.xpm',ImgNewModule);
  195. FNewElementImage:=PixMapFromFile('newelement.xpm',ImgNewElement);
  196. FBoldImage:=PixMapFromFile('bold.xpm',ImgBold);
  197. FUnderlineImage:=PixMapFromFile('underline.xpm',ImgUnderline);
  198. FItalicsImage:=PixMapFromFile('italic.xpm',ImgItalic);
  199. FParagraphImage:=PixMapFromFile('para.xpm',ImgPara);
  200. FVarImage:=PixMapFromFile('var.xpm',ImgVar);
  201. FRemarkImage:=PixMapFromFile('remark.xpm',ImgRemark);
  202. FLinkImage:=PixMapFromFile('link.xpm',ImgLink);
  203. FTableImage:=PixMapFromFile('table.xpm',ImgTable);
  204. { Tool bars }
  205. {$ifdef debug}
  206. Writeln('Main toolbar');
  207. {$endif}
  208. FMainToolBar:=TFPGtkToolbar.Create;
  209. With FMainToolbar do
  210. begin
  211. Style:=DefaultToolbarStyle;
  212. ButtonRelief:=DefaultToolbarRelief;
  213. EnableTooltips:=DefaultTooltips;
  214. // AppendElement (ButtonType:TGtkToolbarChildType; PrevRadioBut:TFPgtkWidget; Text:string; TooltipText:string; TooltipPrivate:string; Icon:TFPgtkWidget; CallBack:TFPgtkSignalProcedure; data:pointer) : TFPgtkWidget;
  215. AppendItem(SMenuNew,SHintFileNew,'',FNewImage,@FileNewClick,Nil);
  216. AppendItem(SMenuOpen,SHintFileOpen,'',FOpenImage,@FileOpenClick,Nil);
  217. AppendItem(SmenuSave,SHintFileSave,'',FSaveImage,@FileSaveClick,Nil);
  218. AppendItem(SMenuSaveAs,SHintFileSaveAs,'',FSaveAsImage,@FileSaveAsClick,Nil);
  219. AppendSpace;
  220. AppendItem(SMenuInsertPackage,SHintInsertPackage,'',FNewPackageImage,@InsertNodeClick,Pointer(ntPackage));
  221. AppendItem(SMenuInsertModule,SHintInsertModule,'',FNewModuleImage,@InsertNodeClick,Pointer(ntModule));
  222. AppendItem(SMenuInsertEleMent,SHintInsertElement,'',FNewElementImage,@InsertNodeClick,Pointer(ntElement));
  223. AppendSpace;
  224. end;
  225. {$ifdef debug}
  226. Writeln('Format Toolbars');
  227. {$endif}
  228. FFormatToolBar:=TFPGtkToolbar.Create;
  229. With FFormatToolbar do
  230. begin
  231. Style:=DefaultToolBarStyle;
  232. ButtonRelief:=DefaultToolbarRelief;
  233. EnableTooltips:=DefaultTooltips;
  234. AppendItem(SMenuFormatParaGraph,Format(SMarkSelection,[SMenuFormatParaGraph]),'',FParagraphImage,@TagClick,Pointer(ttParagraph));
  235. AppendItem(SMenuFormatBold,Format(SMarkSelection,[SMenuFormatBold]),'',FBoldImage,@TagClick,Pointer(ttBold));
  236. AppendItem(SMenuFormatItalics,Format(SMarkSelection,[SMenuFormatItalics]),'',FItalicsImage,@TagClick,Pointer(ttItalic));
  237. AppendItem(SMenuFormatUnderline,Format(SMarkSelection,[SMenuFormatUnderline]),'',FUnderlineImage,@TagClick,Pointer(ttUnderline));
  238. AppendItem(SMenuFormatVariable,Format(SMarkSelection,[SMenuFormatVariable]),'',FVarImage,@TagClick,Pointer(ttVariable));
  239. AppendItem(SmenuFormatRemark,Format(SMarkSelection,[SmenuFormatRemark]),'',FRemarkImage,@TagClick,Pointer(ttRemark));
  240. FFormatToolbar.AppendSpace;
  241. end;
  242. {$ifdef debug}
  243. Writeln('Tools toolbar');
  244. {$endif}
  245. FToolsToolBar:=TFPGtkToolbar.Create;
  246. With FToolsToolbar do
  247. begin
  248. Style:=DefaultToolBarStyle;
  249. ButtonRelief:=DefaultToolBarRelief;
  250. EnableTooltips:=DefaultToolTips;
  251. AppendItem(SMenuInsertLink,SHintInsertLink,'',FlinkImage,@LinkCLick,Nil);
  252. AppendItem(SMenuInsertTable,SHintInsertTable,'',FTableImage,@TableClick,Nil);
  253. AppendSpace;
  254. end;
  255. {$ifdef debug}
  256. Writeln('end Toolbars');
  257. {$endif}
  258. V:=TFPGtkHBox.Create;
  259. V.PackStart(FMainToolbar,False,False,2);
  260. V.PackStart(FFormatToolBar,False,False,2);
  261. V.Packstart(FToolsToolbar,True,True,2);
  262. FToolbarFrame:=TFPGtkFrame.Create;
  263. FtoolbarFrame.Add(V);
  264. { Pages }
  265. FPages:=TFPGtkNotebook.Create;
  266. { Place everything on form }
  267. FVBox:=TFPGTKVBox.create;
  268. FVBox.PackStart(FMenu,false, true, 0);
  269. FVBox.PackStart(FToolBarFrame,false, true, 0);
  270. FVBox.PackStart(FPages,true, true, 0);
  271. Self.add(FVBox);
  272. setusize(640,480);
  273. ConnectDeleteEvent(@OnDeleteEvent,Nil);
  274. end;
  275. Constructor TMainForm.create;
  276. begin
  277. FRecent:=TStringList.Create;
  278. Inherited Create(gtk_window_dialog);
  279. CreateForm;
  280. LoadOptions;
  281. LoadRecent;
  282. end;
  283. Destructor TMainForm.Destroy;
  284. begin
  285. SaveRecent;
  286. FRecent.Free;
  287. Inherited;
  288. end;
  289. Procedure TMainForm.LoadRecent;
  290. Var
  291. I,Count : Integer;
  292. S : String;
  293. begin
  294. FRecent.Clear;
  295. With TInifile.Create(GetoptionFileName) do
  296. begin
  297. Count:=ReadInteger('Recent','Count',0);
  298. For I:=1 to Count do
  299. begin
  300. S:=ReadString('Recent','File'+IntToStr(i),'');
  301. If S<>'' then
  302. FRecent.Add(S);
  303. end;
  304. end;
  305. BuildReopenList;
  306. end;
  307. Procedure TMainForm.SaveRecent;
  308. Var
  309. I,Count : Integer;
  310. S : String;
  311. begin
  312. With TInifile.Create(GetoptionFileName) do
  313. try
  314. EraseSection('Recent');
  315. WriteInteger('Recent','Count',FRecent.Count);
  316. For I:=1 to FRecent.Count do
  317. WriteString('Recent','File'+IntToStr(i),FRecent[i-1]);
  318. UpdateFile;
  319. Finally
  320. Free;
  321. end;
  322. end;
  323. {
  324. Menu handlers
  325. }
  326. Procedure TMainForm.DialogSetFilename(Sender : TFPGtkWindow;Data : Pointer; Action : Integer;Initiator : TFPGtkObject);
  327. type
  328. PString = ^AnsiString;
  329. begin
  330. PString(Data)^:=(Sender as TFPgtkFileSelection).Filename;
  331. end;
  332. Procedure TMainForm.AddTorecent(FN : String);
  333. Var
  334. Index : Integer;
  335. begin
  336. FN:=ExpandFileName(FN);
  337. With FRecent do
  338. begin
  339. Index:=IndexOf(FN);
  340. If Index<>-1 then
  341. Delete(Index);
  342. Insert(0,FN);
  343. While Count>MaxRecentUsed do
  344. Delete(Count-1);
  345. end;
  346. BuildReopenList;
  347. end;
  348. Procedure TMainForm.OpenFile(FN : String);
  349. Var
  350. EFN : String;
  351. begin
  352. IF (FN<>'') then
  353. begin
  354. If FileExists(FN) then
  355. With CreatePage do
  356. begin
  357. LoadFromFile(FN);
  358. AddToRecent(Fn);
  359. end;
  360. end;
  361. end;
  362. Procedure TMainForm.FileOpenClick(Sender : TFPGtkObject; Data : Pointer);
  363. var
  364. fs : TFPgtkFileSelection;
  365. FN : String;
  366. begin
  367. fs := TFPgtkFileSelection.Create (gtk_window_dialog);
  368. FN:='';
  369. with fs do
  370. begin
  371. Title:=SOpenFileTitle;
  372. OKButton.ConnectClicked (@(CloseWithResult), inttopointer(drOk));
  373. CancelButton.ConnectClicked (@(CloseWindow), nil);
  374. if execute (nil, @FN, @DialogSetFilename) = drOk then
  375. OpenFile(FN);
  376. end;
  377. end;
  378. Procedure TMainForm.FileNewClick(Sender : TFPGtkObject; Data : Pointer);
  379. Const
  380. template = '<?xml version="1.0" encoding="ISO8859-1"?>'+LineEnding+
  381. '<fpdoc-descriptions>'+LineEnding+
  382. '</fpdoc-descriptions>'+LineEnding;
  383. Var
  384. S : TStringStream;
  385. begin
  386. With CreatePage do
  387. begin
  388. If FileExists(SFileTemplate) then
  389. LoadFromFile(SFileTemplate)
  390. else
  391. begin
  392. S:=TStringStream.Create(Template);
  393. Try
  394. LoadFromStream(S)
  395. finally
  396. S.Free;
  397. end;
  398. end;
  399. end;
  400. end;
  401. Type
  402. TSkeletonData = Record
  403. InputFile,
  404. OutputFile,
  405. PackageName,
  406. AdditionalOptions : String;
  407. DisableArguments,
  408. DisableResults,
  409. DisablePrivate,
  410. DisableProtected,
  411. DisableSeeAlso,
  412. DisableErrors : Boolean;
  413. end;
  414. PSkeletonData = ^TSkeletonData;
  415. Procedure TMainForm.GetSkeletonData(Sender : TFPGtkWindow;Data : Pointer; Action : Integer;Initiator : TFPGtkObject);
  416. begin
  417. With (Sender as TMakeSkelForm), PSkeletonData(Data)^ do
  418. begin
  419. InputFile:=FInputFile.FileName;
  420. OutputFile:=FOutputFile.FileName;
  421. PackageName:=FPackageName.Text;
  422. AdditionalOptions:=FadditionalOptions.Text;
  423. DisableArguments:=FDisableArguments.Active;
  424. DisableResults:=FDisableResults.Active;
  425. DisablePrivate:=FDisablePrivate.Active;
  426. DisableProtected:=FDisableProtected.Active;
  427. DisableSeeAlso:=FDisableSeeAlso.Active;
  428. DisableErrors:=FDisableErrors.Active;
  429. end;
  430. end;
  431. Function CreateSkeletonFile(Const S : TSkeletonData) : Boolean;
  432. Var
  433. Cmd : String;
  434. begin
  435. With S do
  436. begin
  437. cmd:='makeskel ';
  438. cmd:=cmd+format('--input=''%s %s''',[Inputfile,Additionaloptions]);
  439. cmd:=cmd+' --output='+OutputFile;
  440. cmd:=cmd+' --package='+PackageName;
  441. If DisableErrors then
  442. cmd:=cmd+' --disable-errors';
  443. If DisableSeeAlso then
  444. cmd:=cmd+' --disable-seealso';
  445. If DisableProtected then
  446. cmd:=cmd+' --disable-protected'
  447. else if DisablePrivate then
  448. cmd:=cmd+' --disable-private';
  449. If DisableResults then
  450. cmd:=cmd+' --disable-function-results';
  451. If DisableArguments then
  452. cmd:=cmd+' --disable-arguments';
  453. Writeln(cmd);
  454. With TProcess.Create(Nil) do
  455. try
  456. CommandLine:=cmd;
  457. options:=[poWaitOnExit];
  458. Execute;
  459. If (ExitStatus<>0) then
  460. begin
  461. If FileExists(OutputFile) then
  462. Result:=MessageDlg(SSkelErrorWithFile,[ExitStatus],mtWarning,mbYesNo,0)=mrYes
  463. else
  464. begin
  465. MessageDlg(SSkelErrorWithoutFile,[ExitStatus],mtError,[mbOk],0);
  466. Result:=False;
  467. end;
  468. end
  469. else
  470. Result:=FileExists(OutputFile);
  471. finally
  472. Free;
  473. end;
  474. end;
  475. end;
  476. Procedure TMainForm.FileNewFromFileClick(Sender : TFPGtkObject; Data : Pointer);
  477. Var
  478. SkeletonData : TSkeletonData;
  479. CmdLine : String;
  480. begin
  481. With TMakeSkelform.Create do
  482. begin
  483. Title:=SMakeSkelFromSource;
  484. If Execute(Nil,@SkeletonData,@GetSkeletonData)=drOK Then
  485. If CreateSkeletonFile(SkeletonData) then
  486. OpenFile(SkeletonData.OutPutFile)
  487. end;
  488. end;
  489. Procedure TMainForm.SaveEditor(E : TEditorPage);
  490. begin
  491. With E do
  492. begin
  493. if (FileName=SNewDocument) then
  494. SaveEditorAs(E)
  495. else
  496. SaveToFile(FileName);
  497. end;
  498. end;
  499. Procedure TMainForm.SaveEditorAs(E : TEditorPage);
  500. var
  501. fs : TFPgtkFileSelection;
  502. FN : String;
  503. begin
  504. fs := TFPgtkFileSelection.Create (gtk_window_dialog);
  505. FN:='';
  506. with fs do
  507. begin
  508. Title:=SSaveFileTitle;
  509. OKButton.ConnectClicked (@(CloseWithResult), inttopointer(drOk));
  510. CancelButton.ConnectClicked (@(CloseWindow), nil);
  511. FileName:=E.FileName;
  512. if execute (nil, @FN, @DialogSetFilename) = drOk then
  513. begin
  514. IF (FN<>'') then
  515. begin
  516. If ExtractFileExt(FN)='' then
  517. FN:=FN+DefaultExtension;
  518. E.SaveToFile(FN);
  519. AddToRecent(FN);
  520. end;
  521. end;
  522. end;
  523. end;
  524. Function TMainForm.CloseEditor(E : TEditorPage) : Boolean;
  525. begin
  526. Result:=Not E.Modified;
  527. If Not Result then
  528. Case MessageDlg(SFileModified,[E.FileName],mtConfirmation,mbYesNoCancel,0) of
  529. mrYes : begin
  530. SaveEditor(E);
  531. E.Free;
  532. Result:=True;
  533. end;
  534. mrNo : begin
  535. E.Free;
  536. Result:=True;
  537. end;
  538. end
  539. else
  540. E.Free;
  541. end;
  542. Procedure TMainForm.FileSaveClick(Sender : TFPGtkObject; Data : Pointer);
  543. begin
  544. If Assigned(CurrentEditor) then
  545. SaveEditor(CurrentEditor);
  546. end;
  547. Procedure TMainForm.FileSaveAsClick(Sender : TFPGtkObject; Data : Pointer);
  548. begin
  549. If Assigned(CurrentEditor) then
  550. SaveEditorAs(CurrentEditor);
  551. end;
  552. Procedure TMainForm.FileExitClick(Sender : TFPGtkObject; Data : Pointer);
  553. begin
  554. If AllowClose then
  555. Close;//(Sender,Data);
  556. end;
  557. Procedure TMainForm.FileCloseClick(Sender : TFPGtkObject; Data : Pointer);
  558. begin
  559. If Assigned(CurrentEditor) then
  560. CloseEditor(CurrentEditor)
  561. else
  562. Writeln('No current editor to close') ;
  563. end;
  564. Function TMainForm.Currenteditor : TEditorPage;
  565. begin
  566. With FPages do
  567. Result:=(Page as TEditorPage);
  568. end;
  569. Procedure TMainForm.GetNodeData(Sender : TFPGtkWindow;Data : Pointer; Action : Integer;Initiator : TFPGtkObject);
  570. type
  571. PString = ^AnsiString;
  572. begin
  573. With (Sender as TNewNodeForm) do
  574. PString(Data)^:=FENodeName.Text;
  575. end;
  576. Procedure TMainForm.InsertNodeClick(Sender : TFPGtkObject; Data : Pointer);
  577. Var
  578. S : AnsiString;
  579. Nt : TNodeType;
  580. begin
  581. If (CurrentEditor<>Nil) then
  582. begin
  583. With TNewNodeForm.Create do
  584. begin
  585. nt:=TNodeType(Data);
  586. S:=SNew+' '+NodeNames[nt];
  587. Case nt of
  588. ntPackage : S:=S+SForFile+ExtractFileName(CurrentEditor.FileName);
  589. ntModule: If (CurrentEditor.CurrentPackage<>Nil) then
  590. S:=S+SForPackage+CurrentEditor.CurrentPackage['name'];
  591. ntElement: begin
  592. If (CurrentEditor.CurrentModule<>Nil) then
  593. S:=S+SForModule+CurrentEditor.CurrentModule['name'];
  594. If Assigned(CurrentEditor.CurrentElement) then
  595. FENodeName.Selection:=CurrentEditor.CurrentElement['name'];
  596. end;
  597. end;
  598. Title:=S;
  599. S:='';
  600. If Execute(Nil,@S,@GetNodeData)=drOK Then
  601. Case nt of
  602. ntPackage : CurrentEditor.NewPackage(S);
  603. ntModule : CurrentEditor.NewModule(S);
  604. ntElement : CurrentEditor.NewElement(S);
  605. end;
  606. end;
  607. end;
  608. end;
  609. Procedure TMainForm.TagClick(Sender : TFPGtkObject; Data : Pointer);
  610. begin
  611. CurrentEditor.InsertTag(TTagType(Data));
  612. end;
  613. Type
  614. TLinkData = Record
  615. LText,LTarget : String;
  616. end;
  617. PLinkData = ^TLinkData;
  618. TTableData = Record
  619. Cols,Rows : Integer;
  620. UseHeader : Boolean;
  621. end;
  622. PTableData = ^TTableData;
  623. Procedure TMainForm.GetLinkData(Sender : TFPGtkWindow;Data : Pointer; Action : Integer;Initiator : TFPGtkObject);
  624. begin
  625. With (Sender as TLinkForm),PlinkData(Data)^ do
  626. begin
  627. LText:=FlinkText.Text;
  628. LTarget:=FLinkTarget.Entry.Text;
  629. end;
  630. end;
  631. Procedure TMainForm.GetTableData(Sender : TFPGtkWindow;Data : Pointer; Action : Integer;Initiator : TFPGtkObject);
  632. begin
  633. With (Sender as TTableForm),PTableData(Data)^ do
  634. begin
  635. Rows:=FTableRows.AsInteger;
  636. Cols:=FTableCols.AsInteger;
  637. UseHeader:=FUSeHeader.Active;
  638. end;
  639. end;
  640. Procedure TMainForm.LinkClick(Sender : TFPGtkObject; Data : Pointer);
  641. Var
  642. LinkData : TLinkData;
  643. S : TstringList;
  644. L : TFPgtkListItemGroup;
  645. begin
  646. If Assigned(CurrentEditor) then
  647. begin
  648. L:=TFpGtkListItemGroup.Create;
  649. Try
  650. S:=TStringList.Create;
  651. Try
  652. S.Sorted:=True;
  653. CurrentEditor.GetElementList(S);
  654. L.FillFromList(S);
  655. finally
  656. S.Free;
  657. end;
  658. With TLinkForm.Create do
  659. begin
  660. Title:=SInsertLink;
  661. FLinkText.Text:=CurrentEditor.CurrentSelection;
  662. FLinkTarget.List.AppendItems(L);
  663. If Execute(Nil,@LinkData,@GetLinkData)=drOK Then
  664. With LinkData do
  665. CurrentEditor.InsertLink(LTarget,LText);
  666. end;
  667. finally
  668. L.Free;
  669. end;
  670. end;
  671. end;
  672. Procedure TMainForm.TableClick(Sender : TFPGtkObject; Data : Pointer);
  673. Var
  674. TableData : TTableData;
  675. begin
  676. With TTableForm.Create do
  677. begin
  678. Title:=SInsertTable;
  679. FTableRows.AsInteger:=3;
  680. FTableCols.AsInteger:=3;
  681. If Execute(Nil,@TableData,@GetTableData)=drOK Then
  682. With TableData do
  683. CurrentEditor.InsertTable(Cols,Rows,UseHeader);
  684. end;
  685. end;
  686. Function TMainForm.AllowClose : Boolean;
  687. Var
  688. P : TFPgtkWidget;
  689. begin
  690. P:=FPages.Page;
  691. Result:=True;
  692. While (P<>Nil) and Result do
  693. begin
  694. Result:=CloseEditor(P as TEditorPage);
  695. P:=FPages.Page;
  696. end;
  697. end;
  698. Function TMainForm.OnDeleteEvent(Sender:TFPgtkWidget; Event:PGdkEvent; data:pointer): boolean;
  699. begin
  700. Result:=Not AllowClose;
  701. end;
  702. Procedure TMainForm.OptionsClick(Sender : TFPGtkObject; Data : Pointer);
  703. begin
  704. With TOptionsForm.Create do
  705. Execute(Nil,Nil,Nil);
  706. end;
  707. Procedure TMainForm.HelpAboutClick(Sender : TFPGtkObject; Data : Pointer);
  708. begin
  709. With TAboutForm.Create do
  710. Execute(Nil,Nil,Nil);
  711. end;
  712. Type
  713. TRecentMenuItem = Class (TFPGtkMenuItem)
  714. FileName : String;
  715. end;
  716. Procedure TMainForm.FileReopen(Sender: TFPGTKObject;data : Pointer);
  717. begin
  718. OpenFile((Sender as TRecentMenuItem).FileName);
  719. end;
  720. procedure TMainForm.BuildReopenList;
  721. Function NewRecentMenuItem (Nr : Integer;AFileName : string) : TRecentMenuItem;
  722. begin
  723. If Nr<10 then
  724. result := TRecentMenuItem.CreateWithLabel('_'+IntToStr(Nr)+' '+AFileName)
  725. else
  726. result := TRecentMenuItem.CreateWithLabel(AFileName);
  727. result.FileName:=AFileName;
  728. Result.ConnectActivate(@FileReopen,Nil);
  729. end;
  730. var I : integer;
  731. mi : TFPgtkMenuItem;
  732. begin
  733. with FRecent do
  734. begin
  735. with FFileRecent do
  736. begin
  737. if assigned(SubMenu) then
  738. SubMenu.Free;
  739. SubMenu := TFPgtkMenu.Create;
  740. with (submenu as TFPgtkMenu) do
  741. for I := FRecent.count-1 downto 0 do
  742. begin
  743. mi := NewRecentMenuItem (I,FRecent[I]);
  744. Append (mi);
  745. end;
  746. end;
  747. end;
  748. end;
  749. end.