File: project_debug_options.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 (236 lines) | stat: -rw-r--r-- 7,296 bytes parent folder | download
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
unit project_debug_options;

{$mode objfpc}{$H+}

interface

uses
  SysUtils, Classes,
  // LazUtils
  LazTracer,
  // LCL
  Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
  // LazControls
  DividerBevel,
  // IdeIntf
  IDEOptionsIntf, IDEOptEditorIntf, ProjectIntf,
  // IdeConfig
  EnvironmentOpts,
  // IdeDebugger
  IdeDebuggerOpts,
  // IDE
  Project, DebugManager, ProjectDebugLink,
  LazarusIDEStrConsts, debugger_class_options;

type

  { TProjectDebugOptionsFrame }

  TProjectDebugOptionsFrame = class(TAbstractIDEOptionsEditor)
    cbProjectDebugger: TComboBox;
    chkStoreInSession: TCheckBox;
    DividerBevel1: TDividerBevel;
    lblResolvedDebuggerHint: TLabel;
    lbProjectDebugger: TLabel;
    Panel1: TPanel;
    procedure cbProjectDebuggerChange(Sender: TObject);
  private
    fProject: TProject;
    FDebuggerBackend, FDebuggerBackendUnknown: String;
    FDebuggerBackendIdx: Integer;
    FClassOpts: TDebuggerClassOptionsFrame;
    procedure ClassCountChanged(Sender: TObject);
    procedure UpdateDebuggerBackend;
    procedure FillProjectDebuggerDropDown;
    procedure UpdateResolvedDebuggerHint;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    function GetTitle: string; override;
    procedure Setup({%H-}ADialog: TAbstractOptionsEditorDialog); override;
    procedure ReadSettings(AOptions: TAbstractIDEOptions); override;
    procedure WriteSettings(AOptions: TAbstractIDEOptions); override;
    class function SupportedOptionsClass: TAbstractIDEOptionsClass; override;
    //property aProject: TProject read fProject;
  end;

implementation

const
  DBG_IDX_UNKNOWN = -99; // will use "project debugger"
  DBG_IDX_PROJECT =  -2;
  DBG_IDX_IDE     =  -1;
  DBG_TOKEN_IDE = 'IDE';

{$R *.lfm}

{ TProjectDebugOptionsFrame }

procedure TProjectDebugOptionsFrame.cbProjectDebuggerChange(Sender: TObject);
begin
  UpdateResolvedDebuggerHint;
end;

procedure TProjectDebugOptionsFrame.ClassCountChanged(Sender: TObject);
begin
  UpdateResolvedDebuggerHint
end;

procedure TProjectDebugOptionsFrame.UpdateDebuggerBackend;
var
  i: Integer;
begin
  if cbProjectDebugger.Items.Count = 0 then
    exit;

  FDebuggerBackend := '';
  FDebuggerBackendIdx := DBG_IDX_PROJECT;

  i := cbProjectDebugger.ItemIndex;
  if i >= 0 then begin
    FDebuggerBackendIdx := PtrInt(cbProjectDebugger.Items.Objects[i]);
    if FDebuggerBackendIdx = DBG_IDX_IDE then
      FDebuggerBackend := DBG_TOKEN_IDE
    else
    if FDebuggerBackendIdx = DBG_IDX_UNKNOWN then
      FDebuggerBackend := FDebuggerBackendUnknown
    else
    if FDebuggerBackendIdx >= 0 then
      FDebuggerBackend := DebuggerOptions.DebuggerPropertiesConfigList.Opt[FDebuggerBackendIdx].UID;
  end;
end;

procedure TProjectDebugOptionsFrame.FillProjectDebuggerDropDown;
const
  DBG_IDX_OFFSET  = 2; // 2 Hardcoded items (project, ide) // Offset for DropDown.ItemIndex
var
  i, sel: Integer;
  dbg: TDebuggerPropertiesConfigList;
begin
  cbProjectDebugger.Clear;
  sel := -1;
  cbProjectDebugger.AddItem(lisDebugOptionsFrmUseProjectDebugger, TObject(PtrUInt(DBG_IDX_PROJECT)));
  cbProjectDebugger.AddItem(lisDebugOptionsFrmUseIDEDebugger,     TObject(PtrUInt(DBG_IDX_IDE)));
  if FDebuggerBackend = '' then
    sel := 0
  else
  if FDebuggerBackend = DBG_TOKEN_IDE then
    sel := 1;

  dbg := DebuggerOptions.DebuggerPropertiesConfigList;
  for i := 0 to dbg.Count - 1 do begin
    cbProjectDebugger.AddItem(dbg.Opt[i].DisplayName, TObject(PtrUInt(i)));
    if dbg.Opt[i].UID = FDebuggerBackend then
      sel := i + DBG_IDX_OFFSET;
  end;

  if sel < 0 then begin
    sel := cbProjectDebugger.Items.AddObject(Format(
      lisDebugOptionsFrmUnknownDebuggerBacke, [FDebuggerBackend]), TObject(PtrUInt(DBG_IDX_UNKNOWN)));
    FDebuggerBackendUnknown := FDebuggerBackend;
  end;
  cbProjectDebugger.ItemIndex := sel;
  UpdateResolvedDebuggerHint;
end;

procedure TProjectDebugOptionsFrame.UpdateResolvedDebuggerHint;
begin
  UpdateDebuggerBackend;

  lblResolvedDebuggerHint.Visible := False;
  case FDebuggerBackendIdx of
    DBG_IDX_PROJECT: begin
      if FClassOpts.ModifiedDbgPropertiesConfigList.Count = 0 then begin
        lblResolvedDebuggerHint.Caption := drsUsingIDEDefaultDebuggerSe;
        lblResolvedDebuggerHint.Visible := True;
      end;
    end;
    DBG_IDX_IDE: begin
      if FClassOpts.ModifiedDbgPropertiesConfigList.Count > 0 then begin
        lblResolvedDebuggerHint.Caption := drsUsingIDEDefaultDebuggerSe;
        lblResolvedDebuggerHint.Caption := lblResolvedDebuggerHint.Caption + drsIgnoringProjectDebuggerSettings;
        lblResolvedDebuggerHint.Visible := True;
      end;
    end;
    DBG_IDX_UNKNOWN: begin
      lblResolvedDebuggerHint.Caption := drsUsingIDEDefaultDebuggerSe;
      if FClassOpts.ModifiedDbgPropertiesConfigList.Count > 0 then
        lblResolvedDebuggerHint.Caption := lblResolvedDebuggerHint.Caption + drsIgnoringProjectDebuggerSettings;
      lblResolvedDebuggerHint.Visible := True;
    end;
    otherwise begin
      if FClassOpts.ModifiedDbgPropertiesConfigList.Count > 0 then begin
        lblResolvedDebuggerHint.Caption := drsUsingSelectedIDEDebuggerS;
        lblResolvedDebuggerHint.Caption := lblResolvedDebuggerHint.Caption + drsIgnoringProjectDebuggerSettings;
        lblResolvedDebuggerHint.Visible := True;
    end;
    end;
  end;
end;

constructor TProjectDebugOptionsFrame.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FClassOpts := TDebuggerClassOptionsFrame.Create(Self);
  FClassOpts.Parent := Self;
  FClassOpts.Align := alClient;
  FClassOpts.Visible := True;
  FClassOpts.OnModifiedDbgPropertiesCountChanged := @ClassCountChanged;
end;

destructor TProjectDebugOptionsFrame.Destroy;
begin
  FClassOpts.OnModifiedDbgPropertiesCountChanged := nil;
  inherited Destroy;
end;

function TProjectDebugOptionsFrame.GetTitle: string;
begin
  Result := dlgPODebugger;
end;

procedure TProjectDebugOptionsFrame.Setup(ADialog: TAbstractOptionsEditorDialog);
begin
  lbProjectDebugger.Caption := lisDebugOptionsFrmDebuggerBackend;
  chkStoreInSession.Caption := drsStoreProjectDebuggerConfi;
  chkStoreInSession.Hint := drsTheDebuggerBackendSelecti;
  FClassOpts.Setup(ADialog);
end;

procedure TProjectDebugOptionsFrame.ReadSettings(AOptions: TAbstractIDEOptions);
begin
  fProject:=(AOptions as TProjectIDEOptions).Project;
  with fProject.DebuggerLink as TProjectDebugLink do
  begin
    Self.FDebuggerBackend := DebuggerBackend;
    chkStoreInSession.Checked := StoreDebuggerClassConfInSession;
    FClassOpts.ReadSettings(DebuggerPropertiesConfigList);
  end;

  FillProjectDebuggerDropDown;
end;

procedure TProjectDebugOptionsFrame.WriteSettings(AOptions: TAbstractIDEOptions);
begin
  UpdateDebuggerBackend;

  with (AOptions as TProjectIDEOptions).Project.DebuggerLink as TProjectDebugLink do
  begin
    DebuggerBackend := FDebuggerBackend;
    StoreDebuggerClassConfInSession := chkStoreInSession.Checked;
    FClassOpts.WriteSettings(DebuggerPropertiesConfigList);
    MarkDebuggerClassConfAsModified;
  end;

end;

class function TProjectDebugOptionsFrame.SupportedOptionsClass: TAbstractIDEOptionsClass;
begin
  Result := TProjectIDEOptions;
end;

initialization
  RegisterIDEOptionsEditor(GroupProject, TProjectDebugOptionsFrame, ProjectOptionsDebug);

end.