Changeset 27


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.
Location:
trunk
Files:
3 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/AcronymDecoder.lpi

    r25 r27  
    8888      </Item4>
    8989    </RequiredPackages>
    90     <Units Count="14">
     90    <Units Count="15">
    9191      <Unit0>
    9292        <Filename Value="AcronymDecoder.lpr"/>
     
    177177        <ResourceBaseClass Value="Form"/>
    178178      </Unit13>
     179      <Unit14>
     180        <Filename Value="Forms\UFormImportPattern.pas"/>
     181        <IsPartOfProject Value="True"/>
     182        <ComponentName Value="FormImportPattern"/>
     183        <ResourceBaseClass Value="Form"/>
     184      </Unit14>
    179185    </Units>
    180186  </ProjectOptions>
  • trunk/AcronymDecoder.lpr

    r22 r27  
    1111  CoolTranslator, UFormCategorySelect, UFormMain, UFormAcronym, UFormSettings,
    1212  UFormCategories, UFormAcronyms, UFormImportSource, UFormImportSources,
    13   UFormAbout, UFormImportFormat, UFormImportFormats
     13  UFormAbout, UFormImportFormat, UFormImportFormats, UFormImportPattern
    1414  { you can add units after this };
    1515
     
    4444  Application.CreateForm(TFormImportFormat, FormImportFormat);
    4545  Application.CreateForm(TFormImportFormats, FormImportFormats);
     46  Application.CreateForm(TFormImportPattern, FormImportPattern);
    4647  Application.Run;
    4748end.
  • trunk/Forms/UFormAcronyms.lfm

    r22 r27  
    1111  object ListViewAcronyms: TListView
    1212    Left = 8
    13     Height = 510
     13    Height = 480
    1414    Top = 40
    1515    Width = 725
     
    4747    OnChange = ListViewFilter1Change
    4848    Anchors = [akTop, akLeft, akRight]
     49  end
     50  object StatusBar1: TStatusBar
     51    Left = 0
     52    Height = 28
     53    Top = 530
     54    Width = 740
     55    Panels = <   
     56      item
     57        Width = 100
     58      end   
     59      item
     60        Width = 100
     61      end>
     62    SimplePanel = False
    4963  end
    5064  object ListViewSort1: TListViewSort
  • trunk/Forms/UFormAcronyms.pas

    r22 r27  
    2727    MenuItem7: TMenuItem;
    2828    PopupMenuAcronym: TPopupMenu;
     29    StatusBar1: TStatusBar;
    2930    procedure AAddExecute(Sender: TObject);
    3031    procedure AModifyExecute(Sender: TObject);
     
    4142    procedure ListViewSort1Filter(ListViewSort: TListViewSort);
    4243  private
     44    MeaningCount: Integer;
    4345    procedure FilterList(List: TListObject);
    4446    procedure UpdateAcronymsList;
     
    211213  FormMain.AcronymDb.Acronyms.Sort(AcronymComparer);
    212214  FormMain.AcronymDb.AssignToList(ListViewSort1.List);
     215  MeaningCount := ListViewSort1.List.Count;
    213216  FilterList(ListViewSort1.List);
    214217end;
     
    247250  ListViewSort1.Refresh;
    248251  UpdateInterface;
     252  StatusBar1.Panels[0].Text := 'Total: ' + IntToStr(MeaningCount);
     253  StatusBar1.Panels[1].Text := 'Filtered: ' + IntToStr(ListViewAcronyms.Items.Count);
    249254end;
    250255
  • trunk/Forms/UFormImportFormat.lfm

    r25 r27  
    77  ClientHeight = 433
    88  ClientWidth = 664
    9   LCLVersion = '1.7'
     9  OnShow = FormShow
     10  LCLVersion = '1.6.0.4'
    1011  object ButtonOk: TButton
    1112    Left = 560
     
    1314    Top = 384
    1415    Width = 75
     16    Anchors = [akRight, akBottom]
    1517    Caption = 'Ok'
    1618    ModalResult = 1
     
    2224    Top = 384
    2325    Width = 75
     26    Anchors = [akRight, akBottom]
    2427    Caption = 'Cancel'
    2528    ModalResult = 2
     
    2831  object Label1: TLabel
    2932    Left = 20
    30     Height = 22
     33    Height = 20
    3134    Top = 16
    32     Width = 49
     35    Width = 43
    3336    Caption = 'Name:'
    3437    ParentColor = False
     
    3639  object EditName: TEdit
    3740    Left = 179
    38     Height = 32
     41    Height = 28
    3942    Top = 11
    4043    Width = 461
     
    4245    TabOrder = 2
    4346  end
    44   object Label2: TLabel
     47  object Label8: TLabel
    4548    Left = 20
    46     Height = 22
    47     Top = 133
    48     Width = 112
    49     Caption = 'Acronym start:'
    50     ParentColor = False
    51   end
    52   object EditAcronymStart: TEdit
    53     Left = 179
    54     Height = 32
    55     Top = 128
    56     Width = 461
    57     Anchors = [akTop, akLeft, akRight]
    58     TabOrder = 3
    59   end
    60   object Label3: TLabel
    61     Left = 20
    62     Height = 22
    63     Top = 173
    64     Width = 105
    65     Caption = 'Acronym end:'
    66     ParentColor = False
    67   end
    68   object EditAcronymEnd: TEdit
    69     Left = 179
    70     Height = 32
    71     Top = 168
    72     Width = 461
    73     Anchors = [akTop, akLeft, akRight]
    74     TabOrder = 4
    75   end
    76   object Label4: TLabel
    77     Left = 20
    78     Height = 22
    79     Top = 213
    80     Width = 111
    81     Caption = 'Meaning start:'
    82     ParentColor = False
    83   end
    84   object EditMeaningStart: TEdit
    85     Left = 179
    86     Height = 32
    87     Top = 208
    88     Width = 461
    89     Anchors = [akTop, akLeft, akRight]
    90     TabOrder = 5
    91   end
    92   object Label5: TLabel
    93     Left = 20
    94     Height = 22
    95     Top = 253
    96     Width = 104
    97     Caption = 'Meaning end:'
    98     ParentColor = False
    99   end
    100   object EditMeaningEnd: TEdit
    101     Left = 179
    102     Height = 32
    103     Top = 248
    104     Width = 461
    105     Anchors = [akTop, akLeft, akRight]
    106     TabOrder = 6
    107   end
    108   object Label6: TLabel
    109     Left = 20
    110     Height = 22
    111     Top = 293
    112     Width = 132
    113     Caption = 'Description start:'
    114     ParentColor = False
    115   end
    116   object EditDescriptionStart: TEdit
    117     Left = 179
    118     Height = 32
    119     Top = 288
    120     Width = 461
    121     Anchors = [akTop, akLeft, akRight]
    122     TabOrder = 7
    123   end
    124   object Label7: TLabel
    125     Left = 20
    126     Height = 22
    127     Top = 333
    128     Width = 125
    129     Caption = 'Description end:'
    130     ParentColor = False
    131   end
    132   object EditDescriptionEnd: TEdit
    133     Left = 179
    134     Height = 32
    135     Top = 328
    136     Width = 461
    137     Anchors = [akTop, akLeft, akRight]
    138     TabOrder = 8
    139   end
    140   object Label8: TLabel
    141     Left = 24
    142     Height = 22
     49    Height = 20
    14350    Top = 53
    144     Width = 85
     51    Width = 72
    14552    Caption = 'Block start:'
    14653    ParentColor = False
     
    14855  object EditBlockStart: TEdit
    14956    Left = 179
    150     Height = 32
     57    Height = 28
    15158    Top = 48
    15259    Width = 461
    15360    Anchors = [akTop, akLeft, akRight]
    154     TabOrder = 9
     61    TabOrder = 3
    15562  end
    15663  object Label9: TLabel
    157     Left = 24
    158     Height = 22
     64    Left = 20
     65    Height = 20
    15966    Top = 93
    160     Width = 78
     67    Width = 68
    16168    Caption = 'Block end:'
    16269    ParentColor = False
     
    16471  object EditBlockEnd: TEdit
    16572    Left = 179
    166     Height = 32
     73    Height = 28
    16774    Top = 88
    16875    Width = 461
    16976    Anchors = [akTop, akLeft, akRight]
    170     TabOrder = 10
     77    TabOrder = 4
     78  end
     79  object ListViewItemRules: TListView
     80    Left = 20
     81    Height = 230
     82    Top = 144
     83    Width = 620
     84    Anchors = [akTop, akLeft, akRight, akBottom]
     85    Columns = <   
     86      item
     87        Caption = 'Start string'
     88        Width = 100
     89      end   
     90      item
     91        Caption = 'End string'
     92        Width = 100
     93      end   
     94      item
     95        Caption = 'Action'
     96        Width = 100
     97      end   
     98      item
     99        Caption = 'Variable'
     100        Width = 100
     101      end>
     102    OwnerData = True
     103    PopupMenu = PopupMenu1
     104    ReadOnly = True
     105    RowSelect = True
     106    TabOrder = 5
     107    ViewStyle = vsReport
     108    OnData = ListViewItemRulesData
     109    OnDblClick = AModifyExecute
     110  end
     111  object Label2: TLabel
     112    Left = 20
     113    Height = 20
     114    Top = 120
     115    Width = 68
     116    Caption = 'Item rules:'
     117    ParentColor = False
     118  end
     119  object PopupMenu1: TPopupMenu
     120    Images = FormMain.ImageList1
     121    left = 181
     122    top = 240
     123    object MenuItem1: TMenuItem
     124      Action = AAdd
     125    end
     126    object MenuItem2: TMenuItem
     127      Action = AModify
     128    end
     129    object MenuItem3: TMenuItem
     130      Action = ARemove
     131    end
     132    object MenuItem4: TMenuItem
     133      Action = AMoveUp
     134    end
     135    object MenuItem5: TMenuItem
     136      Action = AMoveDown
     137    end
     138  end
     139  object ActionList1: TActionList
     140    Images = FormMain.ImageList1
     141    left = 383
     142    top = 245
     143    object AAdd: TAction
     144      Caption = 'Add'
     145      OnExecute = AAddExecute
     146      ShortCut = 45
     147    end
     148    object AModify: TAction
     149      Caption = 'Modify'
     150      OnExecute = AModifyExecute
     151      ShortCut = 13
     152    end
     153    object ARemove: TAction
     154      Caption = 'Remove'
     155      OnExecute = ARemoveExecute
     156      ShortCut = 46
     157    end
     158    object AMoveUp: TAction
     159      Caption = 'Move up'
     160      OnExecute = AMoveUpExecute
     161    end
     162    object AMoveDown: TAction
     163      Caption = 'Move down'
     164      OnExecute = AMoveDownExecute
     165    end
    171166  end
    172167end
  • trunk/Forms/UFormImportFormat.lrt

    r25 r27  
    33TFORMIMPORTFORMAT.BUTTONCANCEL.CAPTION=Cancel
    44TFORMIMPORTFORMAT.LABEL1.CAPTION=Name:
    5 TFORMIMPORTFORMAT.LABEL2.CAPTION=Acronym start:
    6 TFORMIMPORTFORMAT.LABEL3.CAPTION=Acronym end:
    7 TFORMIMPORTFORMAT.LABEL4.CAPTION=Meaning start:
    8 TFORMIMPORTFORMAT.LABEL5.CAPTION=Meaning end:
    9 TFORMIMPORTFORMAT.LABEL6.CAPTION=Description start:
    10 TFORMIMPORTFORMAT.LABEL7.CAPTION=Description end:
    115TFORMIMPORTFORMAT.LABEL8.CAPTION=Block start:
    126TFORMIMPORTFORMAT.LABEL9.CAPTION=Block end:
     7TFORMIMPORTFORMAT.LISTVIEWITEMRULES.COLUMNS[0].CAPTION=Start string
     8TFORMIMPORTFORMAT.LISTVIEWITEMRULES.COLUMNS[1].CAPTION=End string
     9TFORMIMPORTFORMAT.LISTVIEWITEMRULES.COLUMNS[2].CAPTION=Action
     10TFORMIMPORTFORMAT.LISTVIEWITEMRULES.COLUMNS[3].CAPTION=Variable
     11TFORMIMPORTFORMAT.LABEL2.CAPTION=Item rules:
     12TFORMIMPORTFORMAT.AADD.CAPTION=Add
     13TFORMIMPORTFORMAT.AMODIFY.CAPTION=Modify
     14TFORMIMPORTFORMAT.AREMOVE.CAPTION=Remove
     15TFORMIMPORTFORMAT.AMOVEUP.CAPTION=Move up
     16TFORMIMPORTFORMAT.AMOVEDOWN.CAPTION=Move down
  • 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
  • trunk/Forms/UFormMain.lfm

    r22 r27  
    55  Width = 631
    66  Caption = 'Acronym Decoder'
    7   ClientHeight = 414
     7  ClientHeight = 421
    88  ClientWidth = 631
    99  Menu = MainMenu1
     
    1616  object ListViewAcronyms: TListView
    1717    Left = 8
    18     Height = 333
     18    Height = 340
    1919    Top = 64
    2020    Width = 613
     
    5151  object CheckBoxExactMath: TCheckBox
    5252    Left = 8
    53     Height = 28
     53    Height = 24
    5454    Top = 3
    55     Width = 129
     55    Width = 104
    5656    Caption = 'Exact match'
    5757    OnChange = CheckBoxExactMathChange
  • trunk/Forms/UFormMain.pas

    r26 r27  
    274274begin
    275275  FormAcronyms.ShowModal;
     276  UpdateInterface;
    276277end;
    277278
  • trunk/Languages/AcronymDecoder.cs.po

    r25 r27  
    186186msgstr "Formát dat:"
    187187
     188#: tformimportformat.aadd.caption
     189#, fuzzy
     190msgctxt "tformimportformat.aadd.caption"
     191msgid "Add"
     192msgstr "Přidat"
     193
     194#: tformimportformat.amodify.caption
     195#, fuzzy
     196msgctxt "tformimportformat.amodify.caption"
     197msgid "Modify"
     198msgstr "Upravit"
     199
     200#: tformimportformat.amovedown.caption
     201msgid "Move down"
     202msgstr ""
     203
     204#: tformimportformat.amoveup.caption
     205msgid "Move up"
     206msgstr ""
     207
     208#: tformimportformat.aremove.caption
     209#, fuzzy
     210msgctxt "tformimportformat.aremove.caption"
     211msgid "Remove"
     212msgstr "Odebrat"
     213
    188214#: tformimportformat.buttoncancel.caption
    189215msgctxt "tformimportformat.buttoncancel.caption"
     
    206232
    207233#: tformimportformat.label2.caption
    208 msgid "Acronym start:"
     234#, fuzzy
     235#| msgid "Acronym start:"
     236msgid "Item rules:"
    209237msgstr "Začátek zkratky:"
    210 
    211 #: tformimportformat.label3.caption
    212 msgid "Acronym end:"
    213 msgstr "Konec zkratky:"
    214 
    215 #: tformimportformat.label4.caption
    216 msgid "Meaning start:"
    217 msgstr "Začátek významu:"
    218 
    219 #: tformimportformat.label5.caption
    220 msgid "Meaning end:"
    221 msgstr "Konec významu:"
    222 
    223 #: tformimportformat.label6.caption
    224 msgid "Description start:"
    225 msgstr "Začátek popisu:"
    226 
    227 #: tformimportformat.label7.caption
    228 msgid "Description end:"
    229 msgstr "Konec popisu:"
    230238
    231239#: tformimportformat.label8.caption
     
    236244msgid "Block end:"
    237245msgstr "Konec bloku:"
     246
     247#: tformimportformat.listviewitemrules.columns[0].caption
     248msgid "Start string"
     249msgstr ""
     250
     251#: tformimportformat.listviewitemrules.columns[1].caption
     252msgid "End string"
     253msgstr ""
     254
     255#: tformimportformat.listviewitemrules.columns[2].caption
     256msgid "Action"
     257msgstr ""
     258
     259#: tformimportformat.listviewitemrules.columns[3].caption
     260msgid "Variable"
     261msgstr ""
    238262
    239263#: tformimportformats.aadd.caption
     
    262286msgstr "Název"
    263287
     288#: tformimportpattern.buttoncancel.caption
     289#, fuzzy
     290msgctxt "tformimportpattern.buttoncancel.caption"
     291msgid "Cancel"
     292msgstr "Zrušit"
     293
     294#: tformimportpattern.buttonok.caption
     295#, fuzzy
     296msgctxt "tformimportpattern.buttonok.caption"
     297msgid "Ok"
     298msgstr "Ok"
     299
     300#: tformimportpattern.caption
     301msgid "Import pattern"
     302msgstr ""
     303
     304#: tformimportpattern.label10.caption
     305msgid "Action:"
     306msgstr ""
     307
     308#: tformimportpattern.label11.caption
     309msgid "Variable:"
     310msgstr ""
     311
     312#: tformimportpattern.label8.caption
     313msgid "Start string:"
     314msgstr ""
     315
     316#: tformimportpattern.label9.caption
     317msgid "End string:"
     318msgstr ""
     319
    264320#: tformimportsource.buttoncancel.caption
    265321msgctxt "tformimportsource.buttoncancel.caption"
     
    531587msgstr "Importováno %d nových zkratek."
    532588
     589#: uformimportformat.sremoveimportpattern
     590msgid "Remove import pattern"
     591msgstr ""
     592
     593#: uformimportformat.sremoveimportpatternquery
     594msgid "Do you really want to remove selected import patterns?"
     595msgstr ""
     596
    533597#: uformimportformats.simportformatalreadyexists
    534598msgid "Import format %s already exists!"
     
    569633msgid "modified"
    570634msgstr "upraveno"
     635
  • trunk/Languages/AcronymDecoder.po

    r25 r27  
    176176msgstr ""
    177177
     178#: tformimportformat.aadd.caption
     179msgctxt "TFORMIMPORTFORMAT.AADD.CAPTION"
     180msgid "Add"
     181msgstr ""
     182
     183#: tformimportformat.amodify.caption
     184msgctxt "TFORMIMPORTFORMAT.AMODIFY.CAPTION"
     185msgid "Modify"
     186msgstr ""
     187
     188#: tformimportformat.amovedown.caption
     189msgid "Move down"
     190msgstr ""
     191
     192#: tformimportformat.amoveup.caption
     193msgid "Move up"
     194msgstr ""
     195
     196#: tformimportformat.aremove.caption
     197msgctxt "TFORMIMPORTFORMAT.AREMOVE.CAPTION"
     198msgid "Remove"
     199msgstr ""
     200
    178201#: tformimportformat.buttoncancel.caption
    179202msgctxt "TFORMIMPORTFORMAT.BUTTONCANCEL.CAPTION"
     
    196219
    197220#: tformimportformat.label2.caption
    198 msgid "Acronym start:"
    199 msgstr ""
    200 
    201 #: tformimportformat.label3.caption
    202 msgid "Acronym end:"
    203 msgstr ""
    204 
    205 #: tformimportformat.label4.caption
    206 msgid "Meaning start:"
    207 msgstr ""
    208 
    209 #: tformimportformat.label5.caption
    210 msgid "Meaning end:"
    211 msgstr ""
    212 
    213 #: tformimportformat.label6.caption
    214 msgid "Description start:"
    215 msgstr ""
    216 
    217 #: tformimportformat.label7.caption
    218 msgid "Description end:"
     221msgid "Item rules:"
    219222msgstr ""
    220223
     
    225228#: tformimportformat.label9.caption
    226229msgid "Block end:"
     230msgstr ""
     231
     232#: tformimportformat.listviewitemrules.columns[0].caption
     233msgid "Start string"
     234msgstr ""
     235
     236#: tformimportformat.listviewitemrules.columns[1].caption
     237msgid "End string"
     238msgstr ""
     239
     240#: tformimportformat.listviewitemrules.columns[2].caption
     241msgid "Action"
     242msgstr ""
     243
     244#: tformimportformat.listviewitemrules.columns[3].caption
     245msgid "Variable"
    227246msgstr ""
    228247
     
    252271msgstr ""
    253272
     273#: tformimportpattern.buttoncancel.caption
     274msgctxt "TFORMIMPORTPATTERN.BUTTONCANCEL.CAPTION"
     275msgid "Cancel"
     276msgstr ""
     277
     278#: tformimportpattern.buttonok.caption
     279msgctxt "TFORMIMPORTPATTERN.BUTTONOK.CAPTION"
     280msgid "Ok"
     281msgstr ""
     282
     283#: tformimportpattern.caption
     284msgid "Import pattern"
     285msgstr ""
     286
     287#: tformimportpattern.label10.caption
     288msgid "Action:"
     289msgstr ""
     290
     291#: tformimportpattern.label11.caption
     292msgid "Variable:"
     293msgstr ""
     294
     295#: tformimportpattern.label8.caption
     296msgid "Start string:"
     297msgstr ""
     298
     299#: tformimportpattern.label9.caption
     300msgid "End string:"
     301msgstr ""
     302
    254303#: tformimportsource.buttoncancel.caption
    255304msgctxt "TFORMIMPORTSOURCE.BUTTONCANCEL.CAPTION"
     
    521570msgstr ""
    522571
     572#: uformimportformat.sremoveimportpattern
     573msgid "Remove import pattern"
     574msgstr ""
     575
     576#: uformimportformat.sremoveimportpatternquery
     577msgid "Do you really want to remove selected import patterns?"
     578msgstr ""
     579
    523580#: uformimportformats.simportformatalreadyexists
    524581msgid "Import format %s already exists!"
  • trunk/UAcronym.pas

    r25 r27  
    109109  end;
    110110
    111   TImportPattern = record
     111  TImportPatternFlag = (ipfNone, ipfNewItem, ipfSkip);
     112  TImportVariable = (ivNone, ivAcronym, ivMeaning, ivDescription);
     113
     114  { TImportPattern }
     115
     116  TImportPattern = class
    112117    StartString: string;
    113118    EndString: string;
    114     NewItem: Boolean;
     119    Variable: TImportVariable;
     120    Flag: TImportPatternFlag;
     121    procedure Assign(Source: TImportPattern);
     122    procedure SaveToNode(Node: TDOMNode);
     123    procedure LoadFromNode(Node: TDOMNode);
     124  end;
     125
     126  { TImportPatterns }
     127
     128  TImportPatterns = class(TObjectList)
     129    procedure SaveToNode(Node: TDOMNode);
     130    procedure LoadFromNode(Node: TDOMNode);
    115131  end;
    116132
     
    121137    Name: string;
    122138    Block: TImportPattern;
    123     Acronym: TImportPattern;
    124     Meaning: TImportPattern;
    125     Description: TImportPattern;
     139    ItemPatterns: TImportPatterns;
    126140    Formats: TImportFormats;
    127141    procedure Assign(Source: TImportFormat);
    128142    procedure SaveToNode(Node: TDOMNode);
    129143    procedure LoadFromNode(Node: TDOMNode);
     144    constructor Create;
     145    destructor Destroy; override;
    130146  end;
    131147
     
    143159
    144160  TImportSource = class
     161  private
     162    procedure DoPassword(Sender: TObject; var RepeatRequest : Boolean);
     163  public
    145164    Name: string;
    146165    URL: string;
     
    148167    LastTime: TDateTime;
    149168    Sources: TImportSources;
     169    function DownloadHTTP(URL: string; Stream: TStream): Boolean;
    150170    procedure Process;
    151171    procedure Assign(Source: TImportSource);
     
    189209function AcronymComparer(Item1, Item2: Pointer): Integer;
    190210
     211const
     212  ImportVariableString: array [TImportVariable] of string = ('None', 'Acronym',
     213    'Meaning', 'Description');
     214  ImportPatternFlagString: array [TImportPatternFlag] of string = ('None', 'New item',
     215    'Skip');
     216
    191217
    192218implementation
     
    195221  SWrongFileFormat = 'Wrong file format';
    196222
     223
    197224function AcronymComparer(Item1, Item2: Pointer): Integer;
    198225begin
     
    200227end;
    201228
    202 function DownloadHTTP(URL: string; Stream: TStream): Boolean;
     229{ TImportPatterns }
     230
     231procedure TImportPatterns.SaveToNode(Node: TDOMNode);
     232var
     233  I: Integer;
     234  NewNode2: TDOMNode;
     235begin
     236  for I := 0 to Count - 1 do
     237  with TImportPattern(Items[I]) do begin
     238    NewNode2 := Node.OwnerDocument.CreateElement('Pattern');
     239    Node.AppendChild(NewNode2);
     240    SaveToNode(NewNode2);
     241  end;
     242end;
     243
     244procedure TImportPatterns.LoadFromNode(Node: TDOMNode);
     245var
     246  Node2: TDOMNode;
     247  NewItem: TImportPattern;
     248begin
     249  Count := 0;
     250  Node2 := Node.FirstChild;
     251  while Assigned(Node2) and (Node2.NodeName = 'Pattern') do begin
     252    NewItem := TImportPattern.Create;
     253    NewItem.LoadFromNode(Node2);
     254    Add(NewItem);
     255    Node2 := Node2.NextSibling;
     256  end;
     257end;
     258
     259{ TImportPattern }
     260
     261procedure TImportPattern.Assign(Source: TImportPattern);
     262begin
     263  StartString := Source.StartString;
     264  EndString := Source.EndString;
     265  Variable := Source.Variable;
     266  Flag := Source.Flag;
     267end;
     268
     269procedure TImportPattern.SaveToNode(Node: TDOMNode);
     270begin
     271  WriteString(Node, 'StartString', StartString);
     272  WriteString(Node, 'EndString', EndString);
     273  WriteInteger(Node, 'Variable', Integer(Variable));
     274  WriteInteger(Node, 'Flag', Integer(Flag));
     275end;
     276
     277procedure TImportPattern.LoadFromNode(Node: TDOMNode);
     278begin
     279  StartString := ReadString(Node, 'StartString', '');
     280  EndString := ReadString(Node, 'EndString', '');
     281  Variable := TImportVariable(ReadInteger(Node, 'Variable', 0));
     282  Flag := TImportPatternFlag(ReadInteger(Node, 'Flag', 0));
     283end;
     284
     285procedure TImportSource.DoPassword(Sender: TObject; var RepeatRequest: Boolean);
     286begin
     287  if TFPHttpClient(Sender).Password = '' then begin
     288    TFPHttpClient(Sender).UserName := 'test';
     289    TFPHttpClient(Sender).Password := 'test';
     290    RepeatRequest := True;
     291  end else RepeatRequest := False;
     292end;
     293
     294function TImportSource.DownloadHTTP(URL: string; Stream: TStream): Boolean;
    203295var
    204296  HTTPClient: TFPHTTPClient;
    205297begin
    206298  HTTPClient := TFPHttpClient.Create(nil);
     299  HTTPClient.OnPassword := DoPassword;
    207300  HTTPClient.Get(URL, Stream);
    208301  HTTPClient.Free;
     
    232325
    233326procedure TImportFormat.Assign(Source: TImportFormat);
     327var
     328  I: Integer;
    234329begin
    235330  Name := Source.Name;
    236331  Block.StartString := Source.Block.StartString;
    237332  Block.EndString := Source.Block.EndString;
    238   Acronym.StartString := Source.Acronym.StartString;
    239   Acronym.EndString := Source.Acronym.EndString;
    240   Meaning.StartString := Source.Meaning.StartString;
    241   Meaning.EndString := Source.Meaning.EndString;
    242   Description.StartString := Source.Description.StartString;
    243   Description.EndString := Source.Description.EndString;
     333  while ItemPatterns.Count < Source.ItemPatterns.Count do
     334    ItemPatterns.Add(TImportPattern.Create);
     335  if ItemPatterns.Count > Source.ItemPatterns.Count then
     336    ItemPatterns.Count := Source.ItemPatterns.Count;
     337  for I := 0 to ItemPatterns.Count - 1 do begin
     338    TImportPattern(ItemPatterns[I]).Assign(TImportPattern(Source.ItemPatterns[I]));
     339  end;
    244340end;
    245341
    246342procedure TImportFormat.SaveToNode(Node: TDOMNode);
     343var
     344  NewNode: TDOMNode;
    247345begin
    248346  WriteInteger(Node, 'Id', Id);
     
    250348  WriteString(Node, 'BlockStartString', Block.StartString);
    251349  WriteString(Node, 'BlockEndString', Block.EndString);
    252   WriteString(Node, 'AcronymStartString', Acronym.StartString);
    253   WriteString(Node, 'AcronymEndString', Acronym.EndString);
    254   WriteString(Node, 'MeaningStartString', Meaning.StartString);
    255   WriteString(Node, 'MeaningEndString', Meaning.EndString);
    256   WriteString(Node, 'DescriptionStartString', Description.StartString);
    257   WriteString(Node, 'DescriptionEndString', Description.EndString);
     350
     351  NewNode := Node.OwnerDocument.CreateElement('Patterns');
     352  Node.AppendChild(NewNode);
     353  ItemPatterns.SaveToNode(NewNode);
    258354end;
    259355
    260356procedure TImportFormat.LoadFromNode(Node: TDOMNode);
     357var
     358  NewNode: TDOMNode;
    261359begin
    262360  Id := ReadInteger(Node, 'Id', 0);
     
    264362  Block.StartString := ReadString(Node, 'BlockStartString', '');
    265363  Block.EndString := ReadString(Node, 'BlockEndString', '');
    266   Acronym.StartString := ReadString(Node, 'AcronymStartString', '');
    267   Acronym.EndString := ReadString(Node, 'AcronymEndString', '');
    268   Meaning.StartString := ReadString(Node, 'MeaningStartString', '');
    269   Meaning.EndString := ReadString(Node, 'MeaningEndString', '');
    270   Description.StartString := ReadString(Node, 'DescriptionStartString', '');
    271   Description.EndString := ReadString(Node, 'DescriptionEndString', '');
     364
     365  NewNode := Node.FindNode('Patterns');
     366  if Assigned(NewNode) then
     367    ItemPatterns.LoadFromNode(NewNode);
     368end;
     369
     370constructor TImportFormat.Create;
     371begin
     372  Block := TImportPattern.Create;
     373  ItemPatterns := TImportPatterns.Create;
     374end;
     375
     376destructor TImportFormat.Destroy;
     377begin
     378  Block.Free;
     379  ItemPatterns.Free;
     380  inherited Destroy;
    272381end;
    273382
     
    390499  Stream: TMemoryStream;
    391500  S: string;
     501  SS: string;
    392502  NewAcronym: TAcronymEntry;
    393503  P: Integer;
    394   NewName: string;
     504  Q: Integer;
     505  I: Integer;
     506  T: string;
     507  LastLength: Integer;
    395508begin
    396509  Stream := TMemoryStream.Create;
     
    401514      SetLength(S, Stream.Size);
    402515      Stream.Read(S[1], Length(S));
     516
     517      // Find main block
    403518      if Format.Block.StartString <> '' then begin
    404519        P := Pos(Format.Block.StartString, S);
     
    412527      end;
    413528
     529      // Remove unneeded items
    414530      repeat
    415         P := Pos(Format.Acronym.StartString, S);
    416         if P > 0 then begin
    417           // Acronym
    418           Delete(S, 1, P + Length(Format.Acronym.StartString) - 1);
    419           P := Pos(Format.Acronym.EndString, S);
    420           NewName := Trim(StripHTML(Copy(S, 1, P - 1)));
    421           if NewName <> '' then NewAcronym.Name := NewName;
    422           Delete(S, 1, P + Length(Format.Acronym.EndString) - 1);
    423 
    424           // Meaning
    425           if Length(Format.Meaning.StartString) > 0 then begin
    426             P := Pos(Format.Meaning.StartString, S);
    427             Delete(S, 1, P + Length(Format.Meaning.StartString) - 1);
     531        LastLength := Length(S);
     532        for I := 0 to Format.ItemPatterns.Count - 1 do
     533        with TImportPattern(Format.ItemPatterns[I]) do
     534        if Flag = ipfSkip then begin
     535          P := Pos(StartString, S);
     536          if P > 0 then begin
     537            SS := Copy(S, P + Length(StartString), Length(S));
     538            Q := Pos(EndString, SS);
     539            if Q > 0 then begin
     540              Delete(S, P, Q + Length(EndString) + Length(StartString) - 1);
     541            end;
    428542          end;
    429           P := Pos(Format.Meaning.EndString, S);
    430           NewAcronym.Meaning := Trim(StripHTML(Copy(S, 1, P - 1)));
    431           Delete(S, 1, P + Length(Format.Meaning.EndString) - 1);
    432           Sources.AcronymDb.AddAcronym(NewAcronym.Name, NewAcronym.Meaning);
    433         end else Break;
    434       until False;
     543        end;
     544      until Length(S) = LastLength;
     545
     546      // Find items
     547      repeat
     548        LastLength := Length(S);
     549        for I := 0 to Format.ItemPatterns.Count - 1 do
     550        with TImportPattern(Format.ItemPatterns[I]) do
     551        if Flag <> ipfSkip then begin
     552          if Length(StartString) > 0 then begin
     553            P := Pos(StartString, S);
     554            if P > 0 then Delete(S, 1, P + Length(StartString) - 1);
     555          end;
     556
     557          if ((Length(StartString) > 0) and (P > 0)) or (Length(StartString) = 0) then begin
     558            P := Pos(EndString, S);
     559            T := StripHTML(Copy(S, 1, P - 1));
     560            T := StringReplace(T, '&quot;', '"', [rfReplaceAll]);
     561            T := StringReplace(T, '&trade;', 'TM', [rfReplaceAll]);
     562            T := StringReplace(T, '&amp;', '&', [rfReplaceAll]);
     563            T := Trim(T);
     564            case Variable of
     565              ivAcronym: NewAcronym.Name := T;
     566              ivMeaning: NewAcronym.Meaning := T;
     567            end;
     568            Delete(S, 1, P + Length(EndString) - 1);
     569
     570            if (Flag = ipfNewItem) and (Trim(NewAcronym.Name) <> '') and
     571              (Trim(NewAcronym.Meaning) <> '') then
     572              Sources.AcronymDb.AddAcronym(NewAcronym.Name, NewAcronym.Meaning);
     573          end;
     574        end;
     575      until Length(S) = LastLength;
    435576    end;
    436577  finally
Note: See TracChangeset for help on using the changeset viewer.