Ignore:
Timestamp:
Dec 5, 2014, 8:34:59 PM (10 years ago)
Author:
chronos
Message:
  • Added: Confirmation dialog for closing and saving file.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormMain.pas

    r64 r65  
    180180  SDone = 'Done';
    181181  SChanged = 'Changed';
     182  SUnsavedChanges = 'Unsaved changes';
     183  SDoYouWantToSaveProject = 'There are unsaved changes in project. Do you want to save them?';
     184  SCloseProjectFirst = 'Project need to be closed before it can be openned';
    182185
    183186{ TMainForm }
     
    259262procedure TMainForm.ProjectOpen(FileName: string);
    260263begin
    261   AProjectClose.Execute;
     264  if Core.Project.Openned then
     265    raise Exception.Create(SCloseProjectFirst);
    262266  FormSourceCode.MemoSource.Lines.LoadFromFile(UTF8Decode(FileName));
    263267  Core.LastOpenedList.AddItem(FileName);
     
    455459procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: boolean);
    456460begin
    457   if Core.Project.Modified then AProjectSaveAs.Execute;
     461  if Core.Project.Modified then begin
     462    AProjectClose.Execute;
     463    if Core.Project.Openned then CanClose := False;
     464  end;
    458465end;
    459466
     
    564571
    565572procedure TMainForm.AProjectCloseExecute(Sender: TObject);
    566 begin
    567   if Core.Project.Modified then AProjectSaveAs.Execute;
    568   AProgramStop.Execute;
    569   Core.Project.Openned := False;
    570   FormSourceCode.MemoSource.Clear;
    571   UpdateInterface;
     573var
     574  DialogResult: TModalResult;
     575begin
     576  DialogResult := mrNo;
     577  if Core.Project.Modified then begin
     578    DialogResult := MessageDlg(SUnsavedChanges, SDoYouWantToSaveProject, mtConfirmation, [mbYes, mbNo, mbCancel], 0);
     579    if DialogResult = mrYes then begin
     580      AProjectSave.Execute;
     581    end;
     582  end;
     583  if (DialogResult = mrNo) or (DialogResult = mrYes) then begin
     584    AProgramStop.Execute;
     585    Core.Project.Openned := False;
     586    FormSourceCode.MemoSource.Clear;
     587    UpdateInterface;
     588  end;
    572589end;
    573590
     
    575592begin
    576593  AProjectClose.Execute;
     594  if Core.Project.Openned then Exit;
    577595  Core.Project.FileName := 'Examples' + DirectorySeparator + SNewProject + '.b';
    578596  FormSourceCode.MemoSource.Clear;
     
    584602procedure TMainForm.AProjectOpenRecentExecute(Sender: TObject);
    585603begin
     604  AProjectClose.Execute;
     605  if Core.Project.Openned then Exit;
    586606  ProjectOpen(Core.LastOpenedList.Items[TMenuItem(Sender).MenuIndex]);
    587607end;
     
    589609procedure TMainForm.AProjectOpenExecute(Sender: TObject);
    590610begin
    591   AProjectClose.Execute;
    592611  if Core.LastOpenedList.Items.Count > 0 then
    593612    OpenDialog1.FileName := Core.LastOpenedList.Items[0]
     
    595614  OpenDialog1.InitialDir := ExtractFileDir(OpenDialog1.FileName);
    596615  if OpenDialog1.Execute then begin
     616    AProjectClose.Execute;
     617    if Core.Project.Openned then Exit;
    597618    ProjectOpen(OpenDialog1.FileName);
    598619  end;
Note: See TracChangeset for help on using the changeset viewer.