source: tags/1.1.0/Forms/UFormImportFormats.pas

Last change on this file was 51, checked in by chronos, 8 years ago
  • Added: Bottom action toolbar to windows with lists.
File size: 4.9 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 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
46var
47 FormImportFormats: TFormImportFormats;
48
49implementation
50
51{$R *.lfm}
52
53uses
54 UFormMain, UFormImportFormat;
55
56resourcestring
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
64procedure TFormImportFormats.ListView1Data(Sender: TObject; Item: TListItem);
65begin
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;
71end;
72
73procedure TFormImportFormats.ListView1DblClick(Sender: TObject);
74begin
75 AModify.Execute;
76end;
77
78procedure TFormImportFormats.ListView1SelectItem(Sender: TObject;
79 Item: TListItem; Selected: Boolean);
80begin
81 UpdateInterface;
82end;
83
84procedure TFormImportFormats.UpdateList;
85begin
86 ListView1.Items.Count := ImportFormats.Count;
87 ListView1.Refresh;
88 UpdateInterface;
89end;
90
91procedure TFormImportFormats.UpdateInterface;
92begin
93 ARemove.Enabled := Assigned(ListView1.Selected);
94 AModify.Enabled := Assigned(ListView1.Selected);
95end;
96
97procedure TFormImportFormats.FormShow(Sender: TObject);
98begin
99 UpdateList;
100end;
101
102procedure TFormImportFormats.AAddExecute(Sender: TObject);
103var
104 NewImportFormat: TImportFormat;
105begin
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;
119end;
120
121procedure TFormImportFormats.AModifyExecute(Sender: TObject);
122var
123 NewImportFormat: TImportFormat;
124begin
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;
145end;
146
147procedure TFormImportFormats.ARemoveExecute(Sender: TObject);
148var
149 I: Integer;
150begin
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;
160end;
161
162procedure TFormImportFormats.FormCreate(Sender: TObject);
163var
164 I: Integer;
165begin
166 for I := 0 to ToolBar1.ButtonCount - 1 do
167 ToolBar1.Buttons[I].Hint := ToolBar1.Buttons[I].Caption;
168end;
169
170end.
171
Note: See TracBrowser for help on using the repository browser.