root/trunk/UWsConfigDlg.pas

Revision 15, 5.2 kB (checked in by DavidM, 7 years ago)

--

Line 
1 unit UWsConfigDlg;
2
3 interface
4
5 uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls,
6   Buttons, ExtCtrls, Workspaces, Dialogs;
7
8 type
9   TwsConfigDlg = class(TForm)
10     SaveButton: TButton;
11     CancelButton: TButton;
12     Bevel1: TBevel;
13     Label1: TLabel;
14     Label2: TLabel;
15     compilerPath: TEdit;
16     Label3: TLabel;
17     linkerPath: TEdit;
18     editorPath: TEdit;
19     ImportButton: TButton;
20     Label4: TLabel;
21     editorCommand: TEdit;
22     BrowseCompiler: TButton;
23     BrowseLinker: TButton;
24     BrowseEditor: TButton;
25     defaultCheckbox: TCheckBox;
26     Label5: TLabel;
27     name: TEdit;
28     FileDialog: TOpenDialog;
29     procedure FormCreate(Sender: TObject);
30     procedure FormDestroy(Sender: TObject);
31     procedure SaveButtonClick(Sender: TObject);
32     procedure BrowseCompilerClick(Sender: TObject);
33     procedure BrowseLinkerClick(Sender: TObject);
34     procedure BrowseEditorClick(Sender: TObject);
35     procedure ImportButtonClick(Sender: TObject);
36   private
37     { Private declarations }
38   public
39     { Public declarations }
40     isnew : boolean;
41     importPaths : TStringList;
42     procedure SaveOptions( ws : TWorkspace );
43     procedure LoadOptions( ws : TWorkspace );
44   end;
45
46 var
47   wsConfigDlg: TwsConfigDlg;
48
49 implementation
50
51 {$R *.DFM}
52
53 uses MyUtils,FileCtrl, UImportList;
54
55 procedure TWSConfigDlg.SaveOptions( ws : TWorkspace );
56 begin
57   ws.config.compiler := compilerPath.Text;
58   ws.config.linker := linkerPath.Text;
59   ws.config.sourceEditor := editorPath.Text;
60   ws.name := name.Text;
61   ws.config.editorCommand := Self.editorCommand.Text;
62   ws.config.paths.Clear;
63   ws.config.paths.AddStrings( Self.importPaths );
64 end;
65
66 procedure TWSConfigDlg.LoadOptions( ws : TWorkspace );
67 begin
68   if Empty( ws.filename ) then Caption:='Configure New Workspace'
69   else Caption:='Configuration for:  ' + ws.filename;
70
71   compilerPath.Text := ws.config.compiler;
72   linkerPath.Text := ws.config.linker;
73   editorPath.Text := ws.config.sourceEditor;
74   editorCommand.Text := ws.config.editorCommand;
75   Self.name.Text := ws.name;
76   Self.importPaths.Clear;
77   Self.importPaths.AddStrings( ws.config.paths );
78 end;
79
80 procedure TwsConfigDlg.FormCreate(Sender: TObject);
81 begin
82   importPaths := TStringList.Create;
83 end;
84
85 procedure TwsConfigDlg.FormDestroy(Sender: TObject);
86 begin
87   importPaths.Free;
88 end;
89
90 procedure TwsConfigDlg.SaveButtonClick(Sender: TObject);
91 begin
92   if Length( name.Text )<1 then begin
93     Application.MessageBox( PChar('You Must Enter a Workspace Name!'),
94                             'Error', MB_OK );
95     Exit;
96   end  ;
97   Self.ModalResult := mrOk;
98 end;
99
100
101 function  GetParentDir( Path : string ; num : Integer ) : string;
102 var
103   N : Integer;
104 begin
105   while Path[ Length(Path) ] in [ '/', '\' ] do Path:= Copy( Path, 1, Length(Path)-1 );
106
107   while num > 0 do begin
108     Dec( num );
109     N := LastDelimiter( '/\', Path );
110     if N < 1 then Exit;
111     Path := Copy( Path, 1, N-1 );
112   end;
113   Result := Path + '\';
114 end;
115
116 procedure TwsConfigDlg.BrowseCompilerClick(Sender: TObject);
117 var
118   DMD : string;
119   LINK : string;
120 begin
121   //FileDialog.InitialDir := defaultWS.compiler;
122   FileDialog.Title := 'Select DMD compiler (dmd.exe)';
123   FileDialog.Filter := 'Executable files|*.exe';
124   FileDialog.Options := [ofPathMustExist , ofFileMustExist];
125
126   if FileDialog.Execute = false then Exit;
127   if FileDialog.Files.Count < 1 then Exit;
128   DMD := Trim( FileDialog.Files[0] );
129   compilerPath.Text := DMD;
130
131   if Length( Trim(linkerPath.Text) ) = 0 then begin
132     LINK := GetParentDir( ExtractFilePath(DMD), 2 );
133     LINK := Path( LINK, '\dm\bin\link.exe' );
134     if FileExists( LINK ) then linkerPath.Text:= LINK;
135   end;
136 end;
137
138 procedure TwsConfigDlg.BrowseLinkerClick(Sender: TObject);
139 var
140   DMD : string;
141   LINK : string;
142 begin
143   FileDialog.Title := 'Select DMD linker (link.exe)';
144   FileDialog.Filter := 'Executable files|*.exe';
145   FileDialog.Options := [ofPathMustExist , ofFileMustExist];
146
147   if FileExists( compilerPath.Text ) then
148     FileDialog.InitialDir:= GetParentDir( compilerPath.Text, 2) + 'dm\bin';
149   if FileDialog.Execute = false then Exit;
150   if FileDialog.Files.Count < 1 then Exit;
151   LINK := Trim( FileDialog.Files[0] );
152   linkerPath.Text := LINK;
153
154   if Length( Trim(compilerPath.Text) ) = 0 then begin
155     DMD := GetParentDir( ExtractFilePath(LINK), 2 );
156     DMD := Path( DMD, '\dmd\bin\dmd.exe' );
157     if FileExists( DMD ) then compilerPath.Text:= DMD;
158   end ;
159 end;
160
161
162 procedure TwsConfigDlg.BrowseEditorClick(Sender: TObject);
163 var
164   D : string;
165 begin
166   //FileDialog.InitialDir := homedir;
167   FileDialog.Title := 'Select Source Editor';
168   FileDialog.Filter := 'Executable files|*.exe';
169   FileDialog.Options := [ofPathMustExist , ofFileMustExist];
170
171   if FileDialog.Execute = false then Exit;
172   if FileDialog.Files.Count < 1 then Exit;
173   D := Trim( FileDialog.Files[0] );
174   editorPath.Text := D;
175 end;
176
177 procedure TwsConfigDlg.ImportButtonClick(Sender: TObject);
178 begin
179   PathDialog.PathListbox.Items.Clear;
180   PathDialog.PathListbox.Items.AddStrings( Self.importPaths );
181   if PathDialog.ShowModal <> mrOK then Exit;
182   Self.importPaths.Clear;
183   Self.importPaths.AddStrings( PathDialog.PathListbox.Items );
184 end;
185
186 end.
Note: See TracBrowser for help on using the browser.