Consultor Eletrônico



Kbase P127042: How to implement deletion of the last word in editor widget using CTRL-BACKSPACE event
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   11/27/2007
Status: Unverified

GOAL:

How to implement deletion of the last word in editor widget using CTRL-BACKSPACE event

GOAL:

How to delete entire word while typing in editor widget using CTRL-BACKSPACE key

FACT(s) (Environment):

Windows
Progress 9.x
OpenEdge 10.x

FIX:

When typing text in regular editor widget, user might want to delete last word
using the CTRL-BACKSPACE. This feature can be implemented in the ABL using the
following steps:
1. Create a new window in the AppBuilder and drop the editor widget in the frame

2. Open the Section Editor and in the 'Definitions' section add the variable definition:

/* bFlag is used to remember if we pressed CTRL-BACKSPACE while in editor */
DEFINE VARIABLE bFlag AS LOGICAL NO-UNDO.

3. Change to 'Main' section in the Section Editor and add the following code:

/* Best default for GUI applications is... */
PAUSE 0 BEFORE-HIDE.
ON 'CTRL-BACKSPACE':U OF EDITOR-1
DO:
DEFINE VARIABLE lFlag AS LOGICAL NO-UNDO.
DEFINE VARIABLE i1 AS INTEGER NO-UNDO.
DEFINE VARIABLE i2 AS INTEGER NO-UNDO.
DEFINE VARIABLE i3 AS INTEGER NO-UNDO.
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DEFINE VARIABLE a AS CHARACTER NO-UNDO.
DEFINE VARIABLE b AS CHARACTER NO-UNDO.
DEFINE VARIABLE c AS CHARACTER NO-UNDO.

a = SELF:SCREEN-VALUE.

i1 = 1.
/* For the current position take into account number of current row in the editor */
i2 = SELF:CURSOR-OFFSET - (SELF:CURSOR-LINE - 1) .
/* Take the reminder of the string - from the current position to the end of the editor */
c = SUBSTR(SELF:SCREEN-VALUE,i2,LENGTH(SELF:SCREEN-VALUE)) .
/* We will start counting from one position less than the current offset */
i3 = i2 - 1 .
a = SUBSTR(SELF:SCREEN-VALUE,1,i3) .

/* Remember what was the line were we were */
i2 = SELF:CURSOR-LINE.

DO i = i3 TO 1 BY -1.
b = SUBSTR(SELF:SCREEN-VALUE,i,1).
/* We will set the flag only when we find the first non-empty character */
IF lFlag = FALSE AND b NE "" AND b NE " " AND ASC(b) NE -1 AND ASC(b) NE 10 AND ASC(b) NE 13 THEN DO:
lFlag = TRUE.
NEXT.
END.
/* If we already found the valid character and now we detected space, or linefeed then we exit */
IF lFlagG> AND (b = " " OR ASC(b) = 10) THEN DO:
i1 = i .
LEAVE.
END.
END.
/* We take all from beginning to the calculated position, plus the reminder */
SELF:SCREEN-VALUE = SUBSTR(SELF:SCREEN-VALUE, 1, i1) + c .
/* Adjust the cursor offset as we have to add number of newline characters */
SELF:CURSOR-OFFSET = i1 + i2 .
/* We set the bFlag to TRUE in order to use it in VALUE-CHANGED trigger were */
/* we remove the added CHR(127) as a consequence of editor's default action */
bFlag = TRUE.

END.

4. Add additional trigger for the editor widget 'VALUE-CHANGED' event using the Section Editor:

ON VALUE-CHANGED OF EDITOR-1 IN FRAME DEFAULT-FRAME
DO:
/* We define iPos so that we remember where to position the cursor */
DEFINE VARIABLE iPos AS INTEGER NO-UNDO.
/* If we came here as a consequence of pressing the CTRL-BACKSPACE, */
/* then bFLag is set to TRUE and LAST-EVENT:LABEL is "DEL" which is */
/* consequence of editor's widget default action */
IF bFlag AND LAST-EVENT:LABEL = "DEL" THEN DO:
/* let's remeber where we are ... */
iPos = SELF:CURSOR-OFFSET.
/* Remove the CHR(127) appended by the editor's widget default action */
SELF:SCREEN-VALUE = REPLACE(SELF:SCREEN-VALUE,CHR(127), "").
/* Decrement the cursor offset ... */
SELF:CURSOR-OFFSET = iPos - 1.
/* Reset bFlag to FALSE so that this code doesn't fire on a regular */
/* backspace, or delete event and finally return with no-apply. */
bFlag = FALSE.
RETURN NO-APPLY.
END.
END.

5. Check the syntax and save the code

Users entering the text in the editor widget can now delete entire word by pressing the CTRL-BACKSPACE..