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