Ignore:
Timestamp:
Aug 22, 2016, 1:16:56 PM (8 years ago)
Author:
chronos
Message:
  • Added: Add support for acronym category selection in import source format.
  • Modified: Optimalized export speed.
  • Fixed: Export to MediaWiki tables was not correctly generated for multi line strings.
  • Fixed: Add back links from categories to import sources.
  • Added: Multi select support in category list.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormExport.pas

    r96 r97  
    66
    77uses
    8   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
     8  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
     9  UJobProgressView;
    910
    1011type
     
    2223    procedure FormCreate(Sender: TObject);
    2324  private
    24     procedure ExportCSV;
    25     procedure ExportMediaWiki;
    26     procedure ExportMediaWikiTable;
     25    ItemCount: Integer;
     26    procedure JobExportCSV(Job: TJob);
     27    procedure JobExportMediaWiki(Job: TJob);
     28    procedure JobExportMediaWikiTable(Job: TJob);
    2729  public
    2830    { public declarations }
     
    4042
    4143resourcestring
    42   SExpotedAcronyms = 'Exported %d acronyms';
     44  SExportedAcronyms = 'Exported %d acronyms';
     45  SExporting = 'Exporting';
    4346
    4447{ TFormExport }
     
    5962end;
    6063
    61 procedure TFormExport.ExportCSV;
     64procedure TFormExport.JobExportCSV(Job: TJob);
    6265var
    6366  I: Integer;
    6467  J: Integer;
    65   ItemCount: Integer;
     68  Content: string;
    6669begin
    67   Memo1.Lines.Clear;
    68   Memo1.Lines.BeginUpdate;
     70  Job.Progress.Max := Core.AcronymDb.Acronyms.Count;
    6971  ItemCount := 0;
    70   for I := 0 to Core.AcronymDb.Acronyms.Count - 1 do
    71   with TAcronym(Core.AcronymDb.Acronyms[I]) do
    72     for J := 0 to Meanings.Count - 1 do
    73     with TAcronymMeaning(Meanings[J]) do begin
    74       Memo1.Lines.Add('"' + Acronym.Name + '","' + Name + '","' + Description + '","' + Categories.GetString + '"');
    75       Inc(ItemCount);
    76     end;
    77   Memo1.Lines.EndUpdate;
    78   ShowMessage(Format(SExpotedAcronyms, [ItemCount]));
    79 end;
    80 
    81 procedure TFormExport.ExportMediaWiki;
    82 var
    83   I: Integer;
    84   J: Integer;
    85   ItemCount: Integer;
    86 begin
    87   Memo1.Lines.Clear;
    88   Memo1.Lines.BeginUpdate;
    89   ItemCount := 0;
    90   for I := 0 to Core.AcronymDb.Acronyms.Count - 1 do
    91   with TAcronym(Core.AcronymDb.Acronyms[I]) do begin
    92     Memo1.Lines.Add('; ' + Name);
    93     for J := 0 to Meanings.Count - 1 do
    94     with TAcronymMeaning(Meanings[J]) do begin
    95       Memo1.Lines.Add(': ' + Name);
    96       Inc(ItemCount);
    97     end;
    98   end;
    99   Memo1.Lines.EndUpdate;
    100   ShowMessage(Format(SExpotedAcronyms, [ItemCount]));
    101 end;
    102 
    103 procedure TFormExport.ExportMediaWikiTable;
    104 var
    105   I: Integer;
    106   J: Integer;
    107   ItemCount: Integer;
    108 begin
    109   Memo1.Lines.Clear;
    110   Memo1.Lines.BeginUpdate;
    111   ItemCount := 0;
    112   Memo1.Lines.Add('{| class="wikitable sortable"');
    113   Memo1.Lines.Add('! Name !! Meaning !! Description !! Categories');
     72  Content := '';
    11473  for I := 0 to Core.AcronymDb.Acronyms.Count - 1 do
    11574  with TAcronym(Core.AcronymDb.Acronyms[I]) do begin
    11675    for J := 0 to Meanings.Count - 1 do
    11776    with TAcronymMeaning(Meanings[J]) do begin
    118       Memo1.Lines.Add('|-');
    119       Memo1.Lines.Add('| ' + Acronym.Name + ' || ' + Name + ' || ' + Description + ' || ' + Categories.GetString);
     77      Content := Content + '"' + Acronym.Name + '","' + Name + '","' + Description + '","' + Categories.GetString + '"' + LineEnding;
    12078      Inc(ItemCount);
    12179    end;
     80    Job.Progress.Increment;
     81    if Job.Terminate then Break;
    12282  end;
    123   Memo1.Lines.Add('|}');
    124   Memo1.Lines.EndUpdate;
    125   ShowMessage(Format(SExpotedAcronyms, [ItemCount]));
     83  Memo1.Lines.Text := Content;
     84end;
     85
     86procedure TFormExport.JobExportMediaWiki(Job: TJob);
     87var
     88  I: Integer;
     89  J: Integer;
     90  Content: string;
     91begin
     92  Job.Progress.Max := Core.AcronymDb.Acronyms.Count;
     93  ItemCount := 0;
     94  Content := '';
     95  for I := 0 to Core.AcronymDb.Acronyms.Count - 1 do
     96  with TAcronym(Core.AcronymDb.Acronyms[I]) do begin
     97    Content := Content + '; ' + Name + LineEnding;
     98    for J := 0 to Meanings.Count - 1 do
     99    with TAcronymMeaning(Meanings[J]) do begin
     100      Content := Content + ': ' + Name + LineEnding;
     101      Inc(ItemCount);
     102    end;
     103    Job.Progress.Increment;
     104    if Job.Terminate then Break;
     105  end;
     106  Memo1.Lines.Text := Content;
     107end;
     108
     109procedure TFormExport.JobExportMediaWikiTable(Job: TJob);
     110var
     111  I: Integer;
     112  J: Integer;
     113  Line: string;
     114  Content: string;
     115begin
     116  Job.Progress.Max := Core.AcronymDb.Acronyms.Count;
     117  ItemCount := 0;
     118  Content := '{| class="wikitable sortable"' + LineEnding +
     119    '! Name !! Meaning !! Description !! Categories' + LineEnding;
     120  for I := 0 to Core.AcronymDb.Acronyms.Count - 1 do
     121  with TAcronym(Core.AcronymDb.Acronyms[I]) do begin
     122    for J := 0 to Meanings.Count - 1 do
     123    with TAcronymMeaning(Meanings[J]) do begin
     124      Content := Content + '|-' + LineEnding +
     125        '| ' + Acronym.Name + LineEnding + '| ' + Name + LineEnding +
     126        '| ' + Description + LineEnding + '| ' + Categories.GetString + LineEnding;
     127      Inc(ItemCount);
     128    end;
     129    Job.Progress.Increment;
     130    if Job.Terminate then Break;
     131  end;
     132  Content := Content + '|}' + LineEnding;
     133  Memo1.Lines.Text := Content;
    126134end;
    127135
    128136procedure TFormExport.ButtonProcessClick(Sender: TObject);
    129137begin
    130   if ComboBoxDataFormat.ItemIndex = 0 then ExportCSV;
    131   if ComboBoxDataFormat.ItemIndex = 1 then ExportMediaWiki;
    132   if ComboBoxDataFormat.ItemIndex = 2 then ExportMediaWikiTable;
     138  if ComboBoxDataFormat.ItemIndex = 0 then
     139    Core.JobProgressView1.AddJob(SExporting, JobExportCSV);
     140  if ComboBoxDataFormat.ItemIndex = 1 then
     141    Core.JobProgressView1.AddJob(SExporting, JobExportMediaWiki);
     142  if ComboBoxDataFormat.ItemIndex = 2 then
     143    Core.JobProgressView1.AddJob(SExporting, JobExportMediaWikiTable);
     144  Core.JobProgressView1.Start;
     145  ShowMessage(Format(SExportedAcronyms, [ItemCount]));
    133146end;
    134147
Note: See TracChangeset for help on using the changeset viewer.