1 | unit UFormRule;
|
---|
2 |
|
---|
3 | {$mode delphi}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
|
---|
9 | ComCtrls, ActnList, Menus, UGrammer, UFormRuleItems;
|
---|
10 |
|
---|
11 | type
|
---|
12 |
|
---|
13 | { TFormRule }
|
---|
14 |
|
---|
15 | TFormRule = class(TForm)
|
---|
16 | ButtonOk: TButton;
|
---|
17 | ButtonCancel: TButton;
|
---|
18 | CheckBoxCreateNode: TCheckBox;
|
---|
19 | ComboBoxLevel: TComboBox;
|
---|
20 | EditName: TEdit;
|
---|
21 | Label1: TLabel;
|
---|
22 | Label2: TLabel;
|
---|
23 | ListView1: TListView;
|
---|
24 | PageControl1: TPageControl;
|
---|
25 | TabSheet1: TTabSheet;
|
---|
26 | TabSheet2: TTabSheet;
|
---|
27 | TabSheetUsedBy: TTabSheet;
|
---|
28 | procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
---|
29 | procedure FormCreate(Sender: TObject);
|
---|
30 | procedure FormDestroy(Sender: TObject);
|
---|
31 | procedure FormShow(Sender: TObject);
|
---|
32 | procedure ListView1Data(Sender: TObject; Item: TListItem);
|
---|
33 | private
|
---|
34 | FormRuleItems: TFormRuleItems;
|
---|
35 | UsedByRules: TStringList;
|
---|
36 | procedure ReloadUsedByRules;
|
---|
37 | public
|
---|
38 | Rule: TRule;
|
---|
39 | procedure LoadData(Rule: TRule);
|
---|
40 | procedure SaveData(Rule: TRule);
|
---|
41 | end;
|
---|
42 |
|
---|
43 | var
|
---|
44 | FormRule: TFormRule;
|
---|
45 |
|
---|
46 |
|
---|
47 | implementation
|
---|
48 |
|
---|
49 | {$R *.lfm}
|
---|
50 |
|
---|
51 | uses
|
---|
52 | UCore;
|
---|
53 |
|
---|
54 | { TFormRule }
|
---|
55 |
|
---|
56 | procedure TFormRule.FormShow(Sender: TObject);
|
---|
57 | begin
|
---|
58 | EditName.SetFocus;
|
---|
59 | PageControl1.TabIndex := 0; // Select first tab by default
|
---|
60 | Core.PersistentForm1.Load(Self);
|
---|
61 | end;
|
---|
62 |
|
---|
63 | procedure TFormRule.ListView1Data(Sender: TObject; Item: TListItem);
|
---|
64 | begin
|
---|
65 | if Item.Index < UsedByRules.Count then
|
---|
66 | begin
|
---|
67 | Item.Caption := UsedByRules[Item.Index];
|
---|
68 | Item.Data := UsedByRules.Objects[Item.Index];
|
---|
69 | end;
|
---|
70 | end;
|
---|
71 |
|
---|
72 | procedure TFormRule.ReloadUsedByRules;
|
---|
73 | begin
|
---|
74 | ListView1.Items.Count := UsedByRules.Count;
|
---|
75 | ListView1.Refresh;
|
---|
76 | end;
|
---|
77 |
|
---|
78 | procedure TFormRule.FormCreate(Sender: TObject);
|
---|
79 | var
|
---|
80 | I: TRuleLevel;
|
---|
81 | begin
|
---|
82 | Core.CoolTranslator1.TranslateComponentRecursive(Self);
|
---|
83 | FormRuleItems := TFormRuleItems.Create(nil);
|
---|
84 | FormRuleItems.ManualDock(TabSheet1);
|
---|
85 | FormRuleItems.Align := alClient;
|
---|
86 | FormRuleItems.Show;
|
---|
87 | UsedByRules := TStringList.Create;
|
---|
88 | ComboBoxLevel.Items.Clear;
|
---|
89 | for I := Low(TRuleLevel) to High(RuleLevelText) do
|
---|
90 | ComboBoxLevel.Items.Add(RuleLevelText[I]);
|
---|
91 | end;
|
---|
92 |
|
---|
93 | procedure TFormRule.FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
---|
94 | begin
|
---|
95 | Core.PersistentForm1.Save(Self);
|
---|
96 | end;
|
---|
97 |
|
---|
98 | procedure TFormRule.FormDestroy(Sender: TObject);
|
---|
99 | begin
|
---|
100 | FreeAndNil(UsedByRules);
|
---|
101 | FreeAndNil(FormRuleItems);
|
---|
102 | end;
|
---|
103 |
|
---|
104 | procedure TFormRule.LoadData(Rule: TRule);
|
---|
105 | begin
|
---|
106 | Self.Rule := Rule;
|
---|
107 | Rule.Grammer.GetUsedByRule(Rule, UsedByRules);
|
---|
108 | ReloadUsedByRules;
|
---|
109 | EditName.Text := Rule.Name;
|
---|
110 | CheckBoxCreateNode.Checked := Rule.CreateSourceNode;
|
---|
111 | ComboBoxLevel.ItemIndex := Integer(Rule.Level);
|
---|
112 | FormRuleItems.LoadData(Rule.Items);
|
---|
113 | end;
|
---|
114 |
|
---|
115 | procedure TFormRule.SaveData(Rule: TRule);
|
---|
116 | begin
|
---|
117 | Rule.Grammer.Modified := True;
|
---|
118 | Rule.Name := EditName.Text;
|
---|
119 | Rule.CreateSourceNode := CheckBoxCreateNode.Checked;
|
---|
120 | Rule.Level := TRuleLevel(ComboBoxLevel.ItemIndex);
|
---|
121 | FormRuleItems.SaveData(Rule.Items);
|
---|
122 | end;
|
---|
123 |
|
---|
124 | end.
|
---|
125 |
|
---|