Changeset 233 for branches/xpascal/Forms/FormMain.pas
- Timestamp:
- Jun 26, 2023, 6:08:23 PM (17 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/xpascal/Forms/FormMain.pas
r230 r233 4 4 5 5 uses 6 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Menus, 7 ActnList, ExtCtrls, SynHighlighterPas, SynEdit, Source, Optimizer, 8 Generator, FormSource, FormMessages, FormOutput, FormConsole, FormEx; 6 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Menus, LazFileUtils, 7 ActnList, ExtCtrls, SynHighlighterPas, SynEdit, Source, Optimizer, RegistryEx, 8 Generator, FormSource, FormMessages, FormOutput, FormConsole, FormEx, 9 ApplicationInfo; 9 10 10 11 type … … 15 16 ACompile: TAction; 16 17 AConsole: TAction; 18 AFileOpen: TAction; 19 ApplicationInfo1: TApplicationInfo; 17 20 ATest: TAction; 18 21 AGenerateXml: TAction; … … 25 28 MainMenu1: TMainMenu; 26 29 MenuItem1: TMenuItem; 30 MenuItem10: TMenuItem; 27 31 MenuItem2: TMenuItem; 28 32 MenuItem3: TMenuItem; … … 36 40 MenuItemGenerate: TMenuItem; 37 41 MenuItemFile: TMenuItem; 42 OpenDialog1: TOpenDialog; 38 43 PanelOutput: TPanel; 39 44 PanelSource: TPanel; … … 43 48 procedure AConsoleExecute(Sender: TObject); 44 49 procedure AExitExecute(Sender: TObject); 50 procedure AFileOpenExecute(Sender: TObject); 45 51 procedure AGenerateCSharpExecute(Sender: TObject); 46 52 procedure AGeneratePascalExecute(Sender: TObject); … … 51 57 procedure ARunExecute(Sender: TObject); 52 58 procedure FormActivate(Sender: TObject); 59 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); 53 60 procedure FormCreate(Sender: TObject); 54 61 procedure FormDestroy(Sender: TObject); 55 62 procedure FormShow(Sender: TObject); 56 63 private 64 LastFileName: string; 57 65 Prog: TProgram; 58 66 Initialized: Boolean; … … 61 69 FormOutput: TFormOutput; 62 70 FormConsole: TFormConsole; 71 procedure LoadFromRegistry; 72 procedure SaveToRegistry; 73 procedure ProjectOpen(FileName: string); 63 74 procedure Generate(GeneratorClass: TGeneratorClass); 64 75 procedure ExecutorOutput(Text: string); … … 87 98 if not Initialized then begin 88 99 Initialized := True; 89 FormSource.SynEditSource.Lines.LoadFromFile('Examples' + DirectorySeparator + 90 'Example.pas'); 91 ARun.Execute; 100 ProjectOpen(LastFileName); 101 //ARun.Execute; 92 102 end; 93 103 end; … … 104 114 procedure TFormMain.FormShow(Sender: TObject); 105 115 begin 116 LoadFromRegistry; 106 117 FormMessages := TFormMessages.Create(nil); 107 118 FormMessages.Show; … … 119 130 end; 120 131 132 procedure TFormMain.LoadFromRegistry; 133 begin 134 with TRegistryEx.Create do 135 try 136 CurrentContext := ApplicationInfo1.GetRegistryContext; 137 LastFileName := ReadStringWithDefault('LastFileName', 'Examples' + DirectorySeparator + 'Example.pas'); 138 finally 139 Free; 140 end; 141 end; 142 143 procedure TFormMain.SaveToRegistry; 144 begin 145 with TRegistryEx.Create do 146 try 147 CurrentContext := ApplicationInfo1.GetRegistryContext; 148 WriteString('LastFileName', LastFileName); 149 finally 150 Free; 151 end; 152 end; 153 154 procedure TFormMain.ProjectOpen(FileName: string); 155 begin 156 LastFileName := FileName; 157 FormSource.SynEditSource.Lines.LoadFromFile(FileName); 158 end; 159 121 160 procedure TFormMain.Generate(GeneratorClass: TGeneratorClass); 122 161 var … … 130 169 FormOutput.SetText(Generator.Output); 131 170 TargetFileName := 'Generated' + DirectorySeparator + 132 Generator.Name + DirectorySeparator + 'Example'+ Generator.FileExt;171 Generator.Name + DirectorySeparator + ExtractFileNameOnly(LastFileName) + Generator.FileExt; 133 172 ForceDirectories(ExtractFileDir(TargetFileName)); 134 173 FormOutput.SynEditOutput.Lines.SaveToFile(TargetFileName); … … 141 180 begin 142 181 Close; 182 end; 183 184 procedure TFormMain.AFileOpenExecute(Sender: TObject); 185 begin 186 OpenDialog1.InitialDir := ExtractFileDir(LastFileName); 187 OpenDialog1.FileName := ExtractFileName(LastFileName); 188 if OpenDialog1.Execute then begin 189 ProjectOpen(OpenDialog1.FileName); 190 end; 143 191 end; 144 192 … … 224 272 end; 225 273 274 procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction); 275 begin 276 FormConsole.Terminated := True; 277 SaveToRegistry; 278 end; 279 226 280 procedure TFormMain.FormCreate(Sender: TObject); 227 281 begin … … 248 302 begin 249 303 ACompile.Execute; 250 FormOutput.SynEditOutput.Highlighter := nil; 251 FormOutput.SynEditOutput.Lines.Clear; 304 FormConsole.Memo1.Lines.Clear; 252 305 if Assigned(Prog) then begin 253 306 Executor := TExecutor.Create;
Note:
See TracChangeset
for help on using the changeset viewer.