Ignore:
Timestamp:
Jun 26, 2023, 6:08:23 PM (17 months ago)
Author:
chronos
Message:
  • Added: Support for procedures.
  • Added: Project pascal file can be opened from main menu. Last file name is remembered.
  • Modified: Improved XML output of source structure.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/xpascal/Forms/FormMain.pas

    r230 r233  
    44
    55uses
    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;
    910
    1011type
     
    1516    ACompile: TAction;
    1617    AConsole: TAction;
     18    AFileOpen: TAction;
     19    ApplicationInfo1: TApplicationInfo;
    1720    ATest: TAction;
    1821    AGenerateXml: TAction;
     
    2528    MainMenu1: TMainMenu;
    2629    MenuItem1: TMenuItem;
     30    MenuItem10: TMenuItem;
    2731    MenuItem2: TMenuItem;
    2832    MenuItem3: TMenuItem;
     
    3640    MenuItemGenerate: TMenuItem;
    3741    MenuItemFile: TMenuItem;
     42    OpenDialog1: TOpenDialog;
    3843    PanelOutput: TPanel;
    3944    PanelSource: TPanel;
     
    4348    procedure AConsoleExecute(Sender: TObject);
    4449    procedure AExitExecute(Sender: TObject);
     50    procedure AFileOpenExecute(Sender: TObject);
    4551    procedure AGenerateCSharpExecute(Sender: TObject);
    4652    procedure AGeneratePascalExecute(Sender: TObject);
     
    5157    procedure ARunExecute(Sender: TObject);
    5258    procedure FormActivate(Sender: TObject);
     59    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    5360    procedure FormCreate(Sender: TObject);
    5461    procedure FormDestroy(Sender: TObject);
    5562    procedure FormShow(Sender: TObject);
    5663  private
     64    LastFileName: string;
    5765    Prog: TProgram;
    5866    Initialized: Boolean;
     
    6169    FormOutput: TFormOutput;
    6270    FormConsole: TFormConsole;
     71    procedure LoadFromRegistry;
     72    procedure SaveToRegistry;
     73    procedure ProjectOpen(FileName: string);
    6374    procedure Generate(GeneratorClass: TGeneratorClass);
    6475    procedure ExecutorOutput(Text: string);
     
    8798  if not Initialized then begin
    8899    Initialized := True;
    89     FormSource.SynEditSource.Lines.LoadFromFile('Examples' + DirectorySeparator +
    90       'Example.pas');
    91     ARun.Execute;
     100    ProjectOpen(LastFileName);
     101    //ARun.Execute;
    92102  end;
    93103end;
     
    104114procedure TFormMain.FormShow(Sender: TObject);
    105115begin
     116  LoadFromRegistry;
    106117  FormMessages := TFormMessages.Create(nil);
    107118  FormMessages.Show;
     
    119130end;
    120131
     132procedure TFormMain.LoadFromRegistry;
     133begin
     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;
     141end;
     142
     143procedure TFormMain.SaveToRegistry;
     144begin
     145  with TRegistryEx.Create do
     146  try
     147    CurrentContext := ApplicationInfo1.GetRegistryContext;
     148    WriteString('LastFileName', LastFileName);
     149  finally
     150    Free;
     151  end;
     152end;
     153
     154procedure TFormMain.ProjectOpen(FileName: string);
     155begin
     156  LastFileName := FileName;
     157  FormSource.SynEditSource.Lines.LoadFromFile(FileName);
     158end;
     159
    121160procedure TFormMain.Generate(GeneratorClass: TGeneratorClass);
    122161var
     
    130169    FormOutput.SetText(Generator.Output);
    131170    TargetFileName := 'Generated' + DirectorySeparator +
    132       Generator.Name + DirectorySeparator + 'Example' + Generator.FileExt;
     171      Generator.Name + DirectorySeparator + ExtractFileNameOnly(LastFileName) + Generator.FileExt;
    133172    ForceDirectories(ExtractFileDir(TargetFileName));
    134173    FormOutput.SynEditOutput.Lines.SaveToFile(TargetFileName);
     
    141180begin
    142181  Close;
     182end;
     183
     184procedure TFormMain.AFileOpenExecute(Sender: TObject);
     185begin
     186  OpenDialog1.InitialDir := ExtractFileDir(LastFileName);
     187  OpenDialog1.FileName := ExtractFileName(LastFileName);
     188  if OpenDialog1.Execute then begin
     189    ProjectOpen(OpenDialog1.FileName);
     190  end;
    143191end;
    144192
     
    224272end;
    225273
     274procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
     275begin
     276  FormConsole.Terminated := True;
     277  SaveToRegistry;
     278end;
     279
    226280procedure TFormMain.FormCreate(Sender: TObject);
    227281begin
     
    248302begin
    249303  ACompile.Execute;
    250   FormOutput.SynEditOutput.Highlighter := nil;
    251   FormOutput.SynEditOutput.Lines.Clear;
     304  FormConsole.Memo1.Lines.Clear;
    252305  if Assigned(Prog) then begin
    253306    Executor := TExecutor.Create;
Note: See TracChangeset for help on using the changeset viewer.