(large) Editor:screen-value

daynemay

New Member
Hi all,

I am working on some custom behaviours for the Procedure Editor (e.g. pressing CTRL-SHIFT-X will run a COMPILE XREF on the current file; if the cursor is on a file-name, pressing F5 will open that file; etc).

For a lot of these behaviours, it is useful for me to obtain the text on the nth line of the editor. I have written a program to return this. In essence, this program will return

ENTRY ( n, EDITOR:SCREEN-VALUE, CHR(10) )

which works a treat.

However... (there's always a "however")

A number of the programs that I work on are ridiculously large (max: around 280 KB*). When I try to reference EDITOR:SCREEN-VALUE under these circumstances, I get a bit of "DITEM is not large enough to hold strong. (4043)".

I've seen it suggested elsewhere on progresstalk** to use EDITOR:INPUT-VALUE, but the results are exactly the same.

I have tried using EDITOR:SAVE-FILE () to write the contents of the editor to a temporary file, then IMPORTing n lines, but this is much too slow.

I've also tried using the EDITOR:SET-SELECTION(), EDITOR:EDIT-COPY() and the CLIPBOARD handle, but with no real success.

Any suggestions?

Thanks in advance.

Dayne

* Admittedly, this one is a .w, and so in all likelihood I would be working on it in the Section Editor, which would circumvent this problem. But the general problem still holds.

** And now I can't find it regardless of how hard I search - apologies
 

curly

New Member
Hi Dayne,

Try this:

define stream st1.
define variable iOffset as integer no-undo.
define variable cLine as character no-undo.

...

iOffset = editor:convert-to-offset(iLine,1).
editor:save-file(cTmpFile).

input stream st1 from value(cTmpFile).
seek stream st1 to iOffset.
import stream st1 unformatted cLine.

...
It is still using an external temporary file :mad: however 'seek' should give you reasonable performance :eek: ...

Regards,
Marian
 

daynemay

New Member
Hi Marian,

Thanks very much for this. It looks promising...

...although http://www.peg.com/lists/peg/history/200512/msg00004.html says that EDITOR:CONVERT-TO-OFFSET () and EDITOR:CURSOR-OFFSET attribute (among others) aren't available if EDITOR:LARGE.

My experience seems to confirm this:

- EDITOR:CONVERT-TO-OFFSET (40, 13) = 13
- if I MESSAGE EDITOR:CURSOR-OFFSET in an ANY-KEY trigger, I get some weird constant (constant for a given EDITOR widget, that is).

Believe me, I'm not being annoying on purpose. Thanks very much for the tip about SEEK - I look forward to being able to use it.
 

bulklodd

Member
How about the following function which returns the nth string

Code:
FUNCTION GetEditorString RETURNS CHARACTER (iEditor   AS HANDLE,
                                            iLine     AS INTEGER):
   DEFINE VARIABLE pos AS INTEGER    NO-UNDO.
   DEFINE VARIABLE str AS CHARACTER  NO-UNDO.
   
   iEditor:CLEAR-SELECTION().
   iEditor:CURSOR-LINE = iLine.
   iEditor:CURSOR-CHAR = 1.
   pos = iEditor:CURSOR-OFFSET.
   iEditor:CURSOR-LINE = iEditor:CURSOR-LINE + 1 NO-ERROR.
   iEditor:SET-SELECTION(pos,IF pos = iEditor:CURSOR-OFFSET THEN -1 ELSE iEditor:CURSOR-OFFSET).
   str = TRIM(iEditor:SELECTION-TEXT,"~n").
   iEditor:CLEAR-SELECTION().
   RETURN str.
END FUNCTION.
 

daynemay

New Member
Thanks very much for this (FUNCTION GetEditorString() ).

Unfortunately, my problems with CURSOR-OFFSET seem to apply here as well. As I said to Marian above, I'm not being annoying on purpose...

All the help is much appreciated.

Dayne
 

bulklodd

Member
Oh sorry, I missed you want a line from the procedure editor!

In that case the improved version of GetEditorString will help you

Code:
FUNCTION GetEditorString RETURNS CHARACTER (iEditor   AS HANDLE,
                                            iLine     AS INTEGER):
   DEFINE VARIABLE str AS CHARACTER  NO-UNDO.
 
   iEditor:CURSOR-LINE = iLine.
   iEditor:CURSOR-CHAR = 1.
   iEditor:SOURCE-COMMAND("select_line","").
   str = iEditor:SELECTION-TEXT.
   iEditor:SOURCE-COMMAND("deselect","").
   RETURN str.
END FUNCTION.
 

Casper

ProgressTalk.com Moderator
Staff member
Allrighty, call me a fool, but this is the first time I've seen source-command method. Where can I find documentation on this? Can't seem to find it in my online help nor the Progress 4GL Handbook (9.1D, 10.0B and 10.1A).

My compiler seems to be fine with it though :)

Casper.
 

daynemay

New Member
Oh sorry, I missed you want a line from the procedure editor!

In that case the improved version of GetEditorString will help you

Code:
FUNCTION GetEditorString RETURNS CHARACTER (iEditor   AS HANDLE,
                                            iLine     AS INTEGER):
   DEFINE VARIABLE str AS CHARACTER  NO-UNDO.
 
   iEditor:CURSOR-LINE = iLine.
   iEditor:CURSOR-CHAR = 1.
   iEditor:SOURCE-COMMAND("select_line","").
   str = iEditor:SELECTION-TEXT.
   iEditor:SOURCE-COMMAND("deselect","").
   RETURN str.
END FUNCTION.
Bulklodd,

That seems to be doing the trick nicely. Thanks very much for that.

Dayne
 
Top