//*********************************************************************
//*            PROGRAM - OnNewsgroupListPaint 2020-07-09              *
//*                      >> Ereignisscript <<                         *
//*                                                                   *
//* Mit diesem Script wird das Aussehen der Group-Pane beinflusst.    *
//* So können bspw. die Namen der Gruppen gekürzt werden.             *
//*                                                                   *
//* Funktionalitaet: [x] neutral                                      *
//*                  [ ] nur Basis_Modul                              *
//*                  [ ] nur Pathfinder                               *
//*                                                                   *
//* Datum         : 09.12.2008                                        *
//* Autor         : Dietmar Vollmeier                                 *
//* Ueberarbeitet : Thomas Barghahn 2020-07-09                        *
//*                                                                   *
//*********************************************************************
program OnNewsgroupListPaint;

const
  // toggle between 'true' and 'false' to change one of the following
  // settings

  // Do you want to shorten the newsgroup names?
  // (de.comm.software.newsreader -> d.c.s.newsreader)
  ShortenGroups = true;

  // If ShortenGroups is 'true', do you want to keep the last two 
  // strings? (de.comm.software.newsreader -> d.c.software.newsreader)
  KeepTwoStrings = true;

  // Do you want to remove the name of the newsserver?
  RemoveServer = false;

function RenameGroups(paintstring:widestring):widestring;

begin
   case paintstring of
    // list of groups and folders that will be renamed
    // 'alt.sysadmin.recovery'   : result:='asr';
    'Inbox (anchedo)'         : result:='Incoming mail';
    // 'de.admin.news.announce'  : result:='dana';
    // 'de.admin.news.groups'    : result:='dang';
    // 'de.alt.gruppenkasper'    : result:='dag°';
    // 'de.alt.netdigest'        : result:='dan';
    // 'de.alt.sysadmin.recovery': result:='dasr';
   end;
end;

function ShortenRenameGroupsFolders(PaintString:widestring):widestring;

var i            : integer;
    s            : string;
    lpaintstring : widestring;
    ls           : string;

begin

  // remove the name of the newsserver, if it still exists
  // (just compatibility with very old versions of Dialog)

  if RemoveServer=true then
  begin
     i := pos(' (',paintstring);
     if (i > 0) and (copy(paintstring,1,6) <> 'Inbox ') then begin
        s := paintstring;
        delete(s,i,200);
        paintstring := s;
     end;
  end;

  // minimize newsgroup names
  // (news.software.readers -> n.s.readers)

  if ShortenGroups = true then begin
     i := pos('.',paintstring);
     s := '';
  end;

  // check if groups should be renamed
  if RenameGroups(paintstring) <> '' then begin
     paintstring := RenameGroups(paintstring);
     i := 0;
  end;

  // shorten group names for not renamed groups
  if ShortenGroups=true then begin
     while (i > 0) do begin
        if KeepTwoStrings then begin
           lpaintstring:=paintstring;
           ls := s;
        end;
        s := s + copy(paintstring,1,1) + '.';
        paintstring := copy(paintstring,i + 1,1000);
        i := pos('.',paintstring);
     end;
     if (KeepTwoStrings=true) and (lpaintstring <> '') then begin
        s := ls;
        paintstring := lpaintstring;
     end;
     paintstring := s + paintstring;
  end;
  result := paintstring;
end;

function OnNewsgroupListPaint(PaintString:widestring;ColumnIndex:integer):widestring;

   begin
      paintstring:=ShortenRenameGroupsFolders(paintstring);
      result:=paintstring;
   end;

begin
end.