home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epm603a.zip / EPMMAC2.ZIP / GROUPS.E < prev    next >
Text File  |  1994-07-29  |  7KB  |  197 lines

  1. ; Group.e, by Larry Margolis
  2. ;
  3. ; Defines a SaveGroup command which saves the contents of the edit ring
  4. ; as a group, and a LoadGroup command which reloads that group, positioning
  5. ; each file as it was when the SaveGroup was executed.  For OS/2 2.x users,
  6. ; optionally creates a desktop icon for the group.  EPM 6.0 can do this
  7. ; directly; users of other versions must extract the command file at the
  8. ; end and save it as a MAKEGRP.CMD in the PATH.
  9.  
  10. compile if not defined(SMALL)  -- If SMALL not defined, then being separately compiled
  11.  include 'stdconst.e'            -- (needed for MB_ constants)
  12.  define INCLUDING_FILE = 'GROUP.E'
  13. const
  14.    tryinclude 'MYCNF.E'        -- The user's configuration customizations.
  15.  
  16.  compile if not defined(SITE_CONFIG)
  17.     const SITE_CONFIG = 'SITECNF.E'
  18.  compile endif
  19.  compile if SITE_CONFIG
  20.     tryinclude SITE_CONFIG
  21.  compile endif
  22.  
  23. const
  24.  compile if not defined(NLS_LANGUAGE)
  25.    NLS_LANGUAGE = 'ENGLISH'
  26.  compile endif
  27. include NLS_LANGUAGE'.e'          -- Needed for UNNAMED_FILE_NAME
  28.  
  29. defmain
  30.    ''arg(1)
  31. compile endif  -- not defined(SMALL)
  32.  
  33. const
  34. compile if not defined(INCLUDE_DESKTOP_SUPPORT)
  35.    INCLUDE_DESKTOP_SUPPORT = 1
  36. compile endif
  37.    CO_FAILIFEXISTS    = 0
  38.    CO_REPLACEIFEXISTS = 1
  39.    CO_UPDATEIFEXISTS  = 2
  40.    GR_SAVE_PROMPT = 'Save edit ring as a group - optionally to the desktop.'
  41.    GR_SAVE_PROMPT2 = 'The names and cursor positions of all files loaded will be saved..'
  42.    GR_LOAD_PROMPT = 'Load a previously saved group.'
  43.  
  44. defc groups_actionlist
  45. universal ActionsList_FileID  -- This is the fileid that gets the line(s)
  46.  
  47. insertline '|group_savegroup|'GR_SAVE_PROMPT'  'GR_SAVE_PROMPT2'|groups|', ActionsList_FileID.last+1, ActionsList_FileID
  48. insertline '|group_loadgroup|'GR_LOAD_PROMPT'|groups|', ActionsList_FileID.last+1, ActionsList_FileID
  49.  
  50. defc group_savegroup
  51.    if arg(1) = 'S' then       -- button Selected
  52.       sayerror 0
  53.       'savegroup'
  54.    elseif arg(1) = 'I' then   -- button Initialized
  55.       display -8
  56.       sayerror GR_SAVE_PROMPT
  57.       display 8
  58.    elseif arg(1) = 'H' then   -- button Help
  59.       call winmessagebox(GROUPS__MSG, GR_SAVE_PROMPT, MB_OK + MB_INFORMATION + MB_MOVEABLE)
  60.    elseif arg(1) = 'E' then   -- button End
  61. ;;    sayerror 0
  62.    endif
  63.  
  64. defc group_loadgroup
  65.    if arg(1) = 'S' then       -- button Selected
  66.       sayerror 0
  67.       'loadgroup'
  68.    elseif arg(1) = 'I' then   -- button Initialized
  69.       display -8
  70.       sayerror GR_LOAD_PROMPT
  71.       display 8
  72.    elseif arg(1) = 'H' then   -- button Help
  73.       call winmessagebox(GROUPS__MSG, GR_LOAD_PROMPT, MB_OK + MB_INFORMATION + MB_MOVEABLE)
  74.    elseif arg(1) = 'E' then   -- button End
  75. ;;    sayerror 0
  76.    endif
  77.  
  78. compile if not defined(SMALL)  -- If being separately compiled separately, LOADGROUP command
  79.                                -- might not be known - execute via our DEFMAIN.
  80.    define loadgroup_cmd = 'groups loadgroup'
  81. compile else
  82.    define loadgroup_cmd = 'loadgroup'
  83. compile endif
  84.  
  85. defc savegroup =
  86.    universal app_hini
  87.    getfileid startfid
  88.    do i=1 to filesinring(1)  -- Provide an upper limit; prevent looping forever
  89.       if .filename=UNNAMED_FILE_NAME then
  90.          if .last<>1 or textline(1)<>'' then
  91.             activatefile startfid
  92.             sayerror 'An unnamed file exists in the ring; it must have a name to save the ring.'
  93.             return
  94.          endif
  95.       endif
  96.       next_file
  97.       getfileid curfile
  98.       if curfile = startfid then leave; endif
  99.    enddo  -- Loop through all files in ring
  100.  
  101.    group_name = arg(1)
  102.    if group_name='' then
  103.       group_name = entrybox('Group name')
  104.    endif
  105.    if group_name='' then
  106.       return
  107.    endif
  108.    tempstr = queryprofile( app_hini,  group_name, 'ENTRIES')
  109.    if tempstr<>'' then
  110.       if MBID_OK <> winmessagebox('Save Group', 'Group already exists.  OK to replace it?', 16417) then  -- MB_OKCANCEL + MB_ICONEXCLAMATION + MB_MOVEABLE
  111.          return
  112.       endif
  113.    endif
  114.  
  115.    do i=1 to filesinring(1)  -- Provide an upper limit; prevent looping forever
  116.       call setprofile(app_hini, group_name, 'FILE'i, .filename)
  117.       call setprofile(app_hini, group_name, 'POSN'i, .line .col .cursorx .cursory)
  118.       next_file
  119.       getfileid curfile
  120.       if curfile = startfid then leave; endif
  121.    enddo  -- Loop through all files in ring
  122.    call setprofile(app_hini, group_name, 'ENTRIES', i)
  123.  
  124.    if tempstr<>'' & tempstr>i then
  125.       do j = i+1 to tempstr
  126.          call setprofile(app_hini, group_name, 'FILE'j, '')
  127.          call setprofile(app_hini, group_name, 'POSN'j, '')
  128.       enddo
  129.    endif
  130. compile if INCLUDE_DESKTOP_SUPPORT -- Ask whether to include on Desktop?
  131.    if MBID_YES = winmessagebox('Save Group', 'Add a program object to the OS/2 desktop for this group?', 16404) then  -- MB_YESNO + MB_ICONQUESTION + MB_MOVEABLE
  132.       tib_ptr = 1234                /* 4-byte place to put a far pointer */
  133.       pib_ptr = 1234
  134.       call dynalink32('DOSCALLS',           /* dynamic link library name   */
  135.                     '#312',               /* ordinal value for DOS32GETINFOBLOCKS */
  136.                     address(tib_ptr) ||
  137.                     address(pib_ptr) )
  138. ;     sayerror 'tib_ptr =' c2x(tib_ptr) 'pib_ptr =' c2x(pib_ptr)
  139.       pib = peek(itoa(rightstr(pib_ptr,2),10), itoa(leftstr(pib_ptr,2),10), 28)
  140.       epm_cmd = peekz(substr(pib, 13, 4))
  141.  
  142.       class_name = "WPProgram"\0
  143.                       /* ^ = ASCII 94 = 'hat' */
  144.       title = "EPM Group:^"group_name\0
  145.       setup_string = "EXENAME="epm_cmd";PROGTYPE=PM;STARTUPDIR="directory()";PARAMETERS='"loadgroup_cmd group_name"';"\0
  146.       location = "<WP_DESKTOP>"\0
  147.       rc = 0
  148.       hobj=dynalink32('PMWP',           /* dynamic link library name   */
  149.                       '#281',           -- 'WinCreateObject'
  150.                       address(class_name)   ||
  151.                       address(title)        ||
  152.                       address(setup_string) ||
  153.                       address(location)     ||
  154.                       atol(CO_REPLACEIFEXISTS), 2)
  155. ;     if rc then hobj = hobj'; rc='rc '-' sayerrortext(rc); endif
  156. ;     sayerror 'hobject =' hobj
  157.       if not hobj then
  158.          sayerror 'Unable to create the program object in the Desktop folder'
  159.       endif
  160.    endif
  161. compile endif  -- INCLUDE_DESKTOP_SUPPORT
  162.  
  163. defc loadgroup =
  164.    universal app_hini
  165.    getfileid startfid
  166.    group_name = arg(1)
  167.    if group_name='' then
  168.       group_name = entrybox('Group name')
  169.    endif
  170.    if group_name='' then
  171.       return
  172.    endif
  173.    howmany = queryprofile( app_hini,  group_name, 'ENTRIES')
  174.    if howmany='' then
  175.       sayerror 'Group unknown.'
  176.       return
  177.    endif
  178.    do i=1 to howmany
  179.       display -8
  180.       sayerror 'Loading file' i 'of' howmany
  181.       display 8
  182.       this_file = queryprofile(app_hini, group_name, 'FILE'i)
  183.       if leftstr(this_file, 5)='.DOS ' then
  184.          subword(this_file, 2)  -- execute the command
  185.       elseif this_file=UNNAMED_FILE_NAME then
  186.          'xcom e /n'
  187.       else
  188.          'e' this_file
  189.       endif
  190.       if not rc | rc=sayerror('Lines truncated') then
  191.          call prestore_pos(queryprofile(app_hini, group_name, 'POSN'i))
  192.       endif
  193.    enddo
  194.    activatefile startfid
  195.    nextfile
  196.  
  197.