home *** CD-ROM | disk | FTP | other *** search
/ Aminet 10 / aminetcdnumber101996.iso / Aminet / text / edit / FrexxEdA.lha / FrexxEd / fpl / BufList.FPL < prev    next >
Text File  |  1995-08-20  |  3KB  |  130 lines

  1. export int listsize;
  2. void export BufferMakeList()
  3. {
  4.   int originid = GetEntryID();
  5.   int listid = GetEntryID("*bufferlist*");
  6.   int firstid;
  7.   int id;
  8.   string text;
  9.   string name;
  10.   
  11.   firstid = GetBufferID();
  12.   id = firstid;
  13.   listsize=0;
  14.   do {
  15.     name = ReadInfo("full_file_name", id);
  16.     if(!strlen(name))
  17.       name = "*noname*";
  18.     text += sprintf("  %c %8s %6d %-60s %s\n",
  19.                     ReadInfo("changes", id)?'C':'-',
  20.                     ReadInfo("protection", id),
  21.                     ReadInfo("size", id),
  22.                     name,
  23.                     ltostr(id, 32));
  24.     listsize++;
  25.     id=NextBuffer(id);
  26.     if (id==firstid)
  27.       id=0;
  28.   } while (id);
  29.  
  30.   if(!listid) {
  31.     listid = New();
  32.     if(!listid)
  33.       return;
  34.   }
  35.  
  36.   Visible(0);
  37.   CurrentBuffer(listid);
  38.  
  39.   if(!ReadInfo("visible", listid)) {
  40.  
  41.     /* not visible, let's do something about it! */
  42.     if(ReadInfo("views") == 1) { /* only one view */
  43.       /* display it by splitting the current view! */
  44.       Activate(listid, 1, originid);
  45.     } else {
  46.       /* pop up by replacing the next view! */
  47.       Activate(listid, 0, NextView(originid));
  48.     }
  49.  
  50.   }
  51.  
  52.   SetInfo(-1, "_bufferlist", 1); /* set bufferlist-mode */
  53.   Rename("*bufferlist*");      /* always make sure this name is set! */
  54.   Clean("Clear();");         /* clear all old contents from this! */
  55.   Output(text);             /* paste the table */
  56.   BlockSort(listid, 4, 1);     /* sort it according to the file names */
  57.   GotoLine(1);             /* goto first line, first column */
  58.   Output(" (C)  Protect  Size File name\n"); /* write tables headers */
  59.   SetInfo(-1, "changes", 0);     /* make it non-changed */
  60.  
  61.   CurrentBuffer(originid);
  62.   Visible(1);
  63. }
  64.  
  65. void export BufferMarkLine(int code)
  66. {
  67.   int line = ReadInfo("line");
  68.   if(line>1 && line<listsize+2) {
  69.     CursorStack(-1);
  70.     GotoLine(line); /* go to the left of the line */
  71.     SetInfo(-1, "insert_mode", 0);
  72.     if(code)
  73.       Output(itoc(code));
  74.     else
  75.       Output(" ");
  76.     SetInfo(-1, "insert_mode", 1);
  77.     CursorStack(1);
  78.   }
  79. }
  80.  
  81. int GetID(int line)
  82. {
  83.   string str = GetLine(line);
  84.   return strtol(substr(str, strlen(str)-7, 6), 32);
  85. }
  86.  
  87. void export BufferMarkExecute()
  88. {
  89.   int lines = ReadInfo("lines"); /* number of lines in buffer! */
  90.   int count;
  91.   int changed;
  92.   int code;
  93.   for(count=1; count<lines; count++) {
  94.     code = GetChar(0, count);
  95.     if(' ' != code) {
  96.       int id = GetID(count);
  97.       switch(code) {
  98.         case 'D':
  99.           Kill(id);
  100.           break;
  101.         case 'S':
  102.           ExecuteString("Save();", id);
  103.           break;
  104.       }
  105.       changed++;
  106.     }
  107.   }
  108.   if(changed) {
  109.     /* list is modified, re-create it! */
  110.     BufferMakeList();
  111.   }
  112. }
  113.  
  114. void export BufferPopUp()
  115. {
  116.   int lines = ReadInfo("lines"); /* number of lines in buffer! */
  117.   int line = ReadInfo("line");
  118.   if(line>1 && line<=lines) {
  119.     CurrentBuffer(GetID(line));
  120.   }
  121. }
  122.  
  123. ConstructInfo("_bufferlist", "", "", "BL", "", 0, 1);
  124. AssignKey("BufferMarkLine('D');", "d", "_bufferlist");
  125. AssignKey("BufferMarkLine('S');", "s", "_bufferlist");
  126. AssignKey("BufferMarkLine(0);", "u", "_bufferlist");
  127. AssignKey("BufferMarkExecute();", "x", "_bufferlist");
  128. AssignKey("BufferPopUp();", "f", "_bufferlist");
  129. AssignKey("BufferMakeList();", "control x b");
  130.