home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / OUT18.ZIP / OUTEDIT.INC < prev    next >
Encoding:
Text File  |  1986-10-03  |  14.9 KB  |  493 lines

  1.  
  2. (*
  3.  * outline - a simple "outline" oriented document generator
  4.  *
  5.  * outedit.inc - this file contains the section display
  6.  *               and editor procedures.  this is the main
  7.  *               part of the user interface.
  8.  *
  9.  * Author:  Samuel H. Smith,  11-Jan-86
  10.  *
  11.  *)
  12.  
  13.  
  14. procedure display_section(sec:     section_ptr;
  15.                           parent:  anystring);   {display the current
  16.                                                   section on the screen
  17.                                                   for editing}
  18. var
  19.    i:  integer;
  20.  
  21. begin
  22.    gotoxy(1,1);
  23.  
  24.    with sec^ do
  25.    begin
  26.       lowvideo;
  27.       disp('Parent: '+parent);
  28.       clreol;
  29.       writeln;      lowvideo;
  30.       disp('Title:  ');
  31.  
  32.       normvideo;
  33.       disp(title);
  34.       clreol;
  35.       writeln;
  36.  
  37.       lowvideo;
  38.       clreol;
  39.       writeln;
  40.       disp('Text:');
  41.  
  42.       normvideo;
  43.       for i := 1 to max_text do
  44.       begin
  45.          gotoxy(9,wherey);
  46.          disp(text^[i]);
  47.          clreol;
  48.          writeln;
  49.       end;
  50.  
  51.  
  52.       lowvideo;
  53.       clreol;
  54.       disp('Sub-sections:');
  55.  
  56.       writeln;
  57.  
  58.       normvideo;
  59.       for i := 1 to max_subsects do
  60.          if subsect[i] <> nil then
  61.          begin
  62.             if (marksec = sec) and (marksub = i) then
  63.                disp('<mark>  ')
  64.             else
  65.                if subsect[i]^.estimate = 0 then
  66.                   disp('        ')
  67.                else
  68.                   write(subsect[i]^.estimate:5:1,'   ');
  69.  
  70.             disp(subsect[i]^.title);
  71.             clreol;
  72.             writeln;
  73.          end;
  74.    end;
  75.  
  76.    for i := wherey to 24 do
  77.    begin
  78.       clreol;
  79.       writeln;
  80.    end;
  81.  
  82.    lowvideo;
  83.    disp('Keys:  UP,  DOWN,  PGUP (parent),  PGDN (sub-section),  F1 (help)');
  84.    clreol;
  85.    gotoxy(74,wherey);
  86.    write(maxavail shr 6,'k');
  87.    if not saved then
  88.       disp(' *');
  89.  
  90.    normvideo;
  91. end;
  92.  
  93.  
  94. procedure edit_help;     {display a help message for the section editor}
  95. var
  96.    key:  char;
  97.  
  98. begin
  99.    clrscr;
  100.    lowvideo;
  101.    displn(version);
  102.    writeln; normvideo;
  103.    displn('               H E L P  -  O N  -  T A P');
  104.    writeln;
  105.    displn('    Key                  Action');  lowvideo;
  106.    displn('   ═════    ═════════════════════════════');
  107.    writeln;
  108.    displn('   F1       Display this help screen');
  109.    displn('   F2       UnDelete deleted section in front of the current sub-section');
  110.    displn('   F3       Save the outline on disk');
  111.    displn('   F4       Print this section');
  112.    displn('   F6       Mark/unmark the current sub-section');
  113.    displn('   F7       Move the marked sub-section in front of the current sub-section');
  114.    displn('   F8       Copy the marked sub-section in front of the current sub-section');
  115.    displn('   F9       Delete the current sub-section');
  116.    displn('   F10      Change estimate for the current sub-section');
  117.    displn('   UP       Move the cursor up to the previous item');
  118.    displn('   DOWN     Move the cursor down to the next item');
  119.    displn('   PGUP     Go up an outline level (to the Parent-Section)');
  120.    displn('   PGDN     Go down a level to the Sub-Section under the cursor');
  121.    writeln;
  122.  
  123.    gotoxy(74,25);
  124.    write(maxavail shr 6,'k');
  125.    if not saved then
  126.       disp(' *');
  127.  
  128.    gotoxy(1,24);
  129.    normvideo;
  130.    disp('Press ENTER to leave help-on-tap: ');
  131.  
  132.    repeat
  133.    until getkey in [NEWLINE,F1];
  134.  
  135.    clrscr;
  136. end;
  137.  
  138.  
  139. procedure edit_section(sec:        section_ptr;
  140.                        parent:     anystring;
  141.                        dewey:      anystring);   {user interface to
  142.                                                   edit a section of an
  143.                                                   outline.  recursively
  144.                                                   calls itself when the
  145.                                                   user goes "down" a
  146.                                                   section.  this is the
  147.                                                   most elaborate procedure
  148.                                                   since it does all of the
  149.                                                   actual section manipulation}
  150. var
  151.    fld:  integer;
  152.    sub:  integer;
  153.    key:  char;
  154.    temp: section_ptr;
  155.    i:    integer;
  156.    col:  integer;
  157.    est:  real;
  158.    buf:  string[6];
  159.    pag:  integer;
  160.    ssec: string[2];
  161.    mark: integer;
  162.  
  163. begin
  164.  
  165.    fld := 1;
  166.    col := 1;
  167.    mark := 0;
  168.    display_section(sec,parent);
  169.  
  170.    with sec^ do
  171.    repeat
  172.  
  173.       if fld > max_text+1 then
  174.       begin
  175.          sub := fld - (max_text+1);      {calculate the subsection index}
  176.          ssec := itoa(sub) + '.';
  177.          if subsect[sub] <> nil then
  178.             pag := subsect[sub]^.onpage
  179.          else
  180.             pag := 0;
  181.       end
  182.       else
  183.       begin
  184.          pag := onpage;
  185.          ssec := '';
  186.       end;
  187.  
  188.  
  189.       gotoxy(30,(max_text+4));
  190.       clreol;
  191.       lowvideo;
  192.  
  193.       disp('Sec: '+dewey+ssec);
  194.  
  195.       gotoxy(55,(max_text+4));
  196.       if pag <> 0 then
  197.          write('Page:',pag:3);
  198.  
  199.       est := 0;                           {calculate this section's estimate}
  200.       for i := 1 to max_subsects do
  201.          if subsect[i] <> nil then
  202.             est := est + subsect[i]^.estimate;
  203.       if (est <> 0) or (sec = document) then
  204.          estimate := est;
  205.  
  206.       gotoxy(69,(max_text+4));
  207.       if estimate <> 0 then
  208.          write('Est: ',estimate:0:1);
  209.  
  210.       normvideo;
  211.  
  212.  
  213.       if (fld = 1) then                   {edit the section title}
  214.          edit_string(9,2,col,title,key,anystring_length)
  215.       else
  216.  
  217.       if (fld > 1) and (fld <= max_text+1) then
  218.       begin
  219.                                           {edit the section text lines}
  220.          if text = emptytext then
  221.             allocate_text(sec);
  222.  
  223.          edit_string(9,fld+2,col,text^[fld-1],key,anystring_length);
  224.  
  225.       end
  226.  
  227.       else                                {edit the subsect list}
  228.       begin
  229.           sub := fld - (max_text+1);      {calculate the subsection index}
  230.           if subsect[sub] = nil then
  231.              subsect[sub] := new_section;
  232.  
  233.           edit_string(9,sub+(max_text+4),col,
  234.                        subsect[sub]^.title,key,anystring_length);
  235.       end;
  236.  
  237.  
  238.       case key of     {process special function keys from edit-string}
  239.  
  240.          F1:    {get help-on-tap}
  241.                 begin
  242.                    edit_help;
  243.                    display_section(sec,parent);
  244.                 end;
  245.  
  246.  
  247.          F2:    {undelete most recently deleted in front of current subsection}
  248.                 if fld <= (max_text+1) then
  249.                    warning('The cursor must be on a sub-section')
  250.                 else
  251.  
  252.                 if (delsec = nil) then
  253.                    warning('There is nothing to undelete')
  254.                 else
  255.  
  256.                 begin
  257.                    for i := max_subsects-1 downto sub do
  258.                       subsect[i+1] := subsect[i];
  259.                                           {open up a space for the undel'd
  260.                                            subsection to go into}
  261.  
  262.                    subsect[sub] := delsec;
  263.                    display_section(sec,parent);
  264.                                           {put it into the list and
  265.                                            update the screen}
  266.  
  267.                    delsec := nil;         {now there's nothing deleted}
  268.                    saved := false;
  269.                 end;
  270.  
  271.          F3:    {save current outline}
  272.                 begin
  273.                    save_document;
  274.                    clrscr;
  275.                    display_section(sec,parent);
  276.                 end;
  277.  
  278.  
  279.          F4:    {print section}
  280.                 begin
  281.                    print_document(sec,sec^.onpage,dewey);
  282.                    clrscr;
  283.                    display_section(sec,parent);
  284.                 end;
  285.  
  286.  
  287.          F6:    {mark current subsection}
  288.                 if fld <= (max_text+1) then
  289.                    warning('This can''t be marked')
  290.                 else
  291.  
  292.                 begin
  293.                    if (marksub <> 0) and (marksec = sec) then
  294.                                          {if there is already a mark on this
  295.                                           screen, then remove it }
  296.                    begin
  297.                       gotoxy(1,marksub+(max_text+4));
  298.                       disp('      ');
  299.                    end;
  300.  
  301.                    if (marksec = sec) and (marksub = sub) then
  302.                                          {toggle mark off/on}
  303.                       marksec := nil
  304.                    else
  305.                    begin
  306.                       marksub := sub;
  307.                       marksec := sec;
  308.                       gotoxy(1,marksub+(max_text+4));
  309.                       disp('<mark>');
  310.                    end;
  311.                 end;
  312.  
  313.  
  314.          F7:    {move marked subsect in front of current subsection}
  315.                 if fld <= (max_text+1) then
  316.                    warning('The cursor must be on a sub-section')
  317.                 else
  318.  
  319.                 if (marksec = nil) then
  320.                    warning('First mark the section to move')
  321.                 else
  322.  
  323.                 begin
  324.                    temp := marksec^.subsect[marksub];
  325.                                           {grab the subsection to be moved}
  326.  
  327.                    for i := marksub to max_subsects-1 do
  328.                       marksec^.subsect[i] := marksec^.subsect[i+1];
  329.                    marksec^.subsect[max_subsects] := nil;
  330.                                           {delete position of marked
  331.                                            subsect from subsection list}
  332.  
  333.                    if (marksec = sec) and (sub > marksub) then
  334.                       sub := sub - 1;     {adjust if current fld got moved}
  335.  
  336.                    for i := max_subsects-1 downto sub do
  337.                       subsect[i+1] := subsect[i];
  338.                                           {open up a space for the moved
  339.                                            subsection to go into}
  340.  
  341.                    subsect[sub] := temp;
  342.                    fld := sub + (max_text+1);
  343.                                           {put it into the list}
  344.  
  345.                    marksec := nil;
  346.                    marksub := 0;
  347.                    display_section(sec,parent);
  348.                                            {clear the marker and update the
  349.                                             screen to show changes}
  350.                    saved := false;
  351.                 end;
  352.  
  353.  
  354.          F8:    {copy marked subsection in front of current subsection}
  355.                 if fld <= (max_text+1) then
  356.                    warning('The cursor must be on a sub-section')
  357.                 else
  358.  
  359.                 if (marksec = nil) then
  360.                    warning('First mark the section to copy')
  361.                 else
  362.  
  363.                 begin
  364.                    temp := marksec^.subsect[marksub];
  365.                                           {grab the subsection to be moved}
  366.  
  367.                    for i := max_subsects-1 downto sub do
  368.                       subsect[i+1] := subsect[i];
  369.                                           {open up a space for the moved
  370.                                            subsection to go into}
  371.  
  372.                    subsect[sub] := temp;
  373.                    temp^.refcount := temp^.refcount + 1;
  374.                                           {put it into the list and update
  375.                                            the screen}
  376.                    display_section(sec,parent);
  377.                    saved := false;
  378.                 end;
  379.  
  380.  
  381.          F9:    {delete the current subsection (and all subordinate sections)}
  382.                 if fld <= (max_text+1) then
  383.                    warning('The cursor must be on a sub-section')
  384.                 else
  385.  
  386.                 begin
  387.                    if delsec <> nil then
  388.                       delete_section(delsec);        {if there was a previous
  389.                                                       delete, throw it away}
  390.  
  391.                    delsec := subsect[sub];           {hold in to this delete in
  392.                                                       case of undelete}
  393.  
  394.                    for i := sub to max_subsects-1 do
  395.                       subsect[i] := subsect[i+1];
  396.                    subsect[max_subsects] := nil;     {get rid of the entry}
  397.  
  398.                    display_section(sec,parent);
  399.                    saved := false;
  400.                 end;
  401.  
  402.  
  403.  
  404.          F10:   {change estimate}
  405.                 if fld <= (max_text+1) then
  406.                    warning('This can''t be estimated')
  407.                 else
  408.  
  409.                 begin
  410.                    normvideo;
  411.                    gotoxy(1,sub+(max_text+4));
  412.                    write('     ',#13);
  413.                    i := 1;
  414.                    buf := '';
  415.                    edit_string(1,sub+(max_text+4),i,buf,key,5);
  416.                    val(buf,subsect[sub]^.estimate,i);
  417.  
  418.                    lowvideo;
  419.                    gotoxy(1,sub+(max_text+4));
  420.                    write(subsect[sub]^.estimate:5:1,'   ');
  421.                    disp(subsect[sub]^.title);
  422.  
  423.                    saved := false;
  424.                 end;
  425.  
  426.       end;
  427.  
  428.  
  429.       case key of     {select next field/screen based on exit key from edit}
  430.  
  431.          ESC,
  432.          PGUP:  {go up to parent section}
  433.                 ;
  434.  
  435.  
  436.          PGDN:  {go down into current subsection}
  437.                 if fld <= (max_text+1) then
  438.                    fld := max_text+2
  439.                 else
  440.  
  441.                 if (sec = marksec) and (sub = marksub) then
  442.                    warning('First unmark with F4')
  443.                 else
  444.  
  445.                 if subsect[sub]^.title = '' then
  446.                    warning('First enter the title; blank titles are forbidden')
  447.                 else
  448.  
  449.                 begin
  450.                    edit_section(subsect[sub],title,dewey+ssec);
  451.                    display_section(sec,parent);
  452.                 end;
  453.  
  454.  
  455.          UP:    {go up to previous field on screen, skipping blanks}
  456.                 if fld > 1 then
  457.                 begin
  458.                    fld := fld - 1;
  459.                    if (fld > 1) and (fld <= (max_text+1)) then
  460.                       while (fld > 1) and (text^[fld-1] = '') do
  461.                          fld := fld - 1;
  462.                 end
  463.                 else
  464.                    warning('Top of screen');
  465.  
  466.  
  467.          NEWLINE,
  468.          DOWN:  {move down to next field on screen, skipping blanks}
  469.                 if (fld > 1) and (fld <= max_text) then
  470.                 begin
  471.                    if text^[fld-1] = '' then
  472.                       fld := max_text+2
  473.                    else
  474.                       fld := fld + 1;
  475.                 end
  476.                 else
  477.  
  478.                 if (fld - (max_text+1)) < max_subsects then
  479.                    fld := fld + 1
  480.                 else
  481.                    warning('Bottom of screen');
  482.  
  483.  
  484.          F1..F10:  ;
  485.  
  486.          else   warning('Invalid function key');
  487.       end;
  488.  
  489.  
  490.    until (key = PGUP) or (key = ESC);
  491. end;
  492.  
  493.