Changeset 126 for branches/generator/Forms
- Timestamp:
- Nov 30, 2017, 12:02:32 AM (7 years ago)
- Location:
- branches/generator/Forms
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/generator/Forms/UFormGrammer.pas
r124 r126 62 62 procedure TFormGrammer.SaveData(Grammer: TGrammer); 63 63 begin 64 Grammer.Modified := True; 64 65 if ComboBoxStartRule.ItemIndex <> -1 then 65 66 Grammer.TopRule := TRule(ComboBoxStartRule.Items.Objects[ComboBoxStartRule.ItemIndex]) -
branches/generator/Forms/UFormMain.lfm
r124 r126 5 5 Width = 1050 6 6 Caption = 'Language generator' 7 ClientHeight = 6 537 ClientHeight = 644 8 8 ClientWidth = 1050 9 9 Menu = MainMenu1 10 10 OnClose = FormClose 11 OnCloseQuery = FormCloseQuery 11 12 OnShow = FormShow 12 LCLVersion = '1. 6.4.0'13 LCLVersion = '1.8.0.4' 13 14 object MemoBNF: TMemo 14 15 Left = 0 15 Height = 6 1816 Height = 609 16 17 Top = 35 17 18 Width = 1050 18 19 Align = alClient 20 ReadOnly = True 19 21 ScrollBars = ssAutoBoth 20 22 TabOrder = 0 … … 69 71 Caption = 'File' 70 72 object MenuItem11: TMenuItem 71 Action = A New73 Action = AProjectNew 72 74 end 73 75 object MenuItem4: TMenuItem 74 Action = A Open76 Action = AProjectOpen 75 77 end 76 78 object MenuItem10: TMenuItem 77 Action = A Save79 Action = AProjectSave 78 80 end 79 81 object MenuItem5: TMenuItem 80 Action = ASaveAs 82 Action = AProjectSaveAs 83 end 84 object MenuItem13: TMenuItem 85 Action = AProjectClose 81 86 end 82 87 object MenuItem12: TMenuItem … … 119 124 OnExecute = AExitExecute 120 125 end 121 object A Open: TAction126 object AProjectOpen: TAction 122 127 Caption = 'Open...' 123 128 Hint = 'Open...' 124 129 ImageIndex = 4 125 OnExecute = A OpenExecute130 OnExecute = AProjectOpenExecute 126 131 end 127 object A SaveAs: TAction132 object AProjectSaveAs: TAction 128 133 Caption = 'Save as...' 129 134 Hint = 'Save as...' 130 135 ImageIndex = 5 131 OnExecute = A SaveAsExecute136 OnExecute = AProjectSaveAsExecute 132 137 end 133 138 object ABuildCompiler: TAction … … 136 141 OnExecute = ABuildCompilerExecute 137 142 end 138 object A Save: TAction143 object AProjectSave: TAction 139 144 Caption = 'Save' 140 145 ImageIndex = 5 141 OnExecute = A SaveExecute146 OnExecute = AProjectSaveExecute 142 147 end 143 object A New: TAction148 object AProjectNew: TAction 144 149 Caption = 'New' 145 150 ImageIndex = 10 146 OnExecute = A NewExecute151 OnExecute = AProjectNewExecute 147 152 end 148 153 object AGrammerSettings: TAction 149 154 Caption = 'Settings' 150 155 OnExecute = AGrammerSettingsExecute 156 end 157 object AProjectClose: TAction 158 Caption = 'Close' 159 OnExecute = AProjectCloseExecute 151 160 end 152 161 end -
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; -
branches/generator/Forms/UFormRule.pas
r123 r126 96 96 procedure TFormRule.SaveData(Rule: TRule); 97 97 begin 98 Rule.Grammer.Modified := True; 98 99 Rule.Name := EditName.Text; 99 100 Rule.CreateSourceNode := CheckBoxCreateNode.Checked; -
branches/generator/Forms/UFormRuleItem.pas
r124 r126 143 143 procedure TFormRuleItem.SaveData(RuleItem: TRuleItem); 144 144 begin 145 RuleItem.Grammer.Modified := True; 145 146 TFormRuleItems(FormRuleItems).SaveData(RuleItem.SubItems); 146 147 RuleItem.RuleItemType := TRuleItemType(ComboBoxType.ItemIndex); -
branches/generator/Forms/UFormRuleItems.pas
r122 r126 130 130 mtConfirmation, mbYesNo, 0) = mrYes then 131 131 for I := ListView1.Items.Count - 1 downto 0 do 132 if ListView1.Items[I].Selected then 132 if ListView1.Items[I].Selected then begin 133 133 RuleItems.ParentRule.Items.Remove(TRuleItem(ListView1.Items[I].Data)); 134 RuleItems.Grammer.Modified := True; 135 end; 134 136 ReloadList; 135 137 end; -
branches/generator/Forms/UFormRules.pas
r122 r126 121 121 mtConfirmation, mbYesNo, 0) = mrYes then 122 122 for I := ListView1.Items.Count - 1 downto 0 do 123 if ListView1.Items[I].Selected then 123 if ListView1.Items[I].Selected then begin 124 Rules.Grammer.Modified := True; 124 125 Rules.Remove(TRule(ListView1.Items[I].Data)); 126 end; 125 127 ReloadList; 126 128 end;
Note:
See TracChangeset
for help on using the changeset viewer.