Changeset 117 for trunk


Ignore:
Timestamp:
Feb 18, 2022, 10:29:49 AM (3 years ago)
Author:
chronos
Message:
  • Modified: Update recent opened files list directly into registry to better support multiple opened app instances at the same time.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UCore.pas

    r116 r117  
    7171    LastSplitDir: string;
    7272    ProfilePhotoFileName: string;
     73    RecentFileRegistryContext: TRegistryContext;
    7374    procedure FileModified(Sender: TObject);
    7475    function FindFirstNonOption: string;
     
    7778    procedure SaveConfig;
    7879    procedure DoError(Text: string; Line: Integer);
     80    procedure AddItemToLastOpenedList(FileName: string);
    7981  public
    8082    DefaultDataFileClass: TDataFileClass;
     
    202204      ExecuteProgram('explorer.exe', ['"' + SelectDirectoryDialog1.FileName + '"']);
    203205      {$ENDIF}
    204       {$IFDEF LINUX}
     206      {$IFDEF UNIX}
    205207      ExecuteProgram('/usr/bin/xdg-open', [SelectDirectoryDialog1.FileName]);
    206208      {$ENDIF}
     
    337339  if SaveDialog1.Execute then begin
    338340    DataFile.SaveToFile(SaveDialog1.FileName);
    339     LastOpenedList1.AddItem(SaveDialog1.FileName);
     341    AddItemToLastOpenedList(SaveDialog1.FileName);
    340342    UpdateFile;
    341343  end;
     
    346348  if FileExists(DataFile.FileName) then begin
    347349    DataFile.SaveToFile(DataFile.FileName);
    348     LastOpenedList1.AddItem(DataFile.FileName);
     350    AddItemToLastOpenedList(DataFile.FileName);
    349351    UpdateFile;
    350352  end else AFileSaveAs.Execute;
     
    352354
    353355procedure TCore.DataModuleCreate(Sender: TObject);
    354 {$IFDEF Linux}
     356{$IFDEF UNIX}
    355357const
    356358  LinuxDataFilesDir = '/usr/share/vCardStudio';
     
    360362begin
    361363  ProfilePhotoFileName := 'Images/Profile.png';
    362   {$IFDEF Linux}
     364  {$IFDEF UNIX}
    363365  // If installed in Linux system then use installation directory for po files
    364366  if not DirectoryExists(Translator.POFilesFolder) and DirectoryExists(LinuxLanguagesDir) then begin
     
    374376  DefaultDataFileClass := TContactsFile;
    375377  FileClosed := True;
     378  RecentFileRegistryContext := TRegistryContext.Create(ApplicationInfo1.RegistryRoot,
     379    ApplicationInfo1.RegistryKey + '\RecentFiles');
    376380end;
    377381
     
    403407      LoadErrors := '';
    404408      DataFile.LoadFromFile(FileName);
    405       LastOpenedList1.AddItem(FileName);
     409      AddItemToLastOpenedList(FileName);
    406410      if LoadErrors <> '' then begin
    407411        FormError := TFormError.Create(nil);
     
    466470begin
    467471  PersistentForm1.RegistryContext := ApplicationInfo1.GetRegistryContext;
    468   LastOpenedList1.LoadFromRegistry(TRegistryContext.Create(ApplicationInfo1.RegistryRoot,
    469     ApplicationInfo1.RegistryKey + '\RecentFiles'));
     472  LastOpenedList1.LoadFromRegistry(RecentFileRegistryContext);
    470473
    471474  with TRegistryEx.Create do
     
    495498procedure TCore.SaveConfig;
    496499begin
    497   LastOpenedList1.SaveToRegistry(TRegistryContext.Create(ApplicationInfo1.RegistryRoot,
    498     ApplicationInfo1.RegistryKey + '\RecentFiles'));
    499 
    500500  with TRegistryEx.Create do
    501501  try
     
    527527end;
    528528
     529procedure TCore.AddItemToLastOpenedList(FileName: string);
     530begin
     531  with LastOpenedList1 do begin
     532    LoadFromRegistry(RecentFileRegistryContext);
     533    AddItem(FileName);
     534    SaveToRegistry(RecentFileRegistryContext);
     535  end;
     536end;
     537
    529538function TCore.GetProfileImage: TImage;
    530539begin
     
    569578      AFileNew.Execute;
    570579      DataFile.LoadFromFile(FileNameOption);
    571       LastOpenedList1.AddItem(FileNameOption);
     580      AddItemToLastOpenedList(FileNameOption);
    572581    end else
    573582    if ReopenLastFileOnStart and (LastOpenedList1.Items.Count > 0) and FileExists(LastOpenedList1.Items[0]) then begin
Note: See TracChangeset for help on using the changeset viewer.