Changeset 97 for trunk/UAcronym.pas


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/UAcronym.pas

    r89 r97  
    77uses
    88  Classes, SysUtils, Contnrs, XMLRead, XMLWrite, DOM, UXMLUtils,
    9   SpecializedList, fphttpclient, Dialogs, odbcconn, sqldb;
     9  SpecializedList, fphttpclient2, Dialogs, odbcconn, sqldb;
    1010
    1111type
     
    1313  TAcronymMeanings = class;
    1414  TAcronymDb = class;
     15  TImportSource = class;
    1516  TImportSources = class;
    1617  TImportFormats = class;
     
    7374    Name: string;
    7475    AcronymMeanings: TAcronymMeanings;
     76    ImportSources: TImportSources;
    7577    procedure SaveToNode(Node: TDOMNode);
    7678    procedure LoadFromNode(Node: TDOMNode);
     
    9395    procedure AssignToStrings(Strings: TStrings);
    9496    procedure AssignFromStrings(Strings: TStrings);
     97    procedure AddFromStrings(Strings: TStrings);
    9598    function GetString: string;
     99    procedure UpdateLinkImportSources(Item: TImportSource);
     100    procedure UpdateLinkAcronymMeanings(Item: TAcronymMeaning);
    96101  end;
    97102
     
    108113  end;
    109114
    110   TImportPatternFlag = (ipfNone, ipfNewItem, ipfSkip, ipfRemove);
    111   TImportVariable = (ivNone, ivAcronym, ivMeaning, ivDescription);
     115  TImportPatternFlag = (ipfSet, ipfNewItem, ipfSkip, ipfRemove, ipfCleanSet);
     116  TImportVariable = (ivNone, ivAcronym, ivMeaning, ivDescription, ivCategory);
    112117
    113118  { TImportPattern }
     
    244249  SMeaning = 'Meaning';
    245250  SAcronym = 'Acronym';
     251  SCategory = 'Category';
    246252  SNone = 'None';
    247253  SNewItem = 'New item';
     
    258264  ImportVariableString[ivMeaning] := SMeaning;
    259265  ImportVariableString[ivDescription] := SDescription;
    260   ImportPatternFlagString[ipfNone] := SNone;
     266  ImportVariableString[ivCategory] := SCategory;
     267  ImportPatternFlagString[ipfSet] := SNone;
    261268  ImportPatternFlagString[ipfNewItem] := SNewItem;
    262269  ImportPatternFlagString[ipfSkip] := SSkip;
     
    429436  I: Integer;
    430437  T: string;
     438  TT: string;
    431439  LastLength: Integer;
    432440  AddedAcronym: TAcronymMeaning;
     441  NewCategory: TAcronymCategory;
    433442begin
    434443  NewAcronym := TAcronymEntry.Create;
     
    492501              ivMeaning: NewAcronym.Meaning := T;
    493502              ivDescription: NewAcronym.Description := T;
     503              ivCategory: begin
     504                NewAcronym.Categories.Clear;
     505                while T <> '' do begin
     506                  if Pos(',', T) > 0 then begin
     507                    TT := Copy(T, 1, Pos(',', T) - 1);
     508                    Delete(T, 1, Length(TT) + 1);
     509                  end else begin
     510                    TT := T;
     511                    T := '';
     512                  end;
     513                  TT := Trim(TT);
     514                  NewCategory := Sources.AcronymDb.Categories.SearchByName(TT);
     515                  if not Assigned(NewCategory) then begin
     516                    NewCategory := TAcronymCategory.Create;
     517                    NewCategory.Name := TT;
     518                    Sources.AcronymDb.Categories.Add(NewCategory);
     519                  end;
     520                  NewAcronym.Categories.AddObject(TT, NewCategory);
     521                end;
     522              end;
    494523            end;
    495524          end;
     
    501530              AddedAcronym.Description := NewAcronym.Description;
    502531              AddedAcronym.MergeCategories(Categories);
     532              AddedAcronym.Categories.AddFromStrings(NewAcronym.Categories);
     533              AddedAcronym.Categories.UpdateLinkAcronymMeanings(AddedAcronym);
    503534              if AddedAcronym.Sources.IndexOf(Self) = -1 then
    504535                AddedAcronym.Sources.Add(Self);
     
    877908var
    878909  Node2: TDOMNode;
     910  I: Integer;
    879911begin
    880912  Name := ReadString(Node, 'Name', '');
     
    890922  if Assigned(Node2) then
    891923    Categories.LoadRefFromNode(Node2);
     924
     925  // Add reverse references
     926  for I := 0 to Categories.Count - 1 do
     927    TAcronymCategory(Categories[I]).ImportSources.Add(Self);
    892928end;
    893929
     
    902938
    903939destructor TImportSource.Destroy;
    904 begin
     940var
     941  I: Integer;
     942begin
     943  for I := 0 to Categories.Count - 1 do
     944    TAcronymCategory(Categories[I]).ImportSources.Remove(Self);
     945  FreeAndNil(Categories);
    905946  FreeAndNil(ResponseStream);
    906   FreeAndNil(Categories);
    907947  inherited Destroy;
    908948end;
     
    12451285
    12461286procedure TAcronymCategories.AssignFromStrings(Strings: TStrings);
    1247 var
    1248   I: Integer;
    12491287begin
    12501288  Clear;
     1289  AddFromStrings(Strings);
     1290end;
     1291
     1292procedure TAcronymCategories.AddFromStrings(Strings: TStrings);
     1293var
     1294  I: Integer;
     1295begin
    12511296  for I := 0 to Strings.Count - 1 do begin
    12521297    Add(TAcronymCategory(Strings.Objects[I]));
     
    12641309end;
    12651310
     1311procedure TAcronymCategories.UpdateLinkImportSources(Item: TImportSource);
     1312var
     1313  I: Integer;
     1314begin
     1315  for I := 0 to Count - 1 do
     1316    if TAcronymCategory(Items[I]).ImportSources.IndexOf(Item) = -1 then
     1317      TAcronymCategory(Items[I]).ImportSources.Add(Item);
     1318end;
     1319
     1320procedure TAcronymCategories.UpdateLinkAcronymMeanings(Item: TAcronymMeaning);
     1321var
     1322  I: Integer;
     1323begin
     1324  for I := 0 to Count - 1 do
     1325    if TAcronymCategory(Items[I]).AcronymMeanings.IndexOf(Item) = -1 then
     1326      TAcronymCategory(Items[I]).AcronymMeanings.Add(Item);
     1327end;
     1328
    12661329
    12671330{ TAcronym }
     
    13181381begin
    13191382  AcronymMeanings := TAcronymMeanings.Create(False);
     1383  ImportSources := TImportSources.Create(False);
    13201384end;
    13211385
     
    13271391    TAcronymMeaning(AcronymMeanings[I]).Categories.Remove(Self);
    13281392  FreeAndNil(AcronymMeanings);
     1393  for I := 0 to ImportSources.Count - 1 do
     1394    TImportSource(ImportSources[I]).Categories.Remove(Self);
     1395  FreeAndNil(ImportSources);
    13291396  inherited Destroy;
    13301397end;
Note: See TracChangeset for help on using the changeset viewer.