Ignore:
Timestamp:
Jun 7, 2016, 3:56:46 PM (8 years ago)
Author:
chronos
Message:
  • Modified: Now import format supports multiple more generic rules for parsing source content.
  • Added: Show total and filtered number of acronyms in acronyms list.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormImportFormat.pas

    r25 r27  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   UAcronym;
     9  ComCtrls, Menus, ActnList, UAcronym;
    1010
    1111type
     
    1414
    1515  TFormImportFormat = class(TForm)
     16    AAdd: TAction;
     17    AMoveUp: TAction;
     18    AMoveDown: TAction;
     19    AModify: TAction;
     20    ARemove: TAction;
     21    ActionList1: TActionList;
    1622    ButtonOk: TButton;
    1723    ButtonCancel: TButton;
     
    1925    EditBlockStart: TEdit;
    2026    EditName: TEdit;
    21     EditAcronymStart: TEdit;
    22     EditAcronymEnd: TEdit;
    23     EditMeaningStart: TEdit;
    24     EditMeaningEnd: TEdit;
    25     EditDescriptionStart: TEdit;
    26     EditDescriptionEnd: TEdit;
    2727    Label1: TLabel;
    2828    Label2: TLabel;
    29     Label3: TLabel;
    30     Label4: TLabel;
    31     Label5: TLabel;
    32     Label6: TLabel;
    33     Label7: TLabel;
    3429    Label8: TLabel;
    3530    Label9: TLabel;
     31    ListViewItemRules: TListView;
     32    MenuItem1: TMenuItem;
     33    MenuItem2: TMenuItem;
     34    MenuItem3: TMenuItem;
     35    MenuItem4: TMenuItem;
     36    MenuItem5: TMenuItem;
     37    PopupMenu1: TPopupMenu;
     38    procedure AAddExecute(Sender: TObject);
     39    procedure AModifyExecute(Sender: TObject);
     40    procedure AMoveDownExecute(Sender: TObject);
     41    procedure AMoveUpExecute(Sender: TObject);
     42    procedure ARemoveExecute(Sender: TObject);
     43    procedure FormShow(Sender: TObject);
     44    procedure ListViewItemRulesData(Sender: TObject; Item: TListItem);
    3645  private
    3746    { private declarations }
    3847  public
     48    ImportFormat: TImportFormat;
    3949    procedure Load(ImportFormat: TImportFormat);
    4050    procedure Save(ImportFormat: TImportFormat);
     51    procedure ReloadList;
    4152  end;
    4253
     
    4455  FormImportFormat: TFormImportFormat;
    4556
     57
    4658implementation
     59
     60uses
     61  UFormImportPattern;
    4762
    4863{$R *.lfm}
    4964
     65resourcestring
     66  SRemoveImportPattern = 'Remove import pattern';
     67  SRemoveImportPatternQuery = 'Do you really want to remove selected import patterns?';
     68
     69
    5070{ TFormImportFormat }
     71
     72procedure TFormImportFormat.AAddExecute(Sender: TObject);
     73var
     74  NewImportPattern: TImportPattern;
     75begin
     76  NewImportPattern := TImportPattern.Create;
     77  FormImportPattern.Load(NewImportPattern);
     78  if FormImportPattern.ShowModal = mrOk then begin
     79    FormImportPattern.Save(NewImportPattern);
     80    ImportFormat.ItemPatterns.Add(NewImportPattern);
     81    NewImportPattern := nil;
     82    ReloadList;
     83  end;
     84  if Assigned(NewImportPattern) then NewImportPattern.Free;
     85end;
     86
     87procedure TFormImportFormat.AModifyExecute(Sender: TObject);
     88var
     89  NewImportPattern: TImportPattern;
     90begin
     91  if Assigned(ListViewItemRules.Selected) then begin
     92    NewImportPattern := TImportPattern.Create;
     93    NewImportPattern.Assign(ListViewItemRules.Selected.Data);
     94    FormImportPattern.Load(NewImportPattern);
     95    if FormImportPattern.ShowModal = mrOk then begin
     96      FormImportPattern.Save(NewImportPattern);
     97      TImportPattern(ListViewItemRules.Selected.Data).Assign(NewImportPattern);
     98      ReloadList;
     99    end;
     100    if Assigned(NewImportPattern) then NewImportPattern.Free;
     101  end;
     102end;
     103
     104procedure TFormImportFormat.AMoveDownExecute(Sender: TObject);
     105begin
     106  if ListViewItemRules.Selected.Index < (ImportFormat.ItemPatterns.Count - 1) then
     107  with ImportFormat do
     108    ItemPatterns.Exchange(ListViewItemRules.Selected.Index,
     109      ListViewItemRules.Selected.Index + 1);
     110  ReloadList;
     111end;
     112
     113procedure TFormImportFormat.AMoveUpExecute(Sender: TObject);
     114begin
     115  if ListViewItemRules.Selected.Index > 0 then
     116  with ImportFormat do
     117    ItemPatterns.Exchange(ListViewItemRules.Selected.Index,
     118      ListViewItemRules.Selected.Index - 1);
     119  ReloadList;
     120end;
     121
     122procedure TFormImportFormat.ARemoveExecute(Sender: TObject);
     123var
     124  I: Integer;
     125begin
     126  if Assigned(ListViewItemRules.Selected) then begin
     127    if MessageDlg(SRemoveImportPattern, SRemoveImportPatternQuery,
     128    TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin
     129      for I := ListViewItemRules.Items.Count - 1 downto 0 do
     130      if ListViewItemRules.Items[I].Selected then
     131        ImportFormat.ItemPatterns.Remove(ListViewItemRules.Items[I].Data);
     132      ReloadList;
     133    end;
     134  end;
     135end;
     136
     137procedure TFormImportFormat.FormShow(Sender: TObject);
     138begin
     139  ReloadList;
     140end;
     141
     142procedure TFormImportFormat.ListViewItemRulesData(Sender: TObject;
     143  Item: TListItem);
     144begin
     145  if Item.Index < ImportFormat.ItemPatterns.Count then
     146  with TImportPattern(ImportFormat.ItemPatterns[Item.Index]) do begin
     147    Item.Caption := StartString;
     148    Item.SubItems.Add(EndString);
     149    Item.SubItems.Add(ImportPatternFlagString[Flag]);
     150    Item.SubItems.Add(ImportVariableString[Variable]);
     151    Item.Data := ImportFormat.ItemPatterns[Item.Index];
     152  end;
     153end;
    51154
    52155procedure TFormImportFormat.Load(ImportFormat: TImportFormat);
    53156begin
     157  Self.ImportFormat := ImportFormat;
    54158  EditName.Text := ImportFormat.Name;
    55159  EditBlockStart.Text := ImportFormat.Block.StartString;
    56160  EditBlockEnd.Text := ImportFormat.Block.EndString;
    57   EditAcronymStart.Text := ImportFormat.Acronym.StartString;
    58   EditAcronymEnd.Text := ImportFormat.Acronym.EndString;
    59   EditMeaningStart.Text := ImportFormat.Meaning.StartString;
    60   EditMeaningEnd.Text := ImportFormat.Meaning.EndString;
    61   EditDescriptionStart.Text := ImportFormat.Description.StartString;
    62   EditDescriptionEnd.Text := ImportFormat.Description.EndString;
     161  ReloadList;
    63162end;
    64163
     
    68167  ImportFormat.Block.StartString := EditBlockStart.Text;
    69168  ImportFormat.Block.EndString := EditBlockEnd.Text;
    70   ImportFormat.Acronym.StartString := EditAcronymStart.Text;
    71   ImportFormat.Acronym.EndString := EditAcronymEnd.Text;
    72   ImportFormat.Meaning.StartString := EditMeaningStart.Text;
    73   ImportFormat.Meaning.EndString := EditMeaningEnd.Text;
    74   ImportFormat.Description.StartString := EditDescriptionStart.Text;
    75   ImportFormat.Description.EndString := EditDescriptionEnd.Text;
     169end;
     170
     171procedure TFormImportFormat.ReloadList;
     172begin
     173  ListViewItemRules.Items.Count := ImportFormat.ItemPatterns.Count;
     174  ListViewItemRules.Refresh;
    76175end;
    77176
Note: See TracChangeset for help on using the changeset viewer.