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