Changeset 219 for trunk/Forms/FormMain.pas
- Timestamp:
- Jan 17, 2025, 9:05:54 PM (4 days ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/FormMain.pas
r218 r219 1 unit UFormMain; 2 3 {$mode delphi}{$H+} 1 unit FormMain; 4 2 5 3 interface … … 7 5 uses 8 6 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; 12 10 13 11 type … … 15 13 { TFormMain } 16 14 17 TFormMain = class(TForm) 18 AboutDialog1: TAboutDialog; 15 TFormMain = class(TFormEx) 19 16 AFilterShowItemsWithoutFilter: TAction; 20 17 ADocumentCheck: TAction; … … 138 135 procedure FormCloseQuery(Sender: TObject; var CanClose: boolean); 139 136 procedure FormCreate(Sender: TObject); 140 procedure FormDestroy(Sender: TObject);141 137 procedure LastOpenedList1Change(Sender: TObject); 142 138 procedure ListViewAcronymsData(Sender: TObject; Item: TListItem); … … 158 154 function FilterCell(Text1, Text2: string): Boolean; 159 155 procedure ProcessImportsJob(Job: TJob); 160 procedure FilterList(List: T FPGObjectList<TObject>);156 procedure FilterList(List: TObjectList<TObject>); 161 157 procedure OpenRecentClick(Sender: TObject); 162 158 procedure SetToolbarHints; … … 167 163 procedure UpdateInterface; 168 164 procedure ProjectOpen(FileName: string); 169 function CompareStrings(Strings1, Strings2: TStrings): Boolean; 170 end; 171 172 var 173 FormMain: TFormMain; 165 end; 174 166 175 167 resourcestring … … 186 178 187 179 uses 188 UFormImport, UFormSettings, UFormCategories, UFormAcronyms, UFormExport,189 UFormImportSources, UFormImportFormats, UCore, UFormCheck;180 FormImport, FormSettings, FormCategories, FormAcronyms, FormExport, 181 FormImportSources, FormImportFormats, Core, FormCheck; 190 182 191 183 resourcestring … … 232 224 procedure TFormMain.FormHide(Sender: TObject); 233 225 begin 234 if Core. InitializeFinished thenCore.PersistentForm1.Save(Self);226 if Core.Core.InitializeFinished then Core.Core.PersistentForm1.Save(Self); 235 227 UpdateInterface; 236 228 end; … … 243 235 procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction); 244 236 begin 245 Core.PersistentForm1.Save(Self); 246 Core.SaveConfig; 237 Core.Core.SaveConfig; 247 238 end; 248 239 … … 260 251 261 252 procedure TFormMain.ADocumentCheckExecute(Sender: TObject); 253 var 254 FormCheck: TFormCheck; 262 255 begin 263 256 FormCheck := TFormCheck.Create(Self); … … 272 265 273 266 procedure TFormMain.AExportExecute(Sender: TObject); 267 var 268 FormExport: TFormExport; 274 269 begin 275 270 FormExport := TFormExport.Create(Self); … … 287 282 begin 288 283 DoClose := False; 289 if Assigned(Core. AcronymDb) then begin290 if Core. AcronymDb.Modified then begin284 if Assigned(Core.Core.AcronymDb) then begin 285 if Core.Core.AcronymDb.Modified then begin 291 286 ModalResult := MessageDlg(SAppExit, SAppExitQuery, 292 287 mtConfirmation, [mbYes, mbNo, mbCancel], 0); … … 301 296 end; 302 297 if DoClose then begin 303 FreeAndNil(Core. AcronymDb);298 FreeAndNil(Core.Core.AcronymDb); 304 299 UpdateAcronymsList; 305 300 UpdateInterface; … … 311 306 begin 312 307 AFileClose.Execute; 313 if not Assigned(Core. AcronymDb) then begin314 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); 318 313 UpdateAcronymsList; 319 314 UpdateInterface; … … 324 319 begin 325 320 OpenDialog1.DefaultExt := ProjectExt; 326 if Assigned(Core. AcronymDb) then begin327 OpenDialog1.InitialDir := ExtractFileDir(Core. AcronymDb.FileName);321 if Assigned(Core.Core.AcronymDb) then begin 322 OpenDialog1.InitialDir := ExtractFileDir(Core.Core.AcronymDb.FileName); 328 323 OpenDialog1.Filter := SFileFilter; 329 OpenDialog1.FileName := ExtractFileName(Core. AcronymDb.FileName);324 OpenDialog1.FileName := ExtractFileName(Core.Core.AcronymDb.FileName); 330 325 end; 331 326 if OpenDialog1.Execute then begin … … 337 332 begin 338 333 SaveDialog1.DefaultExt := ProjectExt; 339 SaveDialog1.InitialDir := ExtractFileDir(Core. AcronymDb.FileName);334 SaveDialog1.InitialDir := ExtractFileDir(Core.Core.AcronymDb.FileName); 340 335 SaveDialog1.Filter := SFileFilter; 341 SaveDialog1.FileName := ExtractFileName(Core. AcronymDb.FileName);336 SaveDialog1.FileName := ExtractFileName(Core.Core.AcronymDb.FileName); 342 337 if SaveDialog1.Execute then begin 343 Core. AcronymDb.SaveToFile(SaveDialog1.FileName);338 Core.Core.AcronymDb.SaveToFile(SaveDialog1.FileName); 344 339 LastOpenedList1.AddItem(SaveDialog1.FileName); 345 340 UpdateInterface; … … 349 344 procedure TFormMain.AFileSaveExecute(Sender: TObject); 350 345 begin 351 if FileExists(Core. AcronymDb.FileName) then begin352 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); 354 349 UpdateInterface; 355 350 end else AFileSaveAs.Execute; … … 382 377 383 378 procedure TFormMain.AImportExecute(Sender: TObject); 379 var 380 FormImport: TFormImport; 384 381 begin 385 382 FormImport := TFormImport.Create(Self); … … 394 391 395 392 procedure TFormMain.AManageAcronymExecute(Sender: TObject); 393 var 394 FormAcronyms: TFormAcronyms; 396 395 begin 397 396 FormAcronyms := TFormAcronyms.Create(Self); … … 399 398 if Assigned(ListViewAcronyms.Selected) then 400 399 FormAcronyms.FocusAcronym := ListViewAcronyms.Selected.Data; 401 FormAcronyms.Acronyms := Core. AcronymDb.Acronyms;400 FormAcronyms.Acronyms := Core.Core.AcronymDb.Acronyms; 402 401 FormAcronyms.ShowModal; 403 402 UpdateAcronymsList; … … 411 410 begin 412 411 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])); 417 416 UpdateAcronymsList; 418 417 UpdateInterface; … … 423 422 I: Integer; 424 423 begin 425 for I := 0 to Core. AcronymDb.ImportSources.Count - 1 do426 with TImportSource(Core.AcronymDb.ImportSources[I])do424 for I := 0 to Core.Core.AcronymDb.ImportSources.Count - 1 do 425 with Core.Core.AcronymDb.ImportSources[I] do 427 426 if Enabled then begin 428 427 Process; 429 428 ImportTotalItemCount := ImportTotalItemCount + ItemCount; 430 Job.Progress.Max := Core. AcronymDb.ImportSources.Count;429 Job.Progress.Max := Core.Core.AcronymDb.ImportSources.Count; 431 430 Job.Progress.Value := I; 432 431 if Job.Terminate then Break; … … 435 434 436 435 procedure TFormMain.ASettingsExecute(Sender: TObject); 436 var 437 FormSettings: TFormSettings; 437 438 begin 438 439 FormSettings := TFormSettings.Create(Self); … … 441 442 if FormSettings.ShowModal = mrOk then begin 442 443 FormSettings.Save; 443 Core. SaveConfig;444 Core. ThemeManager.UseTheme(Self);444 Core.Core.SaveConfig; 445 Core.Core.ThemeManager.UseTheme(Self); 445 446 end; 446 447 finally … … 450 451 451 452 procedure TFormMain.AShowAboutExecute(Sender: TObject); 452 begin 453 AboutDialog1.Show; 453 var 454 FormAbout: TFormAbout; 455 begin 456 FormAbout := TFormAbout.Create(nil); 457 try 458 FormAbout.ApplicationInfo := Core.Core.ApplicationInfo1; 459 FormAbout.ShowModal; 460 finally 461 FormAbout.Free; 462 end; 454 463 end; 455 464 456 465 procedure TFormMain.AShowAcronymsExecute(Sender: TObject); 466 var 467 FormAcronyms: TFormAcronyms; 457 468 begin 458 469 FormAcronyms := TFormAcronyms.Create(Self); 459 470 try 460 FormAcronyms.Acronyms := Core. AcronymDb.Acronyms;471 FormAcronyms.Acronyms := Core.Core.AcronymDb.Acronyms; 461 472 FormAcronyms.ShowModal; 462 473 UpdateAcronymsList; … … 468 479 469 480 procedure TFormMain.AShowCategoriesExecute(Sender: TObject); 481 var 482 FormCategories: TFormCategories; 470 483 begin 471 484 FormCategories := TFormCategories.Create(Self); 472 485 try 473 FormCategories.Categories := Core. AcronymDb.Categories;486 FormCategories.Categories := Core.Core.AcronymDb.Categories; 474 487 FormCategories.ShowModal; 475 488 UpdateAcronymsList; … … 487 500 488 501 procedure TFormMain.AShowImportFormatsExecute(Sender: TObject); 502 var 503 FormImportFormats: TFormImportFormats; 489 504 begin 490 505 FormImportFormats := TFormImportFormats.Create(Self); 491 506 try 492 FormImportFormats.ImportFormats := Core. AcronymDb.ImportFormats;507 FormImportFormats.ImportFormats := Core.Core.AcronymDb.ImportFormats; 493 508 FormImportFormats.ShowModal; 494 509 UpdateInterface; … … 499 514 500 515 procedure TFormMain.AShowImportSourcesExecute(Sender: TObject); 516 var 517 FormImportSources: TFormImportSources; 501 518 begin 502 519 FormImportSources := TFormImportSources.Create(Self); 503 520 try 504 FormImportSources.ImportSources := Core. AcronymDb.ImportSources;521 FormImportSources.ImportSources := Core.Core.AcronymDb.ImportSources; 505 522 FormImportSources.ShowModal; 506 523 UpdateAcronymsList; … … 511 528 end; 512 529 513 procedure TFormMain.FormDestroy(Sender: TObject);514 begin515 end;516 517 530 procedure TFormMain.FormShow(Sender: TObject); 518 531 begin 519 Core. Initialize;532 Core.Core.Initialize; 520 533 521 534 if Visible then begin 522 Core.PersistentForm1.Load(Self);523 Core.ThemeManager.UseTheme(Self);524 535 ListViewFilter1.UpdateFromListView(ListViewAcronyms); 525 536 UpdateInterface; … … 529 540 ListViewFilter1.StringGrid.SetFocus; 530 541 end; 531 Core. ScaleDPI1.ScaleControl(CoolBar1,Core.ScaleDPI1.DesignDPI);542 Core.Core.ScaleDPI1.ScaleControl(CoolBar1, Core.Core.ScaleDPI1.DesignDPI); 532 543 CoolBar1.AutosizeBands; 533 544 end; … … 587 598 procedure TFormMain.ListViewSort1Filter(ListViewSort: TListViewSort); 588 599 begin 589 Core. AcronymDb.AssignToList(ListViewSort1.List, AFilterEnabledCategories.Checked);600 Core.Core.AcronymDb.AssignToList(ListViewSort1.List, AFilterEnabledCategories.Checked); 590 601 FilterList(ListViewSort1.List); 591 602 end; … … 628 639 begin 629 640 AFileClose.Execute; 630 if not Assigned(Core. AcronymDb) then begin641 if not Assigned(Core.Core.AcronymDb) then begin 631 642 try 632 643 AFileNew.Execute; 633 Core. AcronymDb.LoadFromFile(FileName);644 Core.Core.AcronymDb.LoadFromFile(FileName); 634 645 LastOpenedList1.AddItem(FileName); 635 646 finally … … 640 651 end; 641 652 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>); 653 procedure TFormMain.FilterList(List: TObjectList<TObject>); 656 654 var 657 655 I: Integer; … … 686 684 begin 687 685 AFileClose.Execute; 688 if not Assigned(Core. AcronymDb) then begin686 if not Assigned(Core.Core.AcronymDb) then begin 689 687 AFileNew.Execute; 690 Core. AcronymDb.LoadFromFile(TMenuItem(Sender).Caption);688 Core.Core.AcronymDb.LoadFromFile(TMenuItem(Sender).Caption); 691 689 LastOpenedList1.AddItem(TMenuItem(Sender).Caption); 692 690 UpdateAcronymsList; … … 697 695 procedure TFormMain.UpdateAcronymsList; 698 696 begin 699 if Assigned(Core. AcronymDb) then begin697 if Assigned(Core.Core.AcronymDb) then begin 700 698 ListViewSort1.Refresh; 701 699 end else begin … … 710 708 Title: string; 711 709 begin 712 ListViewAcronyms.Enabled := Assigned(Core. AcronymDb);713 AFileClose.Enabled := Assigned(Core. AcronymDb);714 AFileSave.Enabled := Assigned(Core. AcronymDb) andCore.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); 724 722 CoolBar1.Visible := MenuItemToolbar.Checked; 725 723 PanelParam.Visible := MenuItemParam.Checked; 726 AHide.Enabled := FormMain.Visible;724 AHide.Enabled := Visible; 727 725 AManageAcronym.Enabled := Assigned(ListViewAcronyms.Selected); 728 726 StatusBar1.Visible := MenuItemStatusBar.Checked; 729 727 730 728 Title := ''; 731 if Assigned(Core. AcronymDb) and (ExtractFileNameWithoutExt(ExtractFileName(Core.AcronymDb.FileName)) <> '') then begin732 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 + ')'; 734 732 end; 735 733 if Title <> '' then Title := Title + ' - '; 736 Title := Title + Core. ApplicationInfo1.AppName;734 Title := Title + Core.Core.ApplicationInfo1.AppName; 737 735 {$IFDEF WINDOWS} 738 736 // Under Linux title would affect reg.xml path for storing registry settings … … 740 738 {$ENDIF} 741 739 Caption := Title; 742 if Assigned(Core. AcronymDb) then begin740 if Assigned(Core.Core.AcronymDb) then begin 743 741 StatusBar1.Panels[0].Text := Format(SAcronymsCount, [ 744 Core. AcronymDb.Acronyms.Count]);742 Core.Core.AcronymDb.Acronyms.Count]); 745 743 StatusBar1.Panels[1].Text := Format(SMeaningsCount, [ 746 Core. AcronymDb.GetMeaningsCount]);744 Core.Core.AcronymDb.GetMeaningsCount]); 747 745 end else begin 748 746 StatusBar1.Panels[0].Text := ''; … … 753 751 procedure TFormMain.LoadConfig; 754 752 begin 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'); 758 756 LastOpenedList1.LoadFromRegistry(RegistryContext); 759 757 … … 761 759 // If installed in Linux system then use installation directory for po files 762 760 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'; 764 762 {$ENDIF} 765 763 766 764 with TRegistryEx.Create do 767 765 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); 770 768 AFilterSameLength.Checked := ReadBoolWithDefault('SameLength', False); 771 769 AFilterSameLetterCase.Checked := ReadBoolWithDefault('SameLetterCase', False); … … 784 782 RootKey := HKEY_CURRENT_USER; 785 783 OpenKey(RegistryRunKey, True); 786 Core. StartOnLogon := ValueExists('Acronym Decoder');784 Core.Core.StartOnLogon := ValueExists('Acronym Decoder'); 787 785 finally 788 786 Free; … … 792 790 procedure TFormMain.SaveConfig; 793 791 begin 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'); 796 794 LastOpenedList1.SaveToRegistry(RegistryContext); 797 795 798 796 with TRegistryEx.Create do 799 797 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); 802 800 WriteBool('SameLength', AFilterSameLength.Checked); 803 801 WriteBool('SameLetterCase', AFilterSameLetterCase.Checked); … … 815 813 RootKey := HKEY_CURRENT_USER; 816 814 OpenKey(RegistryRunKey, True); 817 if Core. StartOnLogon then begin818 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') 819 817 else WriteString('Acronym Decoder', Application.ExeName) 820 818 end else DeleteValue('Acronym Decoder');
Note:
See TracChangeset
for help on using the changeset viewer.