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