[209] | 1 | unit MetaEditor;
|
---|
[217] | 2 |
|
---|
[209] | 3 | interface
|
---|
[217] | 4 |
|
---|
[209] | 5 | uses
|
---|
| 6 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
---|
[232] | 7 | Dialogs, _BaseTemplate, ExtCtrls, VirtualTrees, StdCtrls, ComCtrls, Grids,
|
---|
| 8 | MPHexEditor, Wrapgrid;
|
---|
[209] | 9 |
|
---|
| 10 | type
|
---|
[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;
|
---|
[209] | 23 | procedure FormCreate(Sender: TObject);
|
---|
[212] | 24 | procedure VSTInitChildren(Sender: TBaseVirtualTree; Node: PVirtualNode;
|
---|
| 25 | var ChildCount: Cardinal);
|
---|
[217] | 26 | procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
[214] | 27 | procedure VSTFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode;
|
---|
| 28 | Column: TColumnIndex);
|
---|
| 29 | procedure VSTFocusChanging(Sender: TBaseVirtualTree; OldNode,
|
---|
| 30 | NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex;
|
---|
| 31 | var Allowed: Boolean);
|
---|
[217] | 32 | procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
|
---|
| 33 | Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
|
---|
| 34 | procedure VSTPaintText(Sender: TBaseVirtualTree;
|
---|
| 35 | const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
|
---|
| 36 | TextType: TVSTTextType);
|
---|
[209] | 37 | private
|
---|
[217] | 38 | procedure NewCon(ID: Integer);
|
---|
[209] | 39 | public
|
---|
| 40 | end;
|
---|
| 41 |
|
---|
| 42 |
|
---|
| 43 | implementation
|
---|
| 44 | {$R *.dfm}
|
---|
[232] | 45 | uses _MetaManager, _MetaTypes, ConnectionManager, Data, _FileTypes;
|
---|
[209] | 46 |
|
---|
| 47 | type
|
---|
| 48 | PNodeData = ^TNodeData;
|
---|
| 49 |
|
---|
| 50 | TNodeData = record
|
---|
| 51 | Field: TObject;
|
---|
| 52 | end;
|
---|
| 53 |
|
---|
| 54 | function AddVSTEntry(AVST: TCustomVirtualStringTree; ANode: PVirtualNode;
|
---|
| 55 | ARecord: TNodeData): PVirtualNode;
|
---|
| 56 | var
|
---|
| 57 | Data: PNodeData;
|
---|
| 58 | begin
|
---|
| 59 | Result := AVST.AddChild(ANode);
|
---|
| 60 | Data := AVST.GetNodeData(Result);
|
---|
| 61 | AVST.ValidateNode(Result, False);
|
---|
| 62 | Data^ := ARecord;
|
---|
| 63 | end;
|
---|
| 64 |
|
---|
| 65 |
|
---|
[217] | 66 | procedure TForm_Meta.NewCon(ID: Integer);
|
---|
[212] | 67 | var
|
---|
| 68 | i: Integer;
|
---|
| 69 | data: TNodeData;
|
---|
| 70 | node: PVirtualNode;
|
---|
[231] | 71 | Meta: TMetaManager;
|
---|
[232] | 72 | root: TExtensions;
|
---|
[212] | 73 | begin
|
---|
[217] | 74 | if ID >= 0 then
|
---|
[212] | 75 | begin
|
---|
[232] | 76 | //VST
|
---|
[212] | 77 | VST.Clear;
|
---|
| 78 | VST.BeginUpdate;
|
---|
[232] | 79 | root := ConManager.Connection[FConnectionID].MetaData.Root;
|
---|
| 80 | for i := 0 to High(root) do
|
---|
[212] | 81 | begin
|
---|
[232] | 82 | data.Field := root[i];
|
---|
| 83 | node := AddVSTEntry(VST, nil, data);
|
---|
| 84 | VST.HasChildren[node] := True;
|
---|
[212] | 85 | end;
|
---|
| 86 | VST.EndUpdate;
|
---|
| 87 | end;
|
---|
| 88 | end;
|
---|
| 89 |
|
---|
[209] | 90 |
|
---|
[217] | 91 | procedure TForm_Meta.VSTInitChildren(Sender: TBaseVirtualTree;
|
---|
| 92 | Node: PVirtualNode; var ChildCount: Cardinal);
|
---|
[209] | 93 | var
|
---|
[217] | 94 | data: PNodeData;
|
---|
| 95 | newdata: TNodeData;
|
---|
| 96 | newnode: PVirtualNode;
|
---|
[209] | 97 | i: Integer;
|
---|
[217] | 98 | id: Integer;
|
---|
[231] | 99 | Meta: TMetaManager;
|
---|
[209] | 100 | begin
|
---|
[231] | 101 | data := Sender.GetNodeData(node);
|
---|
[232] | 102 | Meta := ConManager.Connection[ConnectionID].MetaData;
|
---|
| 103 | if data.Field is TFile then
|
---|
[212] | 104 | begin
|
---|
[232] | 105 | if TFile(data.Field).ChildCount > 0 then
|
---|
| 106 | begin
|
---|
| 107 | for i := 0 to TFile(data.Field).ChildCount - 1 do
|
---|
| 108 | begin
|
---|
| 109 | id := TFile(data.Field).LinkByIndex[i].DestID;
|
---|
| 110 | Meta.InitFile(id);
|
---|
| 111 | newdata.Field := Meta.FileById[id];
|
---|
| 112 | newnode := AddVSTEntry(TCustomVirtualStringTree(Sender), Node, newdata);
|
---|
| 113 | if Meta.FileById[id].ChildCount > 0 then
|
---|
| 114 | Sender.HasChildren[newnode] := True;
|
---|
| 115 | end;
|
---|
| 116 | end;
|
---|
| 117 | if TFile(data.Field).RawCount > 0 then
|
---|
| 118 | begin
|
---|
| 119 | for i := 0 to TFile(data.Field).RawCount - 1 do
|
---|
| 120 | begin
|
---|
| 121 | // Exit;
|
---|
| 122 | end;
|
---|
| 123 | end;
|
---|
[212] | 124 | end;
|
---|
[232] | 125 | if data.Field is TExtension then
|
---|
| 126 | begin
|
---|
| 127 | if TExtension(data.Field).FileCount = 0 then
|
---|
| 128 | TExtension(data.Field).InitList;
|
---|
| 129 | for i := 0 to TExtension(data.Field).FileCount - 1 do
|
---|
| 130 | begin
|
---|
| 131 | id := TExtension(data.Field).Files[i];
|
---|
| 132 | Meta.InitFile(id);
|
---|
| 133 | newdata.Field := Meta.FileById[id];
|
---|
| 134 | newnode := AddVSTEntry(TCustomVirtualStringTree(Sender), Node, newdata);
|
---|
| 135 | if Meta.FileById[id].ChildCount > 0 then
|
---|
| 136 | Sender.HasChildren[newnode] := True;
|
---|
| 137 | end;
|
---|
| 138 | end;
|
---|
[231] | 139 | ChildCount := Sender.ChildCount[Node];
|
---|
[209] | 140 | end;
|
---|
| 141 |
|
---|
| 142 |
|
---|
[214] | 143 | procedure TForm_Meta.VSTFocusChanged(Sender: TBaseVirtualTree;
|
---|
| 144 | Node: PVirtualNode; Column: TColumnIndex);
|
---|
| 145 | var
|
---|
| 146 | data: PNodeData;
|
---|
| 147 | begin
|
---|
| 148 | data := Sender.GetNodeData(Node);
|
---|
| 149 | if data.Field is TFile then
|
---|
| 150 | begin
|
---|
| 151 | TFile(data.Field).InitEditor;
|
---|
| 152 | if Assigned(TFile(data.Field).Editor) then
|
---|
| 153 | begin
|
---|
[232] | 154 | TFile(data.Field).Editor.Align := alClient;
|
---|
| 155 | tab_meta.InsertControl(TFile(data.Field).Editor);
|
---|
[214] | 156 | TFile(data.Field).Opened := True;
|
---|
| 157 | end;
|
---|
| 158 | end;
|
---|
| 159 | end;
|
---|
| 160 |
|
---|
[217] | 161 |
|
---|
[214] | 162 | procedure TForm_Meta.VSTFocusChanging(Sender: TBaseVirtualTree; OldNode,
|
---|
| 163 | NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex;
|
---|
| 164 | var Allowed: Boolean);
|
---|
| 165 | var
|
---|
| 166 | data: PNodeData;
|
---|
| 167 | i: Integer;
|
---|
| 168 | begin
|
---|
| 169 | data := Sender.GetNodeData(NewNode);
|
---|
| 170 | if data.Field is TFile then
|
---|
| 171 | begin
|
---|
| 172 | TFile(data.Field).InitEditor;
|
---|
| 173 | if Assigned(TFile(data.Field).Editor) then
|
---|
| 174 | Allowed := not TFile(data.Field).Opened
|
---|
| 175 | else
|
---|
| 176 | Allowed := True;
|
---|
| 177 | end;
|
---|
| 178 | if Allowed and Assigned(OldNode) then
|
---|
| 179 | begin
|
---|
| 180 | data := Sender.GetNodeData(OldNode);
|
---|
| 181 | if data.Field is TFile then
|
---|
| 182 | begin
|
---|
| 183 | if TFile(data.Field).Opened then
|
---|
| 184 | begin
|
---|
[232] | 185 | if tab_meta.ControlCount > 0 then
|
---|
| 186 | for i := 0 to tab_meta.ControlCount - 1 do
|
---|
| 187 | tab_meta.RemoveControl(tab_meta.Controls[i]);
|
---|
[214] | 188 | TFile(data.Field).Opened := False;
|
---|
| 189 | end;
|
---|
| 190 | end;
|
---|
| 191 | end;
|
---|
| 192 | end;
|
---|
| 193 |
|
---|
[217] | 194 |
|
---|
[209] | 195 | procedure TForm_Meta.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
|
---|
| 196 | Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
|
---|
| 197 | var
|
---|
| 198 | Data: PNodeData;
|
---|
| 199 | begin
|
---|
| 200 | Data := Sender.GetNodeData(Node);
|
---|
| 201 | CellText := '';
|
---|
| 202 | if TextType = ttNormal then
|
---|
| 203 | begin
|
---|
| 204 | case Column of
|
---|
[212] | 205 | 0:
|
---|
[209] | 206 | begin
|
---|
[212] | 207 | if Data.Field is TFile then
|
---|
| 208 | begin
|
---|
[231] | 209 | CellText := TFile(Data.Field).FileInfo.Name;
|
---|
[212] | 210 | if CellText = '' then
|
---|
| 211 | CellText := 'Unnamed';
|
---|
| 212 | end;
|
---|
[232] | 213 | if Data.Field is TExtension then
|
---|
| 214 | CellText := TExtension(Data.Field).Ext;
|
---|
[209] | 215 | end;
|
---|
| 216 | 1:
|
---|
[212] | 217 | begin
|
---|
| 218 | if Data.Field is TFile then
|
---|
[231] | 219 | CellText := TFile(Data.Field).FileInfo.Extension;
|
---|
[212] | 220 | end;
|
---|
[209] | 221 | 2:
|
---|
[212] | 222 | begin
|
---|
| 223 | if Data.Field is TFile then
|
---|
[231] | 224 | CellText := IntToStr(TFile(Data.Field).FileInfo.ID);
|
---|
[212] | 225 | end;
|
---|
| 226 | end;
|
---|
[209] | 227 | end;
|
---|
| 228 | end;
|
---|
| 229 |
|
---|
[217] | 230 |
|
---|
[212] | 231 | procedure TForm_Meta.VSTPaintText(Sender: TBaseVirtualTree;
|
---|
| 232 | const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
|
---|
| 233 | TextType: TVSTTextType);
|
---|
| 234 | var
|
---|
| 235 | Data: PNodeData;
|
---|
| 236 | begin
|
---|
| 237 | Data := Sender.GetNodeData(Node);
|
---|
| 238 | if TextType = ttNormal then
|
---|
| 239 | begin
|
---|
| 240 | case Column of
|
---|
| 241 | 0:
|
---|
| 242 | begin
|
---|
| 243 | if Data.Field is TFile then
|
---|
[213] | 244 | begin
|
---|
[231] | 245 | if Length(TFile(Data.Field).FileInfo.Name) = 0 then
|
---|
[213] | 246 | TargetCanvas.Font.Color := $C06060;
|
---|
[231] | 247 | if TFile(Data.Field).FileInfo.Size = 0 then
|
---|
[213] | 248 | TargetCanvas.Font.Color := $2020A0;
|
---|
| 249 | end;
|
---|
[212] | 250 | end;
|
---|
| 251 | end;
|
---|
| 252 | end;
|
---|
| 253 | end;
|
---|
| 254 |
|
---|
[209] | 255 |
|
---|
[217] | 256 |
|
---|
| 257 | procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
[209] | 258 | begin
|
---|
[229] | 259 | // Meta.Free;
|
---|
[217] | 260 | inherited;
|
---|
[209] | 261 | end;
|
---|
[217] | 262 |
|
---|
| 263 | procedure TForm_Meta.FormCreate(Sender: TObject);
|
---|
| 264 | begin
|
---|
| 265 | inherited;
|
---|
| 266 | OnNewConnection := NewCon;
|
---|
| 267 |
|
---|
| 268 | VST.NodeDataSize := SizeOf(TNodeData);
|
---|
| 269 | VST.Font.Charset := AppSettings.CharSet;
|
---|
| 270 | VST.Clear;
|
---|
| 271 |
|
---|
| 272 | UpdateConList;
|
---|
| 273 | end;
|
---|
| 274 |
|
---|
[209] | 275 | end.
|
---|