source: branches/generator/Forms/UFormRuleItem.pas

Last change on this file was 192, checked in by chronos, 6 years ago
  • Modified: Apply interface language to all forms.
File size: 6.3 KB
Line 
1unit UFormRuleItem;
2
3{$mode delphi}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
9 ComCtrls, UGrammer;
10
11type
12
13 { TFormRuleItem }
14
15 TFormRuleItem = class(TForm)
16 ButtonCancel: TButton;
17 ButtonOk: TButton;
18 CheckBoxLookupTable: TCheckBox;
19 CheckBoxAnyExcept: TCheckBox;
20 CheckBoxEscapedString: TCheckBox;
21 CheckBoxOptional: TCheckBox;
22 CheckBoxRepetitive: TCheckBox;
23 ComboBoxLookupTableAction: TComboBox;
24 ComboBoxType: TComboBox;
25 EditTerminal: TEdit;
26 EditTerminalFrom: TEdit;
27 EditTerminalTo: TEdit;
28 Label1: TLabel;
29 Label2: TLabel;
30 LabelNonTerminal: TLabel;
31 LabelTerminal: TLabel;
32 LabelTerminal1: TLabel;
33 LabelTerminal2: TLabel;
34 ListBoxNonTerminals: TListBox;
35 ListBoxLookupTable: TListBox;
36 PageControl1: TPageControl;
37 TabSheetTerminalRange: TTabSheet;
38 TabSheetTerminal: TTabSheet;
39 TabSheetNonTerminal: TTabSheet;
40 TabSheetSubItems: TTabSheet;
41 procedure CheckBoxLookupTableChange(Sender: TObject);
42 procedure ComboBoxTypeChange(Sender: TObject);
43 procedure EditTerminalKeyPress(Sender: TObject; var Key: char);
44 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
45 procedure FormCreate(Sender: TObject);
46 procedure FormDestroy(Sender: TObject);
47 procedure FormShow(Sender: TObject);
48 private
49 FormRuleItems: TForm;
50 procedure ReloadNonTerminals(Grammer: TGrammer);
51 procedure ReloadLookupTables(Grammer: TGrammer);
52 public
53 RuleItem: TRuleItem;
54 procedure UpdateInterface;
55 procedure LoadData(RuleItem: TRuleItem);
56 procedure SaveData(RuleItem: TRuleItem);
57 end;
58
59var
60 FormRuleItem: TFormRuleItem;
61
62
63implementation
64
65uses
66 UCore, UFormRuleItems;
67
68{$R *.lfm}
69
70{ TFormRuleItem }
71
72procedure TFormRuleItem.ComboBoxTypeChange(Sender: TObject);
73begin
74 RuleItem.RuleItemType := TRuleItemType(ComboBoxType.ItemIndex);
75 UpdateInterface;
76end;
77
78procedure TFormRuleItem.CheckBoxLookupTableChange(Sender: TObject);
79begin
80 UpdateInterface;
81end;
82
83procedure TFormRuleItem.EditTerminalKeyPress(Sender: TObject; var Key: char);
84begin
85 if Key = #13 then ButtonOk.Click;
86end;
87
88procedure TFormRuleItem.FormClose(Sender: TObject; var CloseAction: TCloseAction
89 );
90begin
91 Core.PersistentForm1.Save(Self);
92end;
93
94procedure TFormRuleItem.FormCreate(Sender: TObject);
95begin
96 Core.CoolTranslator1.TranslateComponentRecursive(Self);
97 FormRuleItems := TFormRuleItems.Create(nil);
98 FormRuleItems.ManualDock(TabSheetSubItems);
99 FormRuleItems.Align := alClient;
100 FormRuleItems.Show;
101end;
102
103procedure TFormRuleItem.FormDestroy(Sender: TObject);
104begin
105 FreeAndNil(FormRuleItems);
106end;
107
108procedure TFormRuleItem.FormShow(Sender: TObject);
109begin
110 Core.PersistentForm1.Load(Self);
111 case RuleItem.RuleItemType of
112 ritTerminal: EditTerminal.SetFocus;
113 ritNonTerminal: ListBoxNonTerminals.SetFocus;
114 ritSubItems: TFormRuleItems(FormRuleItems).ListView1.SetFocus;
115 ritTerminalRange: EditTerminalFrom.SetFocus;
116 end;
117end;
118
119
120procedure TFormRuleItem.ReloadNonTerminals(Grammer: TGrammer);
121var
122 Rule: TRule;
123begin
124 ListBoxNonTerminals.Items.Clear;
125 for Rule in Grammer.Rules do begin
126 ListBoxNonTerminals.Items.AddObject(Rule.Name, Rule);
127 end;
128 ListBoxNonTerminals.Sorted := True;
129end;
130
131procedure TFormRuleItem.ReloadLookupTables(Grammer: TGrammer);
132var
133 Item: TLookupTable;
134begin
135 ListBoxLookupTable.Items.Clear;
136 for Item in Grammer.LookupTables do begin
137 ListBoxLookupTable.Items.AddObject(Item.Name, Item);
138 end;
139 ListBoxLookupTable.Sorted := True;
140end;
141
142procedure TFormRuleItem.UpdateInterface;
143begin
144 PageControl1.PageIndex := Integer(RuleItem.RuleItemType);
145 EditTerminal.Visible := RuleItem.RuleItemType = ritTerminal;
146 LabelTerminal.Visible := RuleItem.RuleItemType = ritTerminal;
147 ListBoxNonTerminals.Visible := RuleItem.RuleItemType = ritNonTerminal;
148 LabelNonTerminal.Visible := RuleItem.RuleItemType = ritNonTerminal;
149 CheckBoxOptional.Enabled := RuleItem.ParentRule.Items.RuleType = rtAnd;
150 CheckBoxRepetitive.Enabled := RuleItem.ParentRule.Items.RuleType = rtAnd;
151 CheckBoxEscapedString.Enabled := (RuleItem.RuleItemType = ritTerminal) or
152 (RuleItem.RuleItemType = ritTerminalRange);
153 ListBoxLookupTable.Enabled := CheckBoxLookupTable.Checked;
154 ComboBoxLookupTableAction.Enabled := CheckBoxLookupTable.Checked;
155end;
156
157procedure TFormRuleItem.LoadData(RuleItem: TRuleItem);
158begin
159 Self.RuleItem := RuleItem;
160 ReloadNonTerminals(RuleItem.Grammer);
161 ComboBoxType.ItemIndex := Integer(RuleItem.RuleItemType);
162 ListBoxNonTerminals.ItemIndex := ListBoxNonTerminals.Items.IndexOfObject(RuleItem.NonTerminal);
163 EditTerminal.Text := RuleItem.Terminal;
164 EditTerminalFrom.Text := RuleItem.TerminalFrom;
165 EditTerminalTo.Text := RuleItem.TerminalTo;
166 CheckBoxOptional.Checked := RuleItem.Optional;
167 CheckBoxRepetitive.Checked := RuleItem.Repetitive;
168 CheckBoxAnyExcept.Checked := RuleItem.AnyExcept;
169 TFormRuleItems(FormRuleItems).LoadData(RuleItem.SubItems);
170 CheckBoxEscapedString.Checked := RuleItem.EscapedStrings;
171 // Lookup table
172 CheckBoxLookupTable.Checked := RuleItem.LookupTableUsed;
173 ReloadLookupTables(RuleItem.Grammer);
174 ComboBoxLookupTableAction.ItemIndex := Integer(RuleItem.LookupTableAction);
175 ListBoxLookupTable.ItemIndex := ListBoxLookupTable.Items.IndexOfObject(RuleItem.LookupTable);
176 UpdateInterface;
177end;
178
179procedure TFormRuleItem.SaveData(RuleItem: TRuleItem);
180begin
181 RuleItem.Grammer.Modified := True;
182 TFormRuleItems(FormRuleItems).SaveData(RuleItem.SubItems);
183 RuleItem.RuleItemType := TRuleItemType(ComboBoxType.ItemIndex);
184 RuleItem.Terminal := EditTerminal.Text;
185 RuleItem.TerminalFrom := EditTerminalFrom.Text;
186 RuleItem.TerminalTo := EditTerminalTo.Text;
187 if ListBoxNonTerminals.ItemIndex <> -1 then
188 RuleItem.NonTerminal := TRule(ListBoxNonTerminals.Items.Objects[ListBoxNonTerminals.ItemIndex])
189 else RuleItem.NonTerminal := nil;
190 RuleItem.Optional := CheckBoxOptional.Checked;
191 RuleItem.Repetitive := CheckBoxRepetitive.Checked;
192 RuleItem.AnyExcept := CheckBoxAnyExcept.Checked;
193 RuleItem.EscapedStrings := CheckBoxEscapedString.Checked;
194 // Lookup table
195 RuleItem.LookupTableUsed := CheckBoxLookupTable.Checked;
196 RuleItem.LookupTableAction := TLookupTableAction(ComboBoxLookupTableAction.ItemIndex);
197 if ListBoxLookupTable.ItemIndex <> -1 then
198 RuleItem.LookupTable := TLookupTable(ListBoxLookupTable.Items.Objects[ListBoxLookupTable.ItemIndex])
199 else RuleItem.LookupTable := nil;
200end;
201
202end.
203
Note: See TracBrowser for help on using the repository browser.