Ignore:
Timestamp:
Nov 27, 2017, 10:04:52 AM (7 years ago)
Author:
chronos
Message:
  • Modified: Rule items interface moved to separate unit UFormRuleItems.
File:
1 edited

Legend:

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

    r113 r116  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   ComCtrls, ActnList, Menus, URules;
     9  ComCtrls, ActnList, Menus, URules, UFormRuleItems;
    1010
    1111type
     
    1414
    1515  TFormRule = class(TForm)
    16     AAdd: TAction;
    17     AMoveUp: TAction;
    18     AMoveDown: TAction;
    19     AModify: TAction;
    20     ARemove: TAction;
    21     ActionList1: TActionList;
    2216    ButtonOk: TButton;
    2317    ButtonCancel: TButton;
    24     ComboBox1: TComboBox;
    2518    EditName: TEdit;
    2619    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);
    4624    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);
    5225  private
    53     { private declarations }
     26    FormRuleItems: TFormRuleItems;
    5427  public
    5528    Rule: TRule;
    56     procedure UpdateInterface;
    57     procedure ReloadList;
    5829    procedure LoadData(Rule: TRule);
    5930    procedure SaveData(Rule: TRule);
     
    7647begin
    7748  EditName.SetFocus;
    78   ReloadList;
    79   UpdateInterface;
    8049end;
    8150
    82 procedure TFormRule.ListViewData(Sender: TObject; Item: TListItem);
     51procedure TFormRule.FormCreate(Sender: TObject);
    8352begin
    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;
    17157end;
    17258
     
    17460begin
    17561  Self.Rule := Rule;
    176   ComboBox1.ItemIndex := Integer(Rule.RuleType);
    17762  EditName.Text := Rule.Name;
    178   Rule.Items := Rule.Items;
     63  FormRuleItems.LoadData(Rule.Items);
    17964end;
    18065
    18166procedure TFormRule.SaveData(Rule: TRule);
    18267begin
    183   Rule.RuleType := TRuleType(ComboBox1.ItemIndex);
    18468  Rule.Name := EditName.Text;
     69  FormRuleItems.SaveData(Rule.Items);
    18570end;
    18671
Note: See TracChangeset for help on using the changeset viewer.