~chronoscz/vcard-studio/trunk

« back to all changes in this revision

Viewing changes to Forms/UFormContacts.pas

  • Committer: chronos
  • Date: 2018-01-29 09:54:40 UTC
  • Revision ID: svn-v4:b2f690cb-8b89-471c-b043-dbd4632e1e77:trunk:3
* Added: Allow to edit more contacts fields.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
    procedure AModifyExecute(Sender: TObject);
31
31
    procedure ARemoveExecute(Sender: TObject);
32
32
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
 
33
    procedure FormCreate(Sender: TObject);
33
34
    procedure FormShow(Sender: TObject);
34
35
    procedure ListView1Data(Sender: TObject; Item: TListItem);
35
36
    procedure ListView1DblClick(Sender: TObject);
36
37
    procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
37
38
      Selected: Boolean);
38
39
  private
 
40
    FContacts: TContacts;
 
41
    procedure SetContacts(AValue: TContacts);
39
42
 
40
43
  public
41
 
    Contacts: TContacts;
 
44
    property Contacts: TContacts read FContacts write SetContacts;
42
45
    procedure ReloadList;
43
46
    procedure UpdateInterface;
44
47
  end;
54
57
uses
55
58
  UFormContact, UCore;
56
59
 
 
60
resourcestring
 
61
  SRemoveContacts = 'Remove contacts';
 
62
  SRemoveContactsQuery = 'Do you want to remove selected contacts?';
 
63
 
57
64
{ TFormContacts }
58
65
 
59
66
procedure TFormContacts.ListView1Data(Sender: TObject; Item: TListItem);
60
67
begin
61
68
  if Assigned(Contacts) and (Item.Index < Contacts.Count) then
62
69
  with TContact(Contacts[Item.Index]) do begin
63
 
    Item.Caption := FullName;
 
70
    Item.Caption := FirstName;
 
71
    Item.SubItems.Add(MiddleName);
 
72
    Item.SubItems.Add(LastName);
64
73
    Item.Data := Contacts[Item.Index];
65
74
  end;
66
75
end;
76
85
  UpdateInterface;
77
86
end;
78
87
 
 
88
procedure TFormContacts.SetContacts(AValue: TContacts);
 
89
begin
 
90
  if FContacts = AValue then Exit;
 
91
  FContacts := AValue;
 
92
  ReloadList;
 
93
  UpdateInterface;
 
94
end;
 
95
 
79
96
procedure TFormContacts.FormShow(Sender: TObject);
80
97
begin
81
98
  Core.PersistentForm1.Load(Self);
86
103
procedure TFormContacts.AAddExecute(Sender: TObject);
87
104
var
88
105
  FormContact: TFormContact;
 
106
  Contact: TContact;
89
107
begin
90
108
  FormContact := TFormContact.Create(nil);
 
109
  try
91
110
  if FormContact.ShowModal = mrOK then begin
92
 
    FormContact.SaveData(TContact(ListView1.Selected.Data));
 
111
    Contact := TContact.Create;
 
112
    FormContact.SaveData(Contact);
 
113
    Contacts.Add(Contact);
 
114
    Core.DataFile.Modified := True;
93
115
    ReloadList;
94
116
    UpdateInterface;
95
117
  end;
96
 
  FormContact.Free;
 
118
  finally
 
119
    FormContact.Free;
 
120
  end;
97
121
end;
98
122
 
99
123
procedure TFormContacts.AModifyExecute(Sender: TObject);
101
125
  FormContact: TFormContact;
102
126
begin
103
127
  FormContact := TFormContact.Create(nil);
104
 
  FormContact.LoadData(TContact(ListView1.Selected.Data));
105
 
  if FormContact.ShowModal = mrOK then begin
106
 
    FormContact.SaveData(TContact(ListView1.Selected.Data));
107
 
    ReloadList;
108
 
    UpdateInterface;
 
128
  try
 
129
    FormContact.LoadData(TContact(ListView1.Selected.Data));
 
130
    if FormContact.ShowModal = mrOK then begin
 
131
      FormContact.SaveData(TContact(ListView1.Selected.Data));
 
132
      Core.DataFile.Modified := True;
 
133
      ReloadList;
 
134
      UpdateInterface;
 
135
    end;
 
136
  finally
 
137
    FormContact.Free;
109
138
  end;
110
 
  FormContact.Free;
111
139
end;
112
140
 
113
141
procedure TFormContacts.ARemoveExecute(Sender: TObject);
114
142
var
115
143
  I: Integer;
116
144
begin
117
 
  for I := ListView1.Items.Count - 1 downto 0 do
118
 
    if ListView1.Items[I].Selected then begin
119
 
      Contacts.Delete(I);
120
 
    end;
121
 
  UpdateInterface;
 
145
  if Assigned(ListView1.Selected) then
 
146
  if MessageDlg(SRemoveContacts, SRemoveContactsQuery,
 
147
    TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin
 
148
    for I := ListView1.Items.Count - 1 downto 0 do
 
149
      if ListView1.Items[I].Selected then begin
 
150
        Contacts.Delete(I);
 
151
      end;
 
152
    Core.DataFile.Modified := True;
 
153
    ReloadList;
 
154
    UpdateInterface;
 
155
  end;
122
156
end;
123
157
 
124
158
procedure TFormContacts.FormClose(Sender: TObject; var CloseAction: TCloseAction
127
161
  Core.PersistentForm1.Save(Self);
128
162
end;
129
163
 
 
164
procedure TFormContacts.FormCreate(Sender: TObject);
 
165
begin
 
166
  FContacts := nil;
 
167
end;
 
168
 
130
169
procedure TFormContacts.ReloadList;
131
170
begin
132
171
  if Assigned(Contacts) then
137
176
 
138
177
procedure TFormContacts.UpdateInterface;
139
178
begin
140
 
  AModify.Enabled := Assigned(ListView1.Selected);
141
 
  ARemove.Enabled := Assigned(ListView1.Selected);
 
179
  AAdd.Enabled := Assigned(Contacts);
 
180
  AModify.Enabled := Assigned(Contacts) and Assigned(ListView1.Selected);
 
181
  ARemove.Enabled := Assigned(Contacts) and Assigned(ListView1.Selected);
142
182
end;
143
183
 
144
184
end.