Ignore:
Timestamp:
Dec 8, 2021, 4:44:21 PM (3 years ago)
Author:
chronos
Message:
  • Added: Show textual name of contact field in contact field form and prefill field name and attributes. Update that name back according used field name and attributes.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormProperty.pas

    r42 r56  
    1515    ButtonCancel: TButton;
    1616    ButtonOk: TButton;
     17    ComboBoxField: TComboBox;
    1718    EditName: TEdit;
    1819    EditAttributes: TEdit;
     
    2122    Label2: TLabel;
    2223    Label3: TLabel;
     24    Label4: TLabel;
    2325    procedure ButtonOkClick(Sender: TObject);
     26    procedure ComboBoxFieldChange(Sender: TObject);
     27    procedure EditAttributesChange(Sender: TObject);
     28    procedure EditNameChange(Sender: TObject);
    2429    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    2530    procedure FormCreate(Sender: TObject);
     
    2732  private
    2833    FContactProperty: TContactProperty;
     34    procedure UpdateField;
    2935    procedure SetContactProperty(AValue: TContactProperty);
    3036    procedure LoadData;
     
    5157end;
    5258
     59procedure TFormProperty.ComboBoxFieldChange(Sender: TObject);
     60var
     61  Field: TContactField;
     62  Attributes: TStringList;
     63  I: Integer;
     64begin
     65  if ComboBoxField.ItemIndex <> -1 then begin
     66    Field := TContactsFile(Core.DataFile).Fields[ComboBoxField.ItemIndex];
     67    if Assigned(Field) then begin
     68      EditName.Text := Field.SysName;
     69      Attributes := TStringList.Create;
     70      try
     71        Attributes.NameValueSeparator := '=';
     72        Attributes.Delimiter := ';';
     73        Attributes.StrictDelimiter := True;
     74        for I := 0 to Length(Field.Groups) - 1 do
     75          Attributes.Add(Field.Groups[I]);
     76        EditAttributes.Text := Attributes.DelimitedText;
     77      finally
     78        Attributes.Free;
     79      end;
     80    end;
     81  end;
     82end;
     83
     84procedure TFormProperty.EditAttributesChange(Sender: TObject);
     85begin
     86  UpdateField;
     87end;
     88
     89procedure TFormProperty.EditNameChange(Sender: TObject);
     90begin
     91  UpdateField;
     92end;
     93
    5394procedure TFormProperty.FormClose(Sender: TObject; var CloseAction: TCloseAction);
    5495begin
     
    61102  Core.ThemeManager1.UseTheme(Self);
    62103  FContactProperty := nil;
     104  TContactsFile(Core.DataFile).Fields.LoadToStrings(ComboBoxField.Items);
    63105end;
    64106
     
    66108begin
    67109  Core.PersistentForm1.Load(Self);
     110end;
     111
     112procedure TFormProperty.UpdateField;
     113var
     114  Field: TContactField;
     115  Groups: TStringList;
     116  GroupsArray: TStringArray;
     117  I: Integer;
     118begin
     119  Groups := TStringList.Create;
     120  try
     121    Groups.NameValueSeparator := '=';
     122    Groups.Delimiter := ';';
     123    Groups.StrictDelimiter := True;
     124    Groups.DelimitedText := EditAttributes.Text;
     125    SetLength(GroupsArray, Groups.Count);
     126    for I := 0 to Groups.Count - 1 do
     127      GroupsArray[I] := Groups[I];
     128  finally
     129    Groups.Free;
     130  end;
     131  Field := TContactsFile(Core.DataFile).Fields.GetBySysNameGroups(EditName.Text,
     132    GroupsArray);
     133  if Assigned(Field) then
     134    ComboBoxField.ItemIndex := TContactsFile(Core.DataFile).Fields.IndexOf(Field);
    68135end;
    69136
Note: See TracChangeset for help on using the changeset viewer.