8
Classes, SysUtils, ComCtrls, Debugger, DebuggerDlg, LazarusIDEStrConsts, Forms,
9
IDEWindowIntf, DebuggerStrConst,
10
BaseDebugManager, IDEImagesIntf, Dialogs;
16
THistoryDialog = class(TDebuggerDlg)
18
OpenDialog1: TOpenDialog;
19
SaveDialog1: TSaveDialog;
20
tbMakeSnap: TToolButton;
22
tbHistorySelected: TToolButton;
25
ToolButton1: TToolButton;
28
tbRemove: TToolButton;
29
ToolButton2: TToolButton;
30
tbExport: TToolButton;
31
ToolButton4: TToolButton;
32
tbImport: TToolButton;
33
procedure lvHistoryDblClick(Sender: TObject);
34
procedure lvHistorySelectItem(Sender: TObject; Item: TListItem; Selected: Boolean);
35
procedure tbClearClick(Sender: TObject);
36
procedure tbHistClick(Sender: TObject);
37
procedure tbHistorySelectedClick(Sender: TObject);
38
procedure tbMakeSnapClick(Sender: TObject);
39
procedure tbPowerClick(Sender: TObject);
40
procedure tbRemoveClick(Sender: TObject);
41
procedure tbExportClick(Sender: TObject);
42
procedure tbImportClick(Sender: TObject);
44
FInSnapshotChanged: Boolean;
45
imgCurrentLine: Integer;
46
FPowerImgIdx, FPowerImgIdxGrey: Integer;
47
FEnabledImgIdx, FDisabledIdx: Integer;
48
procedure SnapshotChanged(Sender: TObject);
49
procedure UpdateToolbar;
51
function ColSizeGetter(AColId: Integer; var ASize: Integer): Boolean;
52
procedure ColSizeSetter(AColId: Integer; ASize: Integer);
54
{ public declarations }
55
constructor Create(TheOwner: TComponent); override;
56
property SnapshotManager;
64
HistoryDlgWindowCreator: TIDEWindowCreator;
70
COL_WIDTHS: Array[0..2] of integer = ( 25, 120, 250);
72
function HistoryDlgColSizeGetter(AForm: TCustomForm; AColId: Integer; var ASize: Integer): Boolean;
74
Result := AForm is THistoryDialog;
76
Result := THistoryDialog(AForm).ColSizeGetter(AColId, ASize);
79
procedure HistoryDlgColSizeSetter(AForm: TCustomForm; AColId: Integer; ASize: Integer);
81
if AForm is THistoryDialog then
82
THistoryDialog(AForm).ColSizeSetter(AColId, ASize);
87
procedure THistoryDialog.lvHistoryDblClick(Sender: TObject);
89
if (lvHistory.Items.Count = 0) or (lvHistory.Selected = nil) then exit;
90
if tbHist.Down then begin
91
if (SnapshotManager.HistoryIndex = lvHistory.Selected.Index) and
92
(SnapshotManager.HistorySelected)
94
SnapshotManager.HistorySelected := False;
97
SnapshotManager.HistoryIndex := lvHistory.Selected.Index;
98
SnapshotManager.HistorySelected := True;
101
if (SnapshotManager.SnapshotIndex = lvHistory.Selected.Index) and
102
(SnapshotManager.SnapshotSelected)
104
SnapshotManager.SnapshotSelected := False;
107
SnapshotManager.SnapshotIndex := lvHistory.Selected.Index;
108
SnapshotManager.SnapshotSelected := True;
113
procedure THistoryDialog.lvHistorySelectItem(Sender: TObject; Item: TListItem;
119
procedure THistoryDialog.tbClearClick(Sender: TObject);
121
if SnapshotManager <> nil
122
then SnapshotManager.Clear;
125
procedure THistoryDialog.tbHistClick(Sender: TObject);
127
if (SnapshotManager = nil) or (FInSnapshotChanged) then exit;
128
if tbHistorySelected.Down then begin
129
if tbSnap.Down then SnapshotManager.SnapshotSelected := True;
130
if tbHist.Down then SnapshotManager.HistorySelected := True;
132
SnapshotChanged(nil);
135
procedure THistoryDialog.tbHistorySelectedClick(Sender: TObject);
137
if tbHistorySelected.Down
138
then tbHistorySelected.ImageIndex := FEnabledImgIdx
139
else tbHistorySelected.ImageIndex := FDisabledIdx;
140
if SnapshotManager = nil then exit;
142
then SnapshotManager.HistorySelected := tbHistorySelected.Down
143
else SnapshotManager.SnapshotSelected := tbHistorySelected.Down
146
procedure THistoryDialog.tbMakeSnapClick(Sender: TObject);
148
if (SnapshotManager = nil) or (SnapshotManager.Current = nil) then exit;
149
SnapshotManager.Current.AddToSnapshots;
152
procedure THistoryDialog.tbPowerClick(Sender: TObject);
155
then tbPower.ImageIndex := FPowerImgIdx
156
else tbPower.ImageIndex := FPowerImgIdxGrey;
157
if SnapshotManager <> nil
158
then SnapshotManager.Active := tbPower.Down;
161
procedure THistoryDialog.tbRemoveClick(Sender: TObject);
163
if lvHistory.Selected = nil then exit;
164
if tbHist.Down then begin
165
SnapshotManager.History[lvHistory.Selected.Index].RemoveFromHistory;
167
SnapshotManager.Snapshots[lvHistory.Selected.Index].RemoveFromSnapshots;
171
procedure THistoryDialog.tbExportClick(Sender: TObject);
175
if (SnapshotManager = nil) then exit;
176
if SaveDialog1.Execute then begin
177
tl := TStringList.Create;
178
tl.Text := SnapshotManager.GetAsXML;
179
tl.SaveToFile(SaveDialog1.FileName);
184
procedure THistoryDialog.tbImportClick(Sender: TObject);
188
if (SnapshotManager = nil) then exit;
189
if OpenDialog1.Execute then begin
190
tl := TStringList.Create;
191
tl.LoadFromFile(OpenDialog1.FileName);
192
SnapshotManager.SetFromXML(tl.Text);
197
procedure THistoryDialog.SnapshotChanged(Sender: TObject);
203
if (SnapshotManager = nil) or FInSnapshotChanged then exit;
205
FInSnapshotChanged:= True;
209
FInSnapshotChanged := False;
213
lvHistory.BeginUpdate;
217
Lst := SnapshotManager.Snapshots;
218
if SnapshotManager.SnapshotSelected
219
then cur := SnapshotManager.SnapshotIndex
222
Lst := SnapshotManager.History;
223
if SnapshotManager.HistorySelected
224
then cur := SnapshotManager.HistoryIndex
229
while lvHistory.Items.Count > i do lvHistory.Items.Delete(i);
230
while lvHistory.Items.Count < i do begin
231
Item := lvHistory.Items.Add;
232
Item.SubItems.add('');
233
Item.SubItems.add('');
236
if Lst.Count = 0 then exit;
238
for i := 0 to Lst.Count - 1 do begin
239
lvHistory.Items[i].Caption := '';
242
lvHistory.Items[i].ImageIndex := imgCurrentLine;
245
else lvHistory.Items[i].ImageIndex := -1;
247
lvHistory.Items[i].SubItems[0] := TimeToStr(Lst[i].TimeStamp);
248
lvHistory.Items[i].SubItems[1] := Lst[i].LocationAsText;
249
lvHistory.Items[i].Data := Lst[i];
256
then lvHistory.Items[j].MakeVisible(False);
259
procedure THistoryDialog.UpdateToolbar;
264
if SnapshotManager.Snapshots.Count > 0 then begin
265
tbSnap.Enabled := True;
267
tbSnap.Enabled := False;
273
Lst := SnapshotManager.Snapshots;
274
Sel := SnapshotManager.SnapshotSelected;
276
Lst := SnapshotManager.History;
277
Sel := SnapshotManager.HistorySelected;
280
tbHistorySelected.Enabled := Lst.Count > 0;
281
if not tbHistorySelected.Enabled
282
then tbHistorySelected.Down := False
283
else tbHistorySelected.Down := Sel;
284
tbHistorySelectedClick(tbHistorySelected);
286
tbClear.Enabled := (SnapshotManager.History.Count > 0) or (SnapshotManager.Snapshots.Count > 0);
288
tbMakeSnap.Enabled := (SnapshotManager.Current <> nil) and (not SnapshotManager.Current.IsSnapshot);
289
tbRemove.Enabled := lvHistory.Selected <> nil;
292
function THistoryDialog.ColSizeGetter(AColId: Integer; var ASize: Integer): Boolean;
294
if (AColId - 1 >= 0) and (AColId - 1 < lvHistory.ColumnCount) then begin
295
ASize := lvHistory.Column[AColId - 1].Width;
296
Result := ASize <> COL_WIDTHS[AColId - 1];
302
procedure THistoryDialog.ColSizeSetter(AColId: Integer; ASize: Integer);
305
COL_HISTORY_CUR: lvHistory.Column[0].Width := ASize;
306
COL_HISTORY_TIME: lvHistory.Column[1].Width := ASize;
307
COL_HISTORY_LOC: lvHistory.Column[2].Width := ASize;
311
constructor THistoryDialog.Create(TheOwner: TComponent);
315
inherited Create(TheOwner);
316
FInSnapshotChanged := False;
317
Caption:= histdlgFormName;
318
lvHistory.Column[0].Caption := histdlgColumnCur;
319
lvHistory.Column[1].Caption := histdlgColumnTime;
320
lvHistory.Column[2].Caption := histdlgColumnLoc;
322
SnapshotNotification.OnChange := @SnapshotChanged;
323
SnapshotNotification.OnCurrent := @SnapshotChanged;
325
imgCurrentLine := IDEImages.LoadImage(16, 'debugger_current_line');
326
lvHistory.SmallImages := IDEImages.Images_16;
328
ToolBar1.Images := IDEImages.Images_16;
330
FPowerImgIdx := IDEImages.LoadImage(16, 'debugger_power');
331
FPowerImgIdxGrey := IDEImages.LoadImage(16, 'debugger_power_grey');
332
FEnabledImgIdx := IDEImages.LoadImage(16, 'debugger_enable');
333
FDisabledIdx := IDEImages.LoadImage(16, 'debugger_disable');
335
tbPower.Hint := histdlgBtnPowerHint;
336
tbHistorySelected.Hint := histdlgBtnEnableHint;
338
tbClear.ImageIndex := IDEImages.LoadImage(16, 'menu_clean');
339
tbClear.Hint := histdlgBtnClearHint;
341
tbHist.ImageIndex := IDEImages.LoadImage(16, 'clock');
342
tbHist.Hint := histdlgBtnShowHistHint;
344
tbSnap.ImageIndex := IDEImages.LoadImage(16, 'camera');
345
tbSnap.Hint := histdlgBtnShowSnapHint;
347
tbMakeSnap.ImageIndex := IDEImages.LoadImage(16, 'camera_add');
348
tbMakeSnap.Hint := histdlgBtnMakeSnapHint;
350
tbRemove.ImageIndex := IDEImages.LoadImage(16, 'laz_delete');
351
tbRemove.Hint := histdlgBtnRemoveHint;
353
tbImport.ImageIndex := IDEImages.LoadImage(16, 'laz_open');
354
tbImport.Hint := histdlgBtnImport;
356
tbExport.ImageIndex := IDEImages.LoadImage(16, 'laz_save');
357
tbExport.Hint := histdlgBtnExport;
360
tbHistorySelectedClick(nil);
362
for i := low(COL_WIDTHS) to high(COL_WIDTHS) do
363
lvHistory.Column[i].Width := COL_WIDTHS[i];
369
HistoryDlgWindowCreator := IDEWindowCreators.Add(DebugDialogNames[ddtHistory]);
370
HistoryDlgWindowCreator.OnCreateFormProc := @CreateDebugDialog;
371
HistoryDlgWindowCreator.OnSetDividerSize := @HistoryDlgColSizeSetter;
372
HistoryDlgWindowCreator.OnGetDividerSize := @HistoryDlgColSizeGetter;
373
HistoryDlgWindowCreator.DividerTemplate.Add('HistoryColCur', COL_HISTORY_CUR, @drsHistoryColWidthCurrent);
374
HistoryDlgWindowCreator.DividerTemplate.Add('HistoryColTime', COL_HISTORY_TIME, @drsHistoryColWidthTime);
375
HistoryDlgWindowCreator.DividerTemplate.Add('HistoryColLocation', COL_HISTORY_LOC, @drsHistoryColWidthLocation);
376
HistoryDlgWindowCreator.CreateSimpleLayout;