1 {
2 ***************************************************************************
3 * *
4 * This source is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This code is distributed in the hope that it will be useful, but *
10 * WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * General Public License for more details. *
13 * *
14 * A copy of the GNU General Public License is available on the World *
15 * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
16 * obtain it by writing to the Free Software Foundation, *
17 * Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA. *
18 * *
19 ***************************************************************************
20
21 Author: Mattias Gaertner
22
23 Abstract:
24 Run Parameters Options (TRunParamsOptions)
25 and Dialog for them (TRunParamsOptsDlg)
26
27 Run Parameters are project specific options for the debugger like
28 command line parameters and working directory.
29
30 The options saved in a TRunParamsOptions are stored in the project info file
31 (.lpi) together with the rest of the project.
32
33 The dialog will be activated by main.pp with the function
34 ShowRunParamsOptsDlg (see below) when the user clicks on the
35 menu->Run->Run Parameters.
36 }
37 unit RunParamsOpts;
38
39 {$mode objfpc}
40 {$H+}
41
42 {$I ide.inc}
43
44 interface
45
46 uses
47 {$IFDEF IDE_MEM_CHECK}
48 MemCheck,
49 {$ENDIF}
50 Classes, SysUtils,
51 // LCL
52 Controls, Forms, Buttons, StdCtrls, ComCtrls, Dialogs, ButtonPanel, ExtCtrls,
53 // IdeIntf
54 BaseIDEIntf, IDEHelpIntf, ProjectIntf, IDEDialogs, IDEImagesIntf, MacroIntf,
55 // LazUtils
56 LazFileUtils, LazFileCache, LazUTF8, Laz2_XMLCfg,
57 // IDE
58 IDEProcs, MiscOptions, SysVarUserOverrideDlg, InputHistory, LazarusIDEStrConsts,
59 EnvironmentOpts;
60
61 { The xml format version:
62 When the format changes (new values, changed formats) we can distinguish old
63 files and are able to convert them.
64 }
65 const
66 RunParamsOptionsVersion = 2;
67
68 type
69 {
70 the storage object for run parameters
71 }
72
73 TRunParamsOptionsModeSave = (rpsLPS, rpsLPI);
74
75 { TRunParamsOptionsMode }
76
77 TRunParamsOptionsMode = class(TAbstractRunParamsOptionsMode)
78 private
79 fSaveIn: TRunParamsOptionsModeSave;
80 protected
81 procedure AssignTo(Dest: TPersistent); override;
82 public
83 property SaveIn: TRunParamsOptionsModeSave read fSaveIn write fSaveIn;
84 public
85 procedure AssignEnvironmentTo(Strings: TStrings); override;
86
LegacyLoadnull87 function LegacyLoad(XMLConfig: TXMLConfig; const Path: string;
88 AdjustPathDelims: boolean): TModalResult;
Loadnull89 function Load(XMLConfig: TXMLConfig; const Path: string;
90 AdjustPathDelims: boolean): TModalResult;
LegacySavenull91 function LegacySave(XMLConfig: TXMLConfig; const Path: string;
92 UsePathDelim: TPathDelimSwitch): TModalResult;
Savenull93 function Save(XMLConfig: TXMLConfig; const Path: string;
94 UsePathDelim: TPathDelimSwitch): TModalResult;
95
96 procedure Clear; override;
97 end;
98
99 { TRunParamsOptions }
100
101 TRunParamsOptions = class(TAbstractRunParamsOptions)
102 protected
103 procedure AssignTo(Dest: TPersistent); override;
CreateModenull104 function CreateMode(const AName: string): TAbstractRunParamsOptionsMode; override;
105 procedure SetActiveModeName(const AValue: string); override;
106 public
107 procedure AssignEnvironmentTo(Strings: TStrings); override;
108
LegacyLoadnull109 function LegacyLoad(XMLConfig: TXMLConfig; const Path: string;
110 AdjustPathDelims: boolean): TModalResult;
Loadnull111 function Load(XMLConfig: TXMLConfig; const Path: string;
112 AdjustPathDelims: boolean; const ASaveIn: TRunParamsOptionsModeSave): TModalResult;
LegacySavenull113 function LegacySave(XMLConfig: TXMLConfig; const Path: string;
114 UsePathDelim: TPathDelimSwitch): TModalResult;
Savenull115 function Save(XMLConfig: TXMLConfig; const Path: string;
116 UsePathDelim: TPathDelimSwitch; const ASaveIn: TRunParamsOptionsModeSave;
117 const ALegacyList: Boolean): TModalResult;
GetActiveModenull118 function GetActiveMode: TRunParamsOptionsMode;
119 end;
120
121 { TRunParamsOptsDlg - the form of the run parameters options dialog }
122
123 TRunParamsOptsDlg = class(TForm)
124 ButtonPanel: TButtonPanel;
125 CmdLineParametersComboBox: TComboBox;
126 CmdLineParametersGroupBox: TGroupBox;
127 DeleteModeButton: TToolButton;
128 DisplayEdit: TEdit;
129 DisplayGroupBox: TGroupBox;
130 EnvVarsPage: TTabSheet;
131 GeneralPage: TTabSheet;
132 HostApplicationBrowseBtn: TButton;
133 HostApplicationEdit: TEdit;
134 HostApplicationGroupBox: TGroupBox;
135 IncludeSystemVariablesCheckBox: TCheckBox;
136 ModesComboBox: TComboBox;
137 ModesLabel: TLabel;
138 NewModeButton: TToolButton;
139 Notebook: TPageControl;
140 Panel1: TPanel;
141 PreviewMemo: TMemo;
142 PreviewMultilineCheckBox: TCheckBox;
143 PreviewPage: TTabSheet;
144 SaveInComboBox: TComboBox;
145 SaveInLabel: TLabel;
146 SystemVariablesGroupBox: TGroupBox;
147 SystemVariablesListView: TListView;
148 ToolBar1: TToolBar;
149 UseDisplayCheckBox: TCheckBox;
150 UseLaunchingApplicationCheckBox: TCheckBox;
151 UseLaunchingApplicationComboBox: TComboBox;
152 UseLaunchingApplicationGroupBox: TGroupBox;
153 UserOverridesAddButton: TBitBtn;
154 UserOverridesDeleteButton: TBitBtn;
155 UserOverridesEditButton: TBitBtn;
156 UserOverridesGroupBox: TGroupBox;
157 UserOverridesListView: TListView;
158 WorkingDirectoryBtn: TButton;
159 WorkingDirectoryComboBox: TComboBox;
160 WorkingDirectoryGroupBox: TGroupBox;
161 procedure DeleteModeButtonClick(Sender: TObject);
162 procedure EnvVarsPageResize(Sender: TObject);
163 procedure FormClose(Sender: TObject; var {%H-}CloseAction: TCloseAction);
164 procedure FormCreate(Sender: TObject);
165 procedure HelpButtonClick(Sender: TObject);
166 procedure ModesComboBoxChange(Sender: TObject);
167 procedure NotebookChange(Sender: TObject);
168 procedure OkButtonClick(Sender: TObject);
169 procedure HostApplicationBrowseBtnClick(Sender: TObject);
170 procedure NewModeButtonClick(Sender: TObject);
171 procedure PreviewMultilineCheckBoxChange(Sender: TObject);
172 procedure UseLaunchingApplicationCheckBoxChange(Sender: TObject);
173 procedure UserOverridesListViewSelectItem(Sender: TObject; {%H-}Item: TListItem;
174 {%H-}Selected: Boolean);
175 procedure WorkingDirectoryBtnClick(Sender: TObject);
176 procedure UserOverridesAddButtonClick(Sender: TObject);
177 procedure UserOverridesEditButtonClick(Sender: TObject);
178 procedure UserOverridesDeleteButtonClick(Sender: TObject);
179 private
180 fHistoryLists: THistoryLists;
181 fOptions: TRunParamsOptions;
182 fSaveToOptions: TRunParamsOptions;
183 fLastSelectedMode: TRunParamsOptionsMode;
184 procedure SetupNotebook;
185 procedure SetupLocalPage;
186 procedure SetupEnvironmentPage;
187 procedure SetupPreviewPage;
188 procedure SetOptions(NewOptions: TRunParamsOptions);
189 procedure FillListView(ListView: TListView; sl: TStringList);
190 procedure FillSystemVariablesListView;
191 procedure FillUserOverridesListView(const AMode: TRunParamsOptionsMode);
192 procedure ReloadModesComboBox;
193 procedure UpdatePreview;
194 procedure SaveToOptions;
195 procedure SaveToOptionsMode(const AMode: TRunParamsOptionsMode);
196 procedure LoadFromOptionsMode(const AMode: TRunParamsOptionsMode);
197 procedure SaveUserOverrides(const AMode: TRunParamsOptionsMode);
198 procedure SelectMode(const AName: string);
SelectedModenull199 function SelectedMode: TRunParamsOptionsMode;
200 procedure SetComboBoxText(AComboBox: TComboBox; AText: ansistring);
201 public
202 constructor Create(AnOwner: TComponent); override;
203 destructor Destroy; override;
204 property Options: TRunParamsOptions Write SetOptions;
205 property HistoryLists: THistoryLists read fHistoryLists write fHistoryLists;
206 end;
207
ShowRunParamsOptsDlgnull208 function ShowRunParamsOptsDlg(RunParamsOptions: TRunParamsOptions; HistoryLists: THistoryLists): TModalResult;
209
210 implementation
211
212 {$R *.lfm}
213
214 const
215 DefaultLauncherTitle = '''Lazarus Run Output''';
216 DefaultLauncherApplication = '$(LazarusDir)/tools/runwait.sh $(TargetCmdLine)';
217
218 hlLaunchingApplication = 'LaunchingApplication';
219 hlCmdLineParameters = 'CommandLineParameters';
220 hlWorkingDirectory = 'WorkingDirectory';
221
FindTerminalInPathnull222 function FindTerminalInPath(const ATerm: String = ''): String;
223 var
224 List: TStrings;
225 i: Integer;
226 s: String;
227 Term: String;
228 begin
229 Result := '';
230 Term := ATerm;
231 if Term = '' then
232 Term := GetEnvironmentVariableUTF8('TERM');
233 List := TStringList.Create;
234 {$IFDEF MSWINDOWS}
235 List.Delimiter := ';';
236 if Term = '' then
237 Term := 'cmd.exe';
238 {$ELSE}
239 List.Delimiter := ':';
240 if Term = '' then
241 Term := 'xterm';
242 {$ENDIF}
243 List.DelimitedText := GetEnvironmentVariableUTF8('PATH');
244 for i := 0 to List.Count - 1 do
245 begin
246 S := List.Strings[i] + PathDelim + Term;
247 if FileExistsCached(S) and FileIsExecutableCached(S) then
248 begin
249 // gnome-terminal is not compatible to xterm params.
250 if Term = 'gnome-terminal' then
251 Result := S + ' -t ' + DefaultLauncherTitle + ' -e ' +
252 '''' + DefaultLauncherApplication + ''''
253 else if SameText(Term,'cmd.exe') then
254 Result := S + ' /C ${TargetCmdLine}'
255 else
256 Result := S + ' -T ' + DefaultLauncherTitle + ' -e ' +
257 DefaultLauncherApplication;
258 break;
259 end;
260 end;
261 List.Free;
262 end;
263
264 var
265 DefaultLaunchingApplicationPathPlusParams: string;
266
GetDefaultLaunchingApplicationPathPlusParamsnull267 function GetDefaultLaunchingApplicationPathPlusParams: string;
268 begin
269 Result:=DefaultLaunchingApplicationPathPlusParams;
270 if Result<>'' then exit;
271 Result:=FindTerminalInPath;
272 DefaultLaunchingApplicationPathPlusParams:=Result;
273 end;
274
ShowRunParamsOptsDlgnull275 function ShowRunParamsOptsDlg(RunParamsOptions: TRunParamsOptions;
276 HistoryLists: THistoryLists): TModalResult;
277 var
278 RunParamsOptsForm: TRunParamsOptsDlg;
279 begin
280 Result := mrCancel;
281 RunParamsOptsForm := TRunParamsOptsDlg.Create(nil);
282 try
283 RunParamsOptsForm.HistoryLists := HistoryLists;
284 RunParamsOptsForm.Options := RunParamsOptions;
285 Result := RunParamsOptsForm.ShowModal;
286 finally
287 RunParamsOptsForm.Free;
288 end;
289 end;
290
291 { TRunParamsOptions }
292
293 procedure TRunParamsOptions.AssignEnvironmentTo(Strings: TStrings);
294 begin
295 if GetActiveMode=nil then
296 BaseIDEIntf.AssignEnvironmentTo(Strings, nil)
297 else
298 GetActiveMode.AssignEnvironmentTo(Strings);
299 end;
300
301 procedure TRunParamsOptions.AssignTo(Dest: TPersistent);
302 var
303 ADest: TRunParamsOptions;
304 begin
305 inherited AssignTo(Dest);
306
307 if Dest is TRunParamsOptions then
308 begin
309 ADest := TRunParamsOptions(Dest);
310
311 ADest.ActiveModeName := ActiveModeName;
312 end;
313 end;
314
CreateModenull315 function TRunParamsOptions.CreateMode(const AName: string
316 ): TAbstractRunParamsOptionsMode;
317 begin
318 Result := TRunParamsOptionsMode.Create(AName);
319 end;
320
321 procedure TRunParamsOptions.SetActiveModeName(const AValue: string);
322 var
323 NewMode: TAbstractRunParamsOptionsMode;
324 begin
325 if AValue=ActiveModeName then exit;
326 NewMode:=Find(AValue);
327 if NewMode<>nil then
328 inherited SetActiveModeName(NewMode.Name)
329 else if AValue<>'' then
330 raise EListError.Create('TRunParamsOptions.SetActiveModeName no such mode "'+AValue+'"')
331 else
332 inherited SetActiveModeName('');
333 end;
334
TRunParamsOptions.GetActiveModenull335 function TRunParamsOptions.GetActiveMode: TRunParamsOptionsMode;
336 var
337 AMode: TAbstractRunParamsOptionsMode;
338 begin
339 AMode := Find(ActiveModeName);
340 if AMode=nil then exit(nil);
341 Result := AMode as TRunParamsOptionsMode;
342 end;
343
LegacyLoadnull344 function TRunParamsOptions.LegacyLoad(XMLConfig: TXMLConfig;
345 const Path: string; AdjustPathDelims: boolean): TModalResult;
346 var
347 NewMode: TRunParamsOptionsMode;
348 begin
349 Clear;
350
351 NewMode := Add('default') as TRunParamsOptionsMode;
352 NewMode.SaveIn := rpsLPI;
353 Result := NewMode.LegacyLoad(XMLConfig, Path+'RunParams/', AdjustPathDelims);
354 ActiveModeName := 'default';
355 end;
356
LegacySavenull357 function TRunParamsOptions.LegacySave(XMLConfig: TXMLConfig;
358 const Path: string; UsePathDelim: TPathDelimSwitch): TModalResult;
359 var
360 AMode: TRunParamsOptionsMode;
361 begin
362 Result := mrOK;
363
364 AMode := GetActiveMode;
365 if (AMode<>nil) and (AMode.SaveIn=rpsLPI) then
366 AMode.LegacySave(XMLConfig, Path+'RunParams/', UsePathDelim);
367 end;
368
Loadnull369 function TRunParamsOptions.Load(XMLConfig: TXMLConfig; const Path: string;
370 AdjustPathDelims: boolean; const ASaveIn: TRunParamsOptionsModeSave
371 ): TModalResult;
372 var
373 Cnt, I: Integer;
374 NewMode: TRunParamsOptionsMode;
375 ModePath, NewActiveModeName, ModesPath: string;
376 IsLegacyList: Boolean;
377 begin
378 //don't clear! needed for merging lpi and lps
379
380 ModesPath := Path + 'Modes/';
381 IsLegacyList := XMLConfig.IsLegacyList(ModesPath);
382 Cnt := XMLConfig.GetListItemCount(ModesPath, 'Mode', IsLegacyList);
383 Result := mrOK;
384
385 for I := 0 to Cnt-1 do
386 begin
387 ModePath := ModesPath+XMLConfig.GetListItemXPath('Mode', I, IsLegacyList, False)+'/';
388 NewMode := Add(XMLConfig.GetValue(ModePath+'Name', '')) as TRunParamsOptionsMode;
389 NewMode.SaveIn := ASaveIn;
390 Result := NewMode.Load(XMLConfig, ModePath, AdjustPathDelims);
391 if Result<>mrOK then
392 Exit;
393 end;
394
395 if ASaveIn=rpsLPS then
396 begin
397 NewActiveModeName := XMLConfig.GetValue(Path + 'Modes/ActiveMode', '');
398 // sanity check -> modes from LPI could be modified independently on LPS and
399 // NewActiveModeName doesn't have to exist any more
400 if Assigned(Find(NewActiveModeName)) then
401 ActiveModeName := NewActiveModeName;
402 end;
403
404 if (GetActiveMode=nil) and (Count>0) then
405 ActiveModeName := Modes[0].Name;
406 end;
407
TRunParamsOptions.Savenull408 function TRunParamsOptions.Save(XMLConfig: TXMLConfig; const Path: string;
409 UsePathDelim: TPathDelimSwitch; const ASaveIn: TRunParamsOptionsModeSave;
410 const ALegacyList: Boolean): TModalResult;
411 var
412 AMode: TRunParamsOptionsMode;
413 I, Cnt: Integer;
414 ModesPath, ModePath: string;
415 begin
416 Result := mrOK;
417 ModesPath := Path+'Modes/';
418
419 // save a format version to distinguish old formats
420 XMLConfig.SetValue(Path + 'FormatVersion/Value',
421 RunParamsOptionsVersion);
422
423 Cnt := 0;
424 for I := 0 to Count-1 do
425 begin
426 AMode := Modes[I] as TRunParamsOptionsMode;
427
428 if AMode.SaveIn=ASaveIn then
429 begin
430 ModePath := ModesPath+XMLConfig.GetListItemXPath('Mode', Cnt, ALegacyList, False)+'/';
431 Result := AMode.Save(XMLConfig, ModePath, UsePathDelim);
432 if Result<>mrOK then
433 Exit;
434 Inc(Cnt);
435 end;
436 end;
437
438 XMLConfig.SetListItemCount(ModesPath, Cnt, ALegacyList);
439 if ASaveIn=rpsLPS then
440 XMLConfig.SetValue(Path + 'Modes/ActiveMode', ActiveModeName);
441 end;
442
443 { TRunParamsOptionsMode }
444
LegacyLoadnull445 function TRunParamsOptionsMode.LegacyLoad(XMLConfig: TXMLConfig;
446 const Path: string; AdjustPathDelims: boolean): TModalResult;
447
fnull448 function f(const Filename: string): string;
449 begin
450 Result := SwitchPathDelims(Filename, AdjustPathDelims);
451 end;
452
453 procedure LoadUserOverrides(const APath: string);
454 var
455 i, Cnt: integer;
456 begin
457 Cnt := XMLConfig.GetValue(APath + 'Count', 0);
458 for i := 0 to Cnt - 1 do
459 begin
460 UserOverrides.Values[XMLConfig.GetValue(
461 APath + 'Variable' + IntToStr(i) + '/Name', '')] :=
462 XMLConfig.GetValue(APath + 'Variable' + IntToStr(i) + '/Value', '');
463 end;
464 end;
465
466 begin
467 // local options
468 HostApplicationFilename := f(XMLConfig.GetValue(
469 Path + 'local/HostApplicationFilename/Value',
470 HostApplicationFilename));
471 CmdLineParams := f(XMLConfig.GetValue(
472 Path + 'local/CommandLineParams/Value', CmdLineParams));
473 UseLaunchingApplication := XMLConfig.GetValue(
474 Path + 'local/LaunchingApplication/Use', UseLaunchingApplication);
475 LaunchingApplicationPathPlusParams :=
476 f(XMLConfig.GetValue(Path + 'local/LaunchingApplication/PathPlusParams',
477 f(GetDefaultLaunchingApplicationPathPlusParams)));
478 WorkingDirectory := f(XMLConfig.GetValue(
479 Path + 'local/WorkingDirectory/Value', WorkingDirectory));
480 UseDisplay := XMLConfig.GetValue(Path + 'local/Display/Use',
481 UseDisplay);
482 Display := XMLConfig.GetValue(Path + 'local/Display/Value', Display);
483
484 // environment options
485 LoadUserOverrides(Path + 'environment/UserOverrides/');
486 IncludeSystemVariables := XMLConfig.GetValue(
487 Path + 'environment/IncludeSystemVariables/Value',
488 IncludeSystemVariables);
489
490 Result := mrOk;
491 end;
492
LegacySavenull493 function TRunParamsOptionsMode.LegacySave(XMLConfig: TXMLConfig;
494 const Path: string; UsePathDelim: TPathDelimSwitch): TModalResult;
495
fnull496 function f(const AFilename: string): string;
497 begin
498 Result:=SwitchPathDelims(AFilename,UsePathDelim);
499 end;
500
501 procedure SaveUserOverrides(const APath: string);
502 var
503 i: integer;
504 begin
505 XMLConfig.SetDeleteValue(APath + 'Count', UserOverrides.Count, 0);
506 for i := 0 to UserOverrides.Count - 1 do
507 begin
508 XMLConfig.SetValue(APath + 'Variable' + IntToStr(i) + '/Name',
509 UserOverrides.Names[i]); // no default
510 XMLConfig.SetDeleteValue(APath + 'Variable' + IntToStr(i) + '/Value',
511 UserOverrides.Values[UserOverrides.Names[i]],'');
512 end;
513 end;
514
515 begin
516 // local options
517 XMLConfig.SetDeleteValue(Path + 'local/HostApplicationFilename/Value',
518 f(HostApplicationFilename), '');
519 XMLConfig.SetDeleteValue(Path + 'local/CommandLineParams/Value',
520 f(CmdLineParams), '');
521 XMLConfig.SetDeleteValue(Path + 'local/LaunchingApplication/Use',
522 UseLaunchingApplication, False);
523 XMLConfig.SetDeleteValue(Path + 'local/LaunchingApplication/PathPlusParams',
524 f(LaunchingApplicationPathPlusParams), f(GetDefaultLaunchingApplicationPathPlusParams));
525 XMLConfig.SetDeleteValue(Path + 'local/WorkingDirectory/Value',
526 f(WorkingDirectory), '');
527 XMLConfig.SetDeleteValue(Path + 'local/Display/Use',
528 UseDisplay, False);
529 XMLConfig.SetDeleteValue(Path + 'local/Display/Value',
530 Display, ':0');
531
532 // environment options
533 SaveUserOverrides(Path + 'environment/UserOverrides/');
534 XMLConfig.SetDeleteValue(Path + 'environment/IncludeSystemVariables/Value',
535 IncludeSystemVariables, False);
536
537 Result := mrOk;
538 end;
539
Loadnull540 function TRunParamsOptionsMode.Load(XMLConfig: TXMLConfig; const Path: string;
541 AdjustPathDelims: boolean): TModalResult;
542
fnull543 function f(const Filename: string): string;
544 begin
545 Result := SwitchPathDelims(Filename, AdjustPathDelims);
546 end;
547
548 procedure LoadUserOverrides(const APath: string);
549 var
550 i, Cnt: integer;
551 begin
552 Cnt := XMLConfig.GetValue(APath + 'Count', 0);
553 for i := 0 to Cnt - 1 do
554 begin
555 UserOverrides.Values[XMLConfig.GetValue(
556 APath + 'Variable' + IntToStr(i) + '/Name', '')] :=
557 XMLConfig.GetValue(APath + 'Variable' + IntToStr(i) + '/Value', '');
558 end;
559 end;
560
561 begin
562 // local options
563 HostApplicationFilename := f(XMLConfig.GetValue(
564 Path + 'local/HostApplicationFilename/Value',
565 HostApplicationFilename));
566 CmdLineParams := f(XMLConfig.GetValue(
567 Path + 'local/CommandLineParams/Value', CmdLineParams));
568 UseLaunchingApplication := XMLConfig.GetValue(
569 Path + 'local/LaunchingApplication/Use', UseLaunchingApplication);
570 LaunchingApplicationPathPlusParams :=
571 f(XMLConfig.GetValue(Path + 'local/LaunchingApplication/PathPlusParams',
572 f(GetDefaultLaunchingApplicationPathPlusParams)));
573 WorkingDirectory := f(XMLConfig.GetValue(
574 Path + 'local/WorkingDirectory/Value', WorkingDirectory));
575 UseDisplay := XMLConfig.GetValue(Path + 'local/Display/Use',
576 UseDisplay);
577 Display := XMLConfig.GetValue(Path + 'local/Display/Value', Display);
578
579 // environment options
580 LoadUserOverrides(Path + 'environment/UserOverrides/');
581 IncludeSystemVariables := XMLConfig.GetValue(
582 Path + 'environment/IncludeSystemVariables/Value',
583 IncludeSystemVariables);
584
585 Result := mrOk;
586 end;
587
TRunParamsOptionsMode.Savenull588 function TRunParamsOptionsMode.Save(XMLConfig: TXMLConfig; const Path: string;
589 UsePathDelim: TPathDelimSwitch): TModalResult;
590
fnull591 function f(const AFilename: string): string;
592 begin
593 Result:=SwitchPathDelims(AFilename,UsePathDelim);
594 end;
595
596 procedure SaveUserOverrides(const APath: string);
597 var
598 i: integer;
599 begin
600 XMLConfig.SetDeleteValue(APath + 'Count', UserOverrides.Count, 0);
601 for i := 0 to UserOverrides.Count - 1 do
602 begin
603 XMLConfig.SetValue(APath + 'Variable' + IntToStr(i) + '/Name',
604 UserOverrides.Names[i]); // no default
605 XMLConfig.SetDeleteValue(APath + 'Variable' + IntToStr(i) + '/Value',
606 UserOverrides.Values[UserOverrides.Names[i]],'');
607 end;
608 end;
609
610 begin
611 XMLConfig.SetValue(Path + 'Name', Name);
612
613 // local options
614 XMLConfig.SetDeleteValue(Path + 'local/HostApplicationFilename/Value',
615 f(HostApplicationFilename), '');
616 XMLConfig.SetDeleteValue(Path + 'local/CommandLineParams/Value',
617 f(CmdLineParams), '');
618 XMLConfig.SetDeleteValue(Path + 'local/LaunchingApplication/Use',
619 UseLaunchingApplication, False);
620 XMLConfig.SetDeleteValue(Path + 'local/LaunchingApplication/PathPlusParams',
621 f(LaunchingApplicationPathPlusParams), f(GetDefaultLaunchingApplicationPathPlusParams));
622 XMLConfig.SetDeleteValue(Path + 'local/WorkingDirectory/Value',
623 f(WorkingDirectory), '');
624 XMLConfig.SetDeleteValue(Path + 'local/Display/Use',
625 UseDisplay, False);
626 XMLConfig.SetDeleteValue(Path + 'local/Display/Value',
627 Display, ':0');
628
629 // environment options
630 SaveUserOverrides(Path + 'environment/UserOverrides/');
631 XMLConfig.SetDeleteValue(Path + 'environment/IncludeSystemVariables/Value',
632 IncludeSystemVariables, False);
633
634 Result := mrOk;
635 end;
636
637 procedure TRunParamsOptionsMode.AssignEnvironmentTo(Strings: TStrings);
638 var
639 idx: integer;
640 begin
641 BaseIDEIntf.AssignEnvironmentTo(Strings, UserOverrides);
642
643 if UseDisplay then
644 begin
645 // assignment is not allowed in a sorted list
646 // Strings.Values['DISPLAY']:=Display;
647 idx := Strings.IndexOfName('DISPLAY');
648 if idx <> -1 then
649 Strings.Delete(idx);
650 Strings.Add('DISPLAY=' + Display);
651 end;
652 end;
653
654 procedure TRunParamsOptionsMode.AssignTo(Dest: TPersistent);
655 var
656 ADest: TRunParamsOptionsMode;
657 begin
658 inherited AssignTo(Dest);
659
660 if Dest is TRunParamsOptionsMode then
661 begin
662 ADest := Dest as TRunParamsOptionsMode;
663 ADest.SaveIn := SaveIn;
664 end;
665 end;
666
667 procedure TRunParamsOptionsMode.Clear;
668 begin
669 inherited Clear;
670
671 SaveIn := rpsLPS;
672 LaunchingApplicationPathPlusParams := GetDefaultLaunchingApplicationPathPlusParams;
673 end;
674
675
676 { TRunParamsOptsDlg }
677
678 constructor TRunParamsOptsDlg.Create(AnOwner: TComponent);
679 begin
680 inherited Create(AnOwner);
681 fOptions := TRunParamsOptions.Create;
682 Caption := dlgRunParameters;
683 ModesLabel.Caption := dlgMode;
684 SaveInLabel.Caption := dlgSaveIn;
685 NewModeButton.Hint := dlgAddNewMode;
686 DeleteModeButton.Hint := dlgDeleteMode;
687 NewModeButton.ImageIndex := IDEImages.LoadImage('laz_add');
688 DeleteModeButton.ImageIndex := IDEImages.LoadImage('laz_delete');
689 ToolBar1.Images := IDEImages.Images_16;
690 ButtonPanel.OKButton.Caption:=lisMenuOk;
691 ButtonPanel.HelpButton.Caption:=lisMenuHelp;
692 ButtonPanel.CancelButton.Caption:=lisCancel;
693 SaveInComboBox.Items[0] := lisProjectSession+' (.lps)';
694 SaveInComboBox.Items[1] := lisProjectMacro+' (.lpi)';
695 SetupNotebook;
696 end;
697
698 procedure TRunParamsOptsDlg.DeleteModeButtonClick(Sender: TObject);
699 begin
700 if ModesComboBox.ItemIndex=-1 then
701 Exit;
702
703 if fOptions.Count=1 then
704 begin
705 MessageDlg(lisCannotDeleteLastMode, mtError, [mbOK], 0);
706 Exit;
707 end;
708 if MessageDlg(lisDelete2, mtConfirmation, [mbYes, mbNo], 0)<>mrYes then
709 Exit;
710
711 fLastSelectedMode := nil;
712 fOptions.Delete(ModesComboBox.ItemIndex);
713 ReloadModesComboBox;
714 ModesComboBox.ItemIndex := 0;
715 ModesComboBoxChange(ModesComboBox);
716 end;
717
718 destructor TRunParamsOptsDlg.Destroy;
719 begin
720 fOptions.Free;
721
722 inherited Destroy;
723 end;
724
725 procedure TRunParamsOptsDlg.SetupNotebook;
726 begin
727 with Notebook do
728 begin
729 Page[0].Caption := dlgRunOLocal;
730 Page[1].Caption := dlgRunOEnvironment;
731 PageIndex := 0;
732 end;
733
734 SetupLocalPage;
735 SetupEnvironmentPage;
736 SetupPreviewPage;
737 IDEImages.AssignImage(UserOverridesAddButton, 'laz_add');
738 IDEImages.AssignImage(UserOverridesEditButton, 'laz_edit');
739 IDEImages.AssignImage(UserOverridesDeleteButton, 'laz_delete');
740 end;
741
742 procedure TRunParamsOptsDlg.NewModeButtonClick(Sender: TObject);
743 var
744 NewName: string;
745 NewMode: TRunParamsOptionsMode;
746 begin
747 NewName := InputBox(dlgCreateNewRunParametersSettings, lisName, '');
748 if NewName='' then
749 Exit;
750 if fOptions.Find(NewName)<>nil then
751 begin
752 MessageDlg(lisDuplicateModeName, mtError, [mbOK], 0);
753 Exit;
754 end;
755
756 fLastSelectedMode := nil;
757 NewMode := fOptions.Add(NewName) as TRunParamsOptionsMode;
758 SaveToOptionsMode(NewMode);
759 ReloadModesComboBox;
760 SelectMode(NewName);
761 ModesComboBoxChange(ModesComboBox);
762 end;
763
764 procedure TRunParamsOptsDlg.PreviewMultilineCheckBoxChange(Sender: TObject);
765 begin
766 UpdatePreview;
767 end;
768
769 procedure TRunParamsOptsDlg.SetupLocalPage;
770 begin
771 HostApplicationGroupBox.Caption := dlgHostApplication;
772 HostApplicationBrowseBtn.Caption := '...';
773 CmdLineParametersGroupBox.Caption := dlgCommandLineParams;
774 UseLaunchingApplicationGroupBox.Caption := lisUseLaunchingApplicationGroupBox;
775 UseLaunchingApplicationCheckBox.Caption := dlgUseLaunchingApp;
776
777 WorkingDirectoryGroupBox.Caption := dlgROWorkingDirectory;
778 WorkingDirectoryBtn.Caption := '...';
779 DisplayGroupBox.Caption := dlgRunODisplay;
780 UseDisplayCheckBox.Caption := dlgRunOUsedisplay;
781 DisplayEdit.Parent := DisplayGroupBox;
782 end;
783
784 procedure TRunParamsOptsDlg.SetupEnvironmentPage;
785 begin
786 SystemVariablesGroupBox.Caption := dlgRunOSystemVariables;
787
788 with SystemVariablesListView do
789 begin
790 Columns.BeginUpdate;
791 Columns[0].Caption := lisVariable;
792 Columns[1].Caption := lisValue;
793 Columns.EndUpdate;
794 end;
795
796 UserOverridesGroupBox.Caption := dlgRunOUserOverrides;
797
798 with UserOverridesListView do
799 begin
800 Columns.BeginUpdate;
801 Columns[0].Caption := lisVariable;
802 Columns[1].Caption := lisValue;
803 Columns.EndUpdate;
804 end;
805
806 UserOverridesAddButton.Caption := lisDlgAdd;
807 UserOverridesEditButton.Caption := lisDlgEdit;
808 UserOverridesDeleteButton.Caption := lisDelete;
809 IncludeSystemVariablesCheckBox.Caption := dlgIncludeSystemVariables;
810 end;
811
812 procedure TRunParamsOptsDlg.SetupPreviewPage;
813 begin
814 PreviewPage.Caption:=dlgWRDPreview;
815 PreviewMultilineCheckBox.Caption:=lisShowMultipleLines;
816 PreviewMultilineCheckBox.Checked:=MiscellaneousOptions.ShowCompOptMultiLine;
817 end;
818
819 procedure TRunParamsOptsDlg.OkButtonClick(Sender: TObject);
820 begin
821 if SelectedMode<>nil then
822 SaveToOptionsMode(SelectedMode);
823 SaveToOptions;
824 ModalResult := mrOk;
825 end;
826
827 procedure TRunParamsOptsDlg.ReloadModesComboBox;
828 var
829 I: Integer;
830 AMode: TAbstractRunParamsOptionsMode;
831 begin
832 ModesComboBox.Clear;
833 for I := 0 to fOptions.Count-1 do
834 begin
835 AMode := fOptions[I];
836 ModesComboBox.AddItem(AMode.Name, AMode);
837 end;
838 end;
839
840 procedure TRunParamsOptsDlg.UpdatePreview;
841 var
842 sl: TStringList;
843 MultiLine: Boolean;
844
845 procedure AddLines(aCaption, Params: string);
846 var
847 ParamList: TStringList;
848 begin
849 sl.Add(aCaption);
850 if MultiLine then begin
851 ParamList:=TStringList.Create;
852 try
853 SplitCmdLineParams(Params,ParamList);
854 sl.AddStrings(ParamList);
855 finally
856 ParamList.Free;
857 end;
858 end else begin
859 sl.Add(Params);
860 end;
861 end;
862
863 var
864 s: string;
865 begin
866 MultiLine:=PreviewMultilineCheckBox.Checked;
867 if MultiLine then
868 PreviewMemo.ScrollBars:=ssAutoBoth
869 else
870 PreviewMemo.ScrollBars:=ssAutoVertical;
871
872 sl:=TStringList.Create;
873 try
874 s:=HostApplicationEdit.Text;
875 if s<>'' then begin
876 IDEMacros.SubstituteMacros(s);
877 sl.Add('Host Application: '+s);
878 end;
879
880 s:=WorkingDirectoryComboBox.Text;
881 if s<>'' then begin
882 IDEMacros.SubstituteMacros(s);
883 sl.Add('Working Directory: '+s);
884 end;
885
886 if UseLaunchingApplicationCheckBox.Checked then begin
887 s:=UseLaunchingApplicationComboBox.Text;
888 if s<>'' then begin
889 IDEMacros.SubstituteMacros(s);
890 AddLines('Launching Application:',s);
891 end;
892 end;
893
894 s:=CmdLineParametersComboBox.Text;
895 if s<>'' then begin
896 IDEMacros.SubstituteMacros(s);
897 AddLines('Parameters:',s);
898 end;
899
900 if UseDisplayCheckBox.Checked then begin
901 s:=DisplayEdit.Text;
902 if s<>'' then begin
903 IDEMacros.SubstituteMacros(s);
904 sl.Add('Display: '+s);
905 end;
906 end;
907
908 PreviewMemo.Lines.Assign(sl);
909 finally
910 sl.Free;
911 end;
912 end;
913
914 procedure TRunParamsOptsDlg.SaveToOptions;
915 begin
916 fSaveToOptions.Assign(fOptions);
917 end;
918
919 procedure TRunParamsOptsDlg.EnvVarsPageResize(Sender: TObject);
920 var
921 NewHeight: Integer;
922 begin
923 NewHeight:=(Notebook.Page[1].Height - 37) div 2;
924 with UserOverridesGroupBox do
925 SetBounds(Left,Top+Height-NewHeight,Width,NewHeight);
926
927 SystemVariablesListView.Column[0].Width := SystemVariablesListView.Width div 2;
928 SystemVariablesListView.Column[1].Width := SystemVariablesListView.Column[0].Width;
929
930 UserOverridesListView.Column[0].Width := UserOverridesListView.Width div 2;
931 UserOverridesListView.Column[1].Width := UserOverridesListView.Column[0].Width;
932 end;
933
934 procedure TRunParamsOptsDlg.FormClose(Sender: TObject;
935 var CloseAction: TCloseAction);
936 begin
937 MiscellaneousOptions.ShowCompOptMultiLine:=PreviewMultilineCheckBox.Checked;
938 end;
939
940 procedure TRunParamsOptsDlg.FormCreate(Sender: TObject);
941 begin
942 ModesComboBox.DropDownCount := EnvironmentOptions.DropDownCount;
943 SaveInComboBox.DropDownCount := EnvironmentOptions.DropDownCount;
944 CmdLineParametersComboBox.DropDownCount := EnvironmentOptions.DropDownCount;
945 UseLaunchingApplicationComboBox.DropDownCount := EnvironmentOptions.DropDownCount;
946 WorkingDirectoryComboBox.DropDownCount := EnvironmentOptions.DropDownCount;
947 end;
948
949 procedure TRunParamsOptsDlg.HelpButtonClick(Sender: TObject);
950 begin
951 LazarusHelp.ShowHelpForIDEControl(Self);
952 end;
953
954 procedure TRunParamsOptsDlg.HostApplicationBrowseBtnClick(Sender: TObject);
955 var
956 OpenDialog: TIDEOpenDialog;
957 begin
958 OpenDialog := IDEOpenDialogClass.Create(Self);
959 with OpenDialog do
960 begin
961 InputHistories.ApplyFileDialogSettings(OpenDialog);
962 if HostApplicationEdit.Text <> '' then
963 OpenDialog.InitialDir := ExtractFilePath(HostApplicationEdit.Text);
964 OpenDialog.Filename := HostApplicationEdit.Text;
965 if OpenDialog.Execute then
966 begin
967 if (FileIsExecutable(OpenDialog.Filename))
968 or (IDEMessageDialog(lisRunParamsFileNotExecutable,
969 Format(lisRunParamsTheHostApplicationIsNotExecutable,[OpenDialog.Filename]),
970 mtWarning, [mbCancel, mbIgnore]) = mrIgnore) then
971 begin
972 HostApplicationEdit.Text := OpenDialog.Filename;
973 end;
974 end;
975 InputHistories.StoreFileDialogSettings(OpenDialog);
976 end;
977 end;
978
979 procedure TRunParamsOptsDlg.ModesComboBoxChange(Sender: TObject);
980 begin
981 if fLastSelectedMode<>nil then
982 SaveToOptionsMode(fLastSelectedMode);
983 if SelectedMode<>nil then
984 LoadFromOptionsMode(SelectedMode);
985 end;
986
987 procedure TRunParamsOptsDlg.NotebookChange(Sender: TObject);
988 begin
989 UpdatePreview;
990 end;
991
992 procedure TRunParamsOptsDlg.LoadFromOptionsMode(const AMode: TRunParamsOptionsMode);
993 var
994 List: THistoryList;
995 S: String;
996 begin
997 // local
998 HostApplicationEdit.Text := AMode.HostApplicationFilename;
999
1000 // WorkingDirectoryComboBox
1001 List:=HistoryLists.GetList(hlWorkingDirectory,true,rltFile);
1002 List.AppendEntry(AMode.WorkingDirectory);
1003 WorkingDirectoryComboBox.Items.Assign(List);
1004 WorkingDirectoryComboBox.Text := AMode.WorkingDirectory;
1005
1006 SaveInComboBox.ItemIndex := Ord(AMode.SaveIn);
1007 if SaveInComboBox.ItemIndex = -1 then
1008 SaveInComboBox.ItemIndex := 0;
1009
1010 // UseLaunchingApplicationComboBox
1011 UseLaunchingApplicationCheckBox.Checked := AMode.UseLaunchingApplication;
1012 List := HistoryLists.GetList(hlLaunchingApplication,true,rltFile);
1013 List.AppendEntry(AMode.LaunchingApplicationPathPlusParams);
1014 S := FindTerminalInPath;
1015 if S <> '' then
1016 List.AppendEntry(S);
1017 {$IFNDEF MSWINDOWS}
1018 S := FindTerminalInPath('gnome-terminal');
1019 if S <> '' then
1020 List.AppendEntry(S);
1021 S := FindTerminalInPath('konsole');
1022 if S <> '' then
1023 List.AppendEntry(S);
1024 {$ENDIF}
1025 UseLaunchingApplicationComboBox.Items.Assign(List);
1026 UseLaunchingApplicationComboBox.Text := AMode.LaunchingApplicationPathPlusParams;
1027 UseLaunchingApplicationComboBox.Enabled := UseLaunchingApplicationCheckBox.Checked;
1028
1029 // CmdLineParametersComboBox
1030 List:=HistoryLists.GetList(hlCmdLineParameters,true,rltCaseSensitive);
1031 List.AppendEntry(AMode.CmdLineParams);
1032 CmdLineParametersComboBox.Items.Assign(List);
1033 CmdLineParametersComboBox.Text := AMode.CmdLineParams;
1034
1035 UseDisplayCheckBox.Checked := AMode.UseDisplay;
1036 DisplayEdit.Text := AMode.Display;
1037
1038 // environment
1039 FillSystemVariablesListView;
1040 FillUserOverridesListView(AMode);
1041
1042 IncludeSystemVariablesCheckBox.Checked := AMode.IncludeSystemVariables;
1043
1044 fOptions.ActiveModeName := AMode.Name;
1045 fLastSelectedMode := AMode;
1046
1047 UpdatePreview;
1048 end;
1049
1050 procedure TRunParamsOptsDlg.UseLaunchingApplicationCheckBoxChange(Sender: TObject);
1051 begin
1052 UseLaunchingApplicationComboBox.Enabled := (Sender as TCheckBox).Checked;
1053 end;
1054
1055 procedure TRunParamsOptsDlg.UserOverridesListViewSelectItem(Sender: TObject;
1056 Item: TListItem; Selected: Boolean);
1057 var
1058 en: Boolean;
1059 begin
1060 en := Assigned(UserOverridesListView.Selected);
1061 UserOverridesDeleteButton.Enabled := en;
1062 UserOverridesEditButton.Enabled := en;
1063 end;
1064
1065 procedure TRunParamsOptsDlg.WorkingDirectoryBtnClick(Sender: TObject);
1066 var
1067 NewDirectory: String;
1068 begin
1069 NewDirectory:=InputHistories.SelectDirectory('Working directory',true,
1070 ExtractFilePath(WorkingDirectoryComboBox.Text),
1071 ExtractFilename(WorkingDirectoryComboBox.Text));
1072 if NewDirectory<>'' then
1073 WorkingDirectoryComboBox.Text:=NewDirectory;
1074 end;
1075
1076 procedure TRunParamsOptsDlg.UserOverridesAddButtonClick(Sender: TObject);
1077 var
1078 Variable, Value: string;
1079 NewLI, SelLI: TListItem;
1080 begin
1081 SelLI := SystemVariablesListView.Selected;
1082 if SelLI <> nil then
1083 begin
1084 Variable := SelLI.Caption;
1085 Value := SelLI.SubItems[0];
1086 end
1087 else
1088 begin
1089 Variable := '';
1090 Value := '';
1091 end;
1092 if ShowSysVarUserOverrideDialog(Variable, Value) = mrOk then
1093 begin
1094 NewLI := UserOverridesListView.Items.Add;
1095 NewLI.Caption := Variable;
1096 NewLI.SubItems.Add(Value);
1097 UserOverridesListView.Selected := NewLI;
1098 end;
1099 end;
1100
1101 procedure TRunParamsOptsDlg.UserOverridesEditButtonClick(Sender: TObject);
1102 var
1103 Variable, Value: string;
1104 SelLI: TListItem;
1105 begin
1106 SelLI := UserOverridesListView.Selected;
1107 if SelLI = nil then
1108 exit;
1109 Variable := SelLI.Caption;
1110 Value := SelLI.SubItems[0];
1111 if ShowSysVarUserOverrideDialog(Variable, Value) = mrOk then
1112 begin
1113 SelLI.Caption := Variable;
1114 SelLI.SubItems[0] := Value;
1115 end;
1116 end;
1117
1118 procedure TRunParamsOptsDlg.UserOverridesDeleteButtonClick(Sender: TObject);
1119 var
1120 SelLI: TListItem;
1121 OldIndex: integer;
1122 begin
1123 SelLI := UserOverridesListView.Selected;
1124 if SelLI <> nil then
1125 begin
1126 OldIndex := SelLI.Index;
1127 SelLI.Delete;
1128 if OldIndex = UserOverridesListView.Items.Count then
1129 Dec(OldIndex);
1130 if OldIndex >= 0 then
1131 UserOverridesListView.Selected := UserOverridesListView.Items[OldIndex];
1132 end;
1133 end;
1134
1135 procedure TRunParamsOptsDlg.SaveToOptionsMode(const AMode: TRunParamsOptionsMode);
1136
1137 procedure SaveComboHistory(AComboBox: TComboBox; const History: string;
1138 ListType: TRecentListType);
1139 begin
1140 AComboBox.AddHistoryItem(AComboBox.Text,20,true,false);
1141 HistoryLists.GetList(History,true,ListType).Assign(AComboBox.Items);
1142 end;
1143
1144 begin
1145 if (SaveInComboBox.ItemIndex>=Ord(Low(TRunParamsOptionsModeSave)))
1146 and(SaveInComboBox.ItemIndex<=Ord(High(TRunParamsOptionsModeSave))) then
1147 AMode.SaveIn := TRunParamsOptionsModeSave(SaveInComboBox.ItemIndex)
1148 else
1149 AMode.SaveIn := Low(TRunParamsOptionsModeSave);
1150
1151 // local
1152 AMode.HostApplicationFilename := Trim(HostApplicationEdit.Text);
1153 AMode.CmdLineParams := Trim(CmdLineParametersComboBox.Text);
1154 AMode.UseLaunchingApplication := UseLaunchingApplicationCheckBox.Checked;
1155 AMode.LaunchingApplicationPathPlusParams :=
1156 Trim(UseLaunchingApplicationComboBox.Text);
1157 AMode.WorkingDirectory := Trim(WorkingDirectoryComboBox.Text);
1158 AMode.UseDisplay := UseDisplayCheckBox.Checked;
1159 AMode.Display := Trim(DisplayEdit.Text);
1160
1161 // history list: WorkingDirectoryComboBox
1162 SaveComboHistory(WorkingDirectoryComboBox,hlWorkingDirectory,rltFile);
1163
1164 // history list: UseLaunchingApplicationComboBox
1165 SaveComboHistory(UseLaunchingApplicationComboBox,hlLaunchingApplication,rltFile);
1166
1167 // history list: CmdLineParametersComboBox
1168 SaveComboHistory(CmdLineParametersComboBox,hlCmdLineParameters,rltCaseSensitive);
1169
1170 // environment
1171 SaveUserOverrides(AMode);
1172
1173 AMode.IncludeSystemVariables := IncludeSystemVariablesCheckBox.Checked;
1174 end;
1175
1176 procedure TRunParamsOptsDlg.SaveUserOverrides(const AMode: TRunParamsOptionsMode
1177 );
1178 var
1179 i: integer;
1180 begin
1181 AMode.UserOverrides.Clear;
1182 for i := 0 to UserOverridesListView.Items.Count - 1 do
1183 begin
1184 AMode.UserOverrides.Values[UserOverridesListView.Items[i].Caption] :=
1185 UserOverridesListView.Items[i].SubItems[0];
1186 end;
1187 end;
1188
TRunParamsOptsDlg.SelectedModenull1189 function TRunParamsOptsDlg.SelectedMode: TRunParamsOptionsMode;
1190 begin
1191 if ModesComboBox.ItemIndex>=0 then
1192 Result := ModesComboBox.Items.Objects[ModesComboBox.ItemIndex] as TRunParamsOptionsMode
1193 else
1194 Result := nil;
1195 end;
1196
1197 procedure TRunParamsOptsDlg.SelectMode(const AName: string);
1198 var
1199 I: Integer;
1200 begin
1201 for I := 0 to ModesComboBox.Items.Count-1 do
1202 if ModesComboBox.Items[I] = AName then
1203 begin
1204 ModesComboBox.ItemIndex := I;
1205 Exit;
1206 end;
1207 end;
1208
1209 procedure TRunParamsOptsDlg.SetComboBoxText(AComboBox: TComboBox; AText: ansistring);
1210 var
1211 a: integer;
1212 begin
1213 a := AComboBox.Items.IndexOf(AText);
1214 if a >= 0 then
1215 AComboBox.ItemIndex := a
1216 else
1217 begin
1218 AComboBox.Items.Add(AText);
1219 AComboBox.ItemIndex := AComboBox.Items.IndexOf(AText);
1220 end;
1221 end;
1222
1223 procedure TRunParamsOptsDlg.SetOptions(NewOptions: TRunParamsOptions);
1224 begin
1225 fOptions.Assign(NewOptions);
1226 fSaveToOptions := NewOptions;
1227
1228 if fOptions.Count=0 then
1229 fOptions.Add('default');
1230
1231 ReloadModesComboBox;
1232 SelectMode(NewOptions.ActiveModeName);
1233 if (ModesComboBox.ItemIndex=-1) then
1234 ModesComboBox.ItemIndex := 0;
1235
1236 ModesComboBoxChange(ModesComboBox);
1237 end;
1238
1239 procedure TRunParamsOptsDlg.FillListView(ListView: TListView; sl: TStringList);
1240 var
1241 i: integer;
1242 Variable, Value: string;
1243 begin
1244 with ListView.Items do
1245 begin
1246 //BeginUpdate;
1247 for i := 0 to sl.Count - 1 do
1248 begin
1249 Variable := sl.Names[i];
1250 Value := sl.Values[Variable];
1251 if Count <= i then
1252 begin
1253 // add line to listview
1254 Add;
1255 Item[i].SubItems.Add('');
1256 end;
1257 Item[i].Caption := Variable;
1258 Item[i].SubItems[0] := Value;
1259 end;
1260 while Count > sl.Count do
1261 Delete(Count - 1);
1262 //EndUpdate;
1263 end;
1264 end;
1265
1266 procedure TRunParamsOptsDlg.FillSystemVariablesListView;
1267 var
1268 EnvList: TStringList;
1269 begin
1270 EnvList := EnvironmentAsStringList;
1271 FillListView(SystemVariablesListView, EnvList);
1272 EnvList.Free;
1273 end;
1274
1275 procedure TRunParamsOptsDlg.FillUserOverridesListView(
1276 const AMode: TRunParamsOptionsMode);
1277 begin
1278 FillListView(UserOverridesListView, AMode.UserOverrides);
1279 UserOverridesListView.OnSelectItem(nil, nil, false); //update buttons
1280 end;
1281
1282 end.
1283