source: oup/current/Tools/MetaEditor.pas@ 231

Last change on this file since 231 was 231, checked in by alloc, 17 years ago
File size: 6.0 KB
Line 
1unit MetaEditor;
2
3interface
4
5uses
6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7 Dialogs, _BaseTemplate, ExtCtrls, VirtualTrees, StdCtrls;
8
9type
10 TForm_Meta = class(TForm_BaseTemplate)
11 VST: TVirtualStringTree;
12 Panel2: TPanel;
13 splitter: TSplitter;
14 procedure FormCreate(Sender: TObject);
15 procedure VSTInitChildren(Sender: TBaseVirtualTree; Node: PVirtualNode;
16 var ChildCount: Cardinal);
17 procedure FormClose(Sender: TObject; var Action: TCloseAction);
18 procedure VSTFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode;
19 Column: TColumnIndex);
20 procedure VSTFocusChanging(Sender: TBaseVirtualTree; OldNode,
21 NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex;
22 var Allowed: Boolean);
23 procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
24 Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
25 procedure VSTPaintText(Sender: TBaseVirtualTree;
26 const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
27 TextType: TVSTTextType);
28 private
29 procedure NewCon(ID: Integer);
30 public
31 end;
32
33
34implementation
35{$R *.dfm}
36uses _MetaManager, _MetaTypes, ConnectionManager, Data;
37
38type
39 PNodeData = ^TNodeData;
40
41 TNodeData = record
42 Field: TObject;
43 end;
44
45function AddVSTEntry(AVST: TCustomVirtualStringTree; ANode: PVirtualNode;
46 ARecord: TNodeData): PVirtualNode;
47var
48 Data: PNodeData;
49begin
50 Result := AVST.AddChild(ANode);
51 Data := AVST.GetNodeData(Result);
52 AVST.ValidateNode(Result, False);
53 Data^ := ARecord;
54end;
55
56
57procedure TForm_Meta.NewCon(ID: Integer);
58var
59 i: Integer;
60 data: TNodeData;
61 node: PVirtualNode;
62 Meta: TMetaManager;
63begin
64 if ID >= 0 then
65 begin
66 VST.Clear;
67 VST.BeginUpdate;
68 Meta := ConManager.Connection[ID].MetaData;
69 for i := 0 to Meta.FileCount - 1 do
70 begin
71 if Assigned(Meta.FileById[i]) then
72 begin
73 data.Field := Meta.FileById[i];
74 node := AddVSTEntry(VST, nil, data);
75 if Meta.FileById[i].ChildCount > 0 then
76 VST.HasChildren[node] := True;
77 end;
78 end;
79 VST.EndUpdate;
80 end;
81end;
82
83
84procedure TForm_Meta.VSTInitChildren(Sender: TBaseVirtualTree;
85 Node: PVirtualNode; var ChildCount: Cardinal);
86var
87 data: PNodeData;
88 newdata: TNodeData;
89 newnode: PVirtualNode;
90 i: Integer;
91 id: Integer;
92 Meta: TMetaManager;
93begin
94 data := Sender.GetNodeData(node);
95 Meta := ConManager.Connection[ID].MetaData;
96 for i := 0 to TFile(data.Field).ChildCount - 1 do
97 begin
98 id := TFile(data.Field).LinkByIndex[i].DestID;
99 Meta.InitFile(id);
100 newdata.Field := Meta.FileById[id];
101 newnode := AddVSTEntry(TCustomVirtualStringTree(Sender), Node, newdata);
102 if Meta.FileById[id].ChildCount > 0 then
103 Sender.HasChildren[newnode] := True;
104 end;
105 ChildCount := Sender.ChildCount[Node];
106end;
107
108
109procedure TForm_Meta.VSTFocusChanged(Sender: TBaseVirtualTree;
110 Node: PVirtualNode; Column: TColumnIndex);
111var
112 data: PNodeData;
113begin
114 data := Sender.GetNodeData(Node);
115 if data.Field is TFile then
116 begin
117 TFile(data.Field).InitEditor;
118 if Assigned(TFile(data.Field).Editor) then
119 begin
120 panel2.InsertControl(TFile(data.Field).Editor);
121 TFile(data.Field).Opened := True;
122 end;
123 end;
124end;
125
126
127procedure TForm_Meta.VSTFocusChanging(Sender: TBaseVirtualTree; OldNode,
128 NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex;
129 var Allowed: Boolean);
130var
131 data: PNodeData;
132 i: Integer;
133begin
134 data := Sender.GetNodeData(NewNode);
135 if data.Field is TFile then
136 begin
137 TFile(data.Field).InitEditor;
138 if Assigned(TFile(data.Field).Editor) then
139 Allowed := not TFile(data.Field).Opened
140 else
141 Allowed := True;
142 end;
143 if Allowed and Assigned(OldNode) then
144 begin
145 data := Sender.GetNodeData(OldNode);
146 if data.Field is TFile then
147 begin
148 if TFile(data.Field).Opened then
149 begin
150 if panel2.ControlCount > 0 then
151 for i := 0 to panel2.ControlCount - 1 do
152 panel2.RemoveControl(panel2.Controls[i]);
153 TFile(data.Field).Opened := False;
154 end;
155 end;
156 end;
157end;
158
159
160procedure TForm_Meta.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
161 Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
162var
163 Data: PNodeData;
164begin
165 Data := Sender.GetNodeData(Node);
166 CellText := '';
167 if TextType = ttNormal then
168 begin
169 case Column of
170 0:
171 begin
172 if Data.Field is TFile then
173 begin
174 CellText := TFile(Data.Field).FileInfo.Name;
175 if CellText = '' then
176 CellText := 'Unnamed';
177 end;
178 end;
179 1:
180 begin
181 if Data.Field is TFile then
182 CellText := TFile(Data.Field).FileInfo.Extension;
183 end;
184 2:
185 begin
186 if Data.Field is TFile then
187 CellText := IntToStr(TFile(Data.Field).FileInfo.ID);
188 end;
189 end;
190 end;
191end;
192
193
194procedure TForm_Meta.VSTPaintText(Sender: TBaseVirtualTree;
195 const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
196 TextType: TVSTTextType);
197var
198 Data: PNodeData;
199begin
200 Data := Sender.GetNodeData(Node);
201 if TextType = ttNormal then
202 begin
203 case Column of
204 0:
205 begin
206 if Data.Field is TFile then
207 begin
208 if Length(TFile(Data.Field).FileInfo.Name) = 0 then
209 TargetCanvas.Font.Color := $C06060;
210 if TFile(Data.Field).FileInfo.Size = 0 then
211 TargetCanvas.Font.Color := $2020A0;
212 end;
213 end;
214 end;
215 end;
216end;
217
218
219
220procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction);
221begin
222// Meta.Free;
223 inherited;
224end;
225
226procedure TForm_Meta.FormCreate(Sender: TObject);
227begin
228 inherited;
229 OnNewConnection := NewCon;
230
231 VST.NodeDataSize := SizeOf(TNodeData);
232 VST.Font.Charset := AppSettings.CharSet;
233 VST.Clear;
234
235 UpdateConList;
236end;
237
238end.
Note: See TracBrowser for help on using the repository browser.