File: initialsetupdlgdebuggerframe.pas

package info (click to toggle)
lazarus 4.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 275,760 kB
  • sloc: pascal: 2,341,904; xml: 509,420; makefile: 348,726; cpp: 93,608; sh: 3,387; java: 609; perl: 297; sql: 222; ansic: 137
file content (791 lines) | stat: -rw-r--r-- 23,848 bytes parent folder | download | duplicates (3)
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
unit InitialSetupDlgDebuggerFrame;

{$mode ObjFPC}{$H+}

interface

uses
  Classes, SysUtils, Types, Forms, Controls, StdCtrls, ComCtrls, ExtCtrls,
  Dialogs, Buttons, GDBMIDebugger, DbgIntfDebuggerBase, FileUtil, LazFileUtils,
  IDEDialogs, IDEUtils, IDEImagesIntf, FileProcs, FpDebugDebugger,
  {$Ifdef Darwin} FpLldbDebugger, {$ENDIF}
  IdeDebuggerOpts, LazarusIDEStrConsts, InitialSetupProc,
  EnvironmentOpts, LazConf, StrUtils;

type

  TDebuggerIntfClass = class of TDebuggerIntf;

  TDbgCfgStateChangedEvent = procedure(AState: TSDFilenameQuality) of object;

  { TInitDebuggerFrame }

  TInitDebuggerFrame = class(TFrame)
    btnBrowse: TButton;
    cmbDebuggerName: TComboBox;
    cmbDebuggerPath: TComboBox;
    edDebuggerNotes: TMemo;
    edDebuggerName: TEdit;
    edDebuggerPath: TEdit;
    edDebuggerPathResolved: TEdit;
    GroupBox1: TGroupBox;
    lbAboutDebugger: TLabel;
    lbDebuggerPath: TLabel;
    pnlDbgPath: TPanel;
    PnlSelectDbgPath: TPanel;
    rbCreateNew: TRadioButton;
    rbChange: TRadioButton;
    rbKeep: TRadioButton;
    rbIgnore: TRadioButton;
    rbChangePath: TRadioButton;
    SpeedButton1: TSpeedButton;
    procedure btnBrowseClick(Sender: TObject);
    procedure FrameResize(Sender: TObject);
    procedure rbKeepChange(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
  private
    FCurrentState: TCurrentDebuggerSetupResult;
    FCurDbgCfg: TDebuggerPropertiesConfig;
    FSelDbgCfg: TDebuggerPropertiesConfig; // Selected in combo
    FPathDbgCfg: TDebuggerPropertiesConfig; // Path-Combo currently showing for ...

    FOnStateChanged: TDbgCfgStateChangedEvent;
    FInChangeLock, FInPathLock: Integer;
    FLastDbgPath, FUserDbgPath: String;

    function RecommendedClass: TDebuggerIntfClass;
    function CountRecommendedBackend: Integer;
    function RecommendedBackend(AIdx: Integer): TDebuggerPropertiesConfig;

    function  GetVisibleDebuggerClass: TDebuggerIntfClass;
    function  GetVisibleDebuggerCfg: TDebuggerPropertiesConfig;
    function  GetVisibleDebuggerPath: String;
    function  GetVisibleDebuggerDefaultExe: String;

    function  GetCfgDefaultExe(ADbgClass: TDebuggerIntfClass): String;
    function  CfgNeedsDebuggerPath(ADbgClass: TDebuggerIntfClass): boolean;
    function  GetCfgDefaultExe(ADbgCfg: TDebuggerPropertiesConfig): String;
    function  CfgNeedsDebuggerPath(ADbgCfg: TDebuggerPropertiesConfig): boolean;
    function  CfgHasBrokenDebuggerPath(ADbgCfg: TDebuggerPropertiesConfig): boolean;

    procedure ShowCurrentDbgClass;
    procedure ShowRecommentedDbgClass;
    procedure ShowSelectedDbgClass;

    procedure HideDebuggerPath;
    procedure MaybeShowDebuggerPathForCurrentCfg;
    procedure MaybeShowDebuggerPathCombo(ADbgCfg: TDebuggerPropertiesConfig; ADbgClass: TDebuggerIntfClass = nil);
    procedure MaybeShowDebuggerPathResolved;

    function GetDebuggerClassNote(out ANote: String): TSDFilenameQuality;
    function GetDebuggerPathNote(out ANote: String): TSDFilenameQuality;
  public
    procedure Init;
    function UpdateState: TSDFilenameQuality;
    procedure ApplySelection;

    property OnStateChanged: TDbgCfgStateChangedEvent read FOnStateChanged write FOnStateChanged;
  end;

implementation

{$R *.lfm}

const
  resOk   = sddqCompatible;
  resHint = sddqHint;
  resWarn = sddqIncomplete;
  resErr  = sddqInvalid;

  NOTES_MIN_HEIGHT = 100;

function MaxResult(ARes1, ARes2: TSDFilenameQuality): TSDFilenameQuality;
begin
  Result := ARes1;
  if (ARes2 = resErr) or
     ((ARes2 = resWarn) and (Result in [resHint, resOk])) or
     (Result = resOk)
  then
    Result := ARes2;
end;

{ TInitDebuggerFrame }

procedure TInitDebuggerFrame.FrameResize(Sender: TObject);
begin
  VertScrollBar.Range := edDebuggerNotes.Top + edDebuggerNotes.Constraints.MinHeight;
  VertScrollBar.Page := Height;
end;

procedure TInitDebuggerFrame.btnBrowseClick(Sender: TObject);
var
  lExpandedName: string; // Expanded name before Dialog
  lDirName, lFileName: string;
  lTitle: string;
  lChanged: boolean=False;
  Dlg: TIDEOpenDialog;
  Filter: String;
begin
  Dlg:=IDEOpenDialogClass.Create(nil);
  try
    lTitle := GetVisibleDebuggerDefaultExe;
    if lTitle = '' then
      lTitle := '?';
    Dlg.Title := SimpleFormat(lisSelectPathTo, [lTitle]);
    lExpandedName := EnvironmentOptions.GetParsedValue(eopDebuggerFilename, GetVisibleDebuggerPath);
    lDirName := GetValidDirectory(lExpandedName, {out} lFileName);
    Dlg.Options := Dlg.Options+[ofFileMustExist];
    if lFileName='' then
      lFileName := lTitle;
    Filter := dlgFilterAll+'|'+GetAllFilesMask;
    if ExtractFileExt(lFileName)<>'' then
      Filter := dlgFilterExecutable+'|*'+ExtractFileExt(lFileName)+'|'+Filter;
    Dlg.Filter := Filter;
    Dlg.InitialDir := lDirName;
    Dlg.FileName := lFileName;
    if not Dlg.Execute then
      exit;
    lFileName := CleanAndExpandFilename(Dlg.Filename);
    lChanged := UpperCase(lExpandedName)<>UpperCase(lFileName);
  finally
    Dlg.Free;
  end;
  if lChanged then begin // Avoid looing $(macros)
    cmbDebuggerPath.Text := lFileName;
    rbKeepChange(Sender);
  end;
end;

procedure TInitDebuggerFrame.rbKeepChange(Sender: TObject);
var
  st: TSDFilenameQuality;
begin
  if FInChangeLock > 0 then
    exit;
  inc(FInChangeLock);
  try
    if Sender = cmbDebuggerPath then
      inc(FInPathLock);

    FLastDbgPath := cmbDebuggerPath.Text;
    if (FLastDbgPath <> '') and
       (FUserDbgPath <> FLastDbgPath) and
       (cmbDebuggerPath.Items.IndexOf(FLastDbgPath) < 0)
    then
      FUserDbgPath := FLastDbgPath;

    if (Sender = cmbDebuggerName) then
      FSelDbgCfg := TDebuggerPropertiesConfig(cmbDebuggerName.Items.Objects[cmbDebuggerName.ItemIndex]);

    if (Sender = cmbDebuggerName) or (Sender is TRadioButton) then
      FLastDbgPath := '';

    st := UpdateState;
  finally
    if Sender = cmbDebuggerPath then
      dec(FInPathLock);
    dec(FInChangeLock);

    if FOnStateChanged <> nil then
      FOnStateChanged(st);
  end;
end;

procedure TInitDebuggerFrame.SpeedButton1Click(Sender: TObject);
begin
  MessageDlg(Format(
      InitDlgDebugPopupInformation
    , [''+LineEnding, RecommendedClass.Caption]),
    mtInformation, [mbOK], 0
  );
end;

function TInitDebuggerFrame.RecommendedClass: TDebuggerIntfClass;
begin
  Result := TGDBMIDebugger;
  {$If defined(WINDOWS)}
  Result := TFpDebugDebugger;
  {$ElseIf defined(Linux)}
  Result := TFpDebugDebugger;
  {$ElseIf defined(Darwin)}
  Result := TFpLldbDebugger;
  {$ENDIF}
  if dfNotSuitableForOsArch in Result.SupportedFeatures then
    Result := TGDBMIDebugger;
end;

function TInitDebuggerFrame.CountRecommendedBackend: Integer;
var
  i: Integer;
  r: TDebuggerIntfClass;
begin
  Result := 0;
  r := RecommendedClass;
  for i := 0 to DebuggerOptions.DebuggerPropertiesConfigList.Count - 1 do
    if DebuggerOptions.DebuggerPropertiesConfigList.Opt[i].DebuggerClass = r then
      inc(Result);
end;

function TInitDebuggerFrame.RecommendedBackend(AIdx: Integer): TDebuggerPropertiesConfig;
var
  r: TDebuggerIntfClass;
  i: Integer;
begin
  Result := nil;
  r := RecommendedClass;
  for i := 0 to DebuggerOptions.DebuggerPropertiesConfigList.Count - 1 do
    if DebuggerOptions.DebuggerPropertiesConfigList.Opt[i].DebuggerClass = r then begin
      if AIdx = 0 then
        exit(DebuggerOptions.DebuggerPropertiesConfigList.Opt[i]);
      dec(AIdx);
    end;
end;

function TInitDebuggerFrame.GetVisibleDebuggerClass: TDebuggerIntfClass;
var
  c: TDebuggerPropertiesConfig;
begin
  Result := nil;
  if rbCreateNew.Checked then
    exit(RecommendedClass);
  c := GetVisibleDebuggerCfg;
  if c <> nil then
    Result := c.DebuggerClass;
end;

function TInitDebuggerFrame.GetVisibleDebuggerCfg: TDebuggerPropertiesConfig;
begin
  Result := nil;
  if rbCreateNew.Checked then
    exit;
  if edDebuggerName.Visible then
    Result := FCurDbgCfg
  else
  if cmbDebuggerName.Visible then
    Result := FSelDbgCfg;
end;

function TInitDebuggerFrame.GetVisibleDebuggerPath: String;
var
  c: TDebuggerPropertiesConfig;
begin
  Result := '';
  if (not HandleAllocated) or (not cmbDebuggerPath.HandleAllocated) then begin
    c := GetVisibleDebuggerCfg;
    if c <> nil then
      Result := c.DebuggerFilename;
    exit;
  end;
  if PnlSelectDbgPath.Visible then Result := cmbDebuggerPath.Text
  else
  if edDebuggerPath.Visible then Result := edDebuggerPath.Caption;
end;

function TInitDebuggerFrame.GetVisibleDebuggerDefaultExe: String;
begin
  Result := GetCfgDefaultExe(GetVisibleDebuggerCfg);
end;

function TInitDebuggerFrame.GetCfgDefaultExe(ADbgClass: TDebuggerIntfClass): String;
begin
  Result := '';
  if ADbgClass <> nil then begin
    Result := ADbgClass.ExeBaseName;
    if Result <> '' then
      Result := Result + GetExecutableExt;
  end;
end;

function TInitDebuggerFrame.CfgNeedsDebuggerPath(ADbgClass: TDebuggerIntfClass
  ): boolean;
begin
  Result := (ADbgClass <> nil) and ADbgClass.NeedsExePath;
end;

function TInitDebuggerFrame.GetCfgDefaultExe(ADbgCfg: TDebuggerPropertiesConfig): String;
begin
  Result := '';
  if (ADbgCfg <> nil) then
    Result := GetCfgDefaultExe(ADbgCfg.DebuggerClass);
end;

function TInitDebuggerFrame.CfgNeedsDebuggerPath(ADbgCfg: TDebuggerPropertiesConfig): boolean;
begin
  Result := (ADbgCfg <> nil) and (ADbgCfg.DebuggerClass <> nil) and
            ADbgCfg.DebuggerClass.NeedsExePath;
end;

function TInitDebuggerFrame.CfgHasBrokenDebuggerPath(
  ADbgCfg: TDebuggerPropertiesConfig): boolean;
begin
  Result := CfgNeedsDebuggerPath(ADbgCfg);
  if Result then
    Result := CheckDebuggerQuality(ADbgCfg.DebuggerFilename) <> sdfOk ;
end;

procedure TInitDebuggerFrame.ShowCurrentDbgClass;
begin
  if FCurDbgCfg <> nil then
    edDebuggerName.Caption := FCurDbgCfg.DisplayName
  else
    edDebuggerName.Caption := '';
  cmbDebuggerName.Visible := False;
  edDebuggerName.Visible := True;
  GroupBox1.Caption := InitDlgDebugCurrent;
end;

procedure TInitDebuggerFrame.ShowRecommentedDbgClass;
begin
  edDebuggerName.Caption := RecommendedClass.Caption;
  cmbDebuggerName.Visible := False;
  edDebuggerName.Visible := True;
  GroupBox1.Caption := InitDlgDebugNew;
end;

procedure TInitDebuggerFrame.ShowSelectedDbgClass;
begin
  cmbDebuggerName.Visible := True;
  edDebuggerName.Visible := False;
  GroupBox1.Caption := InitDlgDebugNew;
end;

procedure TInitDebuggerFrame.HideDebuggerPath;
begin
  pnlDbgPath.Visible := False;
end;

procedure TInitDebuggerFrame.MaybeShowDebuggerPathForCurrentCfg;
begin
  PnlSelectDbgPath.Visible := False;
  edDebuggerPathResolved.Visible := False;
  edDebuggerPath.Visible   := CfgNeedsDebuggerPath(FCurDbgCfg);
  pnlDbgPath.Visible       := edDebuggerPath.Visible;

  if not edDebuggerPath.Visible then
    exit;

  lbDebuggerPath.Caption := InitDlgDebugExternalExePathDisplay;
  edDebuggerPath.Caption := FCurDbgCfg.DebuggerFilename;

  MaybeShowDebuggerPathResolved;
end;

procedure TInitDebuggerFrame.MaybeShowDebuggerPathCombo(
  ADbgCfg: TDebuggerPropertiesConfig; ADbgClass: TDebuggerIntfClass);
var
  p: TStringDynArray;
  DefExe, s: string;
  i: Integer;
begin
  if (ADbgClass = nil) and (ADbgCfg <> nil) then
    ADbgClass := ADbgCfg.DebuggerClass;

  edDebuggerPath.Visible   := False;
  edDebuggerPathResolved.Visible := False;
  PnlSelectDbgPath.Visible := CfgNeedsDebuggerPath(ADbgClass);
  pnlDbgPath.Visible       := PnlSelectDbgPath.Visible;

  if not PnlSelectDbgPath.Visible then begin
    FPathDbgCfg := nil;
    exit;
  end;

  DefExe := GetCfgDefaultExe(ADbgClass);
  if DefExe = '' then
    DefExe := '?';
  lbDebuggerPath.Caption := Format(
    InitDlgDebugExternalExePathPrompt,
    [DefExe]
  );

  if FInPathLock = 0 then begin
    if ADbgCfg = FPathDbgCfg then
      cmbDebuggerPath.Items.Clear
    else
      cmbDebuggerPath.Clear;
    if (ADbgCfg <> nil) and (ADbgCfg.DebuggerFilename <> '') then
      cmbDebuggerPath.AddItem(ADbgCfg.DebuggerFilename, TObject(-1));

    s := '';
    if ADbgClass <> nil then
      s := ADbgClass.ExePaths;
    p := SplitString(
      s +
      ';$Path($(CompPath))/'+ DefExe +
      ';' + DefExe,
      ';'
    );
    for i := 0 to Length(p) - 1 do begin
      if (p[i] <> '') and
         (cmbDebuggerPath.Items.IndexOf(p[i]) < 0) and
         (CheckDebuggerQuality(p[i]) = sdfOk)
      then
        cmbDebuggerPath.AddItem(p[i], TObject(PtrUInt(i)));
    end;
    if FUserDbgPath <> '' then
      cmbDebuggerPath.AddItem(FUserDbgPath, TObject(-2));

    if ADbgCfg <> FPathDbgCfg then begin
      if (FLastDbgPath <> '') or (ADbgCfg = nil) then
        cmbDebuggerPath.Text := FLastDbgPath
      else
        cmbDebuggerPath.Text := ADbgCfg.DebuggerFilename;
      if (ADbgCfg = nil) and (cmbDebuggerPath.Text = '') and (cmbDebuggerPath.Items.Count > 0) then
        cmbDebuggerPath.ItemIndex := 0;
    end;
  end;

  FPathDbgCfg := ADbgCfg;
  MaybeShowDebuggerPathResolved;
end;

procedure TInitDebuggerFrame.MaybeShowDebuggerPathResolved;
var
  s, r: String;
begin
  s := GetVisibleDebuggerPath;
  r := EnvironmentOptions.GetParsedValue(eopDebuggerFilename, s);
  edDebuggerPathResolved.Text := r;
  edDebuggerPathResolved.Visible := (r <> '') and (UpperCase(r) <> UpperCase(s));
end;

function TInitDebuggerFrame.GetDebuggerClassNote(out ANote: String
  ): TSDFilenameQuality;
var
  c: TDebuggerPropertiesConfig;
begin
  Result := resOk;
  ANote := '';

  c := GetVisibleDebuggerCfg;
  if (c = nil) and rbCreateNew.Checked then
    exit; // rbCreateNew;

  if (FCurrentState = cdsNotSupported) and not(rbChange.Checked or rbCreateNew.Checked) then begin
    Result := resErr;
    ANote := InitDlgDebugClassNoteErrorNotSupported;
    exit;
  end;

  if (c = nil) or (c.DebuggerClass = nil) then begin
    Result := resErr;
    ANote := InitDlgDebugClassNoteErrorNotConfigured;
    if FCurrentState = cdsNotRegistered then
      ANote := ANote + LineEnding + InitDlgDebugClassNoteErrorNotConfiguredMissingPackage;
    exit;
  end;

  if c.DebuggerClass = RecommendedClass then begin
    ANote := ''; //'The backend is of the recommended type';
    exit;
  end;

  Result := resHint;
  if (FCurrentState = cdsUpdateToFpDbgNeeded) and
     not(rbCreateNew.Checked or rbChange.Checked)
  then
    Result := resWarn;
  ANote := InitDlgDebugClassNoteHintNotRecommended;
end;

function TInitDebuggerFrame.GetDebuggerPathNote(out ANote: String
  ): TSDFilenameQuality;
var
  s: String;
begin
  Result := resOk;
  ANote := '';
  if CfgNeedsDebuggerPath(GetVisibleDebuggerClass) then begin
    s := GetVisibleDebuggerPath;

    if s = '' then begin
      Result := resErr;
      if rbCreateNew.Checked then
        ANote := InitDlgDebugPathNoteErrorNoDefaultFound
      else
        ANote := InitDlgDebugPathNoteErrorNoExeSpecified;
    end
    else begin
      Result := resErr;
      case CheckDebuggerQuality(s) of
        sdfOk:            Result := resOk;
        sdfNotFound:      ANote := InitDlgDebugPathNoteErrorExeNotFound;
        sdfIsDirectory:   ANote := InitDlgDebugPathNoteErrorExeIsDirectory;
        sdfNotExecutable: ANote := InitDlgDebugPathNoteErrorExeNotRunnable;
      end;
    end;
  end;
end;

procedure TInitDebuggerFrame.Init;
var
  r: TDebuggerIntfClass;
  i: Integer;
  c: TDebuggerPropertiesConfig;
begin
  inc(FInChangeLock);
  try
    FCurrentState := CheckCurrentDebuggerSetup;
    FCurDbgCfg := DebuggerOptions.CurrentDebuggerPropertiesConfig;
    FPathDbgCfg := TDebuggerPropertiesConfig(-1);

    r := RecommendedClass;

    btnBrowse.Caption:=lisPathEditBrowse;
    SpeedButton1.Images := IDEImages.Images_16;
    SpeedButton1.ImageIndex := IDEImages.LoadImage('btn_help');

    lbAboutDebugger.Caption := Format(
      InitDlgDebugHeaderDefaultForYourOSArchIsS,
      [ r.Caption ]
    );

    if FCurDbgCfg <> nil then begin
      edDebuggerName.Caption := FCurDbgCfg.DisplayName;
      edDebuggerPath.Caption := FCurDbgCfg.DebuggerFilename;
    end
    else begin
      edDebuggerName.Caption := '';
      edDebuggerPath.Caption := '';
    end;

    FSelDbgCfg := nil;
    if DebuggerOptions.DebuggerPropertiesConfigList.Count  > 0 then begin
      for i := 0 to DebuggerOptions.DebuggerPropertiesConfigList.Count - 1 do begin
        c := DebuggerOptions.DebuggerPropertiesConfigList.Opt[i];
        cmbDebuggerName.AddItem(c.DisplayName, c);
      end;
      i := 0;
      if FCurDbgCfg <> nil then
        i := cmbDebuggerName.Items.IndexOfObject(FCurDbgCfg);
      cmbDebuggerName.ItemIndex := i;
      FSelDbgCfg := TDebuggerPropertiesConfig(cmbDebuggerName.Items.Objects[i]);
    end;

    rbKeep.Caption              := InitDlgDebugKeepBackend;
    rbChangePath.Caption        := InitDlgDebugChangePath;
    rbCreateNew.Caption         := InitDlgDebugCreateANewRecommendedBack;
    rbChange.Caption            := InitDlgDebugSelectAnExistingBackend;
    rbIgnore.Caption            := InitDlgDebugIgnore;

    case FCurrentState of
      cdsOk: begin
        rbKeep.Visible              := True;
        rbChangePath.Visible        := CfgNeedsDebuggerPath(FCurDbgCfg);
        rbCreateNew.Visible         := FCurDbgCfg.DebuggerClass <> RecommendedClass;
        rbChange.Visible            := DebuggerOptions.DebuggerPropertiesConfigList.Count > 1;
        rbIgnore.Visible            := False;

        rbKeep.Checked := True;
        end;
      //cdsNoActive: begin
      //  end;
      //cdsNotRegistered: begin
      //  end;
      //cdsNotSupported: begin
      //  end;
      cdsUpdateToFpDbgNeeded: begin
        rbKeep.Visible              := True;
        rbChangePath.Visible        := False;
        rbCreateNew.Visible         := True;
        rbChange.Visible            := DebuggerOptions.DebuggerPropertiesConfigList.Count >= 1;
        rbIgnore.Visible            := False;

        rbKeep.Checked := True;
        end;
      else begin
        rbKeep.Visible              := False;
        rbChangePath.Visible        := False;
        rbCreateNew.Visible         := True;
        rbChange.Visible            := DebuggerOptions.DebuggerPropertiesConfigList.Count >= 1;
        rbIgnore.Visible            := True;

        //rbIgnore.Checked := True;
      end;
    end;
  finally
    dec(FInChangeLock);
  end;
end;

function TInitDebuggerFrame.UpdateState: TSDFilenameQuality;
var
  s, ClassNote, PathNote: String;
  PathRes: TSDFilenameQuality;
  HasUnregistered, HasRebuildNote: Boolean;
  h: Integer;
begin
  inc(FInChangeLock);
  try
    DisableAutoSizing;
    Result := resOk;

    // This only needs update, if a macro in the path changes
    if FCurrentState = cdsOk then begin
      if CfgHasBrokenDebuggerPath(FCurDbgCfg) then begin
        rbKeep.Visible              := False;
        rbIgnore.Visible            := True;
        rbKeep.Checked := False;
      end
      else begin
        rbKeep.Visible              := True;
        rbIgnore.Visible            := False;
        if rbIgnore.Checked then rbKeep.Checked := True;
      end;
    end;

    if rbCreateNew.Checked then begin
      ShowRecommentedDbgClass;
      MaybeShowDebuggerPathCombo(nil, RecommendedClass);
    end
    else
    if rbChangePath.Checked then begin
      ShowCurrentDbgClass;
      MaybeShowDebuggerPathCombo(FCurDbgCfg);
    end
    else
    if rbChange.Checked then begin
      ShowSelectedDbgClass;
      MaybeShowDebuggerPathCombo(FSelDbgCfg);
    end
    else
    begin // rbKeep or rbIgnore
      ShowCurrentDbgClass;
      MaybeShowDebuggerPathForCurrentCfg;
    end;


    s := '';
    h := 0;
    HasUnregistered := DebuggerOptions.DebuggerPropertiesConfigList.Unloaded.Count > 0;
    Result := GetDebuggerClassNote(ClassNote);
    PathRes := GetDebuggerPathNote(PathNote);
    HasRebuildNote := False;

    if (FCurrentState in [cdsNotRegistered, cdsNoActive]) and HasUnregistered then begin
      HasRebuildNote := True;
      s := s + InitDlgDebugStateMissingPackages + LineEnding;
      h := h + 50;
    end
    else
    if (FCurrentState = cdsUpdateToFpDbgNeeded) then begin
      s := s + InitDlgDebugStateUpdateBackend + LineEnding;
      h := h + 40;
      //Result := MaxResult(resHint, Result);
    end;

    if rbChange.Visible and rbCreateNew.Visible and
       ( (FCurrentState <> cdsOk) or
         ((FCurDbgCfg <> nil) and (FCurDbgCfg.DebuggerClass <> RecommendedClass))
       )
    then begin
      if (CountRecommendedBackend = 0) and rbChange.Checked then begin
        s := s + InitDlgDebugStateRecommendedNotInList + LineEnding;
        h := h + 25;
      end
      else
      if (CountRecommendedBackend > 0) and rbCreateNew.Checked then begin
        s := s + InitDlgDebugStateRecommendedFoundInList + LineEnding;
        h := h + 25;
      end
    end;

    if (s <> '') and not ( (Result in [resOk, resHint]) and (PathRes in [resOk, resHint]) ) then
      s := s + LineEnding;

    if (ClassNote <> '') and not (Result in [resOk, resHint]) then begin
      s := s + ClassNote + LineEnding;
      ClassNote := '';
    end;

    if (PathNote <> '') and not (PathRes in [resOk, resHint]) then begin
      s := s + PathNote + LineEnding;
      PathNote := '';
      Result := MaxResult(PathRes, Result);
    end;

    if Result in [resOk, resHint] then begin
      if s <> '' then s := s + LineEnding;
      s := s + InitDlgDebugStateSetupOk + LineEnding;
    end;

    if (ClassNote <> '') then
      s := s + ClassNote + LineEnding;
    if (PathNote <> '') then
      s := s + PathNote + LineEnding;

    if HasRebuildNote then begin
      s := s + LineEnding + Format(InitDlgDebugStateMissingPackageRebuild, [''+LineEnding]);
      h := h + 40;
    end
    else
    if HasUnregistered then begin
      s := s + LineEnding + InitDlgDebugStateMissingPackageFooter;
      h := h + 70;
    end;

    if rbIgnore.Checked and (Result = resErr) and
       (FCurrentState in [cdsNoActive, cdsNotRegistered])
    then
      Result := resWarn;

    edDebuggerNotes.Height := ClientHeight - edDebuggerNotes.Top - 5;
    edDebuggerNotes.Constraints.MinHeight := NOTES_MIN_HEIGHT + h;
    edDebuggerNotes.Text := s;

  finally
    dec(FInChangeLock);

    EnableAutoSizing;
    FrameResize(nil);
  end;
end;

procedure TInitDebuggerFrame.ApplySelection;
var
  c: TDebuggerPropertiesConfig;
  n: String;
  i: Integer;
begin
  if rbChangePath.Checked then begin
    assert(DebuggerOptions.CurrentDebuggerPropertiesConfig<>nil, 'TInitDebuggerFrame.ApplySelection: DebuggerOptions.CurrentDebuggerPropertiesConfig<>nil');
    if DebuggerOptions.CurrentDebuggerPropertiesConfig <> nil then
      DebuggerOptions.CurrentDebuggerPropertiesConfig.DebuggerFilename := GetVisibleDebuggerPath;
    DebuggerOptions.SaveDebuggerPropertiesList; // Update XML
  end
  else
  if rbChange.Checked then begin
    assert(FSelDbgCfg <> nil, 'TInitDebuggerFrame.ApplySelection: FSelDbgCfg <> nil');
    if FSelDbgCfg <> nil then begin
      FSelDbgCfg.DebuggerFilename:=GetVisibleDebuggerPath;
      DebuggerOptions.CurrentDebuggerPropertiesConfig := FSelDbgCfg;
    end;
    DebuggerOptions.SaveDebuggerPropertiesList; // Update XML
  end
  else
  if rbCreateNew.Checked then begin
    c := TDebuggerPropertiesConfig.CreateForDebuggerClass(RecommendedClass, True);
    n := 'Default';
    i := 0;
    if DebuggerOptions.DebuggerPropertiesConfigList.EntryByName(n, c.ConfigClass) <> nil then
      while (i <= DebuggerOptions.DebuggerPropertiesConfigList.Count) and
            (DebuggerOptions.DebuggerPropertiesConfigList.EntryByName(n+' '+IntToStr(i), c.ConfigClass) <> nil)
      do
        inc(i);
    if i > 0 then
      n := n + ' ' + IntToStr(i);
    c.ConfigName := n;
    DebuggerOptions.CurrentDebuggerPropertiesConfig := c;
    if CfgNeedsDebuggerPath(c) then
      c.DebuggerFilename := GetVisibleDebuggerPath;
    DebuggerOptions.SaveDebuggerPropertiesList; // Update XML
  end;

  // else
  //if FCurrentState = cdsUpdateToFpDbgNeeded then begin
  //end;
  // caller will save config, and increase version
end;

end.