ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/oup/current/Tools/MetaEditor.pas
(Generate patch)

Comparing oup/current/Tools/MetaEditor.pas (file contents):
Revision 213 by alloc, Tue Jun 12 17:00:48 2007 UTC vs.
Revision 231 by alloc, Wed Jun 20 22:24:04 2007 UTC

# Line 1 | Line 1
1   unit MetaEditor;
2 +
3   interface
4 +
5   uses
6    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7 <  Dialogs, VirtualTrees, _MetaManager, StdCtrls;
7 >  Dialogs, _BaseTemplate, ExtCtrls, VirtualTrees, StdCtrls;
8  
9   type
10 <  TForm_Meta = class(TForm)
10 >  TForm_Meta = class(TForm_BaseTemplate)
11      VST: TVirtualStringTree;
12 <    Button1: TButton;
13 <    Label3: TLabel;
12 <    combo_connection: TComboBox;
13 <    procedure FormClose(Sender: TObject; var Action: TCloseAction);
12 >    Panel2: TPanel;
13 >    splitter: TSplitter;
14      procedure FormCreate(Sender: TObject);
15    procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
16      Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
17    procedure Button1Click(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
25    MetaManager: TMetaManager;
31    end;
32  
28 var
29  Form_Meta: TForm_Meta;
33  
34   implementation
32 uses
33  Data, _DataTypes, _FileTypes, ConnectionManager, TypeDefs, StrUtils;
35   {$R *.dfm}
36 + uses _MetaManager, _MetaTypes, ConnectionManager, Data;
37  
38   type
39    PNodeData = ^TNodeData;
# Line 52 | Line 54 | begin
54   end;
55  
56  
57 + procedure TForm_Meta.NewCon(ID: Integer);
58 + var
59 +  i: Integer;
60 +  data: TNodeData;
61 +  node: PVirtualNode;
62 +  Meta: TMetaManager;
63 + begin
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;
81 + end;
82 +
83  
84   procedure TForm_Meta.VSTInitChildren(Sender: TBaseVirtualTree;
85    Node: PVirtualNode; var ChildCount: Cardinal);
# Line 61 | Line 89 | var
89    newnode: PVirtualNode;
90    i: Integer;
91    id: Integer;
92 +  Meta: TMetaManager;
93   begin
94 <  data := VST.GetNodeData(node);
95 <  for i := 0 to MetaManager.FileById[TFile(data.Field).FileID].ChildCount - 1 do
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 := MetaManager.FileById[TFile(data.Field).FileID].LinkByIndex[i].DestID;
99 <    MetaManager.InitFile(id);
100 <    newdata.Field := MetaManager.FileById[id];
101 <    newnode := AddVSTEntry(VST, Node, newdata);
102 <    if MetaManager.FileById[id].ChildCount > 0 then
103 <      VST.HasChildren[newnode] := True;
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 := MetaManager.FileById[TFile(data.Field).FileID].ChildCount;
105 >  ChildCount := Sender.ChildCount[Node];
106   end;
107  
108  
109 < procedure TForm_Meta.Button1Click(Sender: TObject);
109 > procedure TForm_Meta.VSTFocusChanged(Sender: TBaseVirtualTree;
110 >  Node: PVirtualNode; Column: TColumnIndex);
111   var
112 <  name: String;
82 <  conid: Integer;
83 <
84 <  a,b,c: Int64;
85 <  i: Integer;
86 <  data: TNodeData;
87 <  node: PVirtualNode;
112 >  data: PNodeData;
113   begin
114 <  if combo_connection.ItemIndex >= 0 then
114 >  data := Sender.GetNodeData(Node);
115 >  if data.Field is TFile then
116    begin
117 <    name := combo_connection.Items.Strings[combo_connection.ItemIndex];
118 <    conid := StrToInt(MidStr(name, Pos('[', name) + 1, Pos(']', name) - Pos('[', name)  - 1));
93 <
94 <    QueryPerformanceFrequency(c);
95 <    QueryPerformanceCounter(a);
96 <    MetaManager := TMetaManager.Create(conid);
97 <    QueryPerformanceCounter(b);
98 <    ShowMessage('Loading Done - ' + FloatToStr((b-a)/c) + 's');
99 <
100 <    VST.Clear;
101 <    VST.BeginUpdate;
102 <    for i := 0 to MetaManager.FileCount - 1 do
117 >    TFile(data.Field).InitEditor;
118 >    if Assigned(TFile(data.Field).Editor) then
119      begin
120 <      if Assigned(MetaManager.FileById[i]) then
121 <      begin
106 <        data.Field := MetaManager.FileById[i];
107 <        node := AddVSTEntry(VST, nil, data);
108 <        if MetaManager.FileById[i].ChildCount > 0 then
109 <          VST.HasChildren[node] := True;
110 <      end;
120 >      panel2.InsertControl(TFile(data.Field).Editor);
121 >      TFile(data.Field).Opened := True;
122      end;
112    VST.EndUpdate;
123    end;
124   end;
125  
116 procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction);
117 begin
118  MetaManager.Free;
119  Action := caFree;
120 end;
121
126  
127 < procedure TForm_Meta.FormCreate(Sender: TObject);
127 > procedure TForm_Meta.VSTFocusChanging(Sender: TBaseVirtualTree; OldNode,
128 >  NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex;
129 >  var Allowed: Boolean);
130   var
131 +  data: PNodeData;
132    i: Integer;
126
127  fn, datatype, boxstring: String;
128  level: Integer;
133   begin
134 <  combo_connection.ItemIndex := -1;
135 <  combo_connection.Items.Clear;
132 <  if ConManager.Count > 0 then
134 >  data := Sender.GetNodeData(NewNode);
135 >  if data.Field is TFile then
136    begin
137 <    for i := 0 to ConManager.Count - 1 do
138 <    begin
139 <      level := ConManager.ConnectionByIndex[i].LevelNumber;
140 <      fn := ExtractFileName(ConManager.ConnectionByIndex[i].FileName);
141 <      if ConManager.ConnectionByIndex[i].Backend = DB_ONI then
142 <        datatype := 'ONI-.dat: '
143 <      else if ConManager.ConnectionByIndex[i].Backend = DB_ADB then
144 <        datatype := 'OUP-DB: '
145 <      else
146 <        datatype := 'Unknown: ';
144 <      boxstring := datatype + fn + ' (Level: ' + IntToStr(level) + ') [' + IntToStr(ConManager.ConnectionByIndex[i].ConnectionID) + ']';
145 <      combo_connection.Items.Add(boxstring);
146 <    end;
147 <    if combo_connection.ItemIndex = -1 then
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 <      combo_connection.ItemIndex := 0;
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;
152
153
154  VST.NodeDataSize := SizeOf(TNodeData);
155  VST.Font.Charset := AppSettings.CharSet;
156  VST.Clear;
157   end;
158  
159  
160
160   procedure TForm_Meta.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
161    Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
162   var
# Line 172 | Line 171 | begin
171          begin
172            if Data.Field is TFile then
173            begin
174 <            CellText := TFile(Data.Field).FileName;
174 >            CellText := TFile(Data.Field).FileInfo.Name;
175              if CellText = '' then
176                CellText := 'Unnamed';
177            end;
# Line 180 | Line 179 | begin
179        1:
180          begin
181            if Data.Field is TFile then
182 <            CellText := TFile(Data.Field).FileExt;
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).FileID);
187 >            CellText := IntToStr(TFile(Data.Field).FileInfo.ID);
188          end;
189      end;
190    end;
191   end;
192  
193 +
194   procedure TForm_Meta.VSTPaintText(Sender: TBaseVirtualTree;
195    const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
196    TextType: TVSTTextType);
# Line 205 | Line 205 | begin
205          begin
206            if Data.Field is TFile then
207            begin
208 <            if Length(TFile(Data.Field).FileName) = 0 then
208 >            if Length(TFile(Data.Field).FileInfo.Name) = 0 then
209                TargetCanvas.Font.Color := $C06060;
210 <            if TFile(Data.Field).FileSize = 0 then
210 >            if TFile(Data.Field).FileInfo.Size = 0 then
211                TargetCanvas.Font.Color := $2020A0;
212            end;
213          end;
# Line 215 | Line 215 | begin
215    end;
216   end;
217  
218 {
218  
219 < procedure WriteStructureInfos;
220 < var
222 <  i, j:    Integer;
223 <  pdata:   PNodeData;
224 <  Data:    TNodeData;
225 <  node:    PVirtualNode;
219 >
220 > procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction);
221   begin
222 <  VST.BeginUpdate;
223 <  if VST.RootNodeCount = 0 then
229 <  begin
230 <    structs := LoadStructureDefinition(ConID, fileid);
231 <    if structs.Data then
232 <    begin
233 <      if Length(structs.Global) > 0 then
234 <      begin
235 <        for i := 0 to High(structs.Global) do
236 <        begin
237 <          Data.Caption  := structs.Global[i].Name;
238 <          Data.Offset   := structs.Global[i].offset;
239 <          Data.DataType := structs.Global[i].datatype;
240 <          Data.Value    := GetValue(structs.Global[i].datatype, structs.Global[i].offset);
241 <          Data.Description := structs.Global[i].description;
242 <          AddVSTEntry(VST, nil, Data);
243 <        end;
244 <      end;
245 <      if Length(structs.Subs) > 0 then
246 <      begin
247 <        for i := 0 to High(structs.Subs) do
248 <        begin
249 <          with structs.Subs[i] do
250 <          begin
251 <            if Length(Entries) > 0 then
252 <            begin
253 <              if Pos('#', SubName) > 0 then
254 <              begin
255 <                Data.Offset  := StrToInt('$'+MidStr(SubName, Pos('#', SubName) + 1, 8));
256 <                Data.Value   := '$' +
257 <                  MidStr(SubName, PosEx('#', SubName, Pos('#', SubName) + 1) + 1, 8);
258 <                Data.Caption := MidStr(SubName, 1, Pos('#', SubName) - 1);
259 <                Data.Description := SubDesc;
260 <              end
261 <              else
262 <              begin
263 <                Data.Caption := SubName;
264 <                Data.Description := SubDesc;
265 <                Data.Offset := 0;
266 <                Data.Value := '';
267 <              end;
268 <              Data.DataType := 0;
269 <              node := AddVSTEntry(VST, nil, Data);
270 <              Data.Description := '';
271 <              for j := 0 to High(Entries) do
272 <              begin
273 <                Data.Caption  := Entries[j].Name;
274 <                Data.Offset   := Entries[j].offset;
275 <                Data.DataType := Entries[j].datatype;
276 <                Data.Value    := GetValue(Entries[j].datatype, Entries[j].offset);
277 <                Data.Description := Entries[j].description;
278 <                AddVSTEntry(VST, node, Data);
279 <              end;
280 <            end;
281 <          end;
282 <        end;
283 <      end;
284 <    end;
285 <    if VST.RootNodeCount > 0 then
286 <      VST.FocusedNode := VST.GetFirst;
287 <  end
288 <  else
289 <  begin
290 <    Node := VST.GetFirst;
291 <    while Assigned(Node) do
292 <    begin
293 <      pdata := VST.GetNodeData(Node);
294 <      if pdata.DataType > 0 then
295 <        pdata.Value := GetValue(pdata.Datatype, pdata.Offset);
296 <      Node := VST.GetNext(Node);
297 <    end;
298 <  end;
299 <  VST.EndUpdate;
222 > //  Meta.Free;
223 >  inherited;
224   end;
225 < }
225 >
226 > procedure TForm_Meta.FormCreate(Sender: TObject);
227 > begin
228 >  inherited;
229 >  OnNewConnection := NewCon;
230 >
231 >  VST.NodeDataSize := SizeOf(TNodeData);
232 >  VST.Font.Charset := AppSettings.CharSet;
233 >  VST.Clear;
234 >
235 >  UpdateConList;
236 > end;
237 >
238   end.

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)