source: tags/1.3.1/Forms/UFormImportFormats.pas

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