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 | procedure AAddExecute(Sender: TObject);
|
---|
26 | procedure AModifyExecute(Sender: TObject);
|
---|
27 | procedure ARemoveExecute(Sender: TObject);
|
---|
28 | procedure FormShow(Sender: TObject);
|
---|
29 | procedure ListView1Data(Sender: TObject; Item: TListItem);
|
---|
30 | procedure ListView1DblClick(Sender: TObject);
|
---|
31 | procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
|
---|
32 | Selected: Boolean);
|
---|
33 | private
|
---|
34 | { private declarations }
|
---|
35 | public
|
---|
36 | ImportFormats: TImportFormats;
|
---|
37 | procedure UpdateList;
|
---|
38 | procedure UpdateInterface;
|
---|
39 | end;
|
---|
40 |
|
---|
41 | var
|
---|
42 | FormImportFormats: TFormImportFormats;
|
---|
43 |
|
---|
44 | implementation
|
---|
45 |
|
---|
46 | {$R *.lfm}
|
---|
47 |
|
---|
48 | uses
|
---|
49 | UFormMain, UFormImportFormat;
|
---|
50 |
|
---|
51 | resourcestring
|
---|
52 | SRemoveImportFormat = 'Remove import formats';
|
---|
53 | SRemoveImportFormatQuery = 'Do you really want to remove selected import formats?';
|
---|
54 | SImportFormatAlreadyExists = 'Import format %s already exists!';
|
---|
55 |
|
---|
56 |
|
---|
57 | { TFormImportFormats }
|
---|
58 |
|
---|
59 | procedure TFormImportFormats.ListView1Data(Sender: TObject; Item: TListItem);
|
---|
60 | begin
|
---|
61 | if Item.Index < ImportFormats.Count then
|
---|
62 | with TImportFormat(ImportFormats[Item.Index]) do begin
|
---|
63 | Item.Caption := Name;
|
---|
64 | Item.Data := ImportFormats[Item.Index];
|
---|
65 | end;
|
---|
66 | end;
|
---|
67 |
|
---|
68 | procedure TFormImportFormats.ListView1DblClick(Sender: TObject);
|
---|
69 | begin
|
---|
70 | AModify.Execute;
|
---|
71 | end;
|
---|
72 |
|
---|
73 | procedure TFormImportFormats.ListView1SelectItem(Sender: TObject;
|
---|
74 | Item: TListItem; Selected: Boolean);
|
---|
75 | begin
|
---|
76 | UpdateInterface;
|
---|
77 | end;
|
---|
78 |
|
---|
79 | procedure TFormImportFormats.UpdateList;
|
---|
80 | begin
|
---|
81 | ListView1.Items.Count := ImportFormats.Count;
|
---|
82 | ListView1.Refresh;
|
---|
83 | UpdateInterface;
|
---|
84 | end;
|
---|
85 |
|
---|
86 | procedure TFormImportFormats.UpdateInterface;
|
---|
87 | begin
|
---|
88 | ARemove.Enabled := Assigned(ListView1.Selected);
|
---|
89 | AModify.Enabled := Assigned(ListView1.Selected);
|
---|
90 | end;
|
---|
91 |
|
---|
92 | procedure TFormImportFormats.FormShow(Sender: TObject);
|
---|
93 | begin
|
---|
94 | UpdateList;
|
---|
95 | end;
|
---|
96 |
|
---|
97 | procedure TFormImportFormats.AAddExecute(Sender: TObject);
|
---|
98 | var
|
---|
99 | NewImportFormat: TImportFormat;
|
---|
100 | begin
|
---|
101 | NewImportFormat := TImportFormat.Create;
|
---|
102 | NewImportFormat.Formats := ImportFormats;
|
---|
103 | FormImportFormat.Load(NewImportFormat);
|
---|
104 | if FormImportFormat.ShowModal = mrOk then begin
|
---|
105 | FormImportFormat.Save(NewImportFormat);
|
---|
106 | if not Assigned(ImportFormats.SearchByName(NewImportFormat.Name)) then begin;
|
---|
107 | ImportFormats.Add(NewImportFormat);
|
---|
108 | NewImportFormat := nil;
|
---|
109 | FormMain.AcronymDb.Modified := True;
|
---|
110 | UpdateList;
|
---|
111 | end else ShowMessage(Format(SImportFormatAlreadyExists, [NewImportFormat.Name]));
|
---|
112 | end;
|
---|
113 | if Assigned(NewImportFormat) then NewImportFormat.Free;
|
---|
114 | end;
|
---|
115 |
|
---|
116 | procedure TFormImportFormats.AModifyExecute(Sender: TObject);
|
---|
117 | var
|
---|
118 | NewImportFormat: TImportFormat;
|
---|
119 | begin
|
---|
120 | if Assigned(ListView1.Selected) then begin
|
---|
121 | NewImportFormat := TImportFormat.Create;
|
---|
122 | NewImportFormat.Assign(ListView1.Selected.Data);
|
---|
123 | FormImportFormat.Load(NewImportFormat);
|
---|
124 | if FormImportFormat.ShowModal = mrOk then begin
|
---|
125 | FormImportFormat.Save(NewImportFormat);
|
---|
126 | if (NewImportFormat.Name <> TImportFormat(ListView1.Selected.Data).Name) then begin
|
---|
127 | if not Assigned(ImportFormats.SearchByName(NewImportFormat.Name)) then begin;
|
---|
128 | TImportFormat(ListView1.Selected.Data).Assign(NewImportFormat);
|
---|
129 | FormMain.AcronymDb.Modified := True;
|
---|
130 | UpdateList;
|
---|
131 | end else ShowMessage(Format(SImportFormatAlreadyExists, [NewImportFormat.Name]));
|
---|
132 | end else begin
|
---|
133 | TImportFormat(ListView1.Selected.Data).Assign(NewImportFormat);
|
---|
134 | FormMain.AcronymDb.Modified := True;
|
---|
135 | UpdateList;
|
---|
136 | end;
|
---|
137 | end;
|
---|
138 | if Assigned(NewImportFormat) then NewImportFormat.Free;
|
---|
139 | end;
|
---|
140 | end;
|
---|
141 |
|
---|
142 | procedure TFormImportFormats.ARemoveExecute(Sender: TObject);
|
---|
143 | var
|
---|
144 | I: Integer;
|
---|
145 | begin
|
---|
146 | if Assigned(ListView1.Selected) then begin
|
---|
147 | if MessageDlg(SRemoveImportFormat, SRemoveImportFormatQuery,
|
---|
148 | TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin
|
---|
149 | for I := ListView1.Items.Count - 1 downto 0 do
|
---|
150 | if ListView1.Items[I].Selected then
|
---|
151 | ImportFormats.Remove(ListView1.Items[I].Data);
|
---|
152 | UpdateList;
|
---|
153 | end;
|
---|
154 | end;
|
---|
155 | end;
|
---|
156 |
|
---|
157 | end.
|
---|
158 |
|
---|