Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Problem with CL_GUI_TEXTEDIT

Former Member
0 Likes
1,759

I use class CL_GUI_TEXTEDIT to enter and edit some text,but also i need to provide some extra functions, for examle, guving possibility to surround selected text with tags <b> and </b>. The simpliest way to provide this - adding button with this handler:


      CALL METHOD G_TEXTEDITOR->GET_SELECTED_TEXTSTREAM
        IMPORTING
          SELECTED_TEXT = SELECTED.

      CONCATENATE '<b>' SELECTED '</b>' INTO SELECTED.

      CALL METHOD G_TEXTEDITOR->SET_SELECTED_TEXTSTREAM
        EXPORTING
          SELECTED_TEXT                 = SELECTED
          ENABLE_EDITING_PROTECTED_TEXT = CL_GUI_TEXTEDIT=>TRUE.

The problem is, that the first part take the selected text, but SET_SELECTED_TEXT running without any exceptions, but do nothing, text in my textedit doesn't change.

(excuse the code,i enter it from my home from memory)

Does anybody have any ideas?

Message was edited by: Aleksandr Bavbel

Message was edited by: Aleksandr Bavbel

Message was edited by: Aleksandr Bavbel

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,239

Please see the same program, create the MAIN gui status and put a button on the application toolbar, give fcode as "SWITCH". Then run the program, enter a few lines, select lines 2-4 and click switch button, you will see that the selected text is then wrapped with your tags.



report zrich_0001 .

data:
      dockingleft  type ref to cl_gui_docking_container,
      text_editor    type ref to cl_gui_textedit,
      repid type syrepid.

data: itext type table of tline-tdline,
      xtext type tline-tdline.

parameters: p_check.

initialization.

  repid = sy-repid.
  create object dockingleft
              exporting repid     = repid
                        dynnr     = sy-dynnr
                        side      = dockingleft->dock_at_left
                        extension = 1070.
  if text_editor is initial.
    create object text_editor
                exporting
                     parent     = dockingleft.

  endif.

  set pf-status 'MAIN'.

at selection-screen.


check  sy-ucomm = 'SWITCH'.

      call method text_editor->get_selected_text_as_r3table
                importing
                    table = itext
                exceptions
                    potential_data_loss = 1.

      xtext = '<b>'.   insert xtext into itext index 1.
      xtext = '</b>'.  append xtext to itext.


      call method text_editor->set_selected_text_as_r3table
              exporting table = itext.


Regards,

Rich Heilman

4 REPLIES 4
Read only

Former Member
0 Likes
1,239

Please check that your handler is working properly, because this problem ,I was facing same problem, I know that you want different method call but just refer my program it will definitely help you here is it:

My Top include is :

PROGRAM SAPMZABCC1 .

Data : ok_code like sy-ucomm,

save_ok like ok_code.

data :begin of zstr,

CLNT like THEAD-MANDT,

object like THEAD-TDOBJECT value 'ZSOB',

name like THEAD-TDNAME value '002',

ID like THEAD-TDID value 'I01',

LANG like THEAD-TDSPRAS value 'E',

end of zstr.

DATA: custom_container1 TYPE REF TO cl_gui_custom_container,

  • custom_container2 TYPE REF TO cl_gui_custom_container,

editor1 TYPE REF TO cl_gui_textedit.

  • editor2 TYPE REF TO cl_gui_textedit.

DATA : begin of tab occurs 0,

line(256) type C,

end of tab.

DATA : begin of tab1 occurs 0,

line(256) type C,

end of tab1.

DATA t_text LIKE TLINE OCCURS 0 WITH HEADER LINE.

DATA t1_text LIKE TLINE OCCURS 0 WITH HEADER LINE.

data t_head like THEAD .

data flag1.

data flag.

DATA : begin of tmp_tab occurs 0,

line(256) type C,

end of tmp_tab.

data len type i.

data line type i.

data : tmp_len type i,

tmplen type i.

class lcl_event definition.

public section.

class-methods : catch_dblclick for event dblclick of cl_gui_textedit importing sender.

endclass.

class lcl_event implementation.

method catch_dblclick.

CALL METHOD cl_gui_cfw=>set_new_ok_code

EXPORTING

new_code = 'SHOW'

.

endmethod.

endclass.

MY PBO is there:

MODULE status_0100 OUTPUT.

SET PF-STATUS 'ZPFSTAT'.

  • SET TITLEBAR 'xxx'.

t_head-tdobject = 'ZOBJ1'.

t_head-tdid = 'I01'.

t_head-tdname = '003'.

t_head-tdspras = 'E'.

IF editor1 IS INITIAL.

CREATE OBJECT custom_container1

EXPORTING

container_name = 'CONTAINER1'

.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

CREATE OBJECT editor1

EXPORTING

wordwrap_mode = 2

wordwrap_position = 72

wordwrap_to_linebreak_mode = 1

parent = custom_container1

EXCEPTIONS

error_cntl_create = 1

error_cntl_init = 2

error_cntl_link = 3

error_dp_create = 4

gui_type_not_supported = 5

others = 6

.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

DATA events TYPE cntl_simple_events.

DATA wa_events TYPE cntl_simple_event.

wa_events-eventid = cl_gui_textedit=>event_double_click.

wa_events-appl_event = space.

APPEND wa_events TO events.

CALL METHOD editor1->set_registered_events

EXPORTING

events = events

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

illegal_event_combination = 3

OTHERS = 4

.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

SET HANDLER lcl_event=>catch_dblclick FOR editor1.

CALL FUNCTION 'READ_TEXT'

EXPORTING

id = t_head-tdid

language = t_head-tdspras

name = t_head-tdname

object = t_head-tdobject

TABLES

lines = t_text

EXCEPTIONS

id = 1

language = 2

name = 3

not_found = 4

object = 5

reference_check = 6

wrong_access_to_archive = 7

OTHERS = 8.

IF sy-subrc <> 0.

CALL FUNCTION 'INIT_TEXT'

EXPORTING

id = t_head-tdid

language = t_head-tdspras

name = t_head-tdname

object = t_head-tdobject

TABLES

lines = t_text

EXCEPTIONS

ID = 1

LANGUAGE = 2

NAME = 3

OBJECT = 4

OTHERS = 5

.

else.

LOOP AT t_text.

tab-line = t_text-tdline.

APPEND tab.

ENDLOOP.

CONCATENATE sy-uname sy-datum sy-timlo INTO tmp_tab-line SEPARATED

BY space.

APPEND tmp_tab-line TO tab.

DESCRIBE TABLE tab LINES tmp_len. " old value

APPEND space TO tab.

DESCRIBE TABLE tab LINES tmplen. " newvalue

CALL METHOD editor1->set_text_as_r3table

EXPORTING

table = tab[]

EXCEPTIONS

error_dp = 1

error_dp_create = 2

OTHERS = 3

.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

CLEAR t_text.

REFRESH t_text.

CALL METHOD editor1->select_lines

EXPORTING

from_line = 1

to_line = tmp_len

EXCEPTIONS

error_cntl_call_method = 1

OTHERS = 2

.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

CALL METHOD editor1->protect_selection

EXPORTING

protect_mode = 1

.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

CALL METHOD editor1->select_lines

EXPORTING

from_line = tmplen

to_line = tmplen

.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

CALL METHOD editor1->protect_selection

EXPORTING

protect_mode = 0

.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

endif.

ENDIF.

ENDMODULE. " STATUS_0100 OUTPUT

My PAI is there:

save_ok = ok_code.

clear ok_code.

when 'SAVE'.

CALL METHOD EDITOR1->GET_TEXT_AS_R3TABLE

EXPORTING

ONLY_WHEN_MODDIFIED = 0

IMPORTING

TABLE = TAB1[].

WHEN 'SHOW'.

CALL METHOD EDITOR1->SET_TEXT_AS_R3TABLE

EXPORTING

TABLE = TAB[].

ENDCASE.

Try this there is concatenate i use for system user system time and system date.Please tell me whether it will help you or not.

Ankur Garg.

Message was edited by: Ankur Garg

Message was edited by: Ankur Garg

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,240

Please see the same program, create the MAIN gui status and put a button on the application toolbar, give fcode as "SWITCH". Then run the program, enter a few lines, select lines 2-4 and click switch button, you will see that the selected text is then wrapped with your tags.



report zrich_0001 .

data:
      dockingleft  type ref to cl_gui_docking_container,
      text_editor    type ref to cl_gui_textedit,
      repid type syrepid.

data: itext type table of tline-tdline,
      xtext type tline-tdline.

parameters: p_check.

initialization.

  repid = sy-repid.
  create object dockingleft
              exporting repid     = repid
                        dynnr     = sy-dynnr
                        side      = dockingleft->dock_at_left
                        extension = 1070.
  if text_editor is initial.
    create object text_editor
                exporting
                     parent     = dockingleft.

  endif.

  set pf-status 'MAIN'.

at selection-screen.


check  sy-ucomm = 'SWITCH'.

      call method text_editor->get_selected_text_as_r3table
                importing
                    table = itext
                exceptions
                    potential_data_loss = 1.

      xtext = '<b>'.   insert xtext into itext index 1.
      xtext = '</b>'.  append xtext to itext.


      call method text_editor->set_selected_text_as_r3table
              exporting table = itext.


Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,239

Thanks a lot, it solve the problem in some way. But with tags <b> it surround text with '/n'.

Read only

Former Member
0 Likes
1,239

The proper way is:


      DATA: ITEXT TYPE TABLE OF TLINE-TDLINE,
           XTEXT TYPE TLINE-TDLINE.

      CALL METHOD G_TEXTEDITOR->GET_SELECTED_TEXT_AS_R3TABLE
        IMPORTING
          TABLE               = ITEXT
        EXCEPTIONS
          POTENTIAL_DATA_LOSS = 1.

      READ TABLE ITEXT INTO XTEXT INDEX 1.
      CONCATENATE '<b>' XTEXT INTO XTEXT.
      MODIFY ITEXT FROM XTEXT INDEX 1.

      DESCRIBE TABLE ITEXT.

      READ TABLE ITEXT INTO XTEXT INDEX SY-TFILL.
      CONCATENATE XTEXT '</b>' INTO XTEXT.
      MODIFY ITEXT FROM XTEXT INDEX SY-TFILL.

      CALL METHOD G_TEXTEDITOR->SET_SELECTED_TEXT_AS_R3TABLE
        EXPORTING
          TABLE = ITEXT.