source: trunk/Forms/FormImportFormats.pas

Last change on this file was 227, checked in by chronos, 44 hours ago
  • Modified: Do not reference global Core object if possible.
File size: 5.2 KB
Line 
1unit FormImportFormats;
2
3interface
4
5uses
6 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
7 ActnList, Menus, Acronym, FormEx;
8
9type
10
11 { TFormImportFormats }
12
13 TFormImportFormats = class(TFormEx)
14 AAdd: TAction;
15 ActionList1: TActionList;
16 AModify: TAction;
17 ARemove: TAction;
18 ListView1: TListView;
19 MenuItem1: TMenuItem;
20 MenuItem2: TMenuItem;
21 MenuItem3: TMenuItem;
22 PopupMenuImportSource: TPopupMenu;
23 ToolBar1: TToolBar;
24 ToolButton1: TToolButton;
25 ToolButton2: TToolButton;
26 ToolButton3: TToolButton;
27 procedure AAddExecute(Sender: TObject);
28 procedure AModifyExecute(Sender: TObject);
29 procedure ARemoveExecute(Sender: TObject);
30 procedure FormCreate(Sender: TObject);
31 procedure FormShow(Sender: TObject);
32 procedure ListView1Data(Sender: TObject; Item: TListItem);
33 procedure ListView1DblClick(Sender: TObject);
34 procedure ListView1KeyPress(Sender: TObject; var Key: char);
35 procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
36 Selected: Boolean);
37 public
38 AcronymDb: TAcronymDb;
39 ImportFormats: TImportFormats;
40 procedure UpdateList;
41 procedure UpdateInterface;
42 end;
43
44
45implementation
46
47{$R *.lfm}
48
49uses
50 FormImportFormat;
51
52resourcestring
53 SRemoveImportFormat = 'Remove import formats';
54 SRemoveImportFormatQuery = 'Do you really want to remove selected import formats?';
55 SImportFormatAlreadyExists = 'Import format %s already exists!';
56
57
58{ TFormImportFormats }
59
60procedure TFormImportFormats.ListView1Data(Sender: TObject; Item: TListItem);
61begin
62 if Item.Index < ImportFormats.Count then
63 with TImportFormat(ImportFormats[Item.Index]) do begin
64 Item.Caption := Name;
65 Item.Data := ImportFormats[Item.Index];
66 end;
67end;
68
69procedure TFormImportFormats.ListView1DblClick(Sender: TObject);
70begin
71 AModify.Execute;
72end;
73
74procedure TFormImportFormats.ListView1KeyPress(Sender: TObject; var Key: char);
75begin
76 if Key = #27 then Close;
77end;
78
79procedure TFormImportFormats.ListView1SelectItem(Sender: TObject;
80 Item: TListItem; Selected: Boolean);
81begin
82 UpdateInterface;
83end;
84
85procedure TFormImportFormats.UpdateList;
86begin
87 ListView1.Items.Count := ImportFormats.Count;
88 ListView1.Refresh;
89 UpdateInterface;
90end;
91
92procedure TFormImportFormats.UpdateInterface;
93begin
94 ARemove.Enabled := Assigned(ListView1.Selected);
95 AModify.Enabled := Assigned(ListView1.Selected);
96end;
97
98procedure TFormImportFormats.FormShow(Sender: TObject);
99begin
100 UpdateList;
101 ScaleDPI.ScaleControl(ToolBar1, ScaleDPI.DesignDPI);
102end;
103
104procedure TFormImportFormats.AAddExecute(Sender: TObject);
105var
106 NewImportFormat: TImportFormat;
107 FormImportFormat: TFormImportFormat;
108begin
109 NewImportFormat := TImportFormat.Create;
110 NewImportFormat.Formats := ImportFormats;
111 FormImportFormat := TFormImportFormat.Create(Self);
112 try
113 FormImportFormat.Load(NewImportFormat);
114 if FormImportFormat.ShowModal = mrOk then begin
115 FormImportFormat.Save(NewImportFormat);
116 if not Assigned(ImportFormats.SearchByName(NewImportFormat.Name)) then begin;
117 ImportFormats.Add(NewImportFormat);
118 NewImportFormat := nil;
119 AcronymDb.Modified := True;
120 UpdateList;
121 end else ShowMessage(Format(SImportFormatAlreadyExists, [NewImportFormat.Name]));
122 end;
123 if Assigned(NewImportFormat) then NewImportFormat.Free;
124 finally
125 FreeAndNil(FormImportFormat);
126 end;
127end;
128
129procedure TFormImportFormats.AModifyExecute(Sender: TObject);
130var
131 NewImportFormat: TImportFormat;
132 FormImportFormat: TFormImportFormat;
133begin
134 if Assigned(ListView1.Selected) then begin
135 NewImportFormat := TImportFormat.Create;
136 NewImportFormat.Assign(ListView1.Selected.Data);
137 FormImportFormat := TFormImportFormat.Create(Self);
138 try
139 FormImportFormat.Load(NewImportFormat);
140 if FormImportFormat.ShowModal = mrOk then begin
141 FormImportFormat.Save(NewImportFormat);
142 if (NewImportFormat.Name <> TImportFormat(ListView1.Selected.Data).Name) then begin
143 if not Assigned(ImportFormats.SearchByName(NewImportFormat.Name)) then begin;
144 TImportFormat(ListView1.Selected.Data).Assign(NewImportFormat);
145 AcronymDb.Modified := True;
146 UpdateList;
147 end else ShowMessage(Format(SImportFormatAlreadyExists, [NewImportFormat.Name]));
148 end else begin
149 TImportFormat(ListView1.Selected.Data).Assign(NewImportFormat);
150 AcronymDb.Modified := True;
151 UpdateList;
152 end;
153 end;
154 if Assigned(NewImportFormat) then NewImportFormat.Free;
155 finally
156 FreeAndNil(FormImportFormat);
157 end;
158 end;
159end;
160
161procedure TFormImportFormats.ARemoveExecute(Sender: TObject);
162var
163 I: Integer;
164begin
165 if Assigned(ListView1.Selected) then begin
166 if MessageDlg(SRemoveImportFormat, SRemoveImportFormatQuery,
167 TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin
168 for I := ListView1.Items.Count - 1 downto 0 do
169 if ListView1.Items[I].Selected then
170 ImportFormats.Remove(ListView1.Items[I].Data);
171 UpdateList;
172 end;
173 end;
174end;
175
176procedure TFormImportFormats.FormCreate(Sender: TObject);
177var
178 I: Integer;
179begin
180 for I := 0 to ToolBar1.ButtonCount - 1 do
181 ToolBar1.Buttons[I].Hint := ToolBar1.Buttons[I].Caption;
182end;
183
184end.
185
Note: See TracBrowser for help on using the repository browser.