Ignore:
Timestamp:
Jan 24, 2025, 11:42:58 PM (6 weeks ago)
Author:
chronos
Message:
  • Modified: Fixed Import sources modification.
  • Modified: Catogires don't have direct object references to import sources and acronym meanings.
  • Modified: Updated acronyms example file.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/Forms/FormImportSources.pas

    r227 r230  
    1414  TFormImportSources = class(TFormEx)
    1515    AAdd: TAction;
     16    APreview: TAction;
    1617    AEnable: TAction;
    1718    ADisable: TAction;
     
    3132    MenuItem6: TMenuItem;
    3233    MenuItem7: TMenuItem;
     34    MenuItem8: TMenuItem;
    3335    PopupMenuImportSource: TPopupMenu;
    3436    ToolBar1: TToolBar;
     
    3739    ToolButton3: TToolButton;
    3840    ToolButton4: TToolButton;
     41    ToolButton5: TToolButton;
    3942    procedure AAddExecute(Sender: TObject);
    4043    procedure ADisableExecute(Sender: TObject);
    4144    procedure AEnableExecute(Sender: TObject);
    4245    procedure AModifyExecute(Sender: TObject);
     46    procedure APreviewExecute(Sender: TObject);
    4347    procedure AProcessExecute(Sender: TObject);
    4448    procedure ARemoveExecute(Sender: TObject);
     49    procedure FormActivate(Sender: TObject);
    4550    procedure FormCreate(Sender: TObject);
    4651    procedure FormShow(Sender: TObject);
     
    5863    procedure ListViewSort1Filter(ListViewSort: TListViewSort);
    5964  private
     65    PreviewAcronymDb: TAcronymDb;
    6066    procedure ProcessImportJob(Job: TJob);
     67    procedure PreviewImportJob(Job: TJob);
    6168    procedure FilterList(List: TObjectList<TObject>);
    6269  public
     
    7380
    7481uses
    75   FormMain, FormImportSource;
     82  FormMain, FormImportSource, FormAcronyms;
    7683
    7784resourcestring
     
    8087  SImportSourceAlreadyExists = 'Import source %s already exists!';
    8188  SProcessSelectedSource = 'Process selected import source';
     89  SPreviewSelectedSource = 'Preview selected import source';
    8290
    8391
     
    96104      Item.SubItems.Add(DateToStr(LastImportTime))
    97105      else Item.SubItems.Add('');
     106    Item.SubItems.Add(Format.Name);
    98107    Item.Checked := Enabled;
    99108  end;
     
    133142function TFormImportSources.ListViewSort1CompareItem(Item1, Item2: TObject
    134143  ): Integer;
    135 begin
     144var
     145  ImportSource1, ImportSource2: TImportSource;
     146begin
     147  ImportSource1 := TImportSource(Item1);
     148  ImportSource2 := TImportSource(Item2);
    136149  Result := 0;
    137150  if Assigned(Item1) and Assigned(Item2) and (ListViewSort1.Order <> soNone) then begin
    138151    with ListViewSort1 do
    139152    case Column of
    140       0: Result := CompareString(TImportSource(Item1).Name, TImportSource(Item2).Name);
    141       1: Result := CompareString(TImportSource(Item1).URL, TImportSource(Item2).URL);
    142       2: Result := CompareString(TImportSource(Item1).Categories.GetString, TImportSource(Item2).Categories.GetString);
    143       3: Result := CompareInteger(TImportSource(Item1).ItemCount, TImportSource(Item2).ItemCount);
    144       4: Result := CompareTime(TImportSource(Item1).LastImportTime, TImportSource(Item2).LastImportTime);
     153      0: Result := CompareString(ImportSource1.Name, ImportSource2.Name);
     154      1: Result := CompareString(ImportSource1.URL, ImportSource2.URL);
     155      2: Result := CompareString(ImportSource1.Categories.GetString, ImportSource2.Categories.GetString);
     156      3: Result := CompareInteger(ImportSource1.ItemCount, ImportSource2.ItemCount);
     157      4: Result := CompareTime(ImportSource1.LastImportTime, ImportSource2.LastImportTime);
     158      5: Result := CompareString(ImportSource1.Format.Name, ImportSource2.Format.Name);
    145159    end;
    146160    if ListViewSort1.Order = soDown then Result := -Result;
     
    164178  ARemove.Enabled := Assigned(ListView1.Selected);
    165179  AModify.Enabled := Assigned(ListView1.Selected);
     180  AProcess.Enabled := Assigned(ListView1.Selected);
     181  APreview.Enabled := Assigned(ListView1.Selected);
    166182end;
    167183
     
    185201  NewImportSource: TImportSource;
    186202  FormImportSource: TFormImportSource;
    187   I: Integer;
    188203begin
    189204  NewImportSource := TImportSource.Create;
     
    197212      if not Assigned(ImportSources.SearchByName(NewImportSource.Name)) then begin;
    198213        ImportSources.Add(NewImportSource);
    199 
    200         // Update reverse references
    201         for I := 0 to NewImportSource.Categories.Count - 1 do
    202           if NewImportSource.Categories.Items[I].ImportSources.IndexOf(NewImportSource) = -1 then
    203             NewImportSource.Categories.Items[I].ImportSources.Add(NewImportSource);
    204214
    205215        NewImportSource := nil;
     
    262272        end;
    263273
    264         // Update reverse references
    265         TImportSource(ListView1.Selected.Data).Categories.UpdateLinkImportSources(TImportSource(ListView1.Selected.Data));
    266 
    267274        UpdateList;
    268275      end;
     
    270277    finally
    271278      FreeAndNil(FormImportSource);
     279    end;
     280  end;
     281end;
     282
     283procedure TFormImportSources.APreviewExecute(Sender: TObject);
     284var
     285  FormAcronyms: TFormAcronyms;
     286begin
     287  if Assigned(ListView1.Selected) then begin
     288    PreviewAcronymDb := TAcronymDb.Create;
     289    try
     290      JobProgressView1.AddJob(SPreviewSelectedSource, PreviewImportJob);
     291      JobProgressView1.Start;
     292      FormAcronyms := TFormAcronyms.Create(nil);
     293      try
     294        FormAcronyms.AcronymDb := PreviewAcronymDb;
     295        FormAcronyms.Acronyms := PreviewAcronymDb.Acronyms;
     296        FormAcronyms.ShowModal;
     297      finally
     298        FormAcronyms.Free;
     299      end;
     300    finally
     301      FreeAndNil(PreviewAcronymDb);
    272302    end;
    273303  end;
     
    287317procedure TFormImportSources.ProcessImportJob(Job: TJob);
    288318begin
    289   TImportSource(ListView1.Selected.Data).Process;
     319  TImportSource(ListView1.Selected.Data).Process(AcronymDb);
     320end;
     321
     322procedure TFormImportSources.PreviewImportJob(Job: TJob);
     323begin
     324  TImportSource(ListView1.Selected.Data).Process(PreviewAcronymDb);
    290325end;
    291326
     
    313348           if Pos(UTF8LowerCase(StringGrid.Cells[4, 0]),
    314349             UTF8LowerCase(DateTimeToStr(TImportSource(List.Items[I]).LastImportTime))) > 0 then Inc(FoundCount);
     350           if Pos(UTF8LowerCase(StringGrid.Cells[5, 0]),
     351             UTF8LowerCase(TImportSource(List.Items[I]).Format.Name)) > 0 then Inc(FoundCount);
    315352           if FoundCount <> EnteredCount then List.Delete(I);
    316353         end;
     
    338375end;
    339376
     377procedure TFormImportSources.FormActivate(Sender: TObject);
     378begin
     379  ListViewFilter1.UpdateFromListView(ListView1);
     380end;
     381
    340382procedure TFormImportSources.FormCreate(Sender: TObject);
    341383var
Note: See TracChangeset for help on using the changeset viewer.