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