| 1 | unit FormImportFormat;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
|
|---|
| 7 | ComCtrls, Menus, ActnList, Acronym, FormEx;
|
|---|
| 8 |
|
|---|
| 9 | type
|
|---|
| 10 |
|
|---|
| 11 | { TFormImportFormat }
|
|---|
| 12 |
|
|---|
| 13 | TFormImportFormat = class(TFormEx)
|
|---|
| 14 | AAdd: TAction;
|
|---|
| 15 | ActionList1: TActionList;
|
|---|
| 16 | AModify: TAction;
|
|---|
| 17 | AMoveDown: TAction;
|
|---|
| 18 | AMoveUp: TAction;
|
|---|
| 19 | ARemove: TAction;
|
|---|
| 20 | ButtonOk: TButton;
|
|---|
| 21 | ButtonCancel: TButton;
|
|---|
| 22 | ComboBoxType: TComboBox;
|
|---|
| 23 | EditBlockEnd: TEdit;
|
|---|
| 24 | EditBlockStart: TEdit;
|
|---|
| 25 | EditName: TEdit;
|
|---|
| 26 | Label1: TLabel;
|
|---|
| 27 | Label2: TLabel;
|
|---|
| 28 | Label3: TLabel;
|
|---|
| 29 | Label8: TLabel;
|
|---|
| 30 | Label9: TLabel;
|
|---|
| 31 | ListViewItemRules: TListView;
|
|---|
| 32 | MenuItem1: TMenuItem;
|
|---|
| 33 | MenuItem2: TMenuItem;
|
|---|
| 34 | MenuItem3: TMenuItem;
|
|---|
| 35 | MenuItem4: TMenuItem;
|
|---|
| 36 | MenuItem5: TMenuItem;
|
|---|
| 37 | PopupMenu1: TPopupMenu;
|
|---|
| 38 | ScrollBox1: TScrollBox;
|
|---|
| 39 | procedure AAddExecute(Sender: TObject);
|
|---|
| 40 | procedure AModifyExecute(Sender: TObject);
|
|---|
| 41 | procedure AMoveDownExecute(Sender: TObject);
|
|---|
| 42 | procedure AMoveUpExecute(Sender: TObject);
|
|---|
| 43 | procedure ARemoveExecute(Sender: TObject);
|
|---|
| 44 | procedure FormCreate(Sender: TObject);
|
|---|
| 45 | procedure FormShow(Sender: TObject);
|
|---|
| 46 | procedure ListViewItemRulesData(Sender: TObject; Item: TListItem);
|
|---|
| 47 | public
|
|---|
| 48 | ImportFormat: TImportFormat;
|
|---|
| 49 | procedure Load(ImportFormat: TImportFormat);
|
|---|
| 50 | procedure Save(ImportFormat: TImportFormat);
|
|---|
| 51 | procedure ReloadList;
|
|---|
| 52 | end;
|
|---|
| 53 |
|
|---|
| 54 | var
|
|---|
| 55 | FormImportFormat: TFormImportFormat;
|
|---|
| 56 | YesNoString: array[Boolean] of string;
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 | implementation
|
|---|
| 60 |
|
|---|
| 61 | uses
|
|---|
| 62 | FormImportPattern;
|
|---|
| 63 |
|
|---|
| 64 | {$R *.lfm}
|
|---|
| 65 |
|
|---|
| 66 | resourcestring
|
|---|
| 67 | SRemoveImportPattern = 'Remove import pattern';
|
|---|
| 68 | SRemoveImportPatternQuery = 'Do you really want to remove selected import patterns?';
|
|---|
| 69 | SYes = 'Yes';
|
|---|
| 70 | SNo = 'No';
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 | { TFormImportFormat }
|
|---|
| 74 |
|
|---|
| 75 | procedure TFormImportFormat.AAddExecute(Sender: TObject);
|
|---|
| 76 | var
|
|---|
| 77 | NewImportPattern: TImportPattern;
|
|---|
| 78 | FormImportPattern: TFormImportPattern;
|
|---|
| 79 | begin
|
|---|
| 80 | FormImportPattern := TFormImportPattern.Create(Self);
|
|---|
| 81 | try
|
|---|
| 82 | NewImportPattern := TImportPattern.Create;
|
|---|
| 83 | FormImportPattern.Load(NewImportPattern);
|
|---|
| 84 | if FormImportPattern.ShowModal = mrOk then begin
|
|---|
| 85 | FormImportPattern.Save(NewImportPattern);
|
|---|
| 86 | ImportFormat.ItemPatterns.Add(NewImportPattern);
|
|---|
| 87 | NewImportPattern := nil;
|
|---|
| 88 | ReloadList;
|
|---|
| 89 | end;
|
|---|
| 90 | if Assigned(NewImportPattern) then NewImportPattern.Free;
|
|---|
| 91 | finally
|
|---|
| 92 | FreeAndNil(FormImportPattern);
|
|---|
| 93 | end;
|
|---|
| 94 | end;
|
|---|
| 95 |
|
|---|
| 96 | procedure TFormImportFormat.AModifyExecute(Sender: TObject);
|
|---|
| 97 | var
|
|---|
| 98 | NewImportPattern: TImportPattern;
|
|---|
| 99 | FormImportPattern: TFormImportPattern;
|
|---|
| 100 | begin
|
|---|
| 101 | FormImportPattern := TFormImportPattern.Create(Self);
|
|---|
| 102 | try
|
|---|
| 103 | if Assigned(ListViewItemRules.Selected) then begin
|
|---|
| 104 | NewImportPattern := TImportPattern.Create;
|
|---|
| 105 | NewImportPattern.Assign(ListViewItemRules.Selected.Data);
|
|---|
| 106 | FormImportPattern.Load(NewImportPattern);
|
|---|
| 107 | if FormImportPattern.ShowModal = mrOk then begin
|
|---|
| 108 | FormImportPattern.Save(NewImportPattern);
|
|---|
| 109 | TImportPattern(ListViewItemRules.Selected.Data).Assign(NewImportPattern);
|
|---|
| 110 | ReloadList;
|
|---|
| 111 | end;
|
|---|
| 112 | if Assigned(NewImportPattern) then NewImportPattern.Free;
|
|---|
| 113 | end;
|
|---|
| 114 | finally
|
|---|
| 115 | FreeAndNil(FormImportPattern);
|
|---|
| 116 | end;
|
|---|
| 117 | end;
|
|---|
| 118 |
|
|---|
| 119 | procedure TFormImportFormat.AMoveDownExecute(Sender: TObject);
|
|---|
| 120 | begin
|
|---|
| 121 | if ListViewItemRules.Selected.Index < (ImportFormat.ItemPatterns.Count - 1) then
|
|---|
| 122 | with ImportFormat do
|
|---|
| 123 | ItemPatterns.Exchange(ListViewItemRules.Selected.Index,
|
|---|
| 124 | ListViewItemRules.Selected.Index + 1);
|
|---|
| 125 | ReloadList;
|
|---|
| 126 | end;
|
|---|
| 127 |
|
|---|
| 128 | procedure TFormImportFormat.AMoveUpExecute(Sender: TObject);
|
|---|
| 129 | begin
|
|---|
| 130 | if ListViewItemRules.Selected.Index > 0 then
|
|---|
| 131 | with ImportFormat do
|
|---|
| 132 | ItemPatterns.Exchange(ListViewItemRules.Selected.Index,
|
|---|
| 133 | ListViewItemRules.Selected.Index - 1);
|
|---|
| 134 | ReloadList;
|
|---|
| 135 | end;
|
|---|
| 136 |
|
|---|
| 137 | procedure TFormImportFormat.ARemoveExecute(Sender: TObject);
|
|---|
| 138 | var
|
|---|
| 139 | I: Integer;
|
|---|
| 140 | begin
|
|---|
| 141 | if Assigned(ListViewItemRules.Selected) then begin
|
|---|
| 142 | if MessageDlg(SRemoveImportPattern, SRemoveImportPatternQuery,
|
|---|
| 143 | TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin
|
|---|
| 144 | for I := ListViewItemRules.Items.Count - 1 downto 0 do
|
|---|
| 145 | if ListViewItemRules.Items[I].Selected then
|
|---|
| 146 | ImportFormat.ItemPatterns.Remove(ListViewItemRules.Items[I].Data);
|
|---|
| 147 | ReloadList;
|
|---|
| 148 | end;
|
|---|
| 149 | end;
|
|---|
| 150 | end;
|
|---|
| 151 |
|
|---|
| 152 | procedure TFormImportFormat.FormCreate(Sender: TObject);
|
|---|
| 153 | begin
|
|---|
| 154 | YesNoString[False] := SNo;
|
|---|
| 155 | YesNoString[True] := SYes;
|
|---|
| 156 | end;
|
|---|
| 157 |
|
|---|
| 158 | procedure TFormImportFormat.FormShow(Sender: TObject);
|
|---|
| 159 | begin
|
|---|
| 160 | ReloadList;
|
|---|
| 161 | end;
|
|---|
| 162 |
|
|---|
| 163 | procedure TFormImportFormat.ListViewItemRulesData(Sender: TObject;
|
|---|
| 164 | Item: TListItem);
|
|---|
| 165 | begin
|
|---|
| 166 | if Item.Index < ImportFormat.ItemPatterns.Count then
|
|---|
| 167 | with TImportPattern(ImportFormat.ItemPatterns[Item.Index]) do begin
|
|---|
| 168 | Item.Caption := StartString;
|
|---|
| 169 | Item.SubItems.Add(EndString);
|
|---|
| 170 | Item.SubItems.Add(ImportPatternFlagString[Flag]);
|
|---|
| 171 | Item.SubItems.Add(ImportVariableString[Variable]);
|
|---|
| 172 | Item.SubItems.Add(YesNoString[Repetition]);
|
|---|
| 173 | Item.Data := ImportFormat.ItemPatterns[Item.Index];
|
|---|
| 174 | end;
|
|---|
| 175 | end;
|
|---|
| 176 |
|
|---|
| 177 | procedure TFormImportFormat.Load(ImportFormat: TImportFormat);
|
|---|
| 178 | begin
|
|---|
| 179 | ComboBoxType.ItemIndex := Integer(ImportFormat.Kind);
|
|---|
| 180 | Self.ImportFormat := ImportFormat;
|
|---|
| 181 | EditName.Text := ImportFormat.Name;
|
|---|
| 182 | EditBlockStart.Text := ImportFormat.Block.StartString;
|
|---|
| 183 | EditBlockEnd.Text := ImportFormat.Block.EndString;
|
|---|
| 184 | ReloadList;
|
|---|
| 185 | end;
|
|---|
| 186 |
|
|---|
| 187 | procedure TFormImportFormat.Save(ImportFormat: TImportFormat);
|
|---|
| 188 | begin
|
|---|
| 189 | ImportFormat.Kind := TImportFormatKind(ComboBoxType.ItemIndex);
|
|---|
| 190 | ImportFormat.Name := EditName.Text;
|
|---|
| 191 | ImportFormat.Block.StartString := EditBlockStart.Text;
|
|---|
| 192 | ImportFormat.Block.EndString := EditBlockEnd.Text;
|
|---|
| 193 | end;
|
|---|
| 194 |
|
|---|
| 195 | procedure TFormImportFormat.ReloadList;
|
|---|
| 196 | begin
|
|---|
| 197 | ListViewItemRules.Items.Count := ImportFormat.ItemPatterns.Count;
|
|---|
| 198 | ListViewItemRules.Refresh;
|
|---|
| 199 | end;
|
|---|
| 200 |
|
|---|
| 201 | end.
|
|---|
| 202 |
|
|---|