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