IDE.Wizard.WizardFileForm.pas 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. unit IDE.Wizard.WizardFileForm;
  2. {
  3. Inno Setup
  4. Copyright (C) 1997-2020 Jordan Russell
  5. Portions by Martijn Laan
  6. For conditions of distribution and use, see LICENSE.TXT.
  7. Compiler IDE Script Wizard File form
  8. }
  9. interface
  10. uses
  11. Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  12. UIStateForm, StdCtrls, ExtCtrls, NewStaticText;
  13. type
  14. PWizardFile = ^TWizardFile;
  15. TWizardFile = record
  16. Source: String;
  17. RecurseSubDirs: Boolean;
  18. CreateAllSubDirs: Boolean;
  19. DestRootDir: String;
  20. DestRootDirIsConstant: Boolean;
  21. DestSubDir: String;
  22. end;
  23. TWizardFileForm = class(TUIStateForm)
  24. OKButton: TButton;
  25. CancelButton: TButton;
  26. GroupBox2: TGroupBox;
  27. DestRootDirComboBox: TComboBox;
  28. DestRootDirEdit: TEdit;
  29. DestRootDirLabel: TNewStaticText;
  30. DestSubDirEdit: TEdit;
  31. SubDirLabel: TNewStaticText;
  32. RequiredLabel1: TNewStaticText;
  33. RequiredLabel2: TNewStaticText;
  34. GroupBox1: TGroupBox;
  35. SourceLabel: TNewStaticText;
  36. SourceEdit: TEdit;
  37. RecurseSubDirsCheck: TCheckBox;
  38. CreateAllSubDirsCheck: TCheckBox;
  39. procedure OKButtonClick(Sender: TObject);
  40. procedure FormCreate(Sender: TObject);
  41. procedure DestRootDirComboBoxChange(Sender: TObject);
  42. procedure RecurseSubDirsCheckClick(Sender: TObject);
  43. private
  44. FAllowAppDestRootDir: Boolean;
  45. FWizardFile: PWizardFile;
  46. procedure SetWizardFile(WizardFile: PWizardFile);
  47. procedure UpdateUI;
  48. public
  49. property AllowAppDestRootDir: Boolean write FAllowAppDestRootDir;
  50. property WizardFile: PWizardFile write SetWizardFile;
  51. end;
  52. implementation
  53. uses
  54. IDE.Messages, Shared.CommonFunc.Vcl, Shared.CommonFunc, IDE.HelperFunc;
  55. {$R *.DFM}
  56. type
  57. TConstant = record
  58. Constant, Description: String;
  59. end;
  60. const
  61. DestRootDirs: array[0..6] of TConstant =
  62. (
  63. ( Constant: '{app}'; Description: 'Application directory'),
  64. ( Constant: '{autopf}'; Description: 'Program Files directory'),
  65. ( Constant: '{autocf}'; Description: 'Common Files directory'),
  66. ( Constant: '{win}'; Description: 'Windows directory'),
  67. ( Constant: '{sys}'; Description: 'Windows system directory'),
  68. ( Constant: '{src}'; Description: 'Setup source directory'),
  69. ( Constant: '{sd}'; Description: 'System drive root directory')
  70. );
  71. procedure TWizardFileForm.SetWizardFile(WizardFile: PWizardFile);
  72. var
  73. I: Integer;
  74. begin
  75. FWizardFile := WizardFile;
  76. SourceEdit.Text := WizardFile.Source;
  77. if NewFileExists(SourceEdit.Text) then
  78. RecurseSubDirsCheck.Enabled := False;
  79. RecurseSubDirsCheck.Checked := WizardFile.RecurseSubDirs;
  80. CreateAllSubDirsCheck.Checked := WizardFile.CreateAllSubDirs;
  81. if WizardFile.DestRootDirIsConstant then begin
  82. for I := Low(DestRootDirs) to High(DestRootDirs) do begin
  83. if DestRootDirs[I].Constant = WizardFile.DestRootDir then begin
  84. DestRootDirComboBox.ItemIndex := I;
  85. Break;
  86. end;
  87. end;
  88. end else begin
  89. DestRootDirComboBox.ItemIndex := DestRootDirComboBox.Items.Count-1;
  90. DestRootDirEdit.Text := WizardFile.DestRootDir;
  91. end;
  92. DestSubDirEdit.Text := WizardFile.DestSubDir;
  93. UpdateUI;
  94. end;
  95. { --- }
  96. procedure TWizardFileForm.FormCreate(Sender: TObject);
  97. procedure MakeBold(const Ctl: TNewStaticText);
  98. begin
  99. Ctl.Font.Style := [fsBold];
  100. end;
  101. var
  102. I: Integer;
  103. begin
  104. InitFormFont(Self);
  105. InitFormTheme(Self);
  106. MakeBold(SourceLabel);
  107. MakeBold(DestRootDirLabel);
  108. MakeBold(RequiredLabel1);
  109. RequiredLabel2.Left := RequiredLabel1.Left + RequiredLabel1.Width;
  110. for I := Low(DestRootDirs) to High(DestRootDirs) do
  111. DestRootDirComboBox.Items.Add(DestRootDirs[I].Description);
  112. DestRootDirComboBox.Items.Add('(Custom)');
  113. DestRootDirComboBox.ItemIndex := 0;
  114. end;
  115. { --- }
  116. procedure TWizardFileForm.UpdateUI;
  117. begin
  118. CreateAllSubDirsCheck.Enabled := RecurseSubDirsCheck.Enabled and RecurseSubDirsCheck.Checked;
  119. if DestRootDirComboBox.ItemIndex = DestRootDirComboBox.Items.Count-1 then begin
  120. DestRootDirEdit.Enabled := True;
  121. DestRootDirEdit.Color := clWindow;
  122. end else begin
  123. DestRootDirEdit.Enabled := False;
  124. DestRootDirEdit.Color := clBtnFace;
  125. end;
  126. end;
  127. { --- }
  128. procedure TWizardFileForm.RecurseSubDirsCheckClick(Sender: TObject);
  129. begin
  130. UpdateUI;
  131. end;
  132. procedure TWizardFileForm.DestRootDirComboBoxChange(Sender: TObject);
  133. begin
  134. UpdateUI;
  135. if DestRootDirEdit.Enabled then
  136. ActiveControl := DestRootDirEdit;
  137. end;
  138. procedure TWizardFileForm.OKButtonClick(Sender: TObject);
  139. var
  140. DestRootDirIndex: Integer;
  141. begin
  142. ModalResult := mrNone;
  143. DestRootDirIndex := DestRootDirComboBox.ItemIndex;
  144. if (DestRootDirIndex = DestRootDirComboBox.Items.Count-1) and (DestRootDirEdit.Text = '') then begin
  145. MsgBox(SWizardFileDestRootDirError, '', mbError, MB_OK);
  146. ActiveControl := DestRootDirEdit;
  147. end else if (DestRootDirs[DestRootDirIndex].Constant = '{app}') and not FAllowAppDestRootDir then begin
  148. MsgBox(SWizardFileAppDestRootDirError, '', mbError, MB_OK);
  149. ActiveControl := DestRootDirComboBox;
  150. end else
  151. ModalResult := mrOk;
  152. if ModalResult = mrOk then begin
  153. FWizardFile.RecurseSubDirs := RecurseSubDirsCheck.Checked;
  154. FWizardFile.CreateAllSubDirs := CreateAllSubDirsCheck.Checked;
  155. if DestRootDirIndex = DestRootDirComboBox.Items.Count-1 then begin
  156. FWizardFile.DestRootDir := DestRootDirEdit.Text;
  157. FWizardFile.DestRootDirIsConstant := False;
  158. end else begin
  159. FWizardFile.DestRootDir := DestRootDirs[DestRootDirIndex].Constant;
  160. FWizardFile.DestRootDirIsConstant := True;
  161. end;
  162. FWizardFile.DestSubDir := DestSubDirEdit.Text;
  163. end;
  164. end;
  165. end.