Changeset 138 for trunk/Forms/UFormContacts.pas
- Timestamp:
- Aug 23, 2022, 10:06:54 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormContacts.pas
r134 r138 5 5 uses 6 6 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls, 7 Menus, ActnList, UVCard, UListViewSort, LazUTF8, Clipbrd, 8 Generics.Collections ;7 Menus, ActnList, UVCard, UListViewSort, LazUTF8, Clipbrd, URegistry, 8 Generics.Collections, Types; 9 9 10 10 type … … 16 16 AClone: TAction; 17 17 ACopy: TAction; 18 AColumns: TAction; 18 19 ACut: TAction; 19 20 APaste: TAction; … … 31 32 MenuItem11: TMenuItem; 32 33 MenuItem12: TMenuItem; 34 Separator1: TMenuItem; 35 MenuItemColumns: TMenuItem; 33 36 MenuItem2: TMenuItem; 34 37 MenuItem3: TMenuItem; … … 53 56 procedure AAddExecute(Sender: TObject); 54 57 procedure ACloneExecute(Sender: TObject); 58 procedure AColumnsExecute(Sender: TObject); 55 59 procedure ACopyExecute(Sender: TObject); 56 60 procedure ACutExecute(Sender: TObject); … … 83 87 procedure DoUpdateInterface; 84 88 procedure UpdateColumns; 89 procedure LoadFromRegistry(Context: TRegistryContext); 90 procedure SaveToRegistry(Context: TRegistryContext); 85 91 public 86 92 ListViewColumns: TContactFieldIndexes; 87 93 FilterItems: TContactFilterItems; 88 property Contacts: TContacts read FContacts write SetContacts;94 Context: TRegistryContext; 89 95 procedure ReloadList; 90 96 procedure BeginUpdate; 91 97 procedure EndUpdate; 92 98 procedure UpdateInterface; 99 property Contacts: TContacts read FContacts write SetContacts; 93 100 end; 94 101 … … 102 109 103 110 uses 104 UFormContact, UCore, UVCardFile ;111 UFormContact, UCore, UVCardFile, UFormColumns; 105 112 106 113 resourcestring … … 315 322 end; 316 323 324 procedure TFormContacts.LoadFromRegistry(Context: TRegistryContext); 325 var 326 I: Integer; 327 Registry: TRegistryEx; 328 ContactFieldIndex: TContactFieldIndex; 329 begin 330 Registry := TRegistryEx.Create; 331 with Registry do 332 try 333 RootKey := Context.RootKey; 334 OpenKey(Context.Key, True); 335 ListViewColumns.Clear; 336 I := 0; 337 while ValueExists('Column' + IntToStr(I)) do begin 338 ContactFieldIndex := TContactFieldIndex(ReadIntegerWithDefault('Column' + IntToStr(I), -1)); 339 ListViewColumns.Add(ContactFieldIndex); 340 Inc(I); 341 end; 342 343 if ListViewColumns.Count = 0 then begin 344 with ListViewColumns do begin 345 Add(cfFullName); 346 Add(cfFirstName); 347 Add(cfMiddleName); 348 Add(cfLastName); 349 Add(cfTel); 350 Add(cfTelCell); 351 Add(cfTelHome); 352 Add(cfTelWork); 353 Add(cfEmailWork); 354 Add(cfOrganization); 355 end; 356 end; 357 finally 358 Free; 359 end; 360 end; 361 362 procedure TFormContacts.SaveToRegistry(Context: TRegistryContext); 363 var 364 I: Integer; 365 Registry: TRegistryEx; 366 begin 367 Registry := TRegistryEx.Create; 368 with Registry do 369 try 370 RootKey := Context.RootKey; 371 OpenKey(Context.Key, True); 372 for I := 0 to ListViewColumns.Count - 1 do 373 WriteInteger('Column' + IntToStr(I), Integer(ListViewColumns[I])); 374 375 // Remove old columns 376 I := ListViewColumns.Count; 377 while ValueExists('Column' + IntToStr(I)) do begin 378 DeleteValue('Column' + IntToStr(I)); 379 Inc(I); 380 end; 381 finally 382 Free; 383 end; 384 end; 385 317 386 procedure TFormContacts.FormShow(Sender: TObject); 318 387 begin … … 320 389 Core.ThemeManager1.UseTheme(Self); 321 390 Core.PersistentForm1.Load(Self); 391 LoadFromRegistry(Context); 322 392 ReloadList; 323 393 UpdateInterface; … … 385 455 end; 386 456 457 procedure TFormContacts.AColumnsExecute(Sender: TObject); 458 var 459 FormColumns: TFormColumns; 460 I: Integer; 461 Field: TContactField; 462 begin 463 FormColumns := TFormColumns.Create(nil); 464 with FormColumns do 465 try 466 for I := 0 to ListViewColumns.Count - 1 do begin 467 Field := TContact.GetFields.GetByIndex(ListViewColumns[I]); 468 if Assigned(Field) then 469 ActiveColumns.AddObject(Field.Title, Field); 470 end; 471 for I := 0 to TContact.GetFields.Count - 1 do begin 472 Field := TContact.GetFields[I]; 473 if ListViewColumns.IndexOf(Field.Index) = -1 then 474 AvailableColumns.AddObject(Field.Title, Field); 475 end; 476 if ShowModal = mrOK then begin 477 ListViewColumns.Clear; 478 for I := 0 to ActiveColumns.Count - 1 do begin 479 ListViewColumns.Add(TContactField(ActiveColumns.Objects[I]).Index); 480 end; 481 UpdateColumns; 482 ReloadList; 483 end; 484 finally 485 Free; 486 end; 487 end; 488 387 489 procedure TFormContacts.ACopyExecute(Sender: TObject); 388 490 var … … 571 673 ); 572 674 begin 675 SaveToRegistry(Context); 573 676 Core.PersistentForm1.Save(Self); 574 677 end; … … 579 682 begin 580 683 FilterItems := TContactFilterItems.Create; 581 582 684 ListViewColumns := TContactFieldIndexes.Create; 583 with ListViewColumns do begin584 Add(cfFullName);585 Add(cfFirstName);586 Add(cfMiddleName);587 Add(cfLastName);588 Add(cfTel);589 Add(cfTelCell);590 Add(cfTelHome);591 Add(cfTelWork);592 Add(cfEmailWork);593 end;594 685 595 686 FContacts := nil;
Note:
See TracChangeset
for help on using the changeset viewer.