| 1 |
unit UProjConfigDlg; |
|---|
| 2 |
|
|---|
| 3 |
interface |
|---|
| 4 |
|
|---|
| 5 |
uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls, |
|---|
| 6 |
Buttons, ExtCtrls, Projects; |
|---|
| 7 |
|
|---|
| 8 |
type |
|---|
| 9 |
TProjConfigDlg = class(TForm) |
|---|
| 10 |
SaveButton: TButton; |
|---|
| 11 |
CancelButton: TButton; |
|---|
| 12 |
Bevel1: TBevel; |
|---|
| 13 |
Label1: TLabel; |
|---|
| 14 |
Label2: TLabel; |
|---|
| 15 |
GroupBox1: TGroupBox; |
|---|
| 16 |
optimize: TCheckBox; |
|---|
| 17 |
debug: TCheckBox; |
|---|
| 18 |
debugsym: TCheckBox; |
|---|
| 19 |
profiling: TCheckBox; |
|---|
| 20 |
name: TEdit; |
|---|
| 21 |
outfilename: TEdit; |
|---|
| 22 |
unittests: TCheckBox; |
|---|
| 23 |
inlining: TCheckBox; |
|---|
| 24 |
Label3: TLabel; |
|---|
| 25 |
outputPath: TEdit; |
|---|
| 26 |
BrowseOutput: TButton; |
|---|
| 27 |
ImportPathButton: TButton; |
|---|
| 28 |
Label4: TLabel; |
|---|
| 29 |
versionNumber: TEdit; |
|---|
| 30 |
defaultCheckbox: TCheckBox; |
|---|
| 31 |
projectPath: TEdit; |
|---|
| 32 |
Label5: TLabel; |
|---|
| 33 |
BrowseProject: TButton; |
|---|
| 34 |
LinkerButton: TButton; |
|---|
| 35 |
releaseVer: TCheckBox; |
|---|
| 36 |
VersionsButton: TButton; |
|---|
| 37 |
procedure SaveButtonClick(Sender: TObject); |
|---|
| 38 |
procedure BrowseProjectClick(Sender: TObject); |
|---|
| 39 |
procedure BrowseOutputClick(Sender: TObject); |
|---|
| 40 |
procedure VersionsButtonClick(Sender: TObject); |
|---|
| 41 |
procedure FormDestroy(Sender: TObject); |
|---|
| 42 |
procedure FormCreate(Sender: TObject); |
|---|
| 43 |
procedure ImportPathButtonClick(Sender: TObject); |
|---|
| 44 |
procedure LinkerButtonClick(Sender: TObject); |
|---|
| 45 |
private |
|---|
| 46 |
{ Private declarations } |
|---|
| 47 |
public |
|---|
| 48 |
{ Public declarations } |
|---|
| 49 |
projDir : string; |
|---|
| 50 |
versions : TStringList ; |
|---|
| 51 |
importPaths :TStringList; |
|---|
| 52 |
linkerFlags :TStringList; |
|---|
| 53 |
procedure SaveOptions( proj: TProject ); |
|---|
| 54 |
procedure LoadOptions( proj: TProject ); |
|---|
| 55 |
function Validate(var S : string) : boolean; |
|---|
| 56 |
end; |
|---|
| 57 |
|
|---|
| 58 |
var |
|---|
| 59 |
ProjConfigDlg: TProjConfigDlg; |
|---|
| 60 |
|
|---|
| 61 |
implementation |
|---|
| 62 |
|
|---|
| 63 |
{$R *.DFM} |
|---|
| 64 |
|
|---|
| 65 |
uses MyUtils, FileCtrl, UVersionList, UImportList, ULinkerList; |
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
procedure TProjConfigDlg.SaveOptions( proj :TProject ); |
|---|
| 70 |
var |
|---|
| 71 |
config : TProjectCfg; |
|---|
| 72 |
I,N : Integer; |
|---|
| 73 |
begin |
|---|
| 74 |
proj.name := Self.name.text; |
|---|
| 75 |
proj.destfilename := ExtractFileName( outfilename.Text ); |
|---|
| 76 |
proj.outPath := outputPath.Text; |
|---|
| 77 |
proj.basepath := projectPath.Text; |
|---|
| 78 |
|
|---|
| 79 |
config := proj.config; |
|---|
| 80 |
config.versions.Clear; |
|---|
| 81 |
config.versions.AddStrings( versions ); |
|---|
| 82 |
|
|---|
| 83 |
for N:=0 to versions.Count-1 do begin |
|---|
| 84 |
I := proj.enabled.IndexOf( versions[N] ); |
|---|
| 85 |
if I>=0 then proj.enabled.Delete(I); |
|---|
| 86 |
end; |
|---|
| 87 |
|
|---|
| 88 |
proj.importPaths.Clear; |
|---|
| 89 |
proj.importPaths.AddStrings( Self.importPaths ); |
|---|
| 90 |
|
|---|
| 91 |
config.linkerFlags.Clear; |
|---|
| 92 |
config.linkerFlags.AddStrings( self.linkerFlags ); |
|---|
| 93 |
|
|---|
| 94 |
config.optimize := optimize.Checked; |
|---|
| 95 |
config.inlineFn := inlining.Checked; |
|---|
| 96 |
config.debugVersion := debug.Checked; |
|---|
| 97 |
config.debugSymbols := debugsym.Checked; |
|---|
| 98 |
config.profileHooks := profiling.Checked; |
|---|
| 99 |
config.unittests := unittests.Checked; |
|---|
| 100 |
config.releaseVersion := releaseVer.Checked; |
|---|
| 101 |
config.versionNumber := versionNumber.Text; |
|---|
| 102 |
end; |
|---|
| 103 |
|
|---|
| 104 |
procedure TProjConfigDlg.LoadOptions( proj : TProject ); |
|---|
| 105 |
begin |
|---|
| 106 |
if Empty( proj.filename ) then Caption:='New Project' |
|---|
| 107 |
else Caption:='Configuration for: ' + proj.filename; |
|---|
| 108 |
|
|---|
| 109 |
name.Text := proj.name; |
|---|
| 110 |
outfilename.Text := proj.destfilename ; |
|---|
| 111 |
outputPath.Text := proj.outPath ; |
|---|
| 112 |
projectPath.Text := proj.basepath; |
|---|
| 113 |
|
|---|
| 114 |
Self.versions.Clear; |
|---|
| 115 |
Self.versions.AddStrings( proj.config.versions ); |
|---|
| 116 |
|
|---|
| 117 |
Self.importPaths.Clear; |
|---|
| 118 |
Self.importPaths.AddStrings( proj.importPaths ); |
|---|
| 119 |
|
|---|
| 120 |
Self.linkerFlags.Clear; |
|---|
| 121 |
Self.LinkerFlags.AddStrings( proj.config.linkerflags ); |
|---|
| 122 |
|
|---|
| 123 |
self.versionNumber.Text := proj.config.versionNumber; |
|---|
| 124 |
with proj do begin |
|---|
| 125 |
optimize.Checked := config.optimize ; |
|---|
| 126 |
inlining.Checked := config.inlineFn ; |
|---|
| 127 |
debug.Checked := config.debugVersion ; |
|---|
| 128 |
debugsym.Checked := config.debugSymbols ; |
|---|
| 129 |
profiling.Checked := config.profileHooks ; |
|---|
| 130 |
unittests.Checked := config.unittests ; |
|---|
| 131 |
releaseVer.Checked := config.releaseVersion; |
|---|
| 132 |
end; |
|---|
| 133 |
end; |
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
function ConfirmCreate( name, dir : string ) : boolean ; |
|---|
| 137 |
var |
|---|
| 138 |
msg : string; |
|---|
| 139 |
begin |
|---|
| 140 |
Result := false; |
|---|
| 141 |
dir := Trim( dir ); |
|---|
| 142 |
if Length( dir )= 0 then begin |
|---|
| 143 |
Application.MessageBox( PChar('Please enter a ' + name) , 'Input required', MB_OK ); |
|---|
| 144 |
Exit; |
|---|
| 145 |
end; |
|---|
| 146 |
|
|---|
| 147 |
msg := name + ' does not exist! Create this directory?\nClick No to cancel'; |
|---|
| 148 |
if Application.MessageBox( PChar( msg ), 'Confirm', MB_YESNO ) = IDNO then Exit; |
|---|
| 149 |
Result:= ForceDirectories( dir ); |
|---|
| 150 |
end; |
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
function TProjConfigDlg.Validate( var S: string ) : boolean ; |
|---|
| 154 |
var |
|---|
| 155 |
V:Integer; |
|---|
| 156 |
begin |
|---|
| 157 |
Result:= false; |
|---|
| 158 |
if Length( Self.name.Text )<1 then begin |
|---|
| 159 |
S := 'You must name this project' ; |
|---|
| 160 |
self.name.SetFocus; |
|---|
| 161 |
Exit; |
|---|
| 162 |
end; |
|---|
| 163 |
|
|---|
| 164 |
If DirectoryExists( Self.projectPath.Text ) = false then begin |
|---|
| 165 |
S := 'That project directory does not exist'; |
|---|
| 166 |
projectPath.SetFocus; |
|---|
| 167 |
Exit; |
|---|
| 168 |
end; |
|---|
| 169 |
|
|---|
| 170 |
if ( Pos( ' ', outfilename.Text )>0 ) or ( Length(outfilename.text)<1 ) then |
|---|
| 171 |
begin |
|---|
| 172 |
S := 'Output filename must be a valid filename'; |
|---|
| 173 |
outfilename.SetFocus; |
|---|
| 174 |
Exit; |
|---|
| 175 |
end; |
|---|
| 176 |
|
|---|
| 177 |
if Find( outfilename.Text, '/\:;| ' )>0 then |
|---|
| 178 |
begin |
|---|
| 179 |
S := 'Invalid Output Filename, It must be a valid filename.'; |
|---|
| 180 |
outfilename.SetFocus; |
|---|
| 181 |
Exit; |
|---|
| 182 |
end; |
|---|
| 183 |
|
|---|
| 184 |
if not Empty( versionNumber.Text ) then |
|---|
| 185 |
if ParseInt( versionNumber.Text, V ) = false then |
|---|
| 186 |
begin |
|---|
| 187 |
S := 'Invalid Version Number'; |
|---|
| 188 |
versionNumber.SetFocus; |
|---|
| 189 |
Exit; |
|---|
| 190 |
end; |
|---|
| 191 |
|
|---|
| 192 |
result:= true; |
|---|
| 193 |
end; |
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 |
procedure TProjConfigDlg.SaveButtonClick(Sender: TObject); |
|---|
| 197 |
var |
|---|
| 198 |
msg:string ; |
|---|
| 199 |
begin |
|---|
| 200 |
name.Text := Trim( Name.Text ); |
|---|
| 201 |
outfilename.Text := Trim( outfilename.Text ); |
|---|
| 202 |
|
|---|
| 203 |
if not Validate( msg ) then begin |
|---|
| 204 |
Application.MessageBox( PChar(Msg), 'Error', MB_OK ); |
|---|
| 205 |
Exit; |
|---|
| 206 |
end; |
|---|
| 207 |
|
|---|
| 208 |
If not DirectoryExists( Self.projectPath.Text ) then begin |
|---|
| 209 |
if not ConfirmCreate( 'Project directory', projectPath.Text ) then Exit; |
|---|
| 210 |
end; |
|---|
| 211 |
|
|---|
| 212 |
if not DirectoryExists( Self.outputPath.Text ) then begin |
|---|
| 213 |
if not ConfirmCreate( 'Output path', outputPath.Text ) then Exit; |
|---|
| 214 |
end; |
|---|
| 215 |
|
|---|
| 216 |
Self.ModalResult := mrOk |
|---|
| 217 |
end; |
|---|
| 218 |
|
|---|
| 219 |
procedure TProjConfigDlg.BrowseProjectClick(Sender: TObject); |
|---|
| 220 |
var |
|---|
| 221 |
D : string; |
|---|
| 222 |
begin |
|---|
| 223 |
D := Self.projDir ; |
|---|
| 224 |
if not DirectoryExists(D) then D:=GetCurrentDir; |
|---|
| 225 |
if SelectDirectory( D, [sdAllowCreate], 0 ) then begin |
|---|
| 226 |
projectPath.Text := D; |
|---|
| 227 |
D := Trim( outputPath.Text ); |
|---|
| 228 |
if Length(D) = 0 then outputPath.Text := projectPath.Text; |
|---|
| 229 |
Exit; |
|---|
| 230 |
end; |
|---|
| 231 |
end; |
|---|
| 232 |
|
|---|
| 233 |
procedure TProjConfigDlg.BrowseOutputClick(Sender: TObject); |
|---|
| 234 |
var |
|---|
| 235 |
D : string; |
|---|
| 236 |
begin |
|---|
| 237 |
D := projDir ; |
|---|
| 238 |
if SelectDirectory( D, [sdAllowCreate], 0 ) then begin |
|---|
| 239 |
outputPath.Text := D; |
|---|
| 240 |
D := Trim( projectPath.Text ); |
|---|
| 241 |
if Length(D) = 0 then projectPath.Text := outputPath.Text; |
|---|
| 242 |
Exit; |
|---|
| 243 |
end; |
|---|
| 244 |
end; |
|---|
| 245 |
|
|---|
| 246 |
|
|---|
| 247 |
procedure TProjConfigDlg.VersionsButtonClick(Sender: TObject); |
|---|
| 248 |
begin |
|---|
| 249 |
VersionDialog.EditList( versions ); |
|---|
| 250 |
end; |
|---|
| 251 |
|
|---|
| 252 |
procedure TProjConfigDlg.FormDestroy(Sender: TObject); |
|---|
| 253 |
begin |
|---|
| 254 |
versions.Free; |
|---|
| 255 |
importPaths.Free; |
|---|
| 256 |
linkerflags.Free; |
|---|
| 257 |
end; |
|---|
| 258 |
|
|---|
| 259 |
procedure TProjConfigDlg.FormCreate(Sender: TObject); |
|---|
| 260 |
begin |
|---|
| 261 |
Self.versions := TStringList.Create; |
|---|
| 262 |
Self.ImportPaths := TStringList.Create; |
|---|
| 263 |
Self.LinkerFlags := TStringList.Create; |
|---|
| 264 |
end; |
|---|
| 265 |
|
|---|
| 266 |
procedure TProjConfigDlg.ImportPathButtonClick(Sender: TObject); |
|---|
| 267 |
begin |
|---|
| 268 |
PathDialog.PathListbox.Items.Clear; |
|---|
| 269 |
PathDialog.PathListbox.Items.AddStrings( Self.importPaths ); |
|---|
| 270 |
if PathDialog.ShowModal <> mrOK then Exit; |
|---|
| 271 |
Self.importPaths.Clear; |
|---|
| 272 |
Self.importPaths.AddStrings( PathDialog.PathListbox.Items ); |
|---|
| 273 |
end; |
|---|
| 274 |
|
|---|
| 275 |
procedure TProjConfigDlg.LinkerButtonClick(Sender: TObject); |
|---|
| 276 |
begin |
|---|
| 277 |
LinkerListDlg.EditList( linkerFlags ); |
|---|
| 278 |
end; |
|---|
| 279 |
|
|---|
| 280 |
end. |
|---|