Changeset 120


Ignore:
Timestamp:
Nov 29, 2017, 1:21:22 PM (7 years ago)
Author:
chronos
Message:
  • Added: Show "Used by" rules in rule edit window.
Location:
branches/generator
Files:
4 edited

Legend:

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

    r119 r120  
    4545    Top = 80
    4646    Width = 640
    47     ActivePage = TabSheet1
     47    ActivePage = TabSheetUsedBy
    4848    Anchors = [akTop, akLeft, akRight, akBottom]
    49     TabIndex = 0
     49    TabIndex = 2
    5050    TabOrder = 2
    5151    object TabSheet1: TTabSheet
     
    5454    object TabSheet2: TTabSheet
    5555      Caption = 'Links'
     56    end
     57    object TabSheetUsedBy: TTabSheet
     58      Caption = 'Used by'
     59      ClientHeight = 359
     60      ClientWidth = 632
     61      object ListView1: TListView
     62        Left = 0
     63        Height = 359
     64        Top = 0
     65        Width = 632
     66        Align = alClient
     67        Columns = <       
     68          item
     69            Caption = 'Name'
     70            Width = 200
     71          end>
     72        OwnerData = True
     73        ReadOnly = True
     74        RowSelect = True
     75        TabOrder = 0
     76        ViewStyle = vsReport
     77        OnData = ListView1Data
     78      end
    5679    end
    5780  end
  • branches/generator/Forms/UFormRule.pas

    r119 r120  
    1919    EditName: TEdit;
    2020    Label1: TLabel;
     21    ListView1: TListView;
    2122    PageControl1: TPageControl;
    2223    TabSheet1: TTabSheet;
    2324    TabSheet2: TTabSheet;
     25    TabSheetUsedBy: TTabSheet;
    2426    procedure FormCreate(Sender: TObject);
    2527    procedure FormDestroy(Sender: TObject);
    2628    procedure FormShow(Sender: TObject);
     29    procedure ListView1Data(Sender: TObject; Item: TListItem);
    2730  private
    2831    FormRuleItems: TFormRuleItems;
     32    UsedByRules: TStringList;
     33    procedure ReloadUsedByRules;
    2934  public
    3035    Rule: TRule;
     
    3944implementation
    4045
     46uses
     47  UCore;
     48
    4149{$R *.lfm}
    4250
     
    4654begin
    4755  EditName.SetFocus;
     56  PageControl1.TabIndex := 0;  // Select first tab by default
     57end;
     58
     59procedure TFormRule.ListView1Data(Sender: TObject; Item: TListItem);
     60begin
     61  if Item.Index < UsedByRules.Count then
     62  begin
     63    Item.Caption := UsedByRules[Item.Index];
     64    Item.Data := UsedByRules.Objects[Item.Index];
     65  end;
     66end;
     67
     68procedure TFormRule.ReloadUsedByRules;
     69begin
     70  ListView1.Items.Count := UsedByRules.Count;
     71  ListView1.Refresh;
    4872end;
    4973
     
    5478  FormRuleItems.Align := alClient;
    5579  FormRuleItems.Show;
     80  UsedByRules := TStringList.Create;
    5681end;
    5782
    5883procedure TFormRule.FormDestroy(Sender: TObject);
    5984begin
     85  FreeAndNil(UsedByRules);
    6086  FreeAndNil(FormRuleItems);
    6187end;
     
    6490begin
    6591  Self.Rule := Rule;
     92  Rule.Grammer.GetUsedByRule(Rule, UsedByRules);
     93  ReloadUsedByRules;
    6694  EditName.Text := Rule.Name;
    6795  CheckBoxCreateNode.Checked := Rule.CreateSourceNode;
  • branches/generator/URules.pas

    r119 r120  
    7676  TRule = class
    7777  private
    78     function GetGrammer: TGrammer;
     78    FGrammer: TGrammer;
    7979    procedure SetGrammer(AValue: TGrammer);
    8080  public
     
    8383    Items: TRuleItems;
    8484    Links: TRuleLinks;
    85     property Grammer: TGrammer read GetGrammer write SetGrammer;
    8685    constructor Create;
    8786    destructor Destroy; override;
     87    procedure GetUsedByRule(RefRule: TRule; UsedByRules: TStrings);
    8888    procedure LoadFromXmlNode(Node: TDOMNode);
    8989    procedure SaveToXmlNode(Node: TDOMNode);
    9090    function GetString: string;
     91    property Grammer: TGrammer read FGrammer write SetGrammer;
    9192  end;
    9293
     
    117118    destructor Destroy; override;
    118119    procedure BuildCompiler;
     120    procedure GetUsedByRule(RefRule: TRule; UsedByRules: TStrings);
    119121    function GetString: string;
    120122    property Modified: Boolean read FModified write SetModified;
     
    308310end;
    309311
     312procedure TGrammer.GetUsedByRule(RefRule: TRule; UsedByRules: TStrings);
     313var
     314  Rule: TRule;
     315begin
     316  UsedByRules.Clear;
     317  for Rule in Rules do
     318    Rule.GetUsedByRule(RefRule, UsedByRules);
     319end;
     320
    310321function TGrammer.GetString: string;
    311322begin
     
    498509end;
    499510
    500 function TRule.GetGrammer: TGrammer;
    501 begin
    502   Result := Items.Grammer;
    503 end;
    504 
    505511procedure TRule.SetGrammer(AValue: TGrammer);
    506512begin
     513  if FGrammer = AValue then Exit;
     514  FGrammer := AValue;
    507515  Items.Grammer := AValue;
    508516end;
     
    520528  FreeAndNil(Items);
    521529  inherited Destroy;
     530end;
     531
     532procedure TRule.GetUsedByRule(RefRule: TRule; UsedByRules: TStrings);
     533var
     534  Item: TRuleItem;
     535begin
     536  for Item in Items do
     537    if (Item.RuleItemType = ritNonTerminal) and
     538      (Item.NonTerminal = RefRule) and
     539      (UsedByRules.IndexOf(Item.ParentRule.Name) = -1) then
     540      UsedByRules.AddObject(Item.ParentRule.Name, Item.ParentRule);
    522541end;
    523542
  • branches/generator/generator.lpr

    r117 r120  
    2626  {$ENDIF}
    2727
    28   Application.Title:='Language generator';
     28  Application.Title := 'Language generator';
    2929  RequireDerivedFormResource := True;
    3030  Application.Initialize;
Note: See TracChangeset for help on using the changeset viewer.