Ignore:
Timestamp:
Jan 17, 2025, 9:05:54 PM (4 days ago)
Author:
chronos
Message:
  • Modified: Updated Common package.
  • Modified: Remove U prefix from unit names.
  • Modified: Use Gneeric.Collections instead of fgl.
  • Modified: Do not use global form variables.
File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/Forms/FormMain.pas

    r218 r219  
    1 unit UFormMain;
    2 
    3 {$mode delphi}{$H+}
     1unit FormMain;
    42
    53interface
     
    75uses
    86  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus,
    9   ComCtrls, StdCtrls, ExtCtrls, ActnList, Grids, UAcronym, UPersistentForm,
    10   URegistry, ULastOpenedList, UListViewSort, UJobProgressView, UAboutDialog,
    11   Registry, fgl, LazUTF8, LazFileUtils;
     7  ComCtrls, StdCtrls, ExtCtrls, ActnList, Grids, Acronym, PersistentForm,
     8  RegistryEx, LastOpenedList, ListViewSort, JobProgressView, FormAbout,
     9  Registry, Generics.Collections, LazUTF8, LazFileUtils, FormEx;
    1210
    1311type
     
    1513  { TFormMain }
    1614
    17   TFormMain = class(TForm)
    18     AboutDialog1: TAboutDialog;
     15  TFormMain = class(TFormEx)
    1916    AFilterShowItemsWithoutFilter: TAction;
    2017    ADocumentCheck: TAction;
     
    138135    procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
    139136    procedure FormCreate(Sender: TObject);
    140     procedure FormDestroy(Sender: TObject);
    141137    procedure LastOpenedList1Change(Sender: TObject);
    142138    procedure ListViewAcronymsData(Sender: TObject; Item: TListItem);
     
    158154    function FilterCell(Text1, Text2: string): Boolean;
    159155    procedure ProcessImportsJob(Job: TJob);
    160     procedure FilterList(List: TFPGObjectList<TObject>);
     156    procedure FilterList(List: TObjectList<TObject>);
    161157    procedure OpenRecentClick(Sender: TObject);
    162158    procedure SetToolbarHints;
     
    167163    procedure UpdateInterface;
    168164    procedure ProjectOpen(FileName: string);
    169     function CompareStrings(Strings1, Strings2: TStrings): Boolean;
    170   end;
    171 
    172 var
    173   FormMain: TFormMain;
     165  end;
    174166
    175167resourcestring
     
    186178
    187179uses
    188   UFormImport, UFormSettings, UFormCategories, UFormAcronyms, UFormExport,
    189   UFormImportSources, UFormImportFormats, UCore, UFormCheck;
     180  FormImport, FormSettings, FormCategories, FormAcronyms, FormExport,
     181  FormImportSources, FormImportFormats, Core, FormCheck;
    190182
    191183resourcestring
     
    232224procedure TFormMain.FormHide(Sender: TObject);
    233225begin
    234   if Core.InitializeFinished then Core.PersistentForm1.Save(Self);
     226  if Core.Core.InitializeFinished then Core.Core.PersistentForm1.Save(Self);
    235227  UpdateInterface;
    236228end;
     
    243235procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
    244236begin
    245   Core.PersistentForm1.Save(Self);
    246   Core.SaveConfig;
     237  Core.Core.SaveConfig;
    247238end;
    248239
     
    260251
    261252procedure TFormMain.ADocumentCheckExecute(Sender: TObject);
     253var
     254  FormCheck: TFormCheck;
    262255begin
    263256  FormCheck := TFormCheck.Create(Self);
     
    272265
    273266procedure TFormMain.AExportExecute(Sender: TObject);
     267var
     268  FormExport: TFormExport;
    274269begin
    275270  FormExport := TFormExport.Create(Self);
     
    287282begin
    288283  DoClose := False;
    289   if Assigned(Core.AcronymDb) then begin
    290     if Core.AcronymDb.Modified then begin
     284  if Assigned(Core.Core.AcronymDb) then begin
     285    if Core.Core.AcronymDb.Modified then begin
    291286       ModalResult := MessageDlg(SAppExit, SAppExitQuery,
    292287       mtConfirmation, [mbYes, mbNo, mbCancel], 0);
     
    301296  end;
    302297  if DoClose then begin
    303     FreeAndNil(Core.AcronymDb);
     298    FreeAndNil(Core.Core.AcronymDb);
    304299    UpdateAcronymsList;
    305300    UpdateInterface;
     
    311306begin
    312307  AFileClose.Execute;
    313   if not Assigned(Core.AcronymDb)  then begin
    314     Core.AcronymDb := TAcronymDb.Create;
    315     Core.AcronymDb.FileName := DefaultFileName;
    316     Core.AcronymDb.Acronyms.Clear;
    317     Core.AcronymDb.OnUpdate.Add(AcronymDbUpdate);
     308  if not Assigned(Core.Core.AcronymDb)  then begin
     309    Core.Core.AcronymDb := TAcronymDb.Create;
     310    Core.Core.AcronymDb.FileName := DefaultFileName;
     311    Core.Core.AcronymDb.Acronyms.Clear;
     312    Core.Core.AcronymDb.OnUpdate.Add(AcronymDbUpdate);
    318313    UpdateAcronymsList;
    319314    UpdateInterface;
     
    324319begin
    325320  OpenDialog1.DefaultExt := ProjectExt;
    326   if Assigned(Core.AcronymDb) then begin
    327     OpenDialog1.InitialDir := ExtractFileDir(Core.AcronymDb.FileName);
     321  if Assigned(Core.Core.AcronymDb) then begin
     322    OpenDialog1.InitialDir := ExtractFileDir(Core.Core.AcronymDb.FileName);
    328323    OpenDialog1.Filter := SFileFilter;
    329     OpenDialog1.FileName := ExtractFileName(Core.AcronymDb.FileName);
     324    OpenDialog1.FileName := ExtractFileName(Core.Core.AcronymDb.FileName);
    330325  end;
    331326  if OpenDialog1.Execute then begin
     
    337332begin
    338333  SaveDialog1.DefaultExt := ProjectExt;
    339   SaveDialog1.InitialDir := ExtractFileDir(Core.AcronymDb.FileName);
     334  SaveDialog1.InitialDir := ExtractFileDir(Core.Core.AcronymDb.FileName);
    340335  SaveDialog1.Filter := SFileFilter;
    341   SaveDialog1.FileName := ExtractFileName(Core.AcronymDb.FileName);
     336  SaveDialog1.FileName := ExtractFileName(Core.Core.AcronymDb.FileName);
    342337  if SaveDialog1.Execute then begin
    343     Core.AcronymDb.SaveToFile(SaveDialog1.FileName);
     338    Core.Core.AcronymDb.SaveToFile(SaveDialog1.FileName);
    344339    LastOpenedList1.AddItem(SaveDialog1.FileName);
    345340    UpdateInterface;
     
    349344procedure TFormMain.AFileSaveExecute(Sender: TObject);
    350345begin
    351   if FileExists(Core.AcronymDb.FileName) then begin
    352     Core.AcronymDb.SaveToFile(Core.AcronymDb.FileName);
    353     LastOpenedList1.AddItem(Core.AcronymDb.FileName);
     346  if FileExists(Core.Core.AcronymDb.FileName) then begin
     347    Core.Core.AcronymDb.SaveToFile(Core.Core.AcronymDb.FileName);
     348    LastOpenedList1.AddItem(Core.Core.AcronymDb.FileName);
    354349    UpdateInterface;
    355350  end else AFileSaveAs.Execute;
     
    382377
    383378procedure TFormMain.AImportExecute(Sender: TObject);
     379var
     380  FormImport: TFormImport;
    384381begin
    385382  FormImport := TFormImport.Create(Self);
     
    394391
    395392procedure TFormMain.AManageAcronymExecute(Sender: TObject);
     393var
     394  FormAcronyms: TFormAcronyms;
    396395begin
    397396  FormAcronyms := TFormAcronyms.Create(Self);
     
    399398    if Assigned(ListViewAcronyms.Selected) then
    400399      FormAcronyms.FocusAcronym := ListViewAcronyms.Selected.Data;
    401     FormAcronyms.Acronyms := Core.AcronymDb.Acronyms;
     400    FormAcronyms.Acronyms := Core.Core.AcronymDb.Acronyms;
    402401    FormAcronyms.ShowModal;
    403402    UpdateAcronymsList;
     
    411410begin
    412411  ImportTotalItemCount := 0;
    413   Core.AcronymDb.AddedCount := 0;
    414   Core.JobProgressView1.AddJob(SProcessImportSources, ProcessImportsJob);
    415   Core.JobProgressView1.Start;
    416   ShowMessage(Format(SAddedCount, [ImportTotalItemCount, Core.AcronymDb.AddedCount]));
     412  Core.Core.AcronymDb.AddedCount := 0;
     413  Core.Core.JobProgressView1.AddJob(SProcessImportSources, ProcessImportsJob);
     414  Core.Core.JobProgressView1.Start;
     415  ShowMessage(Format(SAddedCount, [ImportTotalItemCount, Core.Core.AcronymDb.AddedCount]));
    417416  UpdateAcronymsList;
    418417  UpdateInterface;
     
    423422  I: Integer;
    424423begin
    425   for I := 0 to Core.AcronymDb.ImportSources.Count - 1 do
    426   with TImportSource(Core.AcronymDb.ImportSources[I]) do
     424  for I := 0 to Core.Core.AcronymDb.ImportSources.Count - 1 do
     425  with Core.Core.AcronymDb.ImportSources[I] do
    427426  if Enabled then begin
    428427    Process;
    429428    ImportTotalItemCount := ImportTotalItemCount + ItemCount;
    430     Job.Progress.Max := Core.AcronymDb.ImportSources.Count;
     429    Job.Progress.Max := Core.Core.AcronymDb.ImportSources.Count;
    431430    Job.Progress.Value := I;
    432431    if Job.Terminate then Break;
     
    435434
    436435procedure TFormMain.ASettingsExecute(Sender: TObject);
     436var
     437  FormSettings: TFormSettings;
    437438begin
    438439  FormSettings := TFormSettings.Create(Self);
     
    441442    if FormSettings.ShowModal = mrOk then begin
    442443      FormSettings.Save;
    443       Core.SaveConfig;
    444       Core.ThemeManager.UseTheme(Self);
     444      Core.Core.SaveConfig;
     445      Core.Core.ThemeManager.UseTheme(Self);
    445446    end;
    446447  finally
     
    450451
    451452procedure TFormMain.AShowAboutExecute(Sender: TObject);
    452 begin
    453   AboutDialog1.Show;
     453var
     454  FormAbout: TFormAbout;
     455begin
     456  FormAbout := TFormAbout.Create(nil);
     457  try
     458    FormAbout.ApplicationInfo := Core.Core.ApplicationInfo1;
     459    FormAbout.ShowModal;
     460  finally
     461    FormAbout.Free;
     462  end;
    454463end;
    455464
    456465procedure TFormMain.AShowAcronymsExecute(Sender: TObject);
     466var
     467  FormAcronyms: TFormAcronyms;
    457468begin
    458469  FormAcronyms := TFormAcronyms.Create(Self);
    459470  try
    460     FormAcronyms.Acronyms := Core.AcronymDb.Acronyms;
     471    FormAcronyms.Acronyms := Core.Core.AcronymDb.Acronyms;
    461472    FormAcronyms.ShowModal;
    462473    UpdateAcronymsList;
     
    468479
    469480procedure TFormMain.AShowCategoriesExecute(Sender: TObject);
     481var
     482  FormCategories: TFormCategories;
    470483begin
    471484  FormCategories := TFormCategories.Create(Self);
    472485  try
    473     FormCategories.Categories := Core.AcronymDb.Categories;
     486    FormCategories.Categories := Core.Core.AcronymDb.Categories;
    474487    FormCategories.ShowModal;
    475488    UpdateAcronymsList;
     
    487500
    488501procedure TFormMain.AShowImportFormatsExecute(Sender: TObject);
     502var
     503  FormImportFormats: TFormImportFormats;
    489504begin
    490505  FormImportFormats := TFormImportFormats.Create(Self);
    491506  try
    492     FormImportFormats.ImportFormats := Core.AcronymDb.ImportFormats;
     507    FormImportFormats.ImportFormats := Core.Core.AcronymDb.ImportFormats;
    493508    FormImportFormats.ShowModal;
    494509    UpdateInterface;
     
    499514
    500515procedure TFormMain.AShowImportSourcesExecute(Sender: TObject);
     516var
     517  FormImportSources: TFormImportSources;
    501518begin
    502519  FormImportSources := TFormImportSources.Create(Self);
    503520  try
    504     FormImportSources.ImportSources := Core.AcronymDb.ImportSources;
     521    FormImportSources.ImportSources := Core.Core.AcronymDb.ImportSources;
    505522    FormImportSources.ShowModal;
    506523    UpdateAcronymsList;
     
    511528end;
    512529
    513 procedure TFormMain.FormDestroy(Sender: TObject);
    514 begin
    515 end;
    516 
    517530procedure TFormMain.FormShow(Sender: TObject);
    518531begin
    519   Core.Initialize;
     532  Core.Core.Initialize;
    520533
    521534  if Visible then begin
    522     Core.PersistentForm1.Load(Self);
    523     Core.ThemeManager.UseTheme(Self);
    524535    ListViewFilter1.UpdateFromListView(ListViewAcronyms);
    525536    UpdateInterface;
     
    529540    ListViewFilter1.StringGrid.SetFocus;
    530541  end;
    531   Core.ScaleDPI1.ScaleControl(CoolBar1, Core.ScaleDPI1.DesignDPI);
     542  Core.Core.ScaleDPI1.ScaleControl(CoolBar1, Core.Core.ScaleDPI1.DesignDPI);
    532543  CoolBar1.AutosizeBands;
    533544end;
     
    587598procedure TFormMain.ListViewSort1Filter(ListViewSort: TListViewSort);
    588599begin
    589   Core.AcronymDb.AssignToList(ListViewSort1.List, AFilterEnabledCategories.Checked);
     600  Core.Core.AcronymDb.AssignToList(ListViewSort1.List, AFilterEnabledCategories.Checked);
    590601  FilterList(ListViewSort1.List);
    591602end;
     
    628639begin
    629640  AFileClose.Execute;
    630   if not Assigned(Core.AcronymDb) then begin
     641  if not Assigned(Core.Core.AcronymDb) then begin
    631642    try
    632643      AFileNew.Execute;
    633       Core.AcronymDb.LoadFromFile(FileName);
     644      Core.Core.AcronymDb.LoadFromFile(FileName);
    634645      LastOpenedList1.AddItem(FileName);
    635646    finally
     
    640651end;
    641652
    642 function TFormMain.CompareStrings(Strings1, Strings2: TStrings): Boolean;
    643 var
    644   I: Integer;
    645 begin
    646   Result := Strings1.Count = Strings2.Count;
    647   if not Result then Exit;
    648   for I := 0 to Strings1.Count - 1 do
    649     if (Strings1[I] <> Strings2[I]) or (Strings1.Objects[I] <> Strings2.Objects[I]) then begin
    650       Result := False;
    651       Exit;
    652     end;
    653 end;
    654 
    655 procedure TFormMain.FilterList(List: TFPGObjectList<TObject>);
     653procedure TFormMain.FilterList(List: TObjectList<TObject>);
    656654var
    657655  I: Integer;
     
    686684begin
    687685  AFileClose.Execute;
    688   if not Assigned(Core.AcronymDb) then begin
     686  if not Assigned(Core.Core.AcronymDb) then begin
    689687    AFileNew.Execute;
    690     Core.AcronymDb.LoadFromFile(TMenuItem(Sender).Caption);
     688    Core.Core.AcronymDb.LoadFromFile(TMenuItem(Sender).Caption);
    691689    LastOpenedList1.AddItem(TMenuItem(Sender).Caption);
    692690    UpdateAcronymsList;
     
    697695procedure TFormMain.UpdateAcronymsList;
    698696begin
    699   if Assigned(Core.AcronymDb) then begin
     697  if Assigned(Core.Core.AcronymDb) then begin
    700698    ListViewSort1.Refresh;
    701699  end else begin
     
    710708  Title: string;
    711709begin
    712   ListViewAcronyms.Enabled := Assigned(Core.AcronymDb);
    713   AFileClose.Enabled := Assigned(Core.AcronymDb);
    714   AFileSave.Enabled := Assigned(Core.AcronymDb) and Core.AcronymDb.Modified;
    715   AFileSaveAs.Enabled := Assigned(Core.AcronymDb);
    716   AImport.Enabled := Assigned(Core.AcronymDb);
    717   AExport.Enabled := Assigned(Core.AcronymDb);
    718   AProcessImports.Enabled := Assigned(Core.AcronymDb);
    719   AShowCategories.Enabled := Assigned(Core.AcronymDb);
    720   AShowAcronyms.Enabled := Assigned(Core.AcronymDb);
    721   AShowCategories.Enabled := Assigned(Core.AcronymDb);
    722   AShowImportSources.Enabled := Assigned(Core.AcronymDb);
    723   AShowImportFormats.Enabled := Assigned(Core.AcronymDb);
     710  ListViewAcronyms.Enabled := Assigned(Core.Core.AcronymDb);
     711  AFileClose.Enabled := Assigned(Core.Core.AcronymDb);
     712  AFileSave.Enabled := Assigned(Core.Core.AcronymDb) and Core.Core.AcronymDb.Modified;
     713  AFileSaveAs.Enabled := Assigned(Core.Core.AcronymDb);
     714  AImport.Enabled := Assigned(Core.Core.AcronymDb);
     715  AExport.Enabled := Assigned(Core.Core.AcronymDb);
     716  AProcessImports.Enabled := Assigned(Core.Core.AcronymDb);
     717  AShowCategories.Enabled := Assigned(Core.Core.AcronymDb);
     718  AShowAcronyms.Enabled := Assigned(Core.Core.AcronymDb);
     719  AShowCategories.Enabled := Assigned(Core.Core.AcronymDb);
     720  AShowImportSources.Enabled := Assigned(Core.Core.AcronymDb);
     721  AShowImportFormats.Enabled := Assigned(Core.Core.AcronymDb);
    724722  CoolBar1.Visible := MenuItemToolbar.Checked;
    725723  PanelParam.Visible := MenuItemParam.Checked;
    726   AHide.Enabled := FormMain.Visible;
     724  AHide.Enabled := Visible;
    727725  AManageAcronym.Enabled := Assigned(ListViewAcronyms.Selected);
    728726  StatusBar1.Visible := MenuItemStatusBar.Checked;
    729727
    730728  Title := '';
    731   if Assigned(Core.AcronymDb) and (ExtractFileNameWithoutExt(ExtractFileName(Core.AcronymDb.FileName)) <> '') then begin
    732     Title := ExtractFileNameWithoutExt(ExtractFileName(Core.AcronymDb.FileName));
    733     if Core.AcronymDb.Modified then Title := Title + ' (' + SModified + ')';
     729  if Assigned(Core.Core.AcronymDb) and (ExtractFileNameWithoutExt(ExtractFileName(Core.Core.AcronymDb.FileName)) <> '') then begin
     730    Title := ExtractFileNameWithoutExt(ExtractFileName(Core.Core.AcronymDb.FileName));
     731    if Core.Core.AcronymDb.Modified then Title := Title + ' (' + SModified + ')';
    734732  end;
    735733  if Title <> '' then Title := Title + ' - ';
    736   Title := Title + Core.ApplicationInfo1.AppName;
     734  Title := Title + Core.Core.ApplicationInfo1.AppName;
    737735  {$IFDEF WINDOWS}
    738736  // Under Linux title would affect reg.xml path for storing registry settings
     
    740738  {$ENDIF}
    741739  Caption := Title;
    742   if Assigned(Core.AcronymDb) then begin
     740  if Assigned(Core.Core.AcronymDb) then begin
    743741    StatusBar1.Panels[0].Text := Format(SAcronymsCount, [
    744       Core.AcronymDb.Acronyms.Count]);
     742      Core.Core.AcronymDb.Acronyms.Count]);
    745743    StatusBar1.Panels[1].Text := Format(SMeaningsCount, [
    746       Core.AcronymDb.GetMeaningsCount]);
     744      Core.Core.AcronymDb.GetMeaningsCount]);
    747745  end else begin
    748746    StatusBar1.Panels[0].Text := '';
     
    753751procedure TFormMain.LoadConfig;
    754752begin
    755   Core.PersistentForm1.RegistryContext := Core.ApplicationInfo1.GetRegistryContext;
    756   RegistryContext := TRegistryContext.Create(Core.ApplicationInfo1.RegistryRoot,
    757     Core.ApplicationInfo1.RegistryKey + '\RecentFiles');
     753  Core.Core.PersistentForm1.RegistryContext := Core.Core.ApplicationInfo1.GetRegistryContext;
     754  RegistryContext := TRegistryContext.Create(Core.Core.ApplicationInfo1.RegistryRoot,
     755    Core.Core.ApplicationInfo1.RegistryKey + '\RecentFiles');
    758756  LastOpenedList1.LoadFromRegistry(RegistryContext);
    759757
     
    761759  // If installed in Linux system then use installation directory for po files
    762760  if Application.ExeName = '/usr/bin/' + ExtractFileNameOnly(Application.ExeName) then
    763     Core.Translator.POFilesFolder := '/usr/share/' + ExtractFileNameOnly(Application.ExeName) + '/languages';
     761    Core.Core.Translator.POFilesFolder := '/usr/share/' + ExtractFileNameOnly(Application.ExeName) + '/languages';
    764762  {$ENDIF}
    765763
    766764  with TRegistryEx.Create do
    767765  try
    768     RootKey := RegistryRootHKEY[Core.ApplicationInfo1.RegistryRoot];
    769     OpenKey(Core.ApplicationInfo1.RegistryKey, True);
     766    RootKey := RegistryRootHKEY[Core.Core.ApplicationInfo1.RegistryRoot];
     767    OpenKey(Core.Core.ApplicationInfo1.RegistryKey, True);
    770768    AFilterSameLength.Checked := ReadBoolWithDefault('SameLength', False);
    771769    AFilterSameLetterCase.Checked := ReadBoolWithDefault('SameLetterCase', False);
     
    784782    RootKey := HKEY_CURRENT_USER;
    785783    OpenKey(RegistryRunKey, True);
    786     Core.StartOnLogon := ValueExists('Acronym Decoder');
     784    Core.Core.StartOnLogon := ValueExists('Acronym Decoder');
    787785  finally
    788786    Free;
     
    792790procedure TFormMain.SaveConfig;
    793791begin
    794   RegistryContext := TRegistryContext.Create(Core.ApplicationInfo1.RegistryRoot,
    795     Core.ApplicationInfo1.RegistryKey + '\RecentFiles');
     792  RegistryContext := TRegistryContext.Create(Core.Core.ApplicationInfo1.RegistryRoot,
     793    Core.Core.ApplicationInfo1.RegistryKey + '\RecentFiles');
    796794  LastOpenedList1.SaveToRegistry(RegistryContext);
    797795
    798796  with TRegistryEx.Create do
    799797  try
    800     RootKey := RegistryRootHKEY[Core.ApplicationInfo1.RegistryRoot];
    801     OpenKey(Core.ApplicationInfo1.RegistryKey, True);
     798    RootKey := RegistryRootHKEY[Core.Core.ApplicationInfo1.RegistryRoot];
     799    OpenKey(Core.Core.ApplicationInfo1.RegistryKey, True);
    802800    WriteBool('SameLength', AFilterSameLength.Checked);
    803801    WriteBool('SameLetterCase', AFilterSameLetterCase.Checked);
     
    815813    RootKey := HKEY_CURRENT_USER;
    816814    OpenKey(RegistryRunKey, True);
    817     if Core.StartOnLogon then begin
    818       if Core.StartMinimizedToTray then WriteString('Acronym Decoder', Application.ExeName + ' ' + Application.OptionChar + 't')
     815    if Core.Core.StartOnLogon then begin
     816      if Core.Core.StartMinimizedToTray then WriteString('Acronym Decoder', Application.ExeName + ' ' + Application.OptionChar + 't')
    819817        else WriteString('Acronym Decoder', Application.ExeName)
    820818    end else DeleteValue('Acronym Decoder');
Note: See TracChangeset for help on using the changeset viewer.