/* prf_list.c */
/* V1.1 9-3-92 */

#include "prf.h"

void InsertName(struct prf_info *info)
{
 struct FileNameNode *fnn;
 long                 insert = FALSE;
 long                *cmd;
 UBYTE               *string;
 string = (UBYTE *)info->Special1;
 cmd    = (long  *)info->Special2;
 if(*string)
 {
  if(!(fnn = (struct FileNameNode *)FindName(&info->FileList,string)))
  {
   insert = TRUE;
  }
 }
 if(insert)
 {
  if(fnn = calloc(1,sizeof(struct FileNameNode)))
  {
   strcpy(fnn->fnn_Name,string);
   fnn->fnn_Node.ln_Name = fnn->fnn_Name;
   DetachList(info);
   if(*cmd == CMD_INSERTTAIL) AddTail(&info->FileList,(struct Node *)fnn);
    else AddHead(&info->FileList,(struct Node *)fnn);
   AttachList(info);
  }
 }

}

void RemoveName(struct prf_info *info)
{
 struct FileNameNode *fnn;
 UBYTE               *string;
 string = (UBYTE *)info->Special1;
 if(*(string) > ' ')
 {
  if(fnn = (struct FileNameNode *)FindName(&info->FileList,string))
  {
   DetachList(info);
   Remove((struct Node *)fnn);
   free(fnn);
   AttachList(info);
  }
 }
 else
 {
  DetachList(info);
  fnn = (struct FileNameNode *)RemTail(&info->FileList);
  free(fnn);
  AttachList(info);
 }
}

void DetachList(struct prf_info *info)
{
 if(info->Swd)GT_SetGadgetAttrs(info->SGadgets[GD_List],info->Swd,NULL,GTLV_Labels,-1,TAG_DONE);
}

void AttachList(struct prf_info *info)
{
 if(info->Swd) GT_SetGadgetAttrs(info->SGadgets[GD_List],info->Swd,NULL,GTLV_Labels,&info->FileList,GTLV_ShowSelected,info->SGadgets[11], TAG_DONE);
}

