Changeset 126 for branches/generator/Forms/UFormMain.pas
- Timestamp:
- Nov 30, 2017, 12:02:32 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/generator/Forms/UFormMain.pas
r124 r126 15 15 TFormMain = class(TForm) 16 16 ABuildCompiler: TAction; 17 AProjectClose: TAction; 17 18 AGrammerSettings: TAction; 18 A New: TAction;19 A Save: TAction;19 AProjectNew: TAction; 20 AProjectSave: TAction; 20 21 AExit: TAction; 21 A Open: TAction;22 A SaveAs: TAction;22 AProjectOpen: TAction; 23 AProjectSaveAs: TAction; 23 24 ARules: TAction; 24 25 ActionList1: TActionList; … … 30 31 MenuItem11: TMenuItem; 31 32 MenuItem12: TMenuItem; 33 MenuItem13: TMenuItem; 32 34 MenuItem2: TMenuItem; 33 35 MenuItem3: TMenuItem; … … 46 48 procedure AExitExecute(Sender: TObject); 47 49 procedure AGrammerSettingsExecute(Sender: TObject); 48 procedure ANewExecute(Sender: TObject);49 procedure AOpenExecute(Sender: TObject);50 50 procedure ARulesExecute(Sender: TObject); 51 procedure ASaveAsExecute(Sender: TObject); 52 procedure ASaveExecute(Sender: TObject); 51 procedure AProjectNewExecute(Sender: TObject); 52 procedure AProjectOpenExecute(Sender: TObject); 53 procedure AProjectCloseExecute(Sender: TObject); 54 procedure AProjectSaveAsExecute(Sender: TObject); 55 procedure AProjectSaveExecute(Sender: TObject); 53 56 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); 57 procedure FormCloseQuery(Sender: TObject; var CanClose: boolean); 54 58 procedure FormShow(Sender: TObject); 55 59 private … … 71 75 UFormRules, UCore, UFormGrammer; 72 76 73 { TFormMain } 77 resourcestring 78 SUnsavedChanges = 'Unsaved changes'; 79 SDoYouWantToSaveProject = 'There are unsaved changes in project. Do you want to save them?'; 80 SNewGrammer = 'New grammer.xtg'; 81 82 { TFormMain } 74 83 75 84 procedure TFormMain.ARulesExecute(Sender: TObject); … … 81 90 FormRules.ShowModal; 82 91 ReloadMemo; 92 UpdateInterface; 83 93 FreeAndNil(FormRules); 84 94 end; 85 95 86 procedure TFormMain.A SaveAsExecute(Sender: TObject);96 procedure TFormMain.AProjectSaveAsExecute(Sender: TObject); 87 97 begin 88 98 SaveDialog1.FileName := Core.Grammer.FileName; 89 99 if SaveDialog1.Execute then begin 100 Core.LastOpenedFile := SaveDialog1.FileName; 90 101 Core.Grammer.SaveToXmlFile(SaveDialog1.FileName); 91 102 UpdateInterface; … … 93 104 end; 94 105 95 procedure TFormMain.A SaveExecute(Sender: TObject);106 procedure TFormMain.AProjectSaveExecute(Sender: TObject); 96 107 begin 97 108 Core.Grammer.SaveToXmlFile(Core.Grammer.FileName); … … 104 115 end; 105 116 117 procedure TFormMain.FormCloseQuery(Sender: TObject; var CanClose: boolean); 118 begin 119 AProjectClose.Execute; 120 if Assigned(Core.Grammer) then CanClose := False; 121 end; 122 106 123 procedure TFormMain.FormShow(Sender: TObject); 107 124 begin 108 125 Core.PersistentForm1.Load(Self, True); 126 Core.Initialize; 109 127 ReloadMemo; 110 128 UpdateInterface; … … 113 131 procedure TFormMain.ReloadMemo; 114 132 begin 115 MemoBNF.Lines.Text := Core.Grammer.GetString; 133 if Assigned(Core.Grammer) then 134 MemoBNF.Lines.Text := Core.Grammer.GetString 135 else MemoBNF.Lines.Clear; 116 136 end; 117 137 118 138 procedure TFormMain.UpdateInterface; 119 begin 120 Caption := Core.Grammer.FileName + ' - ' + Application.Title; 139 var 140 NewTitle: string; 141 begin 142 NewTitle := Application.Title; 143 if Assigned(Core.Grammer) then begin 144 NewTitle := ExtractFileNameWithoutExt(ExtractFileName(Core.Grammer.FileName)) + ' - ' + NewTitle; 145 if Core.Grammer.Modified then NewTitle := NewTitle + '*'; 146 end; 147 Caption := NewTitle; 148 AProjectClose.Enabled := Assigned(Core.Grammer); 149 AProjectSave.Enabled := Assigned(Core.Grammer) and Core.Grammer.Modified; 150 AProjectSaveAs.Enabled := Assigned(Core.Grammer); 151 AGrammerSettings.Enabled := Assigned(Core.Grammer); 152 ABuildCompiler.Enabled := Assigned(Core.Grammer); 153 ARules.Enabled := Assigned(Core.Grammer); 121 154 end; 122 155 … … 134 167 if FormGrammer.ShowModal = mrOk then begin 135 168 FormGrammer.SaveData(Core.Grammer); 169 UpdateInterface; 136 170 end; 137 171 FreeAndNil(FormGrammer); 138 172 end; 139 173 140 procedure TFormMain.ANewExecute(Sender: TObject); 141 begin 142 Core.Grammer.Rules.Clear; 143 ReloadMemo; 144 UpdateInterface; 174 procedure TFormMain.AProjectNewExecute(Sender: TObject); 175 begin 176 AProjectClose.Execute; 177 if not Assigned(Core.Grammer) then begin 178 Core.Grammer := TGrammer.Create; 179 Core.Grammer.FileName := SNewGrammer; 180 ReloadMemo; 181 UpdateInterface; 182 end; 145 183 end; 146 184 … … 150 188 end; 151 189 152 procedure TFormMain.AOpenExecute(Sender: TObject); 153 begin 154 OpenDialog1.FileName := Core.Grammer.FileName; 155 if OpenDialog1.Execute then begin 156 Core.Grammer.LoadFromXmlFile(OpenDialog1.FileName); 190 procedure TFormMain.AProjectOpenExecute(Sender: TObject); 191 begin 192 AProjectClose.Execute; 193 if not Assigned(Core.Grammer) then begin 194 OpenDialog1.FileName := Core.LastOpenedFile; 195 if OpenDialog1.Execute then begin 196 Core.LastOpenedFile := OpenDialog1.FileName; 197 Core.Grammer := TGrammer.Create; 198 Core.Grammer.LoadFromXmlFile(OpenDialog1.FileName); 199 ReloadMemo; 200 UpdateInterface; 201 end; 202 end; 203 end; 204 205 procedure TFormMain.AProjectCloseExecute(Sender: TObject); 206 var 207 DialogResult: TModalResult; 208 begin 209 if not Assigned(Core.Grammer) then Exit; 210 211 DialogResult := mrNo; 212 if Core.Grammer.Modified then begin 213 DialogResult := MessageDlg(SUnsavedChanges, SDoYouWantToSaveProject, mtConfirmation, [mbYes, mbNo, mbCancel], 0); 214 if DialogResult = mrYes then begin 215 AProjectSave.Execute; 216 end; 217 end; 218 if (DialogResult = mrNo) or (DialogResult = mrYes) then begin 219 FreeAndNil(Core.Grammer); 157 220 ReloadMemo; 158 221 UpdateInterface;
Note:
See TracChangeset
for help on using the changeset viewer.