Resource

Resource Basics

Resource Name Collect Active Selection
Resource Version 1.0
Category Search Scripts
Downloads 717
Release Date 5/12/2023 11:47:34 AM
 

Resource Details

Description This script opens the selected thumbnails in a new tab.
Installation Instructions n.a.
Usage Instructions Click the drop down next to the tabs in Photo Supreme and select this script from the repository
Changes in this version n.a.
Special Requirements
 

Author Information

Author Name IDimager Support
 

Script

{
  Author: IDimager
  Version 1.0: 12 May 2023
  Changes:
    na
}

  procedure OpenNewTabForDataset(ADatasets: TDBXOMDataSets);
  var
    AColl: TImageCollection;
  begin
    AData := TidElement.Create(nil);
    try
      PublicBroadCast(nil, 'OpenNewTab', nil);
      PublicBroadCastRequest(nil, 'ActiveCollection', AData);
      AColl := AData.Data;
      AColl.Clear;
      AColl.Items._DataSets := ADatasets;
      AColl.CollectionName := 'Search';
      PublicBroadCast(nil, 'RefreshActiveCollection', nil);
    finally
      AData.Free;
    end;
  end;

  procedure SelectionToItems(AItems: TCatalogItems; AErrors: TTntStringList);
  var
    i: Integer;
    AItem: TCatalogItem;
    AFileName: WideString;
    AFound: Boolean;
  begin
    for i := 0 to Selected.Count - 1 do
    begin
      AItem := TCatalogItem.Create(nil);

      AFound := PublicCatalog.FindItemCombinedByGUID(Selected.Items[i].GUID, AItem);

      if AFound then
        AItem.Collection := AItems
      else
      begin
        AErrors.Add(Selected.Items[i].FileName);
        AItem.Free;
      end;
    end;
  end;

var
  AErrors: TTntStringList;
  AGroup: TCatalogPropGroup;
  AItems: TCatalogItems;
  ADatasets: TDBXOMDataSets;
begin
  AGroup := TCatalogPropGroup.Create(nil);
  try
    AErrors := TTntStringList.Create;
    try
      SelectionToItems(AGroup.IncludeItems, AErrors);

      if (AErrors.Count > 0) then
        Say2('These files could not be found', AErrors.Text);
    finally
      AErrors.Free;
    end;

    if AGroup.IncludeItems.Count > 0 then
    begin
      AItems := TCatalogItems.Create(TCatalogItem, '');
      try
        PublicCatalog.EnumGroupResultQuick(AGroup, AItems, -1);
        //Say(AItems.Count);

        // take over the dataset(s) for extra performance
        ADatasets := AItems.Datasets;
        AItems._DataSets := TDBXOMDataSets.Create(TDBXOMDataSet, '');
      finally
        AItems.Free;
      end;

      OpenNewTabForDataset(ADatasets);
    end;
  finally
    AGroup.Free;
  end;
end;