/ide/publishprojectdlg.pas

http://github.com/graemeg/lazarus · Pascal · 377 lines · 279 code · 50 blank · 48 comment · 19 complexity · e6d98483e5fc6283f8fb38e56151ee72 MD5 · raw file

  1. { /***************************************************************************
  2. publishprojectdlg.pp - Lazarus IDE unit
  3. -----------------------------------------
  4. ***************************************************************************/
  5. ***************************************************************************
  6. * *
  7. * This source is free software; you can redistribute it and/or modify *
  8. * it under the terms of the GNU General Public License as published by *
  9. * the Free Software Foundation; either version 2 of the License, or *
  10. * (at your option) any later version. *
  11. * *
  12. * This code is distributed in the hope that it will be useful, but *
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of *
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
  15. * General Public License for more details. *
  16. * *
  17. * A copy of the GNU General Public License is available on the World *
  18. * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
  19. * obtain it by writing to the Free Software Foundation, *
  20. * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  21. * *
  22. ***************************************************************************
  23. Author: Mattias Gaertner
  24. Abstract:
  25. - TPublishProjectDialog
  26. The dialog for TPublishModuleOptions to publish projects and packages.
  27. }
  28. unit PublishProjectDlg;
  29. {$mode objfpc}{$H+}
  30. interface
  31. uses
  32. Classes, SysUtils, LazFileUtils, Forms, Controls, Graphics, Buttons,
  33. StdCtrls, Dialogs, LCLType,
  34. IDEWindowIntf, IDEHelpIntf, IDEDialogs,
  35. ProjectDefs, PackageDefs, PublishModule, IDEOptionDefs, InputHistory,
  36. LazarusIDEStrConsts, IDEProcs, ExtCtrls, ButtonPanel;
  37. type
  38. { TPublishProjectDialog }
  39. TPublishProjectDialog = class(TForm)
  40. ButtonPanel1: TButtonPanel;
  41. DestDirGroupBox: TGroupBox;
  42. DestDirComboBox: TComboBox;
  43. BrowseDestDirBitBtn: TBitBtn;
  44. CommandAfterLabel: TLabel;
  45. CommandAfterCombobox: TComboBox;
  46. FilesGroupbox: TGroupBox;
  47. IgnoreBinariesCheckbox: TCheckBox;
  48. IncludeFilterCombobox: TComboBox;
  49. IncFilterSimpleSyntaxCheckbox: TCheckBox;
  50. UseIncludeFilterCheckbox: TCheckBox;
  51. IncludeFilterGroupbox: TGroupBox;
  52. ExcludeFilterCombobox: TComboBox;
  53. ExcFilterSimpleSyntaxCheckbox: TCheckBox;
  54. UseExcludeFilterCheckbox: TCheckBox;
  55. ExcludeFilterGroupbox: TGroupBox;
  56. ProjectInfoGroupbox: TGroupBox;
  57. SaveEditorInfoOfNonProjectFilesCheckbox: TCheckBox;
  58. SaveClosedEditorFilesInfoCheckbox: TCheckBox;
  59. procedure BrowseDestDirBitBtnCLICK(Sender: TObject);
  60. procedure DestDirGroupBoxRESIZE(Sender: TObject);
  61. procedure FormClose(Sender: TObject; var {%H-}CloseAction: TCloseAction);
  62. procedure FormCreate(Sender: TObject);
  63. procedure HelpButtonClick(Sender: TObject);
  64. procedure OkButtonCLICK(Sender: TObject);
  65. procedure SaveSettingsButtonClick(Sender: TObject);
  66. private
  67. FOptions: TPublishModuleOptions;
  68. procedure SetComboBox(AComboBox: TComboBox; const NewText: string;
  69. MaxItemCount: integer);
  70. procedure LoadHistoryLists;
  71. procedure SaveHistoryLists;
  72. procedure SetOptions(const AValue: TPublishModuleOptions);
  73. function CheckFilter: boolean;
  74. public
  75. constructor Create(TheOwner: TComponent); override;
  76. destructor Destroy; override;
  77. procedure LoadFromOptions(SrcOpts: TPublishModuleOptions);
  78. procedure SaveToOptions(DestOpts: TPublishModuleOptions);
  79. property Options: TPublishModuleOptions read FOptions write SetOptions;
  80. end;
  81. function ShowPublishProjectDialog(
  82. PublishOptions: TPublishModuleOptions): TModalResult;
  83. implementation
  84. {$R *.lfm}
  85. function ShowPublishProjectDialog(
  86. PublishOptions: TPublishModuleOptions): TModalResult;
  87. var
  88. PublishProjectDialog: TPublishProjectDialog;
  89. begin
  90. PublishProjectDialog:=TPublishProjectDialog.Create(nil);
  91. with PublishProjectDialog do begin
  92. Options:=PublishOptions;
  93. Result:=ShowModal;
  94. Free;
  95. end;
  96. end;
  97. { TPublishProjectDialog }
  98. procedure TPublishProjectDialog.DestDirGroupBoxRESIZE(Sender: TObject);
  99. begin
  100. with DestDirComboBox do
  101. SetBounds(Left,Top,
  102. Parent.ClientWidth-2*Left-BrowseDestDirBitBtn.Width-5,Height);
  103. with BrowseDestDirBitBtn do
  104. Left:=DestDirComboBox.Left+DestDirComboBox.Width+5;
  105. with CommandAfterCombobox do
  106. SetBounds(Left,Top,Parent.ClientWidth-2*Left,Height);
  107. end;
  108. procedure TPublishProjectDialog.FormClose(Sender: TObject; var CloseAction: TCloseAction);
  109. begin
  110. IDEDialogLayoutList.SaveLayout(Self);
  111. end;
  112. procedure TPublishProjectDialog.BrowseDestDirBitBtnCLICK(Sender: TObject);
  113. var
  114. SelectDirDialog: TSelectDirectoryDialog;
  115. NewDir: String;
  116. begin
  117. SelectDirDialog:=TSelectDirectoryDialog.Create(Self);
  118. InputHistories.ApplyFileDialogSettings(SelectDirDialog);
  119. SelectDirDialog.Title:=lisChooseDirectory;
  120. if SelectDirDialog.Execute then begin
  121. NewDir:=ExpandFileNameUTF8(SelectDirDialog.Filename);
  122. SeTComboBox(DestDirComboBox,NewDir,20);
  123. end;
  124. SelectDirDialog.Free;
  125. end;
  126. procedure TPublishProjectDialog.FormCreate(Sender: TObject);
  127. begin
  128. DestDirGroupBox.Caption:=lisDestinationDirectory;
  129. CommandAfterLabel.Caption:=lisCommandAfter;
  130. FilesGroupbox.Caption:=dlgEnvFiles;
  131. IgnoreBinariesCheckbox.Caption:=lisIgnoreBinaries;
  132. IncFilterSimpleSyntaxCheckbox.Caption:=lisSimpleSyntax;
  133. IncFilterSimpleSyntaxCheckbox.Hint:=
  134. lisNormallyTheFilterIsARegularExpressionInSimpleSynta;
  135. UseIncludeFilterCheckbox.Caption:=lisUseIncludeFilter;
  136. IncludeFilterGroupbox.Caption:=lisIncludeFilter;
  137. ExcFilterSimpleSyntaxCheckbox.Caption:=lisSimpleSyntax;
  138. ExcFilterSimpleSyntaxCheckbox.Hint:=
  139. lisNormallyTheFilterIsARegularExpressionInSimpleSynta;
  140. UseExcludeFilterCheckbox.Caption:=lisUseExcludeFilter;
  141. ExcludeFilterGroupbox.Caption:=lisExcludeFilter;
  142. ProjectInfoGroupbox.Caption:=lisProjectInformation;
  143. SaveEditorInfoOfNonProjectFilesCheckbox.Caption:=
  144. lisSaveEditorInfoOfNonProjectFiles;
  145. SaveClosedEditorFilesInfoCheckbox.Caption:=lisSaveInfoOfClosedEditorFiles;
  146. ButtonPanel1.OkButton.Caption := lisMenuOk;
  147. ButtonPanel1.OKButton.OnClick := @OkButtonCLICK;
  148. ButtonPanel1.CloseButton.Caption := lisSaveSettings;
  149. ButtonPanel1.CloseButton.ModalResult := mrNone;
  150. ButtonPanel1.CloseButton.Kind := bkCustom;
  151. ButtonPanel1.CloseButton.LoadGlyphFromStock(idButtonSave);
  152. if ButtonPanel1.CloseButton.Glyph.Empty then
  153. ButtonPanel1.CloseButton.LoadGlyphFromResourceName(HInstance, 'laz_save');
  154. ButtonPanel1.CloseButton.OnClick := @SaveSettingsButtonCLICK;
  155. ButtonPanel1.HelpButton.OnClick := @HelpButtonClick;
  156. end;
  157. procedure TPublishProjectDialog.HelpButtonClick(Sender: TObject);
  158. begin
  159. LazarusHelp.ShowHelpForIDEControl(Self);
  160. end;
  161. procedure TPublishProjectDialog.OkButtonCLICK(Sender: TObject);
  162. begin
  163. if not CheckFilter then exit;
  164. if Options<>nil then SaveToOptions(Options);
  165. end;
  166. procedure TPublishProjectDialog.SaveSettingsButtonClick(Sender: TObject);
  167. begin
  168. if not CheckFilter then exit;
  169. if Options<>nil then SaveToOptions(Options);
  170. end;
  171. procedure TPublishProjectDialog.SetComboBox(AComboBox: TComboBox;
  172. const NewText: string; MaxItemCount: integer);
  173. begin
  174. AComboBox.AddHistoryItem(NewText,MaxItemCount,true,false);
  175. end;
  176. procedure TPublishProjectDialog.LoadHistoryLists;
  177. var
  178. List: THistoryList;
  179. begin
  180. // destination directories
  181. List:=InputHistories.HistoryLists.GetList(hlPublishProjectDestDirs,true,rltFile);
  182. List.AppendEntry(SetDirSeparators('$(TestDir)/publishedproject/'));
  183. List.AppendEntry(SetDirSeparators('$(TestDir)/publishedpackage/'));
  184. List.AppendEntry(SetDirSeparators('$(ProjPath)/published/'));
  185. DestDirComboBox.Items.Assign(List);
  186. // command after
  187. List:=InputHistories.HistoryLists.GetList(hlPublishProjectCommandsAfter,true,rltCaseSensitive);
  188. List.AppendEntry(SetDirSeparators(
  189. 'tar czf $MakeFile($(ProjPublishDir)).tgz $(ProjPublishDir)'));
  190. List.AppendEntry(SetDirSeparators(
  191. 'tar czf $(TestDir)/project.tgz -C $(TestDir) publishedproject'));
  192. List.AppendEntry(SetDirSeparators(
  193. 'tar czf $(TestDir)/package.tgz -C $(TestDir) publishedpackage'));
  194. CommandAfterCombobox.Items.Assign(List);
  195. // file filter
  196. List:=InputHistories.HistoryLists.GetList(hlPublishProjectIncludeFileFilter,
  197. true,rltFile);
  198. if List.Count=0 then begin
  199. List.Add(DefPublModIncFilter);
  200. end;
  201. IncludeFilterCombobox.Items.Assign(List);
  202. List:=InputHistories.HistoryLists.GetList(hlPublishProjectExcludeFileFilter,
  203. true,rltFile);
  204. if List.Count=0 then begin
  205. List.Add(DefPublModExcFilter);
  206. end;
  207. ExcludeFilterCombobox.Items.Assign(List);
  208. end;
  209. procedure TPublishProjectDialog.SaveHistoryLists;
  210. begin
  211. // destination directories
  212. SetComboBox(DestDirComboBox,DestDirComboBox.Text,20);
  213. InputHistories.HistoryLists.GetList(hlPublishProjectDestDirs,true,rltFile).Assign(
  214. DestDirComboBox.Items);
  215. // command after
  216. SetComboBox(CommandAfterCombobox,CommandAfterCombobox.Text,20);
  217. InputHistories.HistoryLists.GetList(hlPublishProjectCommandsAfter,true,
  218. rltCaseSensitive).Assign(CommandAfterCombobox.Items);
  219. // file filter
  220. SetComboBox(IncludeFilterCombobox,IncludeFilterCombobox.Text,20);
  221. InputHistories.HistoryLists.GetList(hlPublishProjectIncludeFileFilter,true,
  222. rltFile).Assign(IncludeFilterCombobox.Items);
  223. SetComboBox(ExcludeFilterCombobox,ExcludeFilterCombobox.Text,20);
  224. InputHistories.HistoryLists.GetList(hlPublishProjectExcludeFileFilter,true,
  225. rltFile).Assign(ExcludeFilterCombobox.Items);
  226. end;
  227. procedure TPublishProjectDialog.SetOptions(const AValue: TPublishModuleOptions);
  228. begin
  229. if FOptions=AValue then exit;
  230. FOptions:=AValue;
  231. if FOptions is TPublishPackageOptions then
  232. Caption:=lisPkgEditPublishPackage
  233. else
  234. Caption:=lisPublishProject;
  235. LoadFromOptions(FOptions);
  236. end;
  237. function TPublishProjectDialog.CheckFilter: boolean;
  238. begin
  239. Result:=false;
  240. if Options<>nil then begin
  241. if not Options.IncludeFilterValid then begin
  242. if IDEMessageDialog(lisCCOErrorCaption, lisPublProjInvalidIncludeFilter,
  243. mtError, [mbIgnore,
  244. mbCancel])
  245. =mrCancel
  246. then exit;
  247. end;
  248. if not Options.ExcludeFilterValid then begin
  249. if IDEMessageDialog(lisCCOErrorCaption, lisPublProjInvalidExcludeFilter,
  250. mtError, [mbIgnore,
  251. mbCancel])
  252. =mrCancel
  253. then exit;
  254. end;
  255. end;
  256. Result:=true;
  257. end;
  258. constructor TPublishProjectDialog.Create(TheOwner: TComponent);
  259. begin
  260. inherited Create(TheOwner);
  261. Position:=poScreenCenter;
  262. IDEDialogLayoutList.ApplyLayout(Self,500,500);
  263. if Height<500 then Height:=500;
  264. LoadHistoryLists;
  265. end;
  266. destructor TPublishProjectDialog.Destroy;
  267. begin
  268. SaveHistoryLists;
  269. inherited Destroy;
  270. end;
  271. procedure TPublishProjectDialog.LoadFromOptions(SrcOpts: TPublishModuleOptions);
  272. var
  273. ProjSrcOpts: TPublishProjectOptions;
  274. begin
  275. // destination
  276. SeTComboBox(DestDirComboBox,SrcOpts.DestinationDirectory,20);
  277. SeTComboBox(CommandAfterCombobox,SrcOpts.CommandAfter,20);
  278. // file filter
  279. IgnoreBinariesCheckbox.Checked:=SrcOpts.IgnoreBinaries;
  280. UseIncludeFilterCheckbox.Checked:=SrcOpts.UseIncludeFileFilter;
  281. IncFilterSimpleSyntaxCheckbox.Checked:=SrcOpts.IncludeFilterSimpleSyntax;
  282. SeTComboBox(IncludeFilterCombobox,SrcOpts.IncludeFileFilter,20);
  283. UseExcludeFilterCheckbox.Checked:=SrcOpts.UseExcludeFileFilter;
  284. ExcFilterSimpleSyntaxCheckbox.Checked:=SrcOpts.ExcludeFilterSimpleSyntax;
  285. SeTComboBox(ExcludeFilterCombobox,SrcOpts.ExcludeFileFilter,20);
  286. // project info
  287. if SrcOpts is TPublishProjectOptions then begin
  288. ProjSrcOpts:=TPublishProjectOptions(SrcOpts);
  289. SaveEditorInfoOfNonProjectFilesCheckbox.Checked:=
  290. ProjSrcOpts.SaveEditorInfoOfNonProjectFiles;
  291. SaveClosedEditorFilesInfoCheckbox.Checked:=
  292. ProjSrcOpts.SaveClosedEditorFilesInfo;
  293. ProjectInfoGroupbox.Enabled:=true;
  294. end else begin
  295. ProjectInfoGroupbox.Enabled:=false;
  296. end;
  297. end;
  298. procedure TPublishProjectDialog.SaveToOptions(DestOpts: TPublishModuleOptions);
  299. var
  300. ProjDestOpts: TPublishProjectOptions;
  301. begin
  302. // destination
  303. DestOpts.DestinationDirectory:=DestDirComboBox.Text;
  304. DestOpts.CommandAfter:=CommandAfterCombobox.Text;
  305. // file filter
  306. DestOpts.IgnoreBinaries:=IgnoreBinariesCheckbox.Checked;
  307. DestOpts.UseIncludeFileFilter:=UseIncludeFilterCheckbox.Checked;
  308. DestOpts.IncludeFilterSimpleSyntax:=IncFilterSimpleSyntaxCheckbox.Checked;
  309. DestOpts.IncludeFileFilter:=IncludeFilterCombobox.Text;
  310. DestOpts.UseExcludeFileFilter:=UseExcludeFilterCheckbox.Checked;
  311. DestOpts.ExcludeFilterSimpleSyntax:=ExcFilterSimpleSyntaxCheckbox.Checked;
  312. DestOpts.ExcludeFileFilter:=ExcludeFilterCombobox.Text;
  313. // project info
  314. if DestOpts is TPublishProjectOptions then begin
  315. ProjDestOpts:=TPublishProjectOptions(DestOpts);
  316. ProjDestOpts.SaveEditorInfoOfNonProjectFiles:=
  317. SaveEditorInfoOfNonProjectFilesCheckbox.Checked;
  318. ProjDestOpts.SaveClosedEditorFilesInfo:=
  319. SaveClosedEditorFilesInfoCheckbox.Checked;
  320. end;
  321. end;
  322. end.