source: branches/generator/Forms/UFormRule.pas

Last change on this file was 192, checked in by chronos, 6 years ago
  • Modified: Apply interface language to all forms.
File size: 2.9 KB
Line 
1unit UFormRule;
2
3{$mode delphi}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
9 ComCtrls, ActnList, Menus, UGrammer, UFormRuleItems;
10
11type
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
43var
44 FormRule: TFormRule;
45
46
47implementation
48
49{$R *.lfm}
50
51uses
52 UCore;
53
54{ TFormRule }
55
56procedure TFormRule.FormShow(Sender: TObject);
57begin
58 EditName.SetFocus;
59 PageControl1.TabIndex := 0; // Select first tab by default
60 Core.PersistentForm1.Load(Self);
61end;
62
63procedure TFormRule.ListView1Data(Sender: TObject; Item: TListItem);
64begin
65 if Item.Index < UsedByRules.Count then
66 begin
67 Item.Caption := UsedByRules[Item.Index];
68 Item.Data := UsedByRules.Objects[Item.Index];
69 end;
70end;
71
72procedure TFormRule.ReloadUsedByRules;
73begin
74 ListView1.Items.Count := UsedByRules.Count;
75 ListView1.Refresh;
76end;
77
78procedure TFormRule.FormCreate(Sender: TObject);
79var
80 I: TRuleLevel;
81begin
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]);
91end;
92
93procedure TFormRule.FormClose(Sender: TObject; var CloseAction: TCloseAction);
94begin
95 Core.PersistentForm1.Save(Self);
96end;
97
98procedure TFormRule.FormDestroy(Sender: TObject);
99begin
100 FreeAndNil(UsedByRules);
101 FreeAndNil(FormRuleItems);
102end;
103
104procedure TFormRule.LoadData(Rule: TRule);
105begin
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);
113end;
114
115procedure TFormRule.SaveData(Rule: TRule);
116begin
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);
122end;
123
124end.
125
Note: See TracBrowser for help on using the repository browser.