source: trunk/src/netlabs/macros/bookmark.e@ 2417

Last change on this file since 2417 was 2417, checked in by Andreas Schnellbacher, 14 years ago
  • Added svn keywords.
  • Property svn:keywords set to Date Revision Author HeadURL Id
File size: 31.2 KB
Line 
1/****************************** Module Header *******************************
2*
3* Module Name: bookmark.e
4*
5* Copyright (c) Netlabs EPM Distribution Project 2002
6*
7* $Id: bookmark.e 2417 2011-05-15 23:32:51Z 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; This file adds bookmark support to EPM. It can be linked in or included
22; in the base .ex file. WANT_ATTRIBUTE_SUPPORT must have been set when compiling
23; the base if this is to be linked in, because DEFLOAD and DEFC SAVE have hooks
24; to call routines defined herein.
25
26compile if not defined(SMALL) -- Being compiled separately
27include 'stdconst.e'
28 define INCLUDING_FILE = 'BOOKMARK.E'
29tryinclude 'MYCNF.E'
30 compile if not defined(SITE_CONFIG)
31 const SITE_CONFIG = 'SITECNF.E'
32 compile endif
33 compile if SITE_CONFIG
34 tryinclude SITE_CONFIG
35 compile endif
36 compile if not defined(NLS_LANGUAGE)
37 const NLS_LANGUAGE = 'ENGLISH'
38 compile endif
39include NLS_LANGUAGE'.e'
40compile endif
41
42const
43 COLOR_CLASS = 1
44 PAGEBREAK_CLASS = 6
45 BOOKMARK_CLASS = 13
46 STYLE_CLASS = 14
47 FONT_CLASS = 16
48 EAT_ASCII = \253\255 -- FFFD
49 EAT_MVST = \222\255 -- FFDE
50compile if not defined(INCLUDE_WORKFRAME_SUPPORT)
51 INCLUDE_WORKFRAME_SUPPORT = 1
52compile endif
53compile if not defined(COMPILER_ERROR_COLOR)
54 COMPILER_ERROR_COLOR = 244 -- red + whiteb = 4 + 240
55compile endif
56compile if not defined(NO_DUPLICATE_BOOKMARKS)
57 NO_DUPLICATE_BOOKMARKS = 0
58compile endif
59compile if not defined(SORT_BOOKMARKS)
60 SORT_BOOKMARKS = 0
61compile endif
62
63compile if 0 -- Menu now added in STDCTRL.E (standard EPM) or *MENU.E (NEPMD)
64definit
65 universal defaultmenu, activemenu
66 buildsubmenu defaultmenu, 29, 'Bookmarks', '', 0, 0
67 buildmenuitem defaultmenu, 29, 2901, '~Set...', 'setmark', 0, 0
68 buildmenuitem defaultmenu, 29, 2902, 'Set ~permanent...', 'setmarkp', 0, 0
69 buildmenuitem defaultmenu, 29, 2903, '~List...', 'listmark', 0, 0
70 buildmenuitem defaultmenu, 29, 2904, '~Delete...', 'listdeletebm', 0, 0
71 buildmenuitem defaultmenu, 29, 2905, \0, '', 4, 0
72 buildmenuitem defaultmenu, 29, 2906, 'Sa~ve BM as EA', 'saveattributes', 0, 0
73 buildmenuitem defaultmenu, 29, 2907, 'L~oad BM from EA', 'loadattributes', 0, 0
74 if activemenu=defaultmenu then
75 showmenu activemenu
76 endif
77compile endif
78
79defc bm, setmark
80 universal EPM_utility_array_ID
81 if .readonly then
82 sayerror READ_ONLY__MSG
83 return
84 endif
85 if browse() then
86 sayerror BROWSE_IS__MSG ON__MSG
87 return
88 endif
89 parse arg markname perm line col .
90 if not line then line = .line; endif
91 if not col then col = .col; endif
92 if not markname then -- Following uses a new dialog, so no NLS xlation
93 parse value entrybox( SETMARK__MSG,
94 '/'Set__MSG'/'Setp__MSG'/'Cancel__MSG'/'Help__MSG'/',
95 \0,
96 '',
97 200,
98 atoi(1) || atoi(6020) || gethwndc(APP_HANDLE) ||
99 SETMARK_PROMPT__MSG) with button 2 markname \0
100 if button = \0 | button = \3 then return; endif -- Esc or Cancel
101 perm = asc(button) + 2 --> temp is 3; perm is 4
102 if not markname then
103 sayerror NOTHING_ENTERED__MSG
104 return
105 endif
106 endif
107compile if NO_DUPLICATE_BOOKMARKS
108 rc = get_array_value( EPM_utility_array_ID, 'bmn.'markname, bmindex) -- Find that bookmark name
109 parse value bmindex with bmindex fid .
110 if not (rc | fid = '') then -- FID='' means previously deleted.
111 empty = ''
112 getfileid startid
113 display -2
114 activatefile fid
115 display 2
116 if rc then
117 do_array 2, EPM_utility_array_ID, 'bmi.'bmindex, empty -- Delete the name
118 else
119 line = 0; col = 1; offst = 0
120 do forever
121 class = BOOKMARK_CLASS
122 attribute_action 1, class, offst, col, line -- 1=FIND NEXT ATTR
123 if class = 0 then leave; endif
124 query_attribute class, val, IsPush, offst, col, line
125 if val=bmindex then -- Found!
126 leave
127 endif
128 enddo
129 if class then -- Was found
130 sayerror BM_ALREADY_EXISTS__MSG
131 return
132 endif
133 do_array 2, EPM_utility_array_ID, 'bmi.'bmindex, empty -- Delete the name
134 endif
135 endif
136compile endif -- NO_DUPLICATE_BOOKMARKS
137 do_array 3, EPM_utility_array_ID, 'bmi.0', bmcount -- Index says how many bookmarks there are
138 bmcount = bmcount + 1
139 do_array 2, EPM_utility_array_ID, 'bmi.0', bmcount -- Store back the new number
140 do_array 2, EPM_utility_array_ID, 'bmi.'bmcount, markname -- Store the new name at this index position
141 oldmod = .modify
142 if not isnum(perm) then perm = 3; endif
143 insert_attribute BOOKMARK_CLASS, bmcount, perm, 0, col, line
144 if perm = 4 then
145 call attribute_on(8) -- "Save attributes" flag
146 else
147 .modify = oldmod
148 endif
149 getfileid fid
150 bmcount = bmcount fid perm
151 do_array 2, EPM_utility_array_ID, 'bmn.'markname, bmcount -- Store the index & fileid under this name
152
153compile if INCLUDE_WORKFRAME_SUPPORT
154defc compiler_error
155 universal EPM_utility_array_ID
156 universal defaultmenu, activemenu
157 parse arg markname perm line col .
158 if not line then line = .line; endif
159 'bm' markname perm line col
160 color = COMPILER_ERROR_COLOR
161 oldmod = .modify
162 getfileid fid
163 Insert_Attribute_Pair( COLOR_CLASS, color, line, line, 1, length( textline( line)), fid)
164 .modify = oldmod
165 call attribute_on(1) -- Colors flag
166 if perm=16 then
167 if not attribute_on(16) then -- Was attribute 16 off?
168 'toggle_parse 0'
169 deletemenu defaultmenu, 6, 0, 0 -- Delete the Help menu
170 buildsubmenu defaultmenu, 16, COMPILER_BAR__MSG, COMPILER_BARP__MSG, 0, 0
171 buildmenuitem defaultmenu, 16, 1601, NEXT_COMPILER_MENU__MSG, 'nextbookmark N 16'NEXT_COMPILER_MENUP__MSG, 1, 0
172 buildmenuitem defaultmenu, 16, 1602, PREV_COMPILER_MENU__MSG, 'nextbookmark P 16'PREV_COMPILER_MENUP__MSG, 1, 0
173 buildmenuitem defaultmenu, 16, 1603, \0, '', 4, 0
174 buildmenuitem defaultmenu, 16, 1604, DESCRIBE_COMPILER_MENU__MSG, 'compiler_help'DESCRIBE_COMPILER_MENUP__MSG, 1, 0
175 buildmenuitem defaultmenu, 16, 1605, \0, '', 4, 0
176 buildmenuitem defaultmenu, 16, 1606, CLEAR_ERRORS_MENU__MSG, 'compiler_clear'CLEAR_ERRORS_MENUP__MSG, 1, 0
177 buildmenuitem defaultmenu, 16, 1607, END_DDE_SESSION_MENU__MSG, 'end_dde'END_DDE_SESSION_MENUP__MSG, 1, 0
178 buildmenuitem defaultmenu, 16, 1608, REMOVE_COMPILER_MENU__MSG, 'compiler_dropmenu'REMOVE_COMPILER_MENUP__MSG, 1, 0
179 call add_help_menu( defaultmenu, 1)
180 call maybe_show_menu()
181 endif -- "Added Compiler" flag
182 endif
183
184defc compiler_help
185 universal EPM_utility_array_ID
186 line = .line; col = 1; offst = -300
187 do forever
188 class = BOOKMARK_CLASS
189 attribute_action 1, class, offst, col, line -- 1=FIND NEXT ATTR
190 if class = 0 | line <> .line then
191 sayerror NO_COMPILER_ERROR__MSG
192 return
193 endif
194 query_attribute class, val, IsPush, offst, col, line
195 if IsPush <> 16 then iterate; endif -- If not a compiler error class, skip
196 call get_array_value( EPM_utility_array_ID, 'bmi.'val, markname) -- Get name for mark
197 if leftstr( markname, 9) <> 'WB_ERROR_' then iterate; endif -- ? Curious...
198 leave
199 enddo
200 parse value substr( markname, 10) with linenum '_' errornum
201 bufhndl = buffer( CREATEBUF, 'COMPILER', MAXBUFSIZE, 1) -- create a private buffer
202 if not bufhndl then
203 sayerror 'CREATEBUF' ERROR_NUMBER__MSG RC
204 return
205 endif
206 call windowmessage( 0, getpminfo(EPMINFO_EDITCLIENT), -- Post message to edit client
207 5444, -- get compiler error messages for this line
208 linenum,
209 mpfrom2short( bufhndl, 0))
210
211defc compiler_message
212 parse arg numlines bufsize emsgbuffer .
213 emsgbufptr = atol( emsgbuffer)
214 emsgbufseg = itoa( substr( emsgbufptr, 3), 10)
215 call listbox( DESCRIBE_ERROR__MSG,
216 \0 || atol(bufsize) || emsgbufptr || 7,
217 '/'DETAILS__MSG'/'Cancel__MSG'/'Help__MSG,
218 0, 0, -- 0, 1,
219 min( numlines, 12), 0,
220 gethwndc( APP_HANDLE) || atoi(1) || atoi(1) || atoi(6090) ||
221 SELECT_ERROR__MSG)
222 call buffer( FREEBUF, emsgbufseg)
223
224defc compiler_help_add
225 universal CurrentHLPFiles
226 hlpfile = upcase( word( arg(1), 1))
227 if not wordpos( hlpfile, upcase( CurrentHLPFiles)) then
228 hwndHelpInst = windowmessage( 1, getpminfo(APP_HANDLE),
229 5429, -- EPM_Edit_Query_Help_Instance
230 0,
231 0)
232 if hwndHelpInst == 0 then
233 -- there isn't a help instance deal with.
234 sayerror NO_HELP_INSTANCE__MSG
235 return
236 endif
237
238 newlist2 = CurrentHLPFiles hlpfile \0
239 retval = windowmessage( 1, hwndHelpInst,
240 557, -- HM_SET_HELP_LIBRARY_NAME
241 ltoa( offset( newlist2) || selector( newlist2), 10),
242 0)
243 if retval then
244 sayerror ERROR__MSG retval ERROR_ADDING_HELP__MSG hlpfile
245 -- revert to the previous version of the HLP list.
246 newlist2 = CurrentHLPFiles\0
247 retval2 = windowmessage( 1, hwndHelpInst,
248 557, -- HM_SET_HELP_LIBRARY_NAME
249 ltoa( offset( newlist2) || selector( newlist2), 10),
250 0)
251 if retval2 then
252 sayerror ERROR__MSG retval ERROR_REVERTING__MSG CurrentHLPFiles
253 endif
254 return
255 else
256 CurrentHLPFiles = CurrentHLPFiles hlpfile
257 endif
258 endif
259
260defc compiler_clear
261 universal EPM_utility_array_ID
262 line = 0; col = 1; offst = 0; empty = ''
263 oldmod = .modify
264 do forever
265 class = BOOKMARK_CLASS
266 attribute_action 1, class, offst, col, line -- 1=FIND NEXT ATTR
267 if class = 0 then leave; endif -- No more of that class
268 query_attribute class, val, IsPush, offst, col, line
269 if IsPush = 16 then
270 attribute_action 16, class, offst, col, line -- 16=Delete attribute
271 if not get_array_value( EPM_utility_array_ID, 'bmi.'val, markname) then -- Found that bookmark's name
272 display -2
273 do_array 2, EPM_utility_array_ID, 'bmi.'val, empty -- Delete the name
274 do_array 2, EPM_utility_array_ID, 'bmn.'markname, empty -- Delete the index
275 display 2
276 endif
277 class = COLOR_CLASS
278 offst = -300
279 col = 1
280 line2 = line
281 attribute_action 1, class, offst, col, line2 -- 1=FIND NEXT ATTR
282 if class=0 | line2<>line then iterate; endif -- No color class
283 query_attribute class, val, IsPush, offst, col, line
284 if val <> COMPILER_ERROR_COLOR then iterate; endif -- Not the right color
285 offst2 = offst; col2 = col
286 attribute_action 3, class, offst2, col2, line2 -- 3=FIND MATCH ATTR
287 if class then
288 attribute_action 16, class, offst2, col2, line2 -- 16=Delete attribute
289 endif
290 class = COLOR_CLASS
291 attribute_action 16, class, offst, col, line -- 16=Delete attribute
292 endif
293 enddo
294 .modify = oldmod
295
296defc compiler_dropmenu
297 universal defaultmenu, activemenu
298 deletemenu defaultmenu, 16, 0, 0
299 call maybe_show_menu()
300
301defc end_dde =
302 call windowmessage( 0, getpminfo(EPMINFO_EDITCLIENT), -- Post message to edit client
303 5501, -- EPM_EDIT_ENDWFDDE
304 0,
305 0)
306compile endif -- INCLUDE_WORKFRAME_SUPPORT
307
308defc setmarkp -- Following uses a new dialog, so no NLS xlation
309 markname = entrybox( SETMARK_PROMPT__MSG,
310 '/'Setp__MSG'/'Cancel__MSG,
311 \0,
312 '',
313 200)
314 if markname then
315 'setmark' markname 4
316 endif
317
318defc go, gomark
319 universal EPM_utility_array_ID
320 parse arg markname
321 if not markname then
322 sayerror NEED_BM_NAME__MSG; return
323 endif
324 rc = get_array_value( EPM_utility_array_ID, 'bmn.'markname, bmindex) -- Find that bookmark name
325 parse value bmindex with bmindex fid .
326 if rc | fid='' then -- FID = '' means previously deleted.
327 sayerror UNKNOWN_BOOKMARK__MSG
328 return
329 endif
330 empty = ''
331 display -2
332 activatefile fid
333 display 2
334 if rc then
335 do_array 2, EPM_utility_array_ID, 'bmi.'bmindex, empty -- Delete the name
336 do_array 2, EPM_utility_array_ID, 'bmn.'markname, empty -- Delete the index
337 sayerror FILE_GONE__MSG BM_DELETED__MSG
338 return
339 endif
340; call psave_pos(savepos)
341 line = 0; col = 1; offst = 0
342 do forever
343 class = BOOKMARK_CLASS
344 attribute_action 1, class, offst, col, line -- 1 = FIND NEXT ATTR
345 if class = 0 then leave; endif
346 query_attribute class, val, IsPush, offst, col, line
347 if val = bmindex then
348 .cursory = .windowheight % 2
349 line
350 .col = col
351 return
352 endif
353 enddo
354; call prestore_pos(savepos)
355 do_array 2, EPM_utility_array_ID, 'bmi.'bmindex, empty -- Delete the name
356 do_array 2, EPM_utility_array_ID, 'bmn.'markname, empty -- Delete the index
357 sayerror BM_NOT_FOUND__MSG ITS_DELETED__MSG
358
359defc listmark
360 universal EPM_utility_array_ID
361 do_array 3, EPM_utility_array_ID, 'bmi.0', bmcount -- Index says how many bookmarks there are
362 if bmcount = 0 then
363 sayerror NO_BOOKMARKS__MSG
364 return
365 endif
366 getfileid startfid
367 'xcom e /c bookmark'
368 if rc <> -282 then -- -282 = sayerror("New file")
369 sayerror ERROR__MSG rc BAD_TMP_FILE__MSG sayerrortext(rc)
370 return
371 endif
372 browse_mode = browse() -- query current state
373 if browse_mode then call browse(0); endif
374 .autosave = 0
375 getfileid bmfid
376 empty = ''
377 display -2
378 do i = 1 to bmcount
379 do_array 3, EPM_utility_array_ID, 'bmi.'i, markname -- Get name number i
380 if markname='' then iterate; endif -- has been deleted
381 -- Find that bookmark name
382 if get_array_value( EPM_utility_array_ID, 'bmn.'markname, bmindex) then -- Unexpected; ignore it & continue
383 iterate
384 endif
385 parse value bmindex with bmindex fid .
386 rc = 0
387 activatefile fid
388 if rc then -- The file's gone; don't show the bookmark.
389 do_array 2, EPM_utility_array_ID, 'bmi.'bmindex, empty -- Delete the name
390 do_array 2, EPM_utility_array_ID, 'bmn.'markname, empty -- Delete the index
391 iterate
392 endif
393 insertline markname, bmfid.last+1, bmfid
394 enddo
395 activatefile bmfid
396compile if SORT_BOOKMARKS
397 if .last > 2 then
398 call sort( 2, .last, 1, 40, bmfid, 'I')
399 endif
400compile endif -- SORT_BOOKMARKS
401 if browse_mode then call browse(1); endif -- restore browse state
402 display 2
403 if not .modify then -- Nothing added?
404 sayerror NO_BOOKMARKS__MSG
405 'xcom quit'
406 return
407 endif
408 if listbox_buffer_from_file( startfid, bufhndl, noflines, usedsize) then return; endif
409 parse value listbox( LIST_BOOKMARKS__MSG,
410 \0 || atol( usedsize) || atoi( 32) || atoi( bufhndl),
411 '/'GOMARK__MSG'/'DELETEMARK__MSG'/'Cancel__MSG'/'Help__MSG,
412 0, 0, -- 1, 5,
413 min( noflines, 12), 0,
414 gethwndc( APP_HANDLE) || atoi(1) || atoi(1) || atoi( 6030)) with button 2 markname \0
415 call buffer( FREEBUF, bufhndl)
416 if button = \1 then -- Go to
417 'gomark' markname
418 elseif button = \2 then
419 'deletebm' markname
420 endif
421
422defc deletebm
423 universal EPM_utility_array_ID
424 parse arg markname
425 if not markname then
426 sayerror NEED_BM_NAME__MSG; return
427 endif
428 if get_array_value(EPM_utility_array_ID, 'bmn.'markname, bmindex) then
429 sayerror UNKNOWN_BOOKMARK__MSG
430 return
431 endif
432 empty = ''
433 parse value bmindex with bmindex fid perm .
434 do_array 2, EPM_utility_array_ID, 'bmi.'bmindex, empty -- Delete the name
435 do_array 2, EPM_utility_array_ID, 'bmn.'markname, empty -- Delete the index
436;; call psave_pos(savepos)
437 sayerror BM_DELETED__MSG
438 getfileid startid
439 display -2
440 activatefile fid
441 display 2
442 if rc then -- File no longer in ring - all done.
443 return
444 endif
445 line = 0; col = 1; offst = 0
446 do forever
447 class = BOOKMARK_CLASS
448 attribute_action 1, class, offst, col, line -- 1=FIND NEXT ATTR
449 if class = 0 then leave; endif
450 query_attribute class, val, IsPush, offst, col, line
451 if val = bmindex then
452 oldmod = .modify
453 attribute_action 16, class, offst, col, line -- 16=Delete attribute
454 if perm <> 4 then .modify = oldmod; endif
455 leave
456 endif
457 enddo
458 activatefile startid
459
460defc deletebmclass
461 universal EPM_utility_array_ID
462 parse arg BMtype .
463 if BMtype='' then
464 sayerror NEED_BM_CLASS__MSG; return
465 endif
466 if BMtype=4 then
467 if askyesno(DELETE_PERM_BM__MSG) <> YES_CHAR then return; endif
468 endif
469 line=0; col=1; offst=0; empty = ''
470 oldmod = .modify
471 do forever
472 class = BOOKMARK_CLASS
473 attribute_action 1, class, offst, col, line -- 1=FIND NEXT ATTR
474 if class=0 then leave; endif -- No more of that class
475 query_attribute class, val, IsPush, offst, col, line
476 if IsPush=BMtype then
477 attribute_action 16, class, offst, col, line -- 16=Delete attribute
478 if not get_array_value(EPM_utility_array_ID, 'bmi.'val, markname) then -- Found that bookmark's name
479 display -2
480 do_array 2, EPM_utility_array_ID, 'bmi.'val, empty -- Delete the name
481 do_array 2, EPM_utility_array_ID, 'bmn.'markname, empty -- Delete the index
482 display 2
483 endif
484 endif
485 enddo
486 if BMtype<>4 then .modify=oldmod; endif
487
488; Dependencies: put_file_as_MVST()
489defc saveattributes
490 universal EPM_utility_array_ID
491 universal app_hini
492 universal default_font
493
494 getfileid start_fid
495 compiler_errors_on = (.levelofattributesupport bitand 16) <> 0
496;; call psave_pos(savepos)
497 'xcom e /c attrib'
498 if rc<>-282 then -- -282 = sayerror("New file")
499 sayerror ERROR__MSG rc BAD_TMP_FILE__MSG sayerrortext(rc)
500 return
501 endif
502 browse_mode = browse() -- query current state
503 if browse_mode then call browse(0); endif
504 .autosave = 0
505 getfileid attrib_fid
506 deleteline -- Delete the empty line
507;; activatefile start_fid
508 line=0; col=1; offst=0; found_font = 0
509 style_line=0; style_col=0; style_offst=0; style_list=''
510 do forever
511 class = 0 -- Find any class
512 attribute_action 1, class, offst, col, line, start_fid -- 1=FIND NEXT ATTR
513 if class=0 then leave; endif
514 query_attribute class, val, IsPush, offst, col, line, start_fid
515 l = line
516 if class=BOOKMARK_CLASS then -- get name
517 if IsPush<>4 then iterate; endif -- If not permanent, don't keep it.
518 do_array 3, EPM_utility_array_ID, 'bmi.'val, bmname -- Get the name
519 l = l bmname
520 elseif class=COLOR_CLASS then -- don't save if out of range
521;; if val>255 then iterate; endif
522 if line=style_line & col=style_col & (offst=style_offst+1 | offst=style_offst+2) then
523 iterate
524 endif
525compile if INCLUDE_WORKFRAME_SUPPORT
526 if compiler_errors_on & val=COMPILER_ERROR_COLOR then iterate; endif
527compile endif
528;; if line=style_line & col=style_col & offst=style_offst+2 then iterate; endif
529 elseif class=FONT_CLASS then -- get font info
530;; if val>255 then iterate; endif
531 if line=style_line & col=style_col & offst=style_offst+1 then iterate; endif
532 l = l queryfont(val)
533 found_font = 1
534 elseif class=STYLE_CLASS then -- get style info
535 do_array 3, EPM_utility_array_ID, 'si.'val, stylename -- Get the style name
536 style_line=line; style_col=col; style_offst=offst
537 l = l stylename
538 if val<256 & not pos(chr(val), style_list) then -- a style we haven't seen yet
539 if style_list='' then
540 'xcom e /c style'
541 if rc<>-282 then -- -282 = sayerror("New file")
542 sayerror ERROR__MSG rc BAD_TMP_FILE__MSG sayerrortext(rc)
543 if browse_mode then call browse(1); endif -- restore browse state
544 return
545 endif
546 .autosave = 0
547 getfileid style_fid
548 deleteline -- Delete the empty line
549 endif
550 style_list = style_list || chr(val)
551 insertline stylename || \0 || queryprofile(app_hini, 'Style', stylename), style_fid.last+1, style_fid
552 endif -- new style
553 endif -- class=STYLE_CLASS
554 insertline class val ispush offst col l, attrib_fid.last+1, attrib_fid
555 enddo
556 if found_font & .font <> default_font then
557 insertline FONT_CLASS .font 0 0 0 (-1) queryfont(start_fid.font), 1, attrib_fid -- Insert at beginning.
558 endif
559 put_result = put_file_as_MVST(attrib_fid, start_fid, 'EPM.ATTRIBUTES')
560 if style_list <> '' then
561 if not put_result then
562 call put_file_as_MVST(style_fid, start_fid, 'EPM.STYLES')
563 endif
564 style_fid.modify = 0
565 'xcom quit'
566 endif
567 attrib_fid.modify = 0
568 'xcom quit'
569 if browse_mode then call browse(1); endif -- restore browse state
570 if put_result then
571 stop
572 endif
573
574; Dependencies: find_ea() from EA.E
575defc loadattributes
576 universal EPM_utility_array_ID, app_hini, load_var
577 getfileid fid
578 oldmod = .modify
579 val = get_EAT_ASCII_value('EPM.TABS')
580 if val<>'' then
581 .tabs = val
582 load_var = load_var + 1 -- Flag that tabs were set via EA
583 endif
584 val = get_EAT_ASCII_value('EPM.MARGINS')
585 if val<>'' then
586 .margins = val
587 load_var = load_var + 2 -- Flag that margins were set via EA
588 endif
589 if find_ea('EPM.STYLES', ea_seg, ea_ofs, ea_ptr1, ea_ptr2, ea_len, ea_entrylen, ea_valuelen) then
590 val = peek(ea_seg, ea_ptr2,min(ea_valuelen,8))
591 if leftstr(val,2)=EAT_MVST & substr(val,7,2)=EAT_ASCII then
592 num = itoa(substr(val,5,2),10)
593 ea_ptr2 = ea_ptr2 + 8
594 do i=1 to num
595 len = itoa(peek(ea_seg, ea_ptr2, 2), 10)
596 parse value peek(ea_seg, ea_ptr2 + 2, len) with stylename \0 stylestuff
597 if queryprofile(app_hini, 'Style', stylename)='' then -- Don't have as a local style?
598 call setprofile(app_hini, 'Style', stylename, stylestuff) -- Add it.
599 endif
600 ea_ptr2 = ea_ptr2 + len + 2
601 enddo
602 endif
603 endif
604 need_colors=0; need_fonts=0
605 if find_ea('EPM.ATTRIBUTES', ea_seg, ea_ofs, ea_ptr1, ea_ptr2, ea_len, ea_entrylen, ea_valuelen) then
606 browse_mode = browse() -- Query current state
607 if browse_mode then call browse(0); endif -- Turn off, so we can insert attributes.
608 read_only = .readonly
609 .readonly = 0 -- ditto
610 val = peek(ea_seg, ea_ptr2,min(ea_valuelen,8))
611 if leftstr(val,2)=EAT_MVST & substr(val,7,2)=EAT_ASCII then
612 num = itoa(substr(val,5,2),10)
613 ea_ptr2 = ea_ptr2 + 8
614 do_array 3, EPM_utility_array_ID, 'bmi.0', bmcount -- Index says how many bookmarks there are
615 do_array 3, EPM_utility_array_ID, 'si.0', stylecount
616 fontsel=''; bg='' -- Initialize to simplify later test
617 do i=1 to num
618 len = itoa(peek(ea_seg, ea_ptr2, 2), 10)
619 parse value peek(ea_seg, ea_ptr2 + 2, len) with class val ispush offst col line rest
620 ea_ptr2 = ea_ptr2 + len + 2
621 if class=BOOKMARK_CLASS then -- get name
622 if not get_array_value(EPM_utility_array_ID, 'bmn.'rest, stuff) then -- See if we already had it
623 parse value stuff with oldindex oldfid .
624 if oldfid = fid then
625 'deletebm' rest
626 endif
627 endif
628 bmcount = bmcount + 1
629 do_array 2, EPM_utility_array_ID, 'bmi.'bmcount, rest -- Store the name at this index position
630 if IsPush < 2 then IsPush = 4; endif -- Update old-style bookmarks
631 stuff = bmcount fid IsPush -- flag as permanent
632 do_array 2, EPM_utility_array_ID, 'bmn.'rest, stuff -- Store the index & fileid under this name
633 val = bmcount -- Don't care what the old index was.
634 elseif class=COLOR_CLASS then
635 need_colors = 1
636 elseif class = FONT_CLASS then
637 parse value rest with fontname '.' fontsize '.' fontsel
638 if fontsel = '' then iterate; endif -- Bad value; discard it
639 val = registerfont( fontname, fontsize, fontsel) -- Throw away old value
640 if line = -1 then
641 .font = val
642 iterate
643 endif
644 need_fonts = 1
645 elseif class = STYLE_CLASS then -- Set style info
646 parse value rest with stylename .
647 stylestuff = queryprofile( app_hini, 'Style', stylename)
648 if stylestuff = '' then iterate; endif -- Shouldn't happen
649 parse value stylestuff with fontname '.' fontsize '.' fontsel '.' fg '.' bg
650 if get_array_value( EPM_utility_array_ID, 'sn.'stylename, val) then -- Don't have it; add:
651 stylecount = stylecount + 1 -- Increment index
652 do_array 2, EPM_utility_array_ID, 'si.'stylecount, stylename -- Save index.name
653 do_array 2, EPM_utility_array_ID, 'sn.'stylename, stylecount -- Save name.index
654 val = stylecount
655 endif
656 endif
657 insert_attribute class, val, ispush, 0, col, line
658 if class = STYLE_CLASS then -- Set style info
659 if fontsel <> '' then
660 fontid = registerfont( fontname, fontsize, fontsel)
661 if fontid <> .font then -- Only insert font change for style if different from base font.
662 insert_attribute FONT_CLASS, fontid, ispush, 0, col, line
663 need_fonts = 1
664 endif
665 endif
666 if bg <> '' then
667 insert_attribute COLOR_CLASS, bg * 16 + fg, ispush, 0, col, line
668 need_colors = 1
669 endif
670 endif -- class=STYLE_CLASS
671 enddo
672 do_array 2, EPM_utility_array_ID, 'bmi.0', bmcount -- Store back the new number
673 do_array 2, EPM_utility_array_ID, 'si.0', stylecount
674 if need_colors then
675 call attribute_on(1) -- Colors flag
676 endif
677 if need_fonts then
678 call attribute_on(4) -- Mixed fonts flag
679 endif
680 call attribute_on(8) -- "Save attributes" flag
681 else
682 sayerror UNEXPECTED_ATTRIB__MSG
683 endif
684 if browse_mode then call browse(1); endif -- Restore browse state
685 .readonly = read_only
686 endif -- 'EPM.ATTRIBUTES'
687 .modify = oldmod
688
689defc nextbookmark
690 parse arg next bmclass .
691 class = BOOKMARK_CLASS
692 col = .col; line = .line; offst = 0
693 if next = 'P' then col = col - 1; endif
694 do forever
695 attribute_action 1 + (next = 'P'), class, offst, col, line -- 1 = FIND NEXT ATTR; 2 = FIND PREV ATTR
696 if class = 0 then
697 sayerror BM_NOT_FOUND__MSG
698 return
699 endif
700 query_attribute class, val, IsPush, offst, col, line
701 if IsPush = bmclass | bmclass = '' then
702 .cursory = .windowheight % 2
703 line; .col = col
704 return
705 endif
706 enddo
707
708; The following routine will put the contents of the current file into the
709; .EAarea of another file as an MVST EAT_ASCII attribute. If the given
710; attribute name already exists, it will be replaced (not extended).
711; Dependencies: delete_ea()
712defproc put_file_as_MVST(source_fid, target_fid, ea_name)
713 getfileid start_fid
714 activatefile target_fid
715 call delete_ea(ea_name)
716 if not source_fid.last then -- If nothing to add,
717 activatefile start_fid
718 return -- we're all done.
719 endif
720 activatefile source_fid -- So filesize() will work
721 name_len = length(ea_name)
722 value_len = filesize() + 2 * .last + 8 -- Overhead: 2 bytes/rec length, + 2 bytes each EAT_MVST, codepage, numentries, EAT_ASCII
723 ea_len_incr = 5 + name_len + value_len -- Overhead: 1 flags, 1 len(name), 2 len(value), 1 null ASCIIZ terminator
724 -- +7 rather than +3 because previous calc didn't consider the length
725 -- of the length field.
726 ea_len_incr = ((ea_len_incr + 7)%4)*4; -- round up for long word multiples
727 if ea_len_incr>65535 then
728 call winmessagebox(LONG_EA_TITLE__MSG, LONG_EA__MSG, 16454) -- MB_CANCEL + MB_MOVEABLE + MB_CUACRITICAL
729 return 1
730 endif
731 if target_fid.eaarea then
732 ea_long = atol(target_fid.eaarea)
733 ea_seg = itoa(rightstr(ea_long,2),10)
734 ea_ofs = itoa(leftstr(ea_long,2),10)
735 ea_old_len = ltoa(peek(ea_seg, ea_ofs, 4),10)
736 if ea_old_len+ea_len_incr>65535 then
737 call winmessagebox(LONG_EA_TITLE__MSG, LONG_EA__MSG, 16454) -- MB_CANCEL + MB_MOVEABLE + MB_CUACRITICAL
738 return 1
739 endif
740 call dynalink32(E_DLL,
741 'myrealloc',
742 ea_long ||
743 atol(ea_old_len+ea_len_incr) ||
744 atol(0),
745 2)
746
747 r = 0
748
749 ea_ptr = ea_seg
750 else
751 ea_ptr = atol(dynalink32(E_DLL,
752 'mymalloc',
753 atol(ea_len_incr+4), 2))
754 ea_ptr = ltoa(substr(ea_ptr,3,2)\0\0,10)
755 r = -270 * (ea_ptr = 0)
756
757 ea_ofs = 0
758 ea_old_len = 4 -- Point past length field
759 endif
760
761 if r then sayerror ERROR__MSG r ALLOC_HALTED__MSG; stop; endif
762 activatefile target_fid
763 poke ea_ptr, ea_ofs, atol(ea_old_len+ea_len_incr)
764 ea_ofs = ea_ofs + ea_old_len
765 poke ea_ptr, ea_ofs , atol(ea_len_incr) -- Start of EA: flag byte
766 ea_ofs = ea_ofs + 4;
767 poke ea_ptr, ea_ofs , \0 -- Start of EA: flag byte
768 poke ea_ptr, ea_ofs+1, chr(name_len)
769 poke ea_ptr, ea_ofs+2, atoi(value_len)
770 poke ea_ptr, ea_ofs+4, ea_name
771 poke ea_ptr, ea_ofs+4+name_len, \0 -- Null byte after name
772 poke ea_ptr, ea_ofs+5+name_len, EAT_MVST
773 poke ea_ptr, ea_ofs+7+name_len, atoi(0) -- Code page
774 poke ea_ptr, ea_ofs+9+name_len, atoi(source_fid.last) -- NumEntries
775 poke ea_ptr, ea_ofs+11+name_len, EAT_ASCII -- Each entry is of type ASCII
776 ea_ofs = ea_ofs + 13 + name_len
777 do i=1 to source_fid.last
778 getline line, i, source_fid
779 poke ea_ptr, ea_ofs, atoi(length(line))
780 poke ea_ptr, ea_ofs+2, line
781 ea_ofs = ea_ofs + length(line) + 2
782 enddo
783 .eaarea = mpfrom2short(ea_ptr,0)
784 activatefile start_fid
785
Note: See TracBrowser for help on using the repository browser.