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

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