Ignore:
Timestamp:
Dec 24, 2017, 3:54:08 PM (7 years ago)
Author:
chronos
Message:
  • Added: Open recent files menu action.
  • Added: Generate BNF and EBNF output separately.
  • Added: Allow to hide main toolbar.
File:
1 edited

Legend:

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

    r130 r131  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   Menus, ActnList, ComCtrls, UPersistentForm, UGrammer;
     9  Menus, ActnList, ComCtrls, UPersistentForm, ULastOpenedList, UGrammer,
     10  XMLConf;
    1011
    1112type
     
    1516  TFormMain = class(TForm)
    1617    ABuildCompiler: TAction;
     18    AToolbarVisible: TAction;
     19    AProjectOpenRecent: TAction;
    1720    AProjectClose: TAction;
    1821    AGrammerSettings: TAction;
     
    2528    ActionList1: TActionList;
    2629    CoolBar1: TCoolBar;
     30    LastOpenedList1: TLastOpenedList;
    2731    MainMenu1: TMainMenu;
    2832    MemoEbnf: TMemo;
     
    3438    MenuItem13: TMenuItem;
    3539    MenuItem2: TMenuItem;
     40    MenuItemRecent: TMenuItem;
     41    MenuItemToolbar: TMenuItem;
    3642    MenuItem4: TMenuItem;
    3743    MenuItem5: TMenuItem;
     
    4248    OpenDialog1: TOpenDialog;
    4349    PageControl1: TPageControl;
     50    PopupMenuOpenRecent: TPopupMenu;
    4451    SaveDialog1: TSaveDialog;
    4552    TabSheetRules: TTabSheet;
     
    4754    TabSheetEbnf: TTabSheet;
    4855    ToolBar1: TToolBar;
     56    ToolButton1: TToolButton;
    4957    ToolButton2: TToolButton;
    5058    ToolButton3: TToolButton;
     
    5361    ToolButton6: TToolButton;
    5462    procedure ABuildCompilerExecute(Sender: TObject);
     63    procedure AToolbarVisibleExecute(Sender: TObject);
    5564    procedure AExitExecute(Sender: TObject);
    5665    procedure AGrammerSettingsExecute(Sender: TObject);
     
    5867    procedure AProjectNewExecute(Sender: TObject);
    5968    procedure AProjectOpenExecute(Sender: TObject);
     69    procedure AProjectOpenRecentExecute(Sender: TObject);
    6070    procedure AProjectCloseExecute(Sender: TObject);
    6171    procedure AProjectSaveAsExecute(Sender: TObject);
     
    6474    procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
    6575    procedure FormShow(Sender: TObject);
     76    procedure LastOpenedList1Change(Sender: TObject);
    6677  private
    67     procedure ReloadMemo;
    68     procedure UpdateInterface;
    6978    procedure GrammerChange(Sender: TObject);
    7079    procedure GrammerDestroy(Sender: TObject);
    7180  public
    72     { public declarations }
     81    procedure ReloadMemo;
     82    procedure UpdateInterface;
     83    procedure ProjectOpen(FileName: string);
     84    procedure ProjectNew;
     85    procedure LoadConfig(XmlConfig: TXmlConfig);
     86    procedure SaveConfig(XmlConfig: TXmlConfig);
    7387  end;
    7488
     
    108122  SaveDialog1.FileName := ExtractFileName(Core.Grammer.FileName);
    109123  if SaveDialog1.Execute then begin
    110     Core.LastOpenedFile := SaveDialog1.FileName;
     124    LastOpenedList1.AddItem(SaveDialog1.FileName);
    111125    Core.Grammer.SaveToXmlFile(SaveDialog1.FileName);
    112126    UpdateInterface;
     
    123137begin
    124138  Core.PersistentForm1.Save(Self);
     139  Core.Finalize;
    125140end;
    126141
     
    145160end;
    146161
     162procedure TFormMain.LastOpenedList1Change(Sender: TObject);
     163begin
     164  LastOpenedList1.LoadToMenuItem(MenuItemRecent, AProjectOpenRecentExecute);
     165  LastOpenedList1.LoadToMenuItem(PopupMenuOpenRecent.Items, AProjectOpenRecentExecute);
     166end;
     167
    147168procedure TFormMain.ReloadMemo;
    148169begin
    149170  if Assigned(Core.Grammer) then begin
    150     MemoBnf.Lines.Text := Core.Grammer.GetString;
    151     MemoEbnf.Lines.Text := Core.Grammer.GetString;
     171    MemoBnf.Lines.Text := Core.Grammer.ExportAsString(gnBnf);
     172    MemoEbnf.Lines.Text := Core.Grammer.ExportAsString(gnEbnf);
    152173  end else begin
    153174    MemoBnf.Lines.Clear;
     
    172193  ABuildCompiler.Enabled := Assigned(Core.Grammer);
    173194  ARules.Enabled := Assigned(Core.Grammer);
     195  CoolBar1.Visible := AToolbarVisible.Checked;
    174196end;
    175197
     
    194216    FormRules.UpdateInterface;
    195217  end;
     218end;
     219
     220procedure TFormMain.ProjectOpen(FileName: string);
     221begin
     222  if Assigned(Core.Grammer) then FreeAndNil(Core.Grammer);
     223  LastOpenedList1.AddItem(FileName);
     224  Core.Grammer := TGrammer.Create;
     225  Core.Grammer.OnChange := GrammerChange;
     226  Core.Grammer.OnDestroy := GrammerDestroy;
     227  Core.Grammer.LoadFromXmlFile(FileName);
     228  Core.Grammer.Change;
     229end;
     230
     231procedure TFormMain.ProjectNew;
     232begin
     233  if Assigned(Core.Grammer) then FreeAndNil(Core.Grammer);
     234  Core.Grammer := TGrammer.Create;
     235  Core.Grammer.OnChange := GrammerChange;
     236  Core.Grammer.OnDestroy := GrammerDestroy;
     237  Core.Grammer.FileName := SNewGrammer;
     238  Core.Grammer.Change;
     239end;
     240
     241procedure TFormMain.LoadConfig(XmlConfig: TXmlConfig);
     242begin
     243  AToolbarVisible.Checked := XmlConfig.GetValue('ToolbarVisible', True);
     244  LastOpenedList1.LoadFromXMLConfig(XMLConfig, 'LastOpenedFiles');
     245end;
     246
     247procedure TFormMain.SaveConfig(XmlConfig: TXmlConfig);
     248begin
     249  XmlConfig.SetValue('ToolbarVisible', AToolbarVisible.Checked);
     250  LastOpenedList1.SaveToXMLConfig(XMLConfig, 'LastOpenedFiles');
    196251end;
    197252
     
    214269end;
    215270
     271procedure TFormMain.AProjectOpenRecentExecute(Sender: TObject);
     272begin
     273  if Sender is TMenuItem then ProjectOpen(TMenuItem(Sender).Caption);
     274end;
     275
    216276procedure TFormMain.AProjectNewExecute(Sender: TObject);
    217277begin
    218278  AProjectClose.Execute;
    219279  if not Assigned(Core.Grammer) then begin
    220     Core.Grammer := TGrammer.Create;
    221     Core.Grammer.FileName := SNewGrammer;
    222     Core.Grammer.OnChange := GrammerChange;
    223     Core.Grammer.OnDestroy := GrammerDestroy;
    224     Core.Grammer.Change;
     280    ProjectNew;
    225281  end;
    226282end;
     
    239295end;
    240296
     297procedure TFormMain.AToolbarVisibleExecute(Sender: TObject);
     298begin
     299  UpdateInterface;
     300end;
     301
    241302procedure TFormMain.AProjectOpenExecute(Sender: TObject);
    242303begin
    243304  AProjectClose.Execute;
    244305  if not Assigned(Core.Grammer) then begin
    245     OpenDialog1.InitialDir := ExtractFileDir(Core.LastOpenedFile);
    246     OpenDialog1.FileName := ExtractFileName(Core.LastOpenedFile);
     306    OpenDialog1.InitialDir := ExtractFileDir(LastOpenedList1.GetFirstFileName);
     307    OpenDialog1.FileName := ExtractFileName(LastOpenedList1.GetFirstFileName);
    247308    if OpenDialog1.Execute then begin
    248       Core.LastOpenedFile := OpenDialog1.FileName;
    249       Core.Grammer := TGrammer.Create;
    250       Core.Grammer.OnChange := GrammerChange;
    251       Core.Grammer.OnDestroy := GrammerDestroy;
    252       Core.Grammer.LoadFromXmlFile(OpenDialog1.FileName);
    253       Core.Grammer.Change;
     309      ProjectOpen(OpenDialog1.FileName);
    254310    end;
    255311  end;
Note: See TracChangeset for help on using the changeset viewer.