[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,
|
---|
[233] | 8 | MPHexEditor, Wrapgrid, VTHeaderPopup, Menus, _TreeElement;
|
---|
[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;
|
---|
[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;
|
---|
[238] | 33 | vst_popup: TPopupMenu;
|
---|
| 34 | vst_newRoot: TMenuItem;
|
---|
| 35 | vst_setRoot: TMenuItem;
|
---|
[209] | 36 | procedure FormCreate(Sender: TObject);
|
---|
[212] | 37 | procedure VSTInitChildren(Sender: TBaseVirtualTree; Node: PVirtualNode;
|
---|
| 38 | var ChildCount: Cardinal);
|
---|
[217] | 39 | procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
[214] | 40 | procedure VSTFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode;
|
---|
| 41 | Column: TColumnIndex);
|
---|
| 42 | procedure VSTFocusChanging(Sender: TBaseVirtualTree; OldNode,
|
---|
| 43 | NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex;
|
---|
| 44 | var Allowed: Boolean);
|
---|
[217] | 45 | procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
|
---|
| 46 | Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
|
---|
| 47 | procedure VSTPaintText(Sender: TBaseVirtualTree;
|
---|
| 48 | const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
|
---|
| 49 | TextType: TVSTTextType);
|
---|
[238] | 50 | procedure VSTGetPopupMenu(Sender: TBaseVirtualTree; Node: PVirtualNode;
|
---|
| 51 | Column: TColumnIndex; const P: TPoint; var AskParent: Boolean;
|
---|
| 52 | var PopupMenu: TPopupMenu);
|
---|
| 53 | procedure vst_setRootClick(Sender: TObject);
|
---|
[239] | 54 | procedure vst_newRootClick(Sender: TObject);
|
---|
[209] | 55 | private
|
---|
[233] | 56 | root: TTreeElement;
|
---|
[217] | 57 | procedure NewCon(ID: Integer);
|
---|
[209] | 58 | public
|
---|
[238] | 59 | procedure SetRoot(TreeElem: TTreeElement);
|
---|
[209] | 60 | end;
|
---|
| 61 |
|
---|
| 62 |
|
---|
| 63 | implementation
|
---|
| 64 | {$R *.dfm}
|
---|
[239] | 65 | uses _MetaManager, _MetaTypes, ConnectionManager, Data, _FileTypes, Main;
|
---|
[209] | 66 |
|
---|
| 67 | type
|
---|
| 68 | PNodeData = ^TNodeData;
|
---|
| 69 |
|
---|
| 70 | TNodeData = record
|
---|
[233] | 71 | Field: TTreeElement;
|
---|
[209] | 72 | end;
|
---|
| 73 |
|
---|
| 74 | function AddVSTEntry(AVST: TCustomVirtualStringTree; ANode: PVirtualNode;
|
---|
| 75 | ARecord: TNodeData): PVirtualNode;
|
---|
| 76 | var
|
---|
| 77 | Data: PNodeData;
|
---|
| 78 | begin
|
---|
| 79 | Result := AVST.AddChild(ANode);
|
---|
| 80 | Data := AVST.GetNodeData(Result);
|
---|
| 81 | AVST.ValidateNode(Result, False);
|
---|
| 82 | Data^ := ARecord;
|
---|
| 83 | end;
|
---|
| 84 |
|
---|
| 85 |
|
---|
[217] | 86 | procedure TForm_Meta.NewCon(ID: Integer);
|
---|
[238] | 87 | begin
|
---|
| 88 | if ID >= 0 then
|
---|
| 89 | SetRoot(ConManager.Connection[FConnectionID].MetaData.Root);
|
---|
| 90 | end;
|
---|
| 91 |
|
---|
| 92 |
|
---|
| 93 | procedure TForm_Meta.SetRoot(TreeElem: TTreeElement);
|
---|
[212] | 94 | var
|
---|
| 95 | i: Integer;
|
---|
| 96 | data: TNodeData;
|
---|
| 97 | node: PVirtualNode;
|
---|
| 98 | begin
|
---|
[238] | 99 | if FConnectionID <> TreeElem.ConnectionID then
|
---|
| 100 | SelectConnection(TreeElem.ConnectionID);
|
---|
| 101 | root := TreeElem;
|
---|
| 102 | VST.Clear;
|
---|
| 103 | VST.BeginUpdate;
|
---|
| 104 | for i := 0 to root.ChildCount - 1 do
|
---|
[212] | 105 | begin
|
---|
[238] | 106 | data.Field := root.Child[i];
|
---|
| 107 | node := AddVSTEntry(VST, nil, data);
|
---|
| 108 | if data.Field.ChildCount > 0 then
|
---|
[232] | 109 | VST.HasChildren[node] := True;
|
---|
[212] | 110 | end;
|
---|
[238] | 111 | VST.EndUpdate;
|
---|
[212] | 112 | end;
|
---|
| 113 |
|
---|
[217] | 114 | procedure TForm_Meta.VSTInitChildren(Sender: TBaseVirtualTree;
|
---|
| 115 | Node: PVirtualNode; var ChildCount: Cardinal);
|
---|
[209] | 116 | var
|
---|
[217] | 117 | data: PNodeData;
|
---|
| 118 | newdata: TNodeData;
|
---|
| 119 | newnode: PVirtualNode;
|
---|
[209] | 120 | i: Integer;
|
---|
[231] | 121 | Meta: TMetaManager;
|
---|
[209] | 122 | begin
|
---|
[231] | 123 | data := Sender.GetNodeData(node);
|
---|
[232] | 124 | Meta := ConManager.Connection[ConnectionID].MetaData;
|
---|
[233] | 125 |
|
---|
| 126 | if data.Field.ChildCount > 0 then
|
---|
[232] | 127 | begin
|
---|
[233] | 128 | for i := 0 to data.Field.ChildCount - 1 do
|
---|
[232] | 129 | begin
|
---|
[233] | 130 | newdata.Field := data.Field.Child[i];
|
---|
[232] | 131 | newnode := AddVSTEntry(TCustomVirtualStringTree(Sender), Node, newdata);
|
---|
[233] | 132 | if newdata.Field.ChildCount > 0 then
|
---|
[232] | 133 | Sender.HasChildren[newnode] := True;
|
---|
| 134 | end;
|
---|
| 135 | end;
|
---|
[231] | 136 | ChildCount := Sender.ChildCount[Node];
|
---|
[209] | 137 | end;
|
---|
| 138 |
|
---|
| 139 |
|
---|
[214] | 140 | procedure TForm_Meta.VSTFocusChanged(Sender: TBaseVirtualTree;
|
---|
| 141 | Node: PVirtualNode; Column: TColumnIndex);
|
---|
| 142 | var
|
---|
| 143 | data: PNodeData;
|
---|
| 144 | begin
|
---|
| 145 | data := Sender.GetNodeData(Node);
|
---|
| 146 | if data.Field is TFile then
|
---|
| 147 | begin
|
---|
| 148 | TFile(data.Field).InitEditor;
|
---|
| 149 | if Assigned(TFile(data.Field).Editor) then
|
---|
| 150 | begin
|
---|
[232] | 151 | TFile(data.Field).Editor.Align := alClient;
|
---|
| 152 | tab_meta.InsertControl(TFile(data.Field).Editor);
|
---|
[214] | 153 | TFile(data.Field).Opened := True;
|
---|
| 154 | end;
|
---|
| 155 | end;
|
---|
| 156 | end;
|
---|
| 157 |
|
---|
[217] | 158 |
|
---|
[214] | 159 | procedure TForm_Meta.VSTFocusChanging(Sender: TBaseVirtualTree; OldNode,
|
---|
| 160 | NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex;
|
---|
| 161 | var Allowed: Boolean);
|
---|
| 162 | var
|
---|
| 163 | data: PNodeData;
|
---|
| 164 | i: Integer;
|
---|
| 165 | begin
|
---|
| 166 | data := Sender.GetNodeData(NewNode);
|
---|
| 167 | if data.Field is TFile then
|
---|
| 168 | begin
|
---|
| 169 | TFile(data.Field).InitEditor;
|
---|
| 170 | if Assigned(TFile(data.Field).Editor) then
|
---|
| 171 | Allowed := not TFile(data.Field).Opened
|
---|
| 172 | else
|
---|
| 173 | Allowed := True;
|
---|
| 174 | end;
|
---|
| 175 | if Allowed and Assigned(OldNode) then
|
---|
| 176 | begin
|
---|
| 177 | data := Sender.GetNodeData(OldNode);
|
---|
| 178 | if data.Field is TFile then
|
---|
| 179 | begin
|
---|
| 180 | if TFile(data.Field).Opened then
|
---|
| 181 | begin
|
---|
[232] | 182 | if tab_meta.ControlCount > 0 then
|
---|
| 183 | for i := 0 to tab_meta.ControlCount - 1 do
|
---|
| 184 | tab_meta.RemoveControl(tab_meta.Controls[i]);
|
---|
[214] | 185 | TFile(data.Field).Opened := False;
|
---|
| 186 | end;
|
---|
| 187 | end;
|
---|
| 188 | end;
|
---|
| 189 | end;
|
---|
| 190 |
|
---|
[217] | 191 |
|
---|
[209] | 192 | procedure TForm_Meta.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
|
---|
| 193 | Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
|
---|
| 194 | var
|
---|
| 195 | Data: PNodeData;
|
---|
| 196 | begin
|
---|
| 197 | Data := Sender.GetNodeData(Node);
|
---|
| 198 | CellText := '';
|
---|
| 199 | if TextType = ttNormal then
|
---|
| 200 | begin
|
---|
| 201 | case Column of
|
---|
[212] | 202 | 0:
|
---|
[209] | 203 | begin
|
---|
[233] | 204 | CellText := Data.Field.GetCaption;
|
---|
[209] | 205 | end;
|
---|
| 206 | 1:
|
---|
[212] | 207 | begin
|
---|
| 208 | if Data.Field is TFile then
|
---|
[231] | 209 | CellText := TFile(Data.Field).FileInfo.Extension;
|
---|
[212] | 210 | end;
|
---|
[209] | 211 | 2:
|
---|
[212] | 212 | begin
|
---|
| 213 | if Data.Field is TFile then
|
---|
[231] | 214 | CellText := IntToStr(TFile(Data.Field).FileInfo.ID);
|
---|
[212] | 215 | end;
|
---|
[236] | 216 | 3:
|
---|
| 217 | begin
|
---|
| 218 | if Data.Field is TDataField then
|
---|
| 219 | CellText := TDataField(Data.Field).ValueAsString;
|
---|
| 220 | end;
|
---|
[212] | 221 | end;
|
---|
[209] | 222 | end;
|
---|
| 223 | end;
|
---|
| 224 |
|
---|
[217] | 225 |
|
---|
[212] | 226 | procedure TForm_Meta.VSTPaintText(Sender: TBaseVirtualTree;
|
---|
| 227 | const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
|
---|
| 228 | TextType: TVSTTextType);
|
---|
| 229 | var
|
---|
| 230 | Data: PNodeData;
|
---|
| 231 | begin
|
---|
| 232 | Data := Sender.GetNodeData(Node);
|
---|
| 233 | if TextType = ttNormal then
|
---|
| 234 | begin
|
---|
| 235 | case Column of
|
---|
| 236 | 0:
|
---|
| 237 | begin
|
---|
| 238 | if Data.Field is TFile then
|
---|
[213] | 239 | begin
|
---|
[231] | 240 | if Length(TFile(Data.Field).FileInfo.Name) = 0 then
|
---|
[213] | 241 | TargetCanvas.Font.Color := $C06060;
|
---|
[231] | 242 | if TFile(Data.Field).FileInfo.Size = 0 then
|
---|
[213] | 243 | TargetCanvas.Font.Color := $2020A0;
|
---|
| 244 | end;
|
---|
[212] | 245 | end;
|
---|
| 246 | end;
|
---|
| 247 | end;
|
---|
| 248 | end;
|
---|
| 249 |
|
---|
[209] | 250 |
|
---|
[217] | 251 |
|
---|
[238] | 252 | procedure TForm_Meta.VSTGetPopupMenu(Sender: TBaseVirtualTree;
|
---|
| 253 | Node: PVirtualNode; Column: TColumnIndex; const P: TPoint;
|
---|
| 254 | var AskParent: Boolean; var PopupMenu: TPopupMenu);
|
---|
| 255 | var
|
---|
| 256 | data: PNodeData;
|
---|
| 257 | begin
|
---|
| 258 | inherited;
|
---|
| 259 | AskParent := False;
|
---|
| 260 | if Assigned(Node) then
|
---|
| 261 | begin
|
---|
| 262 | Sender.Selected[Node] := True;
|
---|
| 263 | Sender.FocusedNode := Node;
|
---|
| 264 | data := Sender.GetNodeData(Node);
|
---|
| 265 | if Column = 0 then
|
---|
| 266 | begin
|
---|
| 267 | if TTreeElement(data.Field).GetChildCount > 0 then
|
---|
| 268 | PopupMenu := vst_popup
|
---|
| 269 | else
|
---|
| 270 | PopupMenu := nil;
|
---|
| 271 | end;
|
---|
| 272 | end;
|
---|
| 273 | end;
|
---|
| 274 |
|
---|
[239] | 275 | procedure TForm_Meta.vst_newRootClick(Sender: TObject);
|
---|
| 276 | var
|
---|
| 277 | data: PNodeData;
|
---|
| 278 | form: TForm_BaseTemplate;
|
---|
| 279 | begin
|
---|
| 280 | inherited;
|
---|
| 281 | data := VST.GetNodeData(VST.FocusedNode);
|
---|
| 282 | form := nil;
|
---|
| 283 | form := Form_Main.open_child('meta');
|
---|
| 284 | if form is TForm_Meta then
|
---|
| 285 | TForm_Meta(form).SetRoot(data.Field);
|
---|
| 286 | end;
|
---|
| 287 |
|
---|
[238] | 288 | procedure TForm_Meta.vst_setRootClick(Sender: TObject);
|
---|
| 289 | var
|
---|
| 290 | data: PNodeData;
|
---|
| 291 | begin
|
---|
| 292 | inherited;
|
---|
| 293 | data := VST.GetNodeData(VST.FocusedNode);
|
---|
| 294 | SetRoot(data.Field);
|
---|
| 295 | end;
|
---|
| 296 |
|
---|
[217] | 297 | procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
[209] | 298 | begin
|
---|
[229] | 299 | // Meta.Free;
|
---|
[217] | 300 | inherited;
|
---|
[209] | 301 | end;
|
---|
[217] | 302 |
|
---|
| 303 | procedure TForm_Meta.FormCreate(Sender: TObject);
|
---|
| 304 | begin
|
---|
| 305 | inherited;
|
---|
| 306 | OnNewConnection := NewCon;
|
---|
| 307 |
|
---|
| 308 | VST.NodeDataSize := SizeOf(TNodeData);
|
---|
| 309 | VST.Font.Charset := AppSettings.CharSet;
|
---|
| 310 | VST.Clear;
|
---|
| 311 |
|
---|
| 312 | UpdateConList;
|
---|
| 313 | end;
|
---|
| 314 |
|
---|
[209] | 315 | end.
|
---|