source: trunk/src/netlabs/macros/groups.e@ 3434

Last change on this file since 3434 was 3434, checked in by Andreas Schnellbacher, 6 years ago
  • Renamed select hooks and commands to filesloaded and fileswitched.
  • Cosmetic changes.
  • Property svn:keywords set to Date Revision Author HeadURL Id
File size: 14.8 KB
Line 
1/****************************** Module Header *******************************
2*
3* Module Name: groups.e
4*
5* Copyright (c) Netlabs EPM Distribution Project 2002
6*
7* $Id: groups.e 3434 2019-01-29 18:18:48Z aschn $
8*
9* ===========================================================================
10*
11* This file is part of the Netlabs EPM Distribution package and is free
12* software. You can redistribute it and/or modify it under the terms of the
13* GNU General Public License as published by the Free Software
14* Foundation, in version 2 as it comes in the "COPYING" file of the
15* Netlabs EPM Distribution. This library is distributed in the hope that it
16* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
17* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18* General Public License for more details.
19*
20****************************************************************************/
21
22/*
23Todo:
24- Disable FilesLoaded until all files are loaded in loadgroup.
25*/
26
27; Groups.e, by Larry Margolis
28;
29; Defines a SaveGroup command which saves the contents of the edit ring
30; as a group, and a LoadGroup command which reloads that group, positioning
31; each file as it was when the SaveGroup was executed. For OS/2 2.x users,
32; optionally creates a desktop icon for the group. EPM 6.0 can do this
33; directly; users of other versions must extract the command file at the
34; end and save it as a MAKEGRP.CMD in the PATH.
35
36compile if not defined( SMALL) -- If compiled separately
37define
38 INCLUDING_FILE = 'GROUPS.E'
39
40 include 'stdconst.e'
41const
42 tryinclude 'mycnf.e'
43const
44 compile if not defined( NLS_LANGUAGE)
45 NLS_LANGUAGE = 'ENGLISH'
46 compile endif
47 include NLS_LANGUAGE'.e'
48
49defmain
50 ''arg( 1)
51compile endif
52
53; ---------------------------------------------------------------------------
54const
55; Ask to create a WPS object on the desktop?
56compile if not defined( INCLUDE_DESKTOP_SUPPORT)
57 INCLUDE_DESKTOP_SUPPORT = 1
58compile endif
59 CO_FAILIFEXISTS = 0
60 CO_REPLACEIFEXISTS = 1
61 CO_UPDATEIFEXISTS = 2
62 GROUPS__MSG = 'Groups' -- Messagebox title
63 GR_SAVE_PROMPT = 'Save edit ring as a group - optionally to the desktop'
64 GR_SAVE_PROMPT2 = 'The names and cursor positions of all files loaded will be saved'
65 GR_LOAD_PROMPT = 'Load a previously saved group'
66 GR_DELETE_PROMPT = 'OK to delete group:'
67 GR_NONE_FOUND = 'No saved groups found'
68
69; ---------------------------------------------------------------------------
70; Toolbar actions
71; ---------------------------------------------------------------------------
72defc Groups_ActionList
73universal ActionsList_FileID -- This is the fileid that gets the line(s)
74
75insertline '|group_savegroup|'GR_SAVE_PROMPT' 'GR_SAVE_PROMPT2'|groups|', ActionsList_FileID.last+1, ActionsList_FileID
76insertline '|group_loadgroup|'GR_LOAD_PROMPT'|groups|', ActionsList_FileID.last+1, ActionsList_FileID
77
78; ---------------------------------------------------------------------------
79defc Group_SaveGroup
80 parse arg action_letter parms
81 if action_letter = 'S' then -- button Selected
82 sayerror 0
83 'SaveGroup' parms
84 elseif action_letter = 'I' then -- button Initialized
85 'SayHint' GR_SAVE_PROMPT
86 elseif action_letter = 'H' then -- button Help
87 call WinMessageBox( GROUPS__MSG, GR_SAVE_PROMPT, MB_OK + MB_INFORMATION + MB_MOVEABLE)
88 elseif action_letter = 'E' then -- button End
89;; sayerror 0
90 endif
91
92; ---------------------------------------------------------------------------
93defc Group_LoadGroup
94 parse arg action_letter parms
95 if action_letter = 'S' then -- button Selected
96 sayerror 0
97 'LoadGroup' parms
98 elseif action_letter = 'I' then -- button Initialized
99 'SayHint' GR_LOAD_PROMPT
100 elseif action_letter = 'H' then -- button Help
101 call WinMessageBox( GROUPS__MSG, GR_LOAD_PROMPT, MB_OK + MB_INFORMATION + MB_MOVEABLE)
102 elseif action_letter = 'E' then -- button End
103;; sayerror 0
104 endif
105
106; ---------------------------------------------------------------------------
107define
108compile if not defined( SMALL) -- If being separately compiled separately, LOADGROUP command
109 -- might not be known - execute via our DEFMAIN.
110 loadgroup_cmd = 'groups LoadGroup'
111compile else
112 loadgroup_cmd = 'LoadGroup'
113compile endif
114
115defc SaveGroup
116 universal app_hini
117
118 KeyPath = '\NEPMD\User\Groups'
119
120 getfileid startfid
121 dprintf( 'RINGCMD', 'SaveGroup 1')
122 do i = 1 to filesinring( 1) -- Provide an upper limit; prevent looping forever
123 if .filename = GetUnnamedFilename() then
124 if .last <> 1 or textline( 1) <> '' then
125 activatefile startfid
126 sayerror 'An unnamed file exists in the ring;' ||
127 ' it must have a name to save the ring.'
128 return
129 endif
130 endif
131 next_file
132 getfileid curfid
133 if curfid = startfid then
134 leave
135 endif
136 enddo -- Loop through all files in ring
137
138 group_name = arg( 1)
139 if group_name = '' then
140 group_name = EntryBox( 'Group name')
141 endif
142 if group_name = '' then
143 return
144 endif
145 tempstr = QueryConfigKey( KeyPath'\'group_name'\Entries')
146 if tempstr <> '' then
147 if MBID_OK <> WinMessageBox( 'Save Group',
148 'Group already exists. OK to replace it?',
149 MB_OKCANCEL + MB_ICONEXCLAMATION + MB_MOVEABLE) then
150 return
151 endif
152 endif
153
154 -- Select next file, so that previous selected file will be the last one reloaded
155 next_file
156 getfileid firstfid
157 -- Write all FILEi and POSNi to EPM.INI
158 n = 0
159 dprintf( 'RINGCMD', 'SaveGroup 2')
160 do i = 1 to filesinring( 1) -- Provide an upper limit; prevent looping forever
161 Ignore = ((leftstr( .filename, 1) = '.') | (not .visible))
162 if not Ignore then
163 n = n + 1
164 WriteConfigKey( KeyPath'\'group_name'\File'n, .filename)
165 WriteConfigKey( KeyPath'\'group_name'\Posn'n, .line .col .cursorx .cursory)
166 endif
167 next_file
168 getfileid curfid
169 if curfid = firstfid then
170 leave
171 endif
172 enddo -- Loop through all files in ring
173 WriteConfigKey( KeyPath'\'group_name'\Entries', n)
174 activatefile startfid
175
176 -- Remove the rest
177 if (tempstr <> '') & (tempstr > i) then
178 do j = n + 1 to tempstr
179 DeleteConfigKey( KeyPath'\'group_name'\File'j)
180 DeleteConfigKey( KeyPath'\'group_name'\Posn'j)
181 enddo
182 endif
183
184compile if INCLUDE_DESKTOP_SUPPORT -- Ask whether to include on Desktop?
185 if MBID_YES = WinMessageBox( 'Save Group',
186 'Add a program object to the OS/2 desktop' ||
187 ' for this group?',
188 16404) then -- MB_YESNO + MB_ICONQUESTION + MB_MOVEABLE
189/*
190 tib_ptr = 1234 -- 4-byte place to put a far pointer
191 pib_ptr = 1234
192 call dynalink32( 'DOSCALLS', -- dynamic link library name
193 '#312', -- ordinal value for DOS32GETINFOBLOCKS
194 address( tib_ptr) ||
195 address( pib_ptr) )
196; sayerror 'tib_ptr =' c2x( tib_ptr) 'pib_ptr =' c2x( pib_ptr)
197 pib = peek( itoa( rightstr( pib_ptr, 2), 10),
198 itoa( leftstr( pib_ptr, 2), 10), 28)
199 epm_exe = peekz( substr( pib, 13, 4)) -- that's the EPM executable, but we need the loader
200*/
201 epm_exe = 'EPM.EXE' -- No path required
202 class_name = "WPProgram"\0
203 -- ^ = ASCII 94 = 'hat'
204 title = "EPM Group:^"group_name\0
205 setup_string = "EXENAME="epm_exe";" ||
206 "PROGTYPE=PM;" ||
207 "STARTUPDIR="directory()";" ||
208 "PARAMETERS='"loadgroup_cmd group_name"';"\0
209 location = "<WP_DESKTOP>"\0
210 rc = 0
211 hobj = dynalink32( 'PMWP', -- dynamic link library name
212 '#281', -- 'WinCreateObject'
213 address( class_name) ||
214 address( title) ||
215 address( setup_string) ||
216 address( location) ||
217 atol( CO_REPLACEIFEXISTS), 2)
218; if rc then hobj = hobj'; rc = 'rc '-' sayerrortext( rc); endif
219; sayerror 'hobject =' hobj
220 if not hobj then
221 sayerror 'Unable to create the program object on the Desktop'
222 endif
223 endif
224compile endif -- INCLUDE_DESKTOP_SUPPORT
225
226; ---------------------------------------------------------------------------
227defc LoadGroup
228 universal app_hini
229 universal nepmd_hini
230 universal CurEditCmd
231 KeyPath = '\NEPMD\User\Groups'
232
233 getfileid startfid
234 group_name = arg( 1)
235
236 if (group_name = '') | (group_name = '?') then
237/*
238 -- Entry box disabled. Always start with the list box now.
239 if group_name = '' then
240 parse value EntryBox( 'Specify a group name ',
241 '/'OK__MSG'/'LIST__MSG'/'Cancel__MSG'/',
242 '', '', 64, -- Entrytext, cols, maxchars
243 atoi( 1) ||
244 atoi( 0000) ||
245 GethWndC( APP_HANDLE)) with button 2 group_name \0
246 else
247*/
248 button = \2
249/*
250 endif
251*/
252
253 if button = \2 then -- User asked for a list
254 bufhndl = buffer( CREATEBUF, 'groups', MAXBUFSIZE, 1) -- Create a private buffer
255
256 -- Get first saved group name for testing only
257 next = ''
258 if not NepmdGetNextConfigKey( nepmd_hini, KeyPath, 'C', next) then
259 sayerror GR_NONE_FOUND
260 return
261 endif
262
263 -- Create a tmp file
264 'xcom e /c /q tempfile'
265 if rc <> -282 then -- sayerror( 'New file')
266 sayerror ERROR__MSG rc BAD_TMP_FILE__MSG sayerrortext( rc)
267 call buffer( FREEBUF, bufhndl)
268 return
269 endif
270 .autosave = 0
271 browse_mode = browse() -- query current state
272 if browse_mode then
273 call browse( 0)
274 endif
275
276 -- Get all saved group names and write them to the tmp file
277 do forever
278 insertline next, .last + 1
279 if not NepmdGetNextConfigKey( nepmd_hini, KeyPath, 'C', next) then
280 leave
281 endif
282 enddo
283
284 if .last > 2 then -- E always creates a file with an empty line
285 getfileid fileid
286 call Sort( 2, .last, 1, 40, fileid, 'I')
287 endif
288 if browse_mode then
289 call browse( 1)
290 endif -- restore browse state
291
292 if .last = 1 then
293 'xcom quit'
294 call WinMessageBox( GROUPS__MSG,
295 GR_NONE_FOUND,
296 MB_CANCEL + MB_ICONEXCLAMATION + MB_MOVEABLE)
297 return
298 endif
299
300 -- Fill buffer with and quit tmp file
301 if Listbox_Buffer_From_File( startfid, bufhndl, noflines, usedsize) then
302 return
303 endif
304 parse value ListBox( 'Select group name',
305 \0 || atol( usedsize) || atoi( 32) || atoi( bufhndl),
306 '/~Load/~Delete.../'Cancel__MSG, -- buttons
307 0, 0, -- 1, 35, -- row, col,
308 Min( noflines, 12), 0, -- height, width
309 GethWndC( APP_HANDLE) || atoi( 1) || atoi( 1) ||
310 atoi( 0000)) with button 2 group_name \0
311 call buffer( FREEBUF, bufhndl)
312
313 if button = \2 then -- 'Delete' selected
314 if MBID_OK <> WinMessageBox( GROUPS__MSG,
315 GR_DELETE_PROMPT\10 group_name,
316 MB_OKCANCEL + MB_QUERY + MB_MOVEABLE) then
317 return
318 endif
319 -- Delete KeyPath'\'group_name from nepmd_hini
320 -- Query all subpaths and delete them first
321 do forever
322 next2 = '' -- always restart the query, since list was changed by the deletion
323 if NepmdGetNextConfigKey( nepmd_hini, KeyPath'\'group_name, 'K', next2) then
324 DeleteConfigKey( KeyPath'\'group_name'\'next2)
325 else
326 leave
327 endif
328 enddo
329 -- Open list box again
330 'postme groups loadgroup ?'
331 return
332 endif -- button = \2 (Delete)
333 endif -- button = \2 (List)
334
335 if button <> \1 then
336 return
337 endif
338 endif
339
340 if group_name = '' then
341 return
342 endif
343
344 howmany = QueryConfigKey( KeyPath'\'group_name'\Entries')
345 if rc then
346 sayerror 'Group unknown'
347 return
348 endif
349 if howmany = '' then
350 sayerror 'Group unknown'
351 return
352 endif
353 do i = 1 to howmany
354 'SayHint Loading file' i 'of' howmany
355 this_file = QueryConfigKey( KeyPath'\'group_name'\File'i)
356
357 if leftstr( this_file, 5) = '.DOS ' then
358 subword( this_file, 2) -- execute the command
359 elseif this_file = GetUnnamedFilename() then
360 'xcom e /n'
361 else
362 'e "'this_file'"'
363 CurEditCmd = 'LOADGROUP' -- must follow the 'edit' cmd
364 endif
365 if not rc | rc = sayerror( 'Lines truncated') then
366 this_posn = QueryConfigKey( KeyPath'\'group_name'\Posn'i)
367 call pRestore_Pos( this_posn)
368 endif
369 enddo
370
371; ---------------------------------------------------------------------------
372defc ListGroups
373 universal nepmd_hini
374
375 KeyPath = '\NEPMD\User\Groups'
376 next = ''
377 Groups = ''
378 do while NepmdGetNextConfigKey( nepmd_hini, KeyPath, 'C', next)
379 if Groups = '' then
380 Groups = next
381 else
382 Groups = Groups next
383 endif
384 enddo
385 sayerror 'List of groups is:' groups
386
387; ---------------------------------------------------------------------------
388defc KillGroup
389 universal nepmd_hini
390
391 do once = 1 to 1
392
393 Group = arg( 1)
394 if Group = '' then
395 sayerror "Error: no group name specified."
396 leave
397 endif
398
399 KeyPath = '\NEPMD\User\Groups'
400 next = ''
401 if not NepmdGetNextConfigKey( nepmd_hini, KeyPath, 'C', next) then
402 sayerror "Error: group "Group" doesn't exist."
403 leave
404 endif
405
406 -- Delete KeyPath'\'group_name from nepmd_hini
407 -- Query all subpaths and delete them first
408 do forever
409 next2 = '' -- always restart the query, since list was changed by the deletion
410 if NepmdGetNextConfigKey( nepmd_hini, KeyPath'\'Group, 'K', next2) then
411 DeleteConfigKey( KeyPath'\'Group'\'next2)
412 else
413 leave
414 endif
415 enddo
416
417 enddo
418
Note: See TracBrowser for help on using the repository browser.