Changeset 15 for trunk/UFormMain.pas


Ignore:
Timestamp:
Apr 29, 2016, 12:09:44 AM (9 years ago)
Author:
chronos
Message:
  • Modified: Now project file have XML structure. Loading and saving old format is still supported using .csv extension.
  • Fixed: Question before closing modified unsaved project.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UFormMain.pas

    r14 r15  
    9797    FoundAcronyms: TAcronymMeanings;
    9898    RegistryContext: TRegistryContext;
     99    ProjectClosed: Boolean;
    99100    procedure OpenRecentClick(Sender: TObject);
    100101    procedure UpdateAcronymsList;
     
    146147procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
    147148begin
    148   AFileClose.Execute;
    149149  PersistentForm1.Save(Self);
    150150  SaveConfig;
     
    152152
    153153procedure TFormMain.FormCloseQuery(Sender: TObject; var CanClose: boolean);
     154begin
     155  AFileClose.Execute;
     156  CanClose := ProjectClosed;
     157end;
     158
     159procedure TFormMain.AExitExecute(Sender: TObject);
     160begin
     161  Close;
     162end;
     163
     164procedure TFormMain.AFileCloseExecute(Sender: TObject);
    154165var
    155166  ModalResult: TModalResult;
     
    160171    if ModalResult = mrYes then begin
    161172      AFileSave.Execute;
    162       CanClose := True;
     173      FreeAndNil(AcronymDb);
     174      UpdateAcronymsList;
     175      UpdateInterface;
     176      ProjectClosed := True;
    163177    end
    164178    else if ModalResult = mrNo then begin
    165       CanClose := True;
    166       AcronymDb.Modified := False;
    167     end else CanClose := False;
    168   end;
    169 end;
    170 
    171 procedure TFormMain.AExitExecute(Sender: TObject);
    172 begin
    173   Close;
    174 end;
    175 
    176 procedure TFormMain.AFileCloseExecute(Sender: TObject);
    177 begin
    178   if Assigned(AcronymDb) then begin
    179     if AcronymDb.Modified then AFileSave.Execute;
    180     FreeAndNil(AcronymDb);
     179      FreeAndNil(AcronymDb);
     180      UpdateAcronymsList;
     181      UpdateInterface;
     182      ProjectClosed := True;
     183    end else ProjectClosed := False;
     184  end else ProjectClosed := True;
     185end;
     186
     187procedure TFormMain.AFileNewExecute(Sender: TObject);
     188begin
     189  AFileClose.Execute;
     190  if ProjectClosed  then begin
     191    AcronymDb := TAcronymDb.Create;
     192    AcronymDb.FileName := DefaultFileName;
     193    AcronymDb.Acronyms.Clear;
    181194    UpdateAcronymsList;
    182195    UpdateInterface;
    183196  end;
    184 end;
    185 
    186 procedure TFormMain.AFileNewExecute(Sender: TObject);
    187 begin
    188   AFileClose.Execute;
    189   AcronymDb := TAcronymDb.Create;
    190   AcronymDb.FileName := DefaultFileName;
    191   AcronymDb.Acronyms.Clear;
    192   UpdateAcronymsList;
    193   UpdateInterface;
    194197end;
    195198
     
    201204  if OpenDialog1.Execute then begin
    202205    AFileClose.Execute;
    203     AFileNew.Execute;
    204     AcronymDb.LoadFromFile(OpenDialog1.FileName);
    205     LastOpenedList1.AddItem(OpenDialog1.FileName);
    206     UpdateAcronymsList;
    207     UpdateInterface;
     206    if ProjectClosed then begin
     207      AFileNew.Execute;
     208      AcronymDb.LoadFromFile(OpenDialog1.FileName);
     209      LastOpenedList1.AddItem(OpenDialog1.FileName);
     210      UpdateAcronymsList;
     211      UpdateInterface;
     212    end;
    208213  end;
    209214end;
     
    333338begin
    334339  FormCategories.ShowModal;
     340  UpdateAcronymsList;
     341  UpdateInterface;
    335342end;
    336343
     
    424431begin
    425432  AFileClose.Execute;
    426   AFileNew.Execute;
    427   AcronymDb.LoadFromFile(TMenuItem(Sender).Caption);
    428   LastOpenedList1.AddItem(TMenuItem(Sender).Caption);
    429   UpdateAcronymsList;
    430   UpdateInterface;
     433  if ProjectClosed then begin
     434    AFileNew.Execute;
     435    AcronymDb.LoadFromFile(TMenuItem(Sender).Caption);
     436    LastOpenedList1.AddItem(TMenuItem(Sender).Caption);
     437    UpdateAcronymsList;
     438    UpdateInterface;
     439  end;
    431440end;
    432441
Note: See TracChangeset for help on using the changeset viewer.