home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / prodtool / epm / e_macros / modify.e < prev    next >
Encoding:
Text File  |  1992-07-17  |  7.6 KB  |  223 lines

  1. ;  MODIFY.E                                              Bryan Lewis 12/31/88
  2. ;
  3. ;  New in EPM.  This DEFMODIFY event is triggered when a file's number of
  4. ;  modifications (.modify):
  5. ;  -  goes from zero to nonzero (first modification, so we can change the
  6. ;     textcolor or title to indicate that the file needs to be saved;
  7. ;  -  goes from nonzero to zero (so we can return to the safe textcolor,
  8. ;     usually after a save);
  9. ;  -  goes from less than .autosave to greater than or equal to .autosave.
  10. ;
  11. ;
  12. ;  Note:  .modify does not always increase smoothly, one increment at a time.
  13. ;  For instance, changing a line and hitting Enter increases .modify by 2,
  14. ;  because it registers the change to the previous line as well as the new
  15. ;  line.  So we can't expect .modify to be exactly 1; we have to look for
  16. ;  a transition from zero to nonzero.
  17. ;
  18. ;  Note 2:  E will not retrigger this event while the event is in
  19. ;  progress, to protect against infinite recursion.  So if you make a lot
  20. ;  of changes to a file in the process of autosaving it, it won't get autosaved
  21. ;  twice.
  22. ;
  23. ;  We've provided three methods of showing the modified status.
  24. ;  1. The COLOR method changes the window color, for a very obvious indicator.
  25. ;  2. The FKTEXTCOLOR method changes the color of the bottom line of the
  26. ;     screen, for EOS2 only.
  27. ;  3. The TITLE method does one of two things.  For EOS2 it changes the color
  28. ;     of the filename.  For EPM it adds the string " (mod)" to the title bar.
  29. ;     This isn't as obvious as COLOR, but you can check it even when the file
  30. ;     is shrunk to an icon by clicking on the icon.
  31. ;
  32. ;  You, the macro writer, can add to or replace this behavior.
  33. ;  1. You can write defmodify procedures anywhere in your MYSTUFF.E or
  34. ;     MYKEYS.E files.  All defmodify procedures will be executed in sequence,
  35. ;     just as definit preocedures are.  The pieces can be anywhere.
  36. ;  2. Or you can write a DEFMODIFY event in a linked module, and it will
  37. ;     replace this one entirely.  For example, create a file NEWMOD.E with
  38. ;     your defmodify proc; compile it separately (ETPM NEWMOD); add a link
  39. ;     statement (link 'newmod') to your MYKEYS.E or MYSTUFF.E file.
  40. ;
  41.  
  42. define
  43. compile if EVERSION >= '5.20'  -- 5.20 adds a HINI to the *Profile calls.
  44.    HINI_PARM = 'app_hini,'
  45. compile else
  46.    HINI_PARM = ' '
  47. compile endif
  48.  
  49.  
  50. compile if SHOW_MODIFY_METHOD = 'COLOR'
  51.  
  52. defmodify
  53.  compile if EPM
  54.    universal  appname, app_hini
  55.  compile else
  56.    universal comsfileid
  57.  compile endif
  58.    getfileid fileid
  59.    if .autosave and .modify>=.autosave then
  60.  compile if EPM
  61.       if leftstr(.filename,1,1) <> '.' | .filename = UNNAMED_FILE_NAME then
  62.   compile if EVERSION >= '5.50'
  63.          sayerror AUTOSAVING__MSG
  64.   compile else
  65.          sayatbox(AUTOSAVING__MSG)
  66.   compile endif
  67.  compile else
  68.       if fileid <> comsfileid & substr(.filename,1,1) <> '.' then
  69.  compile endif
  70.  compile if EVERSION >= '5.50'
  71.          'xcom save "'MakeTempName()'"'
  72.  compile else
  73.          'xcom save 'MakeTempName()
  74.  compile endif
  75.          .modify=1                  /* Reraise the modify flag. */
  76.  compile if EVERSION >= '5.50'
  77.          sayerror 0
  78.  compile endif
  79.       endif
  80.    endif
  81.  compile if EVERSION < 5
  82.    fids = fileidfromanchorblock(.anchorblock)  -- Get list of fileids
  83.    do while fids <> ''
  84.       parse value fids with fileid fids
  85.       if .modify then
  86.          fileid.markcolor  = MODIFIED_MARKCOLOR
  87.          fileid.windowcolor= MODIFIED_WINDOWCOLOR
  88.       else -- if .modify==0 then
  89.          fileid.markcolor  = MARKCOLOR
  90.          fileid.windowcolor= WINDOWCOLOR
  91.       endif
  92.    end  -- do while
  93.  compile else                   -- EPM
  94.    if .modify then
  95.       .markcolor= MODIFIED_MARKCOLOR
  96.       .textcolor= MODIFIED_WINDOWCOLOR
  97.    else -- if .modify==0 then
  98.       .markcolor= MARKCOLOR
  99.       .textcolor= TEXTCOLOR
  100.       newcmd=queryprofile( $HINI_PARM appname, INI_TEXTCOLOR)
  101.       if newcmd then .textcolor=newcmd endif
  102.       newcmd=queryprofile( $HINI_PARM appname, INI_MARKCOLOR)
  103.       if newcmd then .markcolor=newcmd endif
  104.    endif
  105.    refresh
  106.    repaint_window()
  107.  compile endif
  108. compile endif -- COLOR
  109.  
  110.  
  111. compile if SHOW_MODIFY_METHOD = 'TITLE'
  112.  compile if EVERSION >= 5
  113. const
  114.    -- This is what we'll append to the file title.
  115.   compile if not defined(SHOW_MODIFY_TEXT)   -- If user didn't define in MYCNF:
  116.    SHOW_MODIFY_TEXT = ' (mod)'
  117.   compile endif
  118.  
  119. defmodify
  120.    if .autosave and .modify>=.autosave then
  121.       getfileid fileid
  122.       if leftstr(.filename,1,1) <> '.' | .filename = UNNAMED_FILE_NAME then
  123.   compile if EVERSION >= '5.50'
  124.          sayerror AUTOSAVING__MSG
  125.   compile else
  126.          sayatbox(AUTOSAVING__MSG)
  127.   compile endif
  128.   compile if EVERSION >= '5.50'
  129.          'xcom save "'MakeTempName()'"'
  130.   compile else
  131.          'xcom save 'MakeTempName()
  132.   compile endif
  133.          .modify=1                  /* Reraise the modify flag. */
  134.   compile if EVERSION >= '5.50'
  135.           sayerror 0
  136.   compile elseif EPM
  137.          refresh
  138.          call repaint_window()
  139.   compile endif
  140.       endif
  141.    endif
  142.    settitletext(.filename) -- This procedure adds the SHOW_MODIFY_TEXT.
  143.  compile else   -- Not EPM
  144.    -- When the file is modified, change the color of the filename.
  145. defmodify
  146.    universal comsfileid
  147.    if .autosave and .modify>=.autosave then
  148.       getfileid fileid
  149.       if fileid <> comsfileid & substr(.filename,1,1) <> '.' then
  150.          'xcom save 'MakeTempName()
  151.          .modify=1                  /* Reraise the modify flag. */
  152.       endif
  153.    endif
  154.    fids = fileidfromanchorblock(.anchorblock)  -- Get list of fileids
  155.    do while fids <> ''
  156.       parse value fids with fileid fids
  157.       if .modify then
  158.          fileid.filenamecolor= MODIFIED_FILENAMECOLOR
  159.          fileid.monofilenamecolor= MODIFIED_MONOFILENAMECOLOR
  160.       else -- if .modify==0 then
  161.          fileid.filenamecolor= FILENAMECOLOR
  162.          fileid.monofilenamecolor= MONOFILENAMECOLOR
  163.       endif
  164.    end  -- do while
  165.  compile endif  -- not EPM
  166. compile endif  -- title
  167.  
  168.  
  169. compile if SHOW_MODIFY_METHOD = 'FKTEXTCOLOR'
  170. defmodify
  171.    universal comsfileid
  172.    if .autosave and .modify>=.autosave then
  173.       getfileid fileid
  174.       if fileid <> comsfileid & substr(.filename,1,1) <> '.' then
  175.          'xcom save 'MakeTempName()
  176.          .modify=1                  /* Reraise the modify flag. */
  177.       endif
  178.    endif
  179.    fids = fileidfromanchorblock(.anchorblock)  -- Get list of fileids
  180.    do while fids <> ''
  181.       parse value fids with fileid fids
  182.       if .modify then
  183.          fileid.functionkeytextcolor= MODIFIED_FKTEXTCOLOR
  184.       else -- if .modify==0 then
  185.          fileid.functionkeytextcolor= FUNCTIONKEYTEXTCOLOR
  186.       endif
  187.    end  -- do while
  188. compile endif  -- statuscolor
  189.  
  190.  
  191. compile if SHOW_MODIFY_METHOD = ''  -- No change in display, just do AUTOSAVE.
  192. defmodify
  193.  compile if not EPM
  194.    universal comsfileid
  195.  compile endif
  196.    if .autosave and .modify>=.autosave then
  197.       getfileid fileid
  198.  compile if EPM
  199.       if leftstr(.filename,1,1) <> '.' | .filename = UNNAMED_FILE_NAME then
  200.   compile if EVERSION >= '5.50'
  201.          sayerror AUTOSAVING__MSG
  202.   compile else
  203.          sayatbox(AUTOSAVING__MSG)
  204.   compile endif
  205.  compile else
  206.       if fileid <> comsfileid & substr(.filename,1,1) <> '.' then
  207.  compile endif
  208.   compile if EVERSION >= '5.50'
  209.          'xcom save "'MakeTempName()'"'
  210.   compile else
  211.          'xcom save 'MakeTempName()
  212.   compile endif
  213.          .modify=1                  /* Reraise the modify flag. */
  214.  compile if EVERSION >= '5.50'
  215.           sayerror 0
  216.  compile elseif EPM
  217.          refresh
  218.          call repaint_window()
  219.  compile endif
  220.       endif
  221.    endif
  222. compile endif  -- No display change.
  223.