home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epm603b.zip / EPMMAC2.ZIP / GROUPS.E < prev    next >
Text File  |  1996-05-23  |  13KB  |  311 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 = 'GROUPS.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.    GROUPS__MSG =    'Groups'  -- Messagebox title
  41.    GR_SAVE_PROMPT = 'Save edit ring as a group - optionally to the desktop.'
  42.    GR_SAVE_PROMPT2 = 'The names and cursor positions of all files loaded will be saved..'
  43.    GR_LOAD_PROMPT = 'Load a previously saved group.'
  44.    GR_DELETE_PROMPT = 'OK to delete group:'
  45.    GR_NONE_FOUND = 'No saved groups found!'
  46.  
  47. defc groups_actionlist
  48. universal ActionsList_FileID  -- This is the fileid that gets the line(s)
  49.  
  50. insertline '|group_savegroup|'GR_SAVE_PROMPT'  'GR_SAVE_PROMPT2'|groups|', ActionsList_FileID.last+1, ActionsList_FileID
  51. insertline '|group_loadgroup|'GR_LOAD_PROMPT'|groups|', ActionsList_FileID.last+1, ActionsList_FileID
  52.  
  53. defc group_savegroup
  54.    parse arg action_letter parms
  55.    if action_letter = 'S' then       -- button Selected
  56.       sayerror 0
  57.       'savegroup' parms
  58.    elseif action_letter = 'I' then   -- button Initialized
  59.       display -8
  60.       sayerror GR_SAVE_PROMPT
  61.       display 8
  62.    elseif action_letter = 'H' then   -- button Help
  63.       call winmessagebox(GROUPS__MSG, GR_SAVE_PROMPT, MB_OK + MB_INFORMATION + MB_MOVEABLE)
  64.    elseif action_letter = 'E' then   -- button End
  65. ;;    sayerror 0
  66.    endif
  67.  
  68. defc group_loadgroup
  69.    parse arg action_letter parms
  70.    if action_letter = 'S' then       -- button Selected
  71.       sayerror 0
  72.       'loadgroup' parms
  73.    elseif action_letter = 'I' then   -- button Initialized
  74.       display -8
  75.       sayerror GR_LOAD_PROMPT
  76.       display 8
  77.    elseif action_letter = 'H' then   -- button Help
  78.       call winmessagebox(GROUPS__MSG, GR_LOAD_PROMPT, MB_OK + MB_INFORMATION + MB_MOVEABLE)
  79.    elseif action_letter = 'E' then   -- button End
  80. ;;    sayerror 0
  81.    endif
  82.  
  83. compile if not defined(SMALL)  -- If being separately compiled separately, LOADGROUP command
  84.                                -- might not be known - execute via our DEFMAIN.
  85.    define loadgroup_cmd = 'groups loadgroup'
  86. compile else
  87.    define loadgroup_cmd = 'loadgroup'
  88. compile endif
  89.  
  90. defc savegroup =
  91.    universal app_hini
  92.    getfileid startfid
  93.    do i=1 to filesinring(1)  -- Provide an upper limit; prevent looping forever
  94.       if .filename=UNNAMED_FILE_NAME then
  95.          if .last<>1 or textline(1)<>'' then
  96.             activatefile startfid
  97.             sayerror 'An unnamed file exists in the ring; it must have a name to save the ring.'
  98.             return
  99.          endif
  100.       endif
  101.       next_file
  102.       getfileid curfile
  103.       if curfile = startfid then leave; endif
  104.    enddo  -- Loop through all files in ring
  105.  
  106.    group_name = arg(1)
  107.    if group_name='' then
  108.       group_name = entrybox('Group name')
  109.    endif
  110.    if group_name='' then
  111.       return
  112.    endif
  113.    tempstr = queryprofile( app_hini,  group_name, 'ENTRIES')
  114.    if tempstr<>'' then
  115.       if MBID_OK <> winmessagebox('Save Group', 'Group already exists.  OK to replace it?', 16417) then  -- MB_OKCANCEL + MB_ICONEXCLAMATION + MB_MOVEABLE
  116.          return
  117.       endif
  118.    endif
  119.  
  120.    do i=1 to filesinring(1)  -- Provide an upper limit; prevent looping forever
  121.       call setprofile(app_hini, group_name, 'FILE'i, .filename)
  122.       call setprofile(app_hini, group_name, 'POSN'i, .line .col .cursorx .cursory)
  123.       next_file
  124.       getfileid curfile
  125.       if curfile = startfid then leave; endif
  126.    enddo  -- Loop through all files in ring
  127.    call setprofile(app_hini, group_name, 'ENTRIES', i)
  128.  
  129.    if tempstr<>'' & tempstr>i then
  130.       do j = i+1 to tempstr
  131.          call setprofile(app_hini, group_name, 'FILE'j, '')
  132.          call setprofile(app_hini, group_name, 'POSN'j, '')
  133.       enddo
  134.    endif
  135. compile if INCLUDE_DESKTOP_SUPPORT -- Ask whether to include on Desktop?
  136.    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
  137.       tib_ptr = 1234                /* 4-byte place to put a far pointer */
  138.       pib_ptr = 1234
  139.       call dynalink32('DOSCALLS',           /* dynamic link library name   */
  140.                     '#312',               /* ordinal value for DOS32GETINFOBLOCKS */
  141.                     address(tib_ptr) ||
  142.                     address(pib_ptr) )
  143. ;     sayerror 'tib_ptr =' c2x(tib_ptr) 'pib_ptr =' c2x(pib_ptr)
  144.       pib = peek(itoa(rightstr(pib_ptr,2),10), itoa(leftstr(pib_ptr,2),10), 28)
  145.       epm_cmd = peekz(substr(pib, 13, 4))
  146.  
  147.       class_name = "WPProgram"\0
  148.                       /* ^ = ASCII 94 = 'hat' */
  149.       title = "EPM Group:^"group_name\0
  150.       setup_string = "EXENAME="epm_cmd";PROGTYPE=PM;STARTUPDIR="directory()";PARAMETERS='"loadgroup_cmd group_name"';"\0
  151.       location = "<WP_DESKTOP>"\0
  152.       rc = 0
  153.       hobj=dynalink32('PMWP',           /* dynamic link library name   */
  154.                       '#281',           -- 'WinCreateObject'
  155.                       address(class_name)   ||
  156.                       address(title)        ||
  157.                       address(setup_string) ||
  158.                       address(location)     ||
  159.                       atol(CO_REPLACEIFEXISTS), 2)
  160. ;     if rc then hobj = hobj'; rc='rc '-' sayerrortext(rc); endif
  161. ;     sayerror 'hobject =' hobj
  162.       if not hobj then
  163.          sayerror 'Unable to create the program object in the Desktop folder'
  164.       endif
  165.    endif
  166. compile endif  -- INCLUDE_DESKTOP_SUPPORT
  167.  
  168. defc loadgroup =
  169.    universal app_hini
  170.    getfileid startfid
  171.    group_name = arg(1)
  172.    if group_name='' | group_name='?' then
  173.       if group_name='' then
  174.          parse value entrybox('Group name',
  175.                               '/'OK__MSG'/'LIST__MSG'/'Cancel__MSG'/',
  176.                               '', '', 64,                -- Entrytext, cols, maxchars
  177.                               atoi(1) || atoi(0000) || gethwndc(APP_HANDLE)) with button 2 group_name \0
  178.       else
  179.          button=\2
  180.       endif
  181.       if button=\2 then -- User asked for a list
  182.          bufhndl = buffer(CREATEBUF, 'groups', MAXBUFSIZE, 1 )  -- Create a private buffer
  183. compile if EPM32
  184.          retlen = \0\0\0\0
  185.          l = dynalink32('PMSHAPI',
  186.                         '#115',               -- PRF32QUERYPROFILESTRING
  187.                         atol(app_hini)    ||  -- HINI_PROFILE
  188.                         atol(0)           ||  -- Application name is NULL; returns all apps
  189.                         atol(0)           ||  -- Key name
  190.                         atol(0)           ||  -- Default return string is NULL
  191.                         atoi(0) || atoi(bufhndl)  ||  -- pointer to returned string buffer
  192.                         atol(65535)       ||       -- max length of returned string
  193.                         address(retlen), 2)         -- length of returned string
  194. compile else
  195.          l =  dynalink( 'PMSHAPI',
  196.                         'PRFQUERYPROFILESTRING',
  197.                         atol_swap(app_hini) ||  -- HINI_PROFILE
  198.                         atol(0)             ||  -- Application name is NULL; returns all apps
  199.                         atol(0)             ||  -- Key name is NULL; returns all keys
  200.                         atol(0)             ||  -- Default return string is NULL
  201.                         address(inidata)    ||  -- pointer to returned string buffer
  202.                         atoi(bufhndl) || atoi(0)  ||  -- pointer to returned string buffer
  203.                         atol_swap(65535), 2)        -- max length of returned string
  204. compile endif
  205.          poke bufhndl, 65535, \0
  206.          if not l then sayerror 'Nothing in .INI file???'; return; endif
  207.          getfileid startfid
  208.          'xcom e /c /q tempfile'
  209.          if rc<>-282 then  -- sayerror('New file')
  210.             sayerror ERROR__MSG rc BAD_TMP_FILE__MSG sayerrortext(rc)
  211.             call buffer(FREEBUF, bufhndl)
  212.             return
  213.          endif
  214.          .autosave = 0
  215.          browse_mode = browse()     -- query current state
  216.          if browse_mode then call browse(0); endif
  217.          buf_ofs = 0
  218.          do while buf_ofs < l
  219.             this_group = peekz(bufhndl, buf_ofs)
  220.             entries = queryprofile(app_hini, this_group, 'ENTRIES')
  221.             if entries <> '' then
  222.                insertline this_group, .last+1
  223.             endif
  224.             buf_ofs = buf_ofs + length(this_group) + 1
  225.          enddo
  226.          call buffer(FREEBUF, bufhndl)
  227.          if .last>2 then
  228.             getfileid fileid
  229.             call sort(2, .last, 1, 40, fileid, 'I')
  230.          endif
  231.          if browse_mode then call browse(1); endif  -- restore browse state
  232.          if .last=1 then
  233.             'xcom quit'
  234.             call winmessagebox(GROUPS__MSG, GR_NONE_FOUND, MB_CANCEL + MB_ICONEXCLAMATION + MB_MOVEABLE)
  235.             return
  236.          endif
  237.  
  238.          if listbox_buffer_from_file(startfid, bufhndl, noflines, usedsize) then return; endif
  239. compile if EPM32
  240.          parse value listbox('Select group name', \0 || atol(usedsize) || atoi(32) || atoi(bufhndl),
  241. compile else
  242.          parse value listbox('Select group name', \0 || atoi(usedsize) || atoi(bufhndl) || atoi(32),
  243. compile endif
  244.                                    '/~Load/~Delete.../'Cancel__MSG, 1, 35, min(noflines,12), 0,   -- Buttons, row, col, height, width
  245.   compile if EVERSION >= 5.60
  246.                                    gethwndc(APP_HANDLE) || atoi(1) || atoi(1) || atoi(0000)) with button 2 group_name \0
  247.   compile else
  248.                                    atoi(1) || atoi(1) || atoi(0000) || gethwndc(APP_HANDLE)) with button 2 group_name \0
  249.   compile endif
  250.          call buffer(FREEBUF, bufhndl)
  251.          if button=\2 then -- 'Delete' selected
  252.             if MBID_OK <> winmessagebox(GROUPS__MSG, GR_DELETE_PROMPT\10 group_name, MB_OKCANCEL + MB_QUERY + MB_MOVEABLE) then
  253.                return
  254.             endif
  255.             call setprofile( app_hini, group_name, '', '')
  256.          endif
  257.       endif  -- button = \2
  258.       if button <> \1 then
  259.          return
  260.       endif
  261.    endif
  262.    if group_name='' then
  263.       return
  264.    endif
  265.    howmany = queryprofile( app_hini,  group_name, 'ENTRIES')
  266.    if howmany='' then
  267.       sayerror 'Group unknown.'
  268.       return
  269.    endif
  270.    do i=1 to howmany
  271.       display -8
  272.       sayerror 'Loading file' i 'of' howmany
  273.       display 8
  274.       this_file = queryprofile(app_hini, group_name, 'FILE'i)
  275.       if leftstr(this_file, 5)='.DOS ' then
  276.          subword(this_file, 2)  -- execute the command
  277.       elseif this_file=UNNAMED_FILE_NAME then
  278.          'xcom e /n'
  279.       else
  280.          'e "'this_file'"'
  281.       endif
  282.       if not rc | rc=sayerror('Lines truncated') then
  283.          call prestore_pos(queryprofile(app_hini, group_name, 'POSN'i))
  284.       endif
  285.    enddo
  286.    activatefile startfid
  287.    nextfile
  288.  
  289. defc listgroups =
  290.    universal app_hini
  291.    groups = ''
  292.    applications = queryprofile(app_hini, '', '')
  293.    do while applications <> ''
  294.       parse value applications with app \0 applications
  295.       group_entries =  queryprofile(app_hini, app, 'ENTRIES')
  296.       if group_entries<>'' then
  297.          groups = groups app
  298.       endif
  299.    enddo
  300.    sayerror 'List of groups is:' groups
  301.  
  302. defc killgroup =
  303.    universal app_hini
  304.    parse arg group
  305.    group_entries =  queryprofile(app_hini, group, 'ENTRIES')
  306.    if group_entries='' then  -- Make sure we don't delete something important!
  307.       sayerror 'Not a group.'
  308.       return
  309.    endif
  310.    call setprofile(app_hini, group, '', '')  -- Delete the entire application
  311.