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