Ignore:
Timestamp:
Nov 29, 2017, 2:03:17 PM (7 years ago)
Author:
chronos
Message:
  • Added: New rule item type "Terminal range" to hold interval of characters.
  • Fixed: Removel of selected items in a list was not working correctly.
Location:
branches/generator/Forms
Files:
7 edited

Legend:

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

    r120 r122  
    4545    Top = 80
    4646    Width = 640
    47     ActivePage = TabSheetUsedBy
     47    ActivePage = TabSheet1
    4848    Anchors = [akTop, akLeft, akRight, akBottom]
    49     TabIndex = 2
     49    TabIndex = 0
    5050    TabOrder = 2
    5151    object TabSheet1: TTabSheet
  • branches/generator/Forms/UFormRuleItem.lfm

    r117 r122  
    4242      'Non-terminal'
    4343      'Subitems'
     44      'Terminal range'
    4445    )
    4546    OnChange = ComboBoxTypeChange
     
    6061    Top = 88
    6162    Width = 632
    62     ActivePage = TabSheetSubItems
     63    ActivePage = TabSheetTerminal
    6364    Anchors = [akTop, akLeft, akRight, akBottom]
    6465    ShowTabs = False
    65     TabIndex = 2
     66    TabIndex = 0
    6667    TabOrder = 3
    6768    object TabSheetTerminal: TTabSheet
    6869      Caption = 'Terminal'
    69       ClientHeight = 168
     70      ClientHeight = 258
    7071      ClientWidth = 624
    71       object EditName: TEdit
     72      object EditTerminal: TEdit
    7273        Left = 152
    7374        Height = 28
    7475        Top = 16
    7576        Width = 400
     77        OnKeyPress = EditTerminalKeyPress
    7678        TabOrder = 0
    7779      end
     
    7981        Left = 8
    8082        Height = 20
    81         Top = 24
     83        Top = 16
    8284        Width = 61
    8385        Caption = 'Terminal:'
     
    8789    object TabSheetNonTerminal: TTabSheet
    8890      Caption = 'NonTerminal'
    89       ClientHeight = 168
     91      ClientHeight = 258
    9092      ClientWidth = 624
    91       object ComboBoxNonTerminal: TComboBox
    92         Left = 152
    93         Height = 28
    94         Top = 16
    95         Width = 404
    96         ItemHeight = 20
    97         Style = csDropDownList
    98         TabOrder = 0
    99       end
    10093      object LabelNonTerminal: TLabel
    10194        Left = 8
    10295        Height = 20
    103         Top = 24
     96        Top = 16
    10497        Width = 92
    10598        Caption = 'Non-terminal:'
    10699        ParentColor = False
    107100      end
     101      object ListBox1: TListBox
     102        Left = 128
     103        Height = 232
     104        Top = 16
     105        Width = 484
     106        Anchors = [akTop, akLeft, akRight, akBottom]
     107        ItemHeight = 0
     108        TabOrder = 0
     109      end
    108110    end
    109111    object TabSheetSubItems: TTabSheet
    110112      Caption = 'SubItems'
     113    end
     114    object TabSheetTerminalRange: TTabSheet
     115      Caption = 'TabSheetTerminalRange'
     116      ClientHeight = 258
     117      ClientWidth = 624
     118      object LabelTerminal1: TLabel
     119        Left = 8
     120        Height = 20
     121        Top = 16
     122        Width = 97
     123        Caption = 'Terminal from:'
     124        ParentColor = False
     125      end
     126      object EditTerminalFrom: TEdit
     127        Left = 152
     128        Height = 28
     129        Top = 16
     130        Width = 400
     131        OnKeyPress = EditTerminalKeyPress
     132        TabOrder = 0
     133      end
     134      object LabelTerminal2: TLabel
     135        Left = 8
     136        Height = 20
     137        Top = 56
     138        Width = 79
     139        Caption = 'Terminal to:'
     140        ParentColor = False
     141      end
     142      object EditTerminalTo: TEdit
     143        Left = 152
     144        Height = 28
     145        Top = 56
     146        Width = 400
     147        OnKeyPress = EditTerminalKeyPress
     148        TabOrder = 1
     149      end
    111150    end
    112151  end
  • branches/generator/Forms/UFormRuleItem.pas

    r118 r122  
    1818    CheckBoxOptional: TCheckBox;
    1919    CheckBoxRepetitive: TCheckBox;
    20     ComboBoxNonTerminal: TComboBox;
    2120    ComboBoxType: TComboBox;
    22     EditName: TEdit;
     21    EditTerminal: TEdit;
     22    EditTerminalFrom: TEdit;
     23    EditTerminalTo: TEdit;
    2324    Label2: TLabel;
    2425    LabelNonTerminal: TLabel;
    2526    LabelTerminal: TLabel;
     27    LabelTerminal1: TLabel;
     28    LabelTerminal2: TLabel;
     29    ListBox1: TListBox;
    2630    PageControl1: TPageControl;
     31    TabSheetTerminalRange: TTabSheet;
    2732    TabSheetTerminal: TTabSheet;
    2833    TabSheetNonTerminal: TTabSheet;
    2934    TabSheetSubItems: TTabSheet;
    3035    procedure ComboBoxTypeChange(Sender: TObject);
     36    procedure EditTerminalKeyPress(Sender: TObject; var Key: char);
    3137    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    3238    procedure FormCreate(Sender: TObject);
     
    6268end;
    6369
     70procedure TFormRuleItem.EditTerminalKeyPress(Sender: TObject; var Key: char);
     71begin
     72  if Key = #13 then ButtonOk.Click;
     73end;
     74
    6475procedure TFormRuleItem.FormClose(Sender: TObject; var CloseAction: TCloseAction
    6576  );
     
    8495begin
    8596  Core.PersistentForm1.Load(Self);
     97  case RuleItem.RuleItemType of
     98    ritTerminal: EditTerminal.SetFocus;
     99    ritNonTerminal: ListBox1.SetFocus;
     100    ritSubItems: TFormRuleItems(FormRuleItems).ListView1.SetFocus;
     101  end;
    86102end;
     103
    87104
    88105procedure TFormRuleItem.ReloadNonTerminals(Grammer: TGrammer);
     
    90107  Rule: TRule;
    91108begin
    92   ComboBoxNonTerminal.Items.Clear;
     109  ListBox1.Items.Clear;
    93110  for Rule in Grammer.Rules do begin
    94     ComboBoxNonTerminal.Items.AddObject(Rule.Name, Rule);
     111    ListBox1.Items.AddObject(Rule.Name, Rule);
    95112  end;
    96   ComboBoxNonTerminal.Sorted := True;
     113  ListBox1.Sorted := True;
    97114end;
    98115
     
    100117begin
    101118  PageControl1.PageIndex := Integer(RuleItem.RuleItemType);
    102   EditName.Visible := RuleItem.RuleItemType = ritTerminal;
     119  EditTerminal.Visible := RuleItem.RuleItemType = ritTerminal;
    103120  LabelTerminal.Visible := RuleItem.RuleItemType = ritTerminal;
    104   ComboBoxNonTerminal.Visible := RuleItem.RuleItemType = ritNonTerminal;
     121  ListBox1.Visible := RuleItem.RuleItemType = ritNonTerminal;
    105122  LabelNonTerminal.Visible := RuleItem.RuleItemType = ritNonTerminal;
    106123end;
     
    111128  ReloadNonTerminals(RuleItem.Grammer);
    112129  ComboBoxType.ItemIndex := Integer(RuleItem.RuleItemType);
    113   ComboBoxNonTerminal.ItemIndex := ComboBoxNonTerminal.Items.IndexOfObject(RuleItem.NonTerminal);
    114   EditName.Text := RuleItem.Terminal;
     130  ListBox1.ItemIndex := ListBox1.Items.IndexOfObject(RuleItem.NonTerminal);
     131  EditTerminal.Text := RuleItem.Terminal;
     132  EditTerminalFrom.Text := RuleItem.TerminalFrom;
     133  EditTerminalTo.Text := RuleItem.TerminalTo;
    115134  CheckBoxOptional.Checked := RuleItem.Optional;
    116135  CheckBoxRepetitive.Checked := RuleItem.Repetitive;
     
    123142  TFormRuleItems(FormRuleItems).SaveData(RuleItem.SubItems);
    124143  RuleItem.RuleItemType := TRuleItemType(ComboBoxType.ItemIndex);
    125   if RuleItem.RuleItemType = ritTerminal then RuleItem.Terminal := EditName.Text
    126   else if RuleItem.RuleItemType = ritNonTerminal then
    127     RuleItem.NonTerminal := TRule(ComboBoxNonTerminal.Items.Objects[ComboBoxNonTerminal.ItemIndex]);
     144  RuleItem.Terminal := EditTerminal.Text;
     145  RuleItem.TerminalFrom := EditTerminalFrom.Text;
     146  RuleItem.TerminalTo := EditTerminalTo.Text;
     147  if ListBox1.ItemIndex <> -1 then
     148    RuleItem.NonTerminal := TRule(ListBox1.Items.Objects[ListBox1.ItemIndex])
     149    else RuleItem.NonTerminal := nil;
    128150  RuleItem.Optional := CheckBoxOptional.Checked;
    129151  RuleItem.Repetitive := CheckBoxRepetitive.Checked;
  • branches/generator/Forms/UFormRuleItems.lfm

    r116 r122  
    1010  OnShow = FormShow
    1111  LCLVersion = '1.6.4.0'
    12   object ListView: TListView
     12  object ListView1: TListView
    1313    Left = 8
    1414    Height = 392
     
    2828    TabOrder = 0
    2929    ViewStyle = vsReport
    30     OnData = ListViewData
    31     OnDblClick = ListViewDblClick
    32     OnKeyPress = ListViewKeyPress
    33     OnSelectItem = ListViewSelectItem
     30    OnData = ListView1Data
     31    OnDblClick = ListView1DblClick
     32    OnKeyPress = ListView1KeyPress
     33    OnSelectItem = ListView1SelectItem
    3434  end
    3535  object ToolBar1: TToolBar
     
    299299      ImageIndex = 0
    300300      OnExecute = AAddExecute
     301      ShortCut = 45
    301302    end
    302303    object AModify: TAction
     
    309310      ImageIndex = 1
    310311      OnExecute = ARemoveExecute
     312      ShortCut = 46
    311313    end
    312314    object AMoveUp: TAction
     
    314316      ImageIndex = 7
    315317      OnExecute = AMoveUpExecute
     318      ShortCut = 16422
    316319    end
    317320    object AMoveDown: TAction
     
    319322      ImageIndex = 6
    320323      OnExecute = AMoveDownExecute
     324      ShortCut = 16424
    321325    end
    322326  end
  • branches/generator/Forms/UFormRuleItems.pas

    r119 r122  
    2222    ComboBox1: TComboBox;
    2323    Label1: TLabel;
    24     ListView: TListView;
     24    ListView1: TListView;
    2525    MenuItem1: TMenuItem;
    2626    MenuItem2: TMenuItem;
     
    4242    procedure FormCreate(Sender: TObject);
    4343    procedure FormShow(Sender: TObject);
    44     procedure ListViewData(Sender: TObject; Item: TListItem);
    45     procedure ListViewDblClick(Sender: TObject);
    46     procedure ListViewKeyPress(Sender: TObject; var Key: char);
    47     procedure ListViewSelectItem(Sender: TObject; Item: TListItem;
     44    procedure ListView1Data(Sender: TObject; Item: TListItem);
     45    procedure ListView1DblClick(Sender: TObject);
     46    procedure ListView1KeyPress(Sender: TObject; var Key: char);
     47    procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
    4848      Selected: Boolean);
    4949  private
     
    6868{ TFormRuleItems }
    6969
    70 procedure TFormRuleItems.ListViewData(Sender: TObject; Item: TListItem);
     70procedure TFormRuleItems.ListView1Data(Sender: TObject; Item: TListItem);
    7171begin
    7272  if (Item.Index >= 0) and (Item.Index < RuleItems.Count) then begin
     
    9797  RuleItem: TRuleItem;
    9898begin
    99   if Assigned(ListView.Selected) then begin
    100     RuleItem := TRuleItem(ListView.Selected.Data);
     99  if Assigned(ListView1.Selected) then begin
     100    RuleItem := TRuleItem(ListView1.Selected.Data);
    101101    FormRuleItem := TFormRuleItem.Create(nil);
    102102    FormRuleItem.LoadData(RuleItem);
     
    111111procedure TFormRuleItems.AMoveDownExecute(Sender: TObject);
    112112begin
    113   RuleItems.ParentRule.Items.Move(ListView.Selected.Index, ListView.Selected.Index + 1);
    114   ListView.ItemIndex := ListView.Selected.Index + 1;
     113  RuleItems.ParentRule.Items.Move(ListView1.Selected.Index, ListView1.Selected.Index + 1);
     114  ListView1.ItemIndex := ListView1.Selected.Index + 1;
    115115  ReloadList;
    116116end;
     
    118118procedure TFormRuleItems.AMoveUpExecute(Sender: TObject);
    119119begin
    120   RuleItems.ParentRule.Items.Move(ListView.Selected.Index, ListView.Selected.Index - 1);
    121   ListView.ItemIndex := ListView.Selected.Index - 1;
     120  RuleItems.ParentRule.Items.Move(ListView1.Selected.Index, ListView1.Selected.Index - 1);
     121  ListView1.ItemIndex := ListView1.Selected.Index - 1;
    122122  ReloadList;
    123123end;
     
    125125procedure TFormRuleItems.ARemoveExecute(Sender: TObject);
    126126var
    127   Item: TListItem;
     127  I: Integer;
    128128begin
    129   for Item in ListView.Items do
    130   if Item.Selected then
    131     RuleItems.ParentRule.Items.Remove(TRuleItem(Item.Data));
     129  if MessageDlg('Remove item(s)', 'Do you want to remove selected item(s)?',
     130    mtConfirmation, mbYesNo, 0) = mrYes then
     131  for I := ListView1.Items.Count - 1 downto 0 do
     132  if ListView1.Items[I].Selected then
     133    RuleItems.ParentRule.Items.Remove(TRuleItem(ListView1.Items[I].Data));
    132134  ReloadList;
    133135end;
     
    144146end;
    145147
    146 procedure TFormRuleItems.ListViewDblClick(Sender: TObject);
     148procedure TFormRuleItems.ListView1DblClick(Sender: TObject);
    147149begin
    148150  AModify.Execute;
    149151end;
    150152
    151 procedure TFormRuleItems.ListViewKeyPress(Sender: TObject; var Key: char);
     153procedure TFormRuleItems.ListView1KeyPress(Sender: TObject; var Key: char);
    152154begin
    153155  if Key = #13 then AModify.Execute;
    154156end;
    155157
    156 procedure TFormRuleItems.ListViewSelectItem(Sender: TObject; Item: TListItem;
     158procedure TFormRuleItems.ListView1SelectItem(Sender: TObject; Item: TListItem;
    157159  Selected: Boolean);
    158160begin
     
    162164procedure TFormRuleItems.UpdateInterface;
    163165begin
    164   AModify.Enabled := Assigned(ListView.Selected);
    165   ARemove.Enabled := Assigned(ListView.Selected);
    166   AMoveUp.Enabled := Assigned(ListView.Selected) and (ListView.Selected.Index > 0);
    167   AMoveDown.Enabled := Assigned(ListView.Selected) and (ListView.Selected.Index < (ListView.Items.Count - 1));
     166  AModify.Enabled := Assigned(ListView1.Selected);
     167  ARemove.Enabled := Assigned(ListView1.Selected);
     168  AMoveUp.Enabled := Assigned(ListView1.Selected) and (ListView1.Selected.Index > 0);
     169  AMoveDown.Enabled := Assigned(ListView1.Selected) and (ListView1.Selected.Index < (ListView1.Items.Count - 1));
    168170end;
    169171
    170172procedure TFormRuleItems.ReloadList;
    171173begin
    172   if Assigned(RuleItems) then ListView.Items.Count := RuleItems.Count
    173     else ListView.Items.Count := 0;
    174   ListView.Refresh;
     174  if Assigned(RuleItems) then ListView1.Items.Count := RuleItems.Count
     175    else ListView1.Items.Count := 0;
     176  ListView1.Refresh;
    175177end;
    176178
  • branches/generator/Forms/UFormRules.lfm

    r121 r122  
    11object FormRules: TFormRules
    2   Left = 386
     2  Left = 348
    33  Height = 611
    4   Top = 221
     4  Top = 230
    55  Width = 857
    66  Caption = 'Rules'
     
    101101      ImageIndex = 0
    102102      OnExecute = AAddExecute
     103      ShortCut = 45
    103104    end
    104105    object AModify: TAction
  • branches/generator/Forms/UFormRules.pas

    r121 r122  
    116116procedure TFormRules.ARemoveExecute(Sender: TObject);
    117117var
    118   Item: TListItem;
    119 begin
    120   for Item in ListView1.Items do
    121   if Item.Selected then
    122     Rules.Remove(TRule(Item.Data));
     118  I: Integer;
     119begin
     120  if MessageDlg('Remove item(s)', 'Do you want to remove selected item(s)?',
     121    mtConfirmation, mbYesNo, 0) = mrYes then
     122  for I := ListView1.Items.Count - 1 downto 0 do
     123  if ListView1.Items[I].Selected then
     124    Rules.Remove(TRule(ListView1.Items[I].Data));
    123125  ReloadList;
    124126end;
Note: See TracChangeset for help on using the changeset viewer.