{
  Version 2.0; Added option to process all areas or just
               those areas for the selected thumbnails
}
  procedure HandleAreas(AAreas: TCatalogAreas);
  var
    i, ALinked, ACreated: Integer;
    AProp: TCatalogItemProp;
  begin
    ALinked := 0;
    ACreated := 0;
    for i := 0 to AAreas.Count - 1 do
    begin
      // unlinked and with a relevant caption?
      if (AAreas.Items[i].PropGUID = '') and
         (not WideSameText(AAreas.Items[i].Caption, Translate('(New Area)')))
      then
      begin
        // unlinked area... create a catalog for it but only if it has a name
        AProp := TCatalogItemProp.Create(nil);
        if (not PublicCatalog.FindPropByName(AAreas.Items[i].Caption, AProp, '{750A8DF3-1242-4B5D-90F4-4C1E4FCBF110}', True)) and  // people
           (not PublicCatalog.FindPropByName(AAreas.Items[i].Caption, AProp, '{D37056E1-AAD7-4D77-A884-B86095D224E3}', True)) and  // others
           (not PublicCatalog.FindPropByName(AAreas.Items[i].Caption, AProp, '{2AD216A8-9A52-482B-87A1-547F0D6C6F6B}', True))   // objects
        then
        begin
          // create a People label for the caption
          AProp.GUID := NewGUID;
          AProp.PropName := AAreas.Items[i].Caption;
          PublicCatalog.StorePropToDatabase(AProp, '{750A8DF3-1242-4B5D-90F4-4C1E4FCBF110}', False);
          Inc(ACreated);
        end;

        // link to the catalog label
        AAreas.Items[i].PropGUID := AProp.GUID;
        PublicCatalog.UpdateArea(AAreas.Items[i]);
        Inc(ALinked);

        AProp.Free;
      end;
    end;

    Say('Finished' + CrLf2 +
        'Created: ' + IntToStr(ACreated) + CrLf +
        'Linked: ' + IntToStr(ALinked) + CrLf +
        ''
        );
  end;

var
  AAreas: TCatalogAreas;
  i: Integer;
begin
  AAreas := TCatalogAreas.Create(TCatalogArea, '');
  if Ask('Are you sure you want to link all unlinked areas to Catalog Labels?') then
    PublicCatalog.EnumAllAreas(AAreas)
  else if Selected.Count > 0 then
  begin
    if Ask('Would you like to link all unlinked areas to Catalog Labels for the currently selected images?') then
    for i := 0 to Selected.Count - 1 do
      PublicCatalog.EnumAreasForImage(Selected.Items[i], AAreas);
  end;

  if AAreas.Count > 0 then
    HandleAreas(AAreas)
  else
    Say('No areas to process');
  AAreas.Free;
end;
