forked from TES5Edit/TES5Edit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmLocalizationForm.pas
211 lines (186 loc) · 5.57 KB
/
frmLocalizationForm.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
unit frmLocalizationForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, VirtualTrees, VirtualEditTree, ExtDlgs, Menus;
type
TfrmLocalization = class(TForm)
Panel1: TPanel;
vetStrings: TVirtualEditTree;
Panel2: TPanel;
Splitter1: TSplitter;
memoText: TMemo;
pnlControls: TPanel;
btnSave: TButton;
pmuStrings: TPopupMenu;
mniFileExport: TMenuItem;
mniFileImport: TMenuItem;
dlgExport: TSaveTextFileDialog;
procedure vetStringsInitNode(Sender: TBaseVirtualTree; ParentNode,
Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
procedure vetStringsInitChildren(Sender: TBaseVirtualTree;
Node: PVirtualNode; var ChildCount: Cardinal);
procedure vetStringsGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);
procedure FormCreate(Sender: TObject);
procedure vetStringsChange(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure btnSaveClick(Sender: TObject);
procedure vetStringsPaintText(Sender: TBaseVirtualTree;
const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
TextType: TVSTTextType);
procedure memoTextChange(Sender: TObject);
procedure pmuStringsPopup(Sender: TObject);
procedure mniFileExportClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure EditValue(aFileName: string; ID: integer);
end;
var
frmLocalization: TfrmLocalization;
implementation
{$R *.dfm}
uses
wbLocalization;
type
TTreeData = record
lFile: TwbLocalizationFile;
ID: Cardinal;
end;
PTreeData = ^TTreeData;
procedure TfrmLocalization.FormCreate(Sender: TObject);
begin
vetStrings.NodeDataSize := SizeOf(TTreeData);
vetStrings.RootNodeCount := wbLocalizationHandler.Count;
pnlControls.Visible := false;
end;
procedure TfrmLocalization.memoTextChange(Sender: TObject);
begin
if memoText.Modified and (vetStrings.FocusedNode.Parent <> vetStrings.RootNode) then
pnlControls.Visible := true;
end;
procedure TfrmLocalization.mniFileExportClick(Sender: TObject);
var
Data: PTreeData;
begin
Data := vetStrings.GetNodeData(vetStrings.FocusedNode);
dlgExport.FileName := Data.lFile.Name + '.txt';
if not dlgExport.Execute then
Exit;
Data.lFile.ExportToFile(dlgExport.FileName);
end;
procedure TfrmLocalization.pmuStringsPopup(Sender: TObject);
//var
// Data: PTreeData;
begin
{Data :=} vetStrings.GetNodeData(vetStrings.FocusedNode);
mniFileExport.Visible := vetStrings.FocusedNode.Parent = vetStrings.RootNode;
end;
procedure TfrmLocalization.vetStringsChange(Sender: TBaseVirtualTree;
Node: PVirtualNode);
var
Data: PTreeData;
begin
Data := Sender.GetNodeData(Node);
if not Assigned(Data) then Exit;
if Data.ID = 0 then
memoText.Lines.Clear
else
memoText.Lines.Text := Data.lFile[Data.ID];
pnlControls.Visible := false;
end;
procedure TfrmLocalization.vetStringsGetText(Sender: TBaseVirtualTree;
Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
var CellText: string);
var
Data: PTreeData;
begin
Data := Sender.GetNodeData(Node);
case Column of
0: begin
if Data.ID > 0 then
CellText := IntToHex(Data.ID, 8)
else
CellText := Data.lFile.Name;
end;
1: begin
if Data.ID > 0 then
CellText := Data.lFile[Data.ID]
else
CellText := '';
end;
end;
end;
procedure TfrmLocalization.vetStringsInitChildren(Sender: TBaseVirtualTree;
Node: PVirtualNode; var ChildCount: Cardinal);
var
Data: PTreeData;
begin
Data := Sender.GetNodeData(Node);
if Data.ID = 0 then
ChildCount := Data.lFile.Count
else
ChildCount := 0;
end;
procedure TfrmLocalization.vetStringsInitNode(Sender: TBaseVirtualTree;
ParentNode, Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
var
Data: PTreeData;
begin
Data := Sender.GetNodeData(Node);
if ParentNode = nil then begin
Data.ID := 0;
Data.lFile := wbLocalizationHandler[Node.Index];
if Data.lFile.Count > 0 then
Include(InitialStates, ivsHasChildren);
end else begin
Data.lFile := PTreeData(Sender.GetNodeData(Node.Parent)).lFile;
Data.ID := Data.lFile.IndexToID(Node.Index);
end;
end;
procedure TfrmLocalization.vetStringsPaintText(Sender: TBaseVirtualTree;
const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
TextType: TVSTTextType);
var
Data: PTreeData;
begin
if Node.Parent <> Sender.RootNode then
Exit;
TargetCanvas.Font.Color := clWindowText;
Data := Sender.GetNodeData(Node);
if Assigned(Data) then
if Data.lFile.Modified then
TargetCanvas.Font.Style := [fsBold];
end;
procedure TfrmLocalization.btnSaveClick(Sender: TObject);
var
Data: PTreeData;
begin
Data := vetStrings.GetNodeData(vetStrings.FocusedNode);
Data.lFile[Data.ID] := memoText.Lines.Text;
memoText.Modified := false;
pnlControls.Visible := false;
vetStrings.Invalidate;
end;
procedure TfrmLocalization.EditValue(aFileName: string; ID: integer);
var
Data: PTreeData;
Node: PVirtualNode;
s: string;
begin
s := ChangeFileExt(aFileName, '') + '_';
Node := vetStrings.GetFirst;
while Assigned(Node) do begin
Data := vetStrings.GetNodeData(Node);
if Data.ID = ID then
if s = Copy(Data.lFile.Name , 0, length(s)) then begin
vetStrings.FocusedNode := Node;
vetStrings.Selected[vetStrings.FocusedNode] := True;
vetStrings.ScrollIntoView(Node, True);
Exit;
end;
Node := vetStrings.GetNext(Node);
end;
end;
end.