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 unit JumpHistoryView;
22
23 {$mode objfpc}{$H+}
24
25 interface
26
27 uses
28 Classes, SysUtils,
29 // LCL
30 Forms, Controls, StdCtrls, Menus,
31 // LazUtils
32 LazUTF8, LazStringUtils,
33 // CodeTools
34 CodeToolManager, CodeCache,
35 // IDE
36 IDEOptionDefs, EnvironmentOpts, LazarusIDEStrConsts, Project, ProjectDefs;
37
38 type
39
40 { TJumpHistoryViewWin }
41
42 TJumpHistoryViewWin = class(TForm)
43 listHistory : TListBox;
44 procedure FormCreate(Sender : TObject);
45 procedure listHistoryClick(Sender : TObject);
46 procedure listHistoryDblClick(Sender : TObject);
47 procedure listHistoryKeyPress(Sender: TObject; var Key: char);
48 procedure OnIdle(Sender : TObject; var {%H-}Done: Boolean);
49 private
50 { private declarations }
51 fOnSelectionChanged : TNotifyEvent;
52 fProjectChangeStamp: integer;
GetSelectedIndexnull53 function GetSelectedIndex : Integer;
54 procedure InitDisplay;
55 protected
56 procedure IndexChanged(Sender: TObject; {%H-}Index: Integer);
57 procedure ListChanged(Sender: TObject; {%H-}Index: Integer);
58 public
59 { public declarations }
60 property SelectedIndex : Integer read GetSelectedIndex;
61 property OnSelectionChanged: TNotifyEvent read fOnSelectionChanged
62 write fOnSelectionChanged;
63 end;
64
65 var
66 JumpHistoryViewWin : TJumpHistoryViewWin = nil;
67
68 implementation
69
70 {$R *.lfm}
71
72 { TJumpHistoryViewWin }
73
74 procedure TJumpHistoryViewWin.FormCreate(Sender : TObject);
75 begin
76 Caption := lisJHJumpHistory;
77 Name := NonModalIDEWindowNames[nmiwJumpHistory];
78 InitDisplay;
79 Application.AddOnIdleHandler(@OnIdle);
80 end;
81
82 procedure TJumpHistoryViewWin.listHistoryClick(Sender : TObject);
83 begin
84 if EnvironmentOptions.MsgViewDblClickJumps then exit;
85 if Assigned(fOnSelectionChanged) then fOnSelectionChanged(self);
86 end;
87
88 procedure TJumpHistoryViewWin.listHistoryDblClick(Sender : TObject);
89 begin
90 if not EnvironmentOptions.MsgViewDblClickJumps then exit;
91 if Assigned(fOnSelectionChanged) then fOnSelectionChanged(self);
92 end;
93
94 procedure TJumpHistoryViewWin.listHistoryKeyPress(Sender: TObject; var Key: char);
95 begin
96 if Key = #13 then begin
97 if Assigned(fOnSelectionChanged) then fOnSelectionChanged(self);
98 end;
99 end;
100
101 procedure TJumpHistoryViewWin.OnIdle(Sender: TObject; var Done: Boolean);
102 begin
103 if (Project1<>nil)
104 and (Project1.JumpHistory.ChangeStamp<>fProjectChangeStamp) then
105 InitDisplay;
106 end;
107
GetSelectedIndexnull108 function TJumpHistoryViewWin.GetSelectedIndex : Integer;
109 begin
110 Result := listHistory.ItemIndex;
111 end;
112
113 procedure TJumpHistoryViewWin.InitDisplay;
114 var
115 i : integer;
116 jh_item : TProjectJumpHistoryPosition;
117 SrcLine, Filename: String;
118 CodeBuf: TCodeBuffer;
119 begin
120 if (Project1<>nil)
121 and (fProjectChangeStamp=Project1.JumpHistory.ChangeStamp) then exit;
122 listHistory.Items.BeginUpdate;
123 listHistory.Clear;
124 if (Project1<>nil) then begin
125 fProjectChangeStamp:=Project1.JumpHistory.ChangeStamp;
126 for i := 0 to Project1.JumpHistory.Count -1 do begin
127 jh_item := Project1.JumpHistory.Items[i];
128 SrcLine:='';
129 CodeBuf:=CodeToolBoss.LoadFile(jh_item.Filename,true,false);
130 if CodeBuf<>nil then
131 SrcLine:=CodeBuf.GetLine(jh_item.CaretXY.Y-1,false);
132 Filename:=jh_item.Filename;
133 if Project1<>nil then
134 Filename:=Project1.GetShortFilename(Filename,true);
135 listHistory.Items.Append(
136 BeautifyLineXY(Filename, SrcLine, jh_item.CaretXY.X, jh_item.CaretXY.Y)
137 );
138 end;
139 //DebugLn(['TJumpHistoryViewWin.InitDisplay Project1.JumpHistory.HistoryIndex=',Project1.JumpHistory.HistoryIndex]);
140 listHistory.ItemIndex := Project1.JumpHistory.HistoryIndex;
141 end;
142 listHistory.Items.EndUpdate;
143 end;
144
145 procedure TJumpHistoryViewWin.IndexChanged(Sender : TObject; Index : Integer);
146 begin
147 listHistory.ItemIndex := Project1.JumpHistory.HistoryIndex;
148 end;
149
150 procedure TJumpHistoryViewWin.ListChanged(Sender : TObject; Index : Integer);
151 begin
152 InitDisplay;
153 end;
154
155 end.
156