-
Notifications
You must be signed in to change notification settings - Fork 2
/
AddKeywords.pas
76 lines (62 loc) · 1.9 KB
/
AddKeywords.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
{
shows an input for a keyword's EDID.
if the keyword exists, it will be added to the objects the scripts runs on
}
unit userscript;
uses praUtil;
var
keyword: IInterface;
function findRecord(edid, sig: string): IInterface;
var
i: integer;
curFile: IwbFile;
group, elem: IInterface;
begin
Result := nil;
for i := 0 to FileCount-1 do
begin
curFile := FileByIndex(i);
group := GroupBySignature(curFile, sig);
if(assigned(group)) then begin
elem := MainRecordByEditorID(group, edid);
if(assigned(elem)) then begin
Result := elem;
exit;
end;
end;
end;
end;
// Called before processing
// You can remove it if script doesn't require initialization code
function Initialize: integer;
var
edid: string;
begin
if(not InputQuery('AddKeyword', 'Input Search keyword EDID', edid)) then begin
Result := 1;
exit;
end;
keyword := findRecord(edid, 'KYWD');
if(not assigned(keyword)) then begin
AddMessage('Could not find keyword '+edid);
Result := 1;
exit;
end;
Result := 0;
end;
// called for every record selected in xEdit
function Process(e: IInterface): integer;
begin
Result := 0;
if(not hasKeywordByPath(e, keyword, 'KWDA')) then begin
addKeywordByPath(e, keyword, 'KWDA');
end;
// processing code goes here
end;
// Called after processing
// You can remove it if script doesn't require finalization code
function Finalize: integer;
begin
Result := 0;
end;
end.