Changeset 4 for trunk/UMainForm.pas


Ignore:
Timestamp:
Feb 9, 2012, 1:43:33 PM (13 years ago)
Author:
chronos
Message:
  • Fixed: New, open, save, save as, close project now working.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UMainForm.pas

    r3 r4  
    4242    MenuItem8: TMenuItem;
    4343    MenuItem9: TMenuItem;
     44    OpenDialog1: TOpenDialog;
     45    SaveDialog1: TSaveDialog;
    4446    StatusBar1: TStatusBar;
    4547    TabControl1: TTabControl;
     
    5355    ToolButton7: TToolButton;
    5456    procedure AExitExecute(Sender: TObject);
     57    procedure AProjectCloseExecute(Sender: TObject);
     58    procedure AProjectNewExecute(Sender: TObject);
     59    procedure AProjectOpenExecute(Sender: TObject);
     60    procedure AProjectSaveAsExecute(Sender: TObject);
     61    procedure AProjectSaveExecute(Sender: TObject);
    5562    procedure ARunExecute(Sender: TObject);
     63    procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
    5664    procedure FormCreate(Sender: TObject);
    5765    procedure FormDestroy(Sender: TObject);
    5866    procedure FormShow(Sender: TObject);
     67    procedure MemoSourceChange(Sender: TObject);
    5968  private
    6069    { private declarations }
    6170  public
     71    Modified: Boolean;
     72    ProjectFileName: string;
    6273    BrainFuckInterpreter: TBrainFuckInterpreter;
     74    procedure UpdateInterface;
    6375  end;
    6476
     
    7183
    7284uses
    73   UInterpreterForm;
     85  UInterpreterForm, UApplicationInfo;
    7486
    7587{ TMainForm }
     
    7789procedure TMainForm.FormShow(Sender: TObject);
    7890begin
     91  UpdateInterface;
     92end;
    7993
     94procedure TMainForm.MemoSourceChange(Sender: TObject);
     95begin
     96  Modified := True;
     97  UpdateInterface;
     98end;
     99
     100procedure TMainForm.UpdateInterface;
     101var
     102  Title: string;
     103begin
     104  AProjectSave.Enabled := Modified;
     105  Title := ApplicationInfo.Name;
     106  if ProjectFileName <> '' then Title := ProjectFileName + ' - ' + Title;
     107  if Modified then Title := Title + ' *';
     108  Caption := Title;
     109  MemoSource.Enabled := ProjectFileName <> '';
     110  AProjectClose.Enabled := ProjectFileName <> '';
     111  ARun.Enabled := ProjectFileName <> '';
     112  ACompile.Enabled := ProjectFileName <> '';
    80113end;
    81114
     
    99132end;
    100133
     134procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: boolean);
     135begin
     136end;
     137
    101138procedure TMainForm.AExitExecute(Sender: TObject);
    102139begin
     
    104141end;
    105142
     143procedure TMainForm.AProjectCloseExecute(Sender: TObject);
     144begin
     145  Modified := False;
     146  ProjectFileName := '';
     147  MemoSource.Clear;
     148  UpdateInterface;
     149end;
     150
     151procedure TMainForm.AProjectNewExecute(Sender: TObject);
     152begin
     153  ProjectFileName := 'Project.bf';
     154  MemoSource.Clear;
     155  UpdateInterface;
     156end;
     157
     158procedure TMainForm.AProjectOpenExecute(Sender: TObject);
     159begin
     160  OpenDialog1.FileName := ProjectFileName;
     161  if OpenDialog1.Execute then begin
     162    MemoSource.Lines.LoadFromFile(OpenDialog1.FileName);
     163    ProjectFileName := OpenDialog1.FileName;
     164    UpdateInterface;
     165  end;
     166end;
     167
     168procedure TMainForm.AProjectSaveAsExecute(Sender: TObject);
     169begin
     170  SaveDialog1.FileName := ProjectFileName;
     171  if SaveDialog1.Execute then begin
     172    MemoSource.Lines.SaveToFile(SaveDialog1.FileName);
     173    ProjectFileName := SaveDialog1.FileName;
     174    Modified := False;
     175    UpdateInterface;
     176  end;
     177end;
     178
     179procedure TMainForm.AProjectSaveExecute(Sender: TObject);
     180begin
     181  if Modified then AProjectSaveAs.Execute;
     182end;
     183
    106184end.
    107185
Note: See TracChangeset for help on using the changeset viewer.