Ignore:
Timestamp:
Aug 8, 2017, 11:15:41 PM (7 years ago)
Author:
chronos
Message:
  • Added: Rule items can be managed.
  • Added: Show BNF syntax on main form.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/generator/Forms/UFormRule.pas

    r109 r110  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   URules;
     9  ComCtrls, ActnList, Menus, URules;
    1010
    1111type
     
    1414
    1515  TFormRule = class(TForm)
     16    AAdd: TAction;
     17    AModify: TAction;
     18    ARemove: TAction;
     19    ActionList1: TActionList;
    1620    ButtonOk: TButton;
    1721    ButtonCancel: TButton;
    1822    EditName: TEdit;
    1923    Label1: TLabel;
     24    ListView: TListView;
     25    MenuItem1: TMenuItem;
     26    MenuItem2: TMenuItem;
     27    MenuItem3: TMenuItem;
     28    PopupMenu1: TPopupMenu;
     29    procedure AAddExecute(Sender: TObject);
     30    procedure AModifyExecute(Sender: TObject);
     31    procedure ARemoveExecute(Sender: TObject);
    2032    procedure FormShow(Sender: TObject);
     33    procedure ListViewData(Sender: TObject; Item: TListItem);
     34    procedure ListViewDblClick(Sender: TObject);
     35    procedure ListViewKeyPress(Sender: TObject; var Key: char);
     36    procedure ListViewSelectItem(Sender: TObject; Item: TListItem;
     37      Selected: Boolean);
    2138  private
    2239    { private declarations }
    2340  public
     41    RuleItems: TRuleItems;
     42    procedure UpdateInterface;
     43    procedure ReloadList;
    2444    procedure LoadData(Rule: TRule);
    2545    procedure SaveData(Rule: TRule);
     
    2949  FormRule: TFormRule;
    3050
     51
    3152implementation
    3253
    3354{$R *.lfm}
     55
     56uses
     57  UFormRuleItem;
    3458
    3559{ TFormRule }
     
    3862begin
    3963  EditName.SetFocus;
     64  ReloadList;
     65  UpdateInterface;
     66end;
     67
     68procedure TFormRule.ListViewData(Sender: TObject; Item: TListItem);
     69begin
     70  if (Item.Index >= 0) and (Item.Index < RuleItems.Count) then begin
     71    Item.Caption := RuleItems[Item.Index].Name;
     72    Item.Data := RuleItems[Item.Index];
     73  end;
     74end;
     75
     76procedure TFormRule.ListViewDblClick(Sender: TObject);
     77begin
     78  AModify.Execute;
     79end;
     80
     81procedure TFormRule.ListViewKeyPress(Sender: TObject; var Key: char);
     82begin
     83  if Key = #13 then AModify.Execute;
     84end;
     85
     86procedure TFormRule.ListViewSelectItem(Sender: TObject; Item: TListItem;
     87  Selected: Boolean);
     88begin
     89  UpdateInterface;
     90end;
     91
     92procedure TFormRule.AAddExecute(Sender: TObject);
     93var
     94  NewRuleItem: TRuleItem;
     95begin
     96  NewRuleItem := TRuleItem.Create;
     97  FormRuleItem.LoadData(NewRuleItem);
     98  if FormRuleItem.ShowModal = mrOk then begin
     99    FormRuleItem.SaveData(NewRuleItem);
     100    RuleItems.Add(NewRuleItem);
     101    ReloadList;
     102  end else FreeAndNil(NewRuleItem);
     103end;
     104
     105procedure TFormRule.AModifyExecute(Sender: TObject);
     106var
     107  RuleItem: TRuleItem;
     108begin
     109  RuleItem := TRuleItem(ListView.Selected.Data);
     110  FormRuleItem.LoadData(RuleItem);
     111  if FormRuleItem.ShowModal = mrOk then begin
     112    FormRuleItem.SaveData(RuleItem);
     113    ReloadList;
     114  end;
     115end;
     116
     117procedure TFormRule.ARemoveExecute(Sender: TObject);
     118var
     119  Item: TListItem;
     120begin
     121  for Item in ListView.Items do
     122  if Item.Selected then
     123    RuleItems.Remove(TRuleItem(Item.Data));
     124  ReloadList;
     125end;
     126
     127procedure TFormRule.UpdateInterface;
     128begin
     129  AModify.Enabled := Assigned(ListView.Selected);
     130  ARemove.Enabled := Assigned(ListView.Selected);
     131end;
     132
     133procedure TFormRule.ReloadList;
     134begin
     135  ListView.Items.Count := RuleItems.Count;
     136  ListView.Refresh;
    40137end;
    41138
     
    43140begin
    44141  EditName.Text := Rule.Name;
     142  RuleItems := Rule.Items;
    45143end;
    46144
Note: See TracChangeset for help on using the changeset viewer.