Changeset 131 for branches/generator/Forms/UFormMain.pas
- Timestamp:
- Dec 24, 2017, 3:54:08 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/generator/Forms/UFormMain.pas
r130 r131 7 7 uses 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, 9 Menus, ActnList, ComCtrls, UPersistentForm, UGrammer; 9 Menus, ActnList, ComCtrls, UPersistentForm, ULastOpenedList, UGrammer, 10 XMLConf; 10 11 11 12 type … … 15 16 TFormMain = class(TForm) 16 17 ABuildCompiler: TAction; 18 AToolbarVisible: TAction; 19 AProjectOpenRecent: TAction; 17 20 AProjectClose: TAction; 18 21 AGrammerSettings: TAction; … … 25 28 ActionList1: TActionList; 26 29 CoolBar1: TCoolBar; 30 LastOpenedList1: TLastOpenedList; 27 31 MainMenu1: TMainMenu; 28 32 MemoEbnf: TMemo; … … 34 38 MenuItem13: TMenuItem; 35 39 MenuItem2: TMenuItem; 40 MenuItemRecent: TMenuItem; 41 MenuItemToolbar: TMenuItem; 36 42 MenuItem4: TMenuItem; 37 43 MenuItem5: TMenuItem; … … 42 48 OpenDialog1: TOpenDialog; 43 49 PageControl1: TPageControl; 50 PopupMenuOpenRecent: TPopupMenu; 44 51 SaveDialog1: TSaveDialog; 45 52 TabSheetRules: TTabSheet; … … 47 54 TabSheetEbnf: TTabSheet; 48 55 ToolBar1: TToolBar; 56 ToolButton1: TToolButton; 49 57 ToolButton2: TToolButton; 50 58 ToolButton3: TToolButton; … … 53 61 ToolButton6: TToolButton; 54 62 procedure ABuildCompilerExecute(Sender: TObject); 63 procedure AToolbarVisibleExecute(Sender: TObject); 55 64 procedure AExitExecute(Sender: TObject); 56 65 procedure AGrammerSettingsExecute(Sender: TObject); … … 58 67 procedure AProjectNewExecute(Sender: TObject); 59 68 procedure AProjectOpenExecute(Sender: TObject); 69 procedure AProjectOpenRecentExecute(Sender: TObject); 60 70 procedure AProjectCloseExecute(Sender: TObject); 61 71 procedure AProjectSaveAsExecute(Sender: TObject); … … 64 74 procedure FormCloseQuery(Sender: TObject; var CanClose: boolean); 65 75 procedure FormShow(Sender: TObject); 76 procedure LastOpenedList1Change(Sender: TObject); 66 77 private 67 procedure ReloadMemo;68 procedure UpdateInterface;69 78 procedure GrammerChange(Sender: TObject); 70 79 procedure GrammerDestroy(Sender: TObject); 71 80 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); 73 87 end; 74 88 … … 108 122 SaveDialog1.FileName := ExtractFileName(Core.Grammer.FileName); 109 123 if SaveDialog1.Execute then begin 110 Core.LastOpenedFile := SaveDialog1.FileName;124 LastOpenedList1.AddItem(SaveDialog1.FileName); 111 125 Core.Grammer.SaveToXmlFile(SaveDialog1.FileName); 112 126 UpdateInterface; … … 123 137 begin 124 138 Core.PersistentForm1.Save(Self); 139 Core.Finalize; 125 140 end; 126 141 … … 145 160 end; 146 161 162 procedure TFormMain.LastOpenedList1Change(Sender: TObject); 163 begin 164 LastOpenedList1.LoadToMenuItem(MenuItemRecent, AProjectOpenRecentExecute); 165 LastOpenedList1.LoadToMenuItem(PopupMenuOpenRecent.Items, AProjectOpenRecentExecute); 166 end; 167 147 168 procedure TFormMain.ReloadMemo; 148 169 begin 149 170 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); 152 173 end else begin 153 174 MemoBnf.Lines.Clear; … … 172 193 ABuildCompiler.Enabled := Assigned(Core.Grammer); 173 194 ARules.Enabled := Assigned(Core.Grammer); 195 CoolBar1.Visible := AToolbarVisible.Checked; 174 196 end; 175 197 … … 194 216 FormRules.UpdateInterface; 195 217 end; 218 end; 219 220 procedure TFormMain.ProjectOpen(FileName: string); 221 begin 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; 229 end; 230 231 procedure TFormMain.ProjectNew; 232 begin 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; 239 end; 240 241 procedure TFormMain.LoadConfig(XmlConfig: TXmlConfig); 242 begin 243 AToolbarVisible.Checked := XmlConfig.GetValue('ToolbarVisible', True); 244 LastOpenedList1.LoadFromXMLConfig(XMLConfig, 'LastOpenedFiles'); 245 end; 246 247 procedure TFormMain.SaveConfig(XmlConfig: TXmlConfig); 248 begin 249 XmlConfig.SetValue('ToolbarVisible', AToolbarVisible.Checked); 250 LastOpenedList1.SaveToXMLConfig(XMLConfig, 'LastOpenedFiles'); 196 251 end; 197 252 … … 214 269 end; 215 270 271 procedure TFormMain.AProjectOpenRecentExecute(Sender: TObject); 272 begin 273 if Sender is TMenuItem then ProjectOpen(TMenuItem(Sender).Caption); 274 end; 275 216 276 procedure TFormMain.AProjectNewExecute(Sender: TObject); 217 277 begin 218 278 AProjectClose.Execute; 219 279 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; 225 281 end; 226 282 end; … … 239 295 end; 240 296 297 procedure TFormMain.AToolbarVisibleExecute(Sender: TObject); 298 begin 299 UpdateInterface; 300 end; 301 241 302 procedure TFormMain.AProjectOpenExecute(Sender: TObject); 242 303 begin 243 304 AProjectClose.Execute; 244 305 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); 247 308 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); 254 310 end; 255 311 end;
Note:
See TracChangeset
for help on using the changeset viewer.