Changeset 116 for branches/generator/Forms/UFormRule.pas
- Timestamp:
- Nov 27, 2017, 10:04:52 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/generator/Forms/UFormRule.pas
r113 r116 7 7 uses 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, 9 ComCtrls, ActnList, Menus, URules ;9 ComCtrls, ActnList, Menus, URules, UFormRuleItems; 10 10 11 11 type … … 14 14 15 15 TFormRule = class(TForm) 16 AAdd: TAction;17 AMoveUp: TAction;18 AMoveDown: TAction;19 AModify: TAction;20 ARemove: TAction;21 ActionList1: TActionList;22 16 ButtonOk: TButton; 23 17 ButtonCancel: TButton; 24 ComboBox1: TComboBox;25 18 EditName: TEdit; 26 19 Label1: TLabel; 27 Label2: TLabel; 28 ListView: TListView; 29 MenuItem1: TMenuItem; 30 MenuItem2: TMenuItem; 31 MenuItem3: TMenuItem; 32 MenuItem4: TMenuItem; 33 MenuItem5: TMenuItem; 34 PopupMenu1: TPopupMenu; 35 ToolBar1: TToolBar; 36 ToolButton1: TToolButton; 37 ToolButton2: TToolButton; 38 ToolButton3: TToolButton; 39 ToolButton4: TToolButton; 40 ToolButton5: TToolButton; 41 procedure AAddExecute(Sender: TObject); 42 procedure AModifyExecute(Sender: TObject); 43 procedure AMoveDownExecute(Sender: TObject); 44 procedure AMoveUpExecute(Sender: TObject); 45 procedure ARemoveExecute(Sender: TObject); 20 PageControl1: TPageControl; 21 TabSheet1: TTabSheet; 22 TabSheet2: TTabSheet; 23 procedure FormCreate(Sender: TObject); 46 24 procedure FormShow(Sender: TObject); 47 procedure ListViewData(Sender: TObject; Item: TListItem);48 procedure ListViewDblClick(Sender: TObject);49 procedure ListViewKeyPress(Sender: TObject; var Key: char);50 procedure ListViewSelectItem(Sender: TObject; Item: TListItem;51 Selected: Boolean);52 25 private 53 { private declarations }26 FormRuleItems: TFormRuleItems; 54 27 public 55 28 Rule: TRule; 56 procedure UpdateInterface;57 procedure ReloadList;58 29 procedure LoadData(Rule: TRule); 59 30 procedure SaveData(Rule: TRule); … … 76 47 begin 77 48 EditName.SetFocus; 78 ReloadList;79 UpdateInterface;80 49 end; 81 50 82 procedure TFormRule. ListViewData(Sender: TObject; Item: TListItem);51 procedure TFormRule.FormCreate(Sender: TObject); 83 52 begin 84 if (Item.Index >= 0) and (Item.Index < Rule.Items.Count) then begin 85 Item.Caption := Rule.Items[Item.Index].GetBNF; 86 Item.Data := Rule.Items[Item.Index]; 87 end; 88 end; 89 90 procedure TFormRule.ListViewDblClick(Sender: TObject); 91 begin 92 AModify.Execute; 93 end; 94 95 procedure TFormRule.ListViewKeyPress(Sender: TObject; var Key: char); 96 begin 97 if Key = #13 then AModify.Execute; 98 end; 99 100 procedure TFormRule.ListViewSelectItem(Sender: TObject; Item: TListItem; 101 Selected: Boolean); 102 begin 103 UpdateInterface; 104 end; 105 106 procedure TFormRule.AAddExecute(Sender: TObject); 107 var 108 NewRuleItem: TRuleItem; 109 begin 110 NewRuleItem := TRuleItem.Create; 111 NewRuleItem.Grammer := Rule.Grammer; 112 FormRuleItem.LoadData(NewRuleItem); 113 if FormRuleItem.ShowModal = mrOk then begin 114 FormRuleItem.SaveData(NewRuleItem); 115 NewRuleItem.ParentRule := Rule; 116 Rule.Items.Add(NewRuleItem); 117 ReloadList; 118 end else FreeAndNil(NewRuleItem); 119 end; 120 121 procedure TFormRule.AModifyExecute(Sender: TObject); 122 var 123 RuleItem: TRuleItem; 124 begin 125 RuleItem := TRuleItem(ListView.Selected.Data); 126 FormRuleItem.LoadData(RuleItem); 127 if FormRuleItem.ShowModal = mrOk then begin 128 FormRuleItem.SaveData(RuleItem); 129 ReloadList; 130 end; 131 end; 132 133 procedure TFormRule.AMoveDownExecute(Sender: TObject); 134 begin 135 Rule.Items.Move(ListView.Selected.Index, ListView.Selected.Index + 1); 136 // ShowMessage(IntToStr(ListView.ItemIndex)); 137 ListView.ItemIndex := ListView.Selected.Index + 1; 138 // ShowMessage(IntToStr(ListView.ItemIndex)); 139 ReloadList; 140 end; 141 142 procedure TFormRule.AMoveUpExecute(Sender: TObject); 143 begin 144 Rule.Items.Move(ListView.Selected.Index, ListView.Selected.Index - 1); 145 ListView.ItemIndex := ListView.Selected.Index - 1; 146 ReloadList; 147 end; 148 149 procedure TFormRule.ARemoveExecute(Sender: TObject); 150 var 151 Item: TListItem; 152 begin 153 for Item in ListView.Items do 154 if Item.Selected then 155 Rule.Items.Remove(TRuleItem(Item.Data)); 156 ReloadList; 157 end; 158 159 procedure TFormRule.UpdateInterface; 160 begin 161 AModify.Enabled := Assigned(ListView.Selected); 162 ARemove.Enabled := Assigned(ListView.Selected); 163 AMoveUp.Enabled := Assigned(ListView.Selected) and (ListView.Selected.Index > 0); 164 AMoveDown.Enabled := Assigned(ListView.Selected) and (ListView.Selected.Index < (ListView.Items.Count - 1)); 165 end; 166 167 procedure TFormRule.ReloadList; 168 begin 169 ListView.Items.Count := Rule.Items.Count; 170 ListView.Refresh; 53 FormRuleItems := TFormRuleItems.Create(nil); 54 FormRuleItems.ManualDock(TabSheet1); 55 FormRuleItems.Align := alClient; 56 FormRuleItems.Show; 171 57 end; 172 58 … … 174 60 begin 175 61 Self.Rule := Rule; 176 ComboBox1.ItemIndex := Integer(Rule.RuleType);177 62 EditName.Text := Rule.Name; 178 Rule.Items := Rule.Items;63 FormRuleItems.LoadData(Rule.Items); 179 64 end; 180 65 181 66 procedure TFormRule.SaveData(Rule: TRule); 182 67 begin 183 Rule.RuleType := TRuleType(ComboBox1.ItemIndex);184 68 Rule.Name := EditName.Text; 69 FormRuleItems.SaveData(Rule.Items); 185 70 end; 186 71
Note:
See TracChangeset
for help on using the changeset viewer.