2007 Feb 13 3:22 PM
Hello all,
I need to develop a custom context menu in the Text Editor.
I am using the <b>CONTEXT_MENU</b> event of the class
<b>CL_GUI_TEXTEDIT </b>for the same.
It is giving a short dump with an exception 'empty_obj' in the method
<b>CL_CTXMNU_MGR=>CREATE_PROXY</b>.
Please help.
2007 Feb 14 4:36 AM
Hello Tejas
The following sample report ZUS_SDN_TEXTEDIT_CTXMENU shows how to trigger context menus in text editor. Please note that the editor must be set <b>enabled</b>.
If you inactivate subroutine <b>SET_REGISTERED_EVENTS</b> the new context menu function will no be displayed. Thus you need to <b>register</b> the event for context menu handling.
*&---------------------------------------------------------------------*
*& Report ZUS_SDN_TEXTEDIT_CTXMENU
*&
*&---------------------------------------------------------------------*
*&
*& Flow logic of screen 100.
* PROCESS BEFORE OUTPUT.
* MODULE STATUS_0100.
**
* PROCESS AFTER INPUT.
* MODULE USER_COMMAND_0100.
*&---------------------------------------------------------------------*
REPORT ZUS_SDN_TEXTEDIT_CTXMENU.
TYPE-POOLS: cntl. " Types for Controls
DATA:
gd_okcode TYPE ui_func,
go_docking TYPE REF TO cl_gui_docking_container,
go_textedit TYPE REF TO cl_gui_textedit,
*
gd_name TYPE thead-tdname,
gs_header TYPE thead,
gd_langu TYPE thead-tdspras,
gt_lines TYPE STANDARD TABLE OF tline.
*---------------------------------------------------------------------*
* CLASS lcl_eventhandler DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
handle_context_menu
FOR EVENT context_menu OF cl_gui_textedit
IMPORTING
menu
sender,
handle_ctxmenu_selected
FOR EVENT context_menu_selected OF cl_gui_textedit
IMPORTING
fcode
sender.
ENDCLASS. "lcl_eventhandler DEFINITION
*---------------------------------------------------------------------*
* CLASS lcl_eventhandler IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler IMPLEMENTATION.
METHOD handle_context_menu.
CALL METHOD menu->add_function
EXPORTING
fcode = 'MY_FUNC'
text = 'My Function'
* ICON =
* FTYPE =
* DISABLED =
* HIDDEN =
* CHECKED =
* ACCELERATOR =
.
ENDMETHOD. "handle_context_menu
METHOD handle_ctxmenu_selected.
CASE fcode.
WHEN 'MY_FUNC'.
MESSAGE 'My function selected from ctxmenu' TYPE 'I'.
WHEN OTHERS.
ENDCASE.
ENDMETHOD. "handle_ctxmenu_selected
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
PARAMETERS:
p_pspnr TYPE prps-pspnr.
START-OF-SELECTION.
* Get the text object
gs_header-tdid = 'LTXT'. " long text
gs_header-tdspras = syst-langu.
CONCATENATE syst-langu p_pspnr
INTO gs_header-tdname.
gs_header-tdobject = 'PMS'.
CALL FUNCTION 'READ_TEXT'
EXPORTING
* CLIENT = SY-MANDT
id = gs_header-tdid
language = gs_header-tdspras
name = gs_header-tdname
object = gs_header-tdobject
* ARCHIVE_HANDLE = 0
* LOCAL_CAT = ' '
* IMPORTING
* HEADER =
TABLES
lines = gt_lines
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.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL SCREEN '0100'.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form SET_REGISTERED_EVENTS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM
set_registered_events .
* define local data
DATA:
lt_events TYPE cntl_simple_events,
ls_event TYPE cntl_simple_event.
TYPES: BEGIN OF cntl_simple_event,
eventid TYPE i,
appl_event TYPE c,
END OF cntl_simple_event.
ls_event-eventid = cl_gui_textedit=>event_context_menu.
APPEND ls_event TO lt_events.
ls_event-eventid = cl_gui_textedit=>event_context_menu_selected.
APPEND ls_event TO lt_events.
CALL METHOD go_textedit->set_registered_events
EXPORTING
events = lt_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.
ENDFORM. " SET_REGISTERED_EVENTS
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'MAIN_0100'.
* SET TITLEBAR 'xxx'.
CLEAR: gd_okcode.
IF ( go_textedit IS NOT BOUND ).
CREATE OBJECT go_docking
EXPORTING
parent = cl_gui_container=>screen0
* REPID =
* DYNNR =
* SIDE = DOCK_AT_LEFT
* EXTENSION = 50
* STYLE =
* LIFETIME = lifetime_default
* CAPTION =
* METRIC = 0
ratio = 90
* NO_AUTODEF_PROGID_DYNNR =
* NAME =
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 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.
CREATE OBJECT go_textedit
EXPORTING
* MAX_NUMBER_CHARS =
* STYLE = 0
wordwrap_mode =
c_textedit_control=>wordwrap_at_windowborder
* WORDWRAP_POSITION =
wordwrap_to_linebreak_mode =
c_textedit_control=>true
* FILEDROP_MODE = DROPFILE_EVENT_OFF
parent = go_docking
* LIFETIME =
* NAME =
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.
CALL METHOD go_textedit->set_text_as_r3table
EXPORTING
table = gt_lines
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.
CALL METHOD go_textedit->set_enable
EXPORTING
enable = cl_gui_cfw=>true
EXCEPTIONS
cntl_error = 1
cntl_system_error = 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.
PERFORM set_registered_events.
SET HANDLER:
lcl_eventhandler=>handle_context_menu FOR go_textedit,
lcl_eventhandler=>handle_ctxmenu_selected FOR go_textedit.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE gd_okcode.
WHEN 'BACK' OR
'EXIT' OR
'CANC'.
SET SCREEN 0. LEAVE SCREEN.
WHEN OTHERS.
ENDCASE.
CLEAR: gd_okcode.
ENDMODULE. " USER_COMMAND_0100 INPUT
Regards
Uwe
2007 Feb 14 4:36 AM
Hello Tejas
The following sample report ZUS_SDN_TEXTEDIT_CTXMENU shows how to trigger context menus in text editor. Please note that the editor must be set <b>enabled</b>.
If you inactivate subroutine <b>SET_REGISTERED_EVENTS</b> the new context menu function will no be displayed. Thus you need to <b>register</b> the event for context menu handling.
*&---------------------------------------------------------------------*
*& Report ZUS_SDN_TEXTEDIT_CTXMENU
*&
*&---------------------------------------------------------------------*
*&
*& Flow logic of screen 100.
* PROCESS BEFORE OUTPUT.
* MODULE STATUS_0100.
**
* PROCESS AFTER INPUT.
* MODULE USER_COMMAND_0100.
*&---------------------------------------------------------------------*
REPORT ZUS_SDN_TEXTEDIT_CTXMENU.
TYPE-POOLS: cntl. " Types for Controls
DATA:
gd_okcode TYPE ui_func,
go_docking TYPE REF TO cl_gui_docking_container,
go_textedit TYPE REF TO cl_gui_textedit,
*
gd_name TYPE thead-tdname,
gs_header TYPE thead,
gd_langu TYPE thead-tdspras,
gt_lines TYPE STANDARD TABLE OF tline.
*---------------------------------------------------------------------*
* CLASS lcl_eventhandler DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
handle_context_menu
FOR EVENT context_menu OF cl_gui_textedit
IMPORTING
menu
sender,
handle_ctxmenu_selected
FOR EVENT context_menu_selected OF cl_gui_textedit
IMPORTING
fcode
sender.
ENDCLASS. "lcl_eventhandler DEFINITION
*---------------------------------------------------------------------*
* CLASS lcl_eventhandler IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler IMPLEMENTATION.
METHOD handle_context_menu.
CALL METHOD menu->add_function
EXPORTING
fcode = 'MY_FUNC'
text = 'My Function'
* ICON =
* FTYPE =
* DISABLED =
* HIDDEN =
* CHECKED =
* ACCELERATOR =
.
ENDMETHOD. "handle_context_menu
METHOD handle_ctxmenu_selected.
CASE fcode.
WHEN 'MY_FUNC'.
MESSAGE 'My function selected from ctxmenu' TYPE 'I'.
WHEN OTHERS.
ENDCASE.
ENDMETHOD. "handle_ctxmenu_selected
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
PARAMETERS:
p_pspnr TYPE prps-pspnr.
START-OF-SELECTION.
* Get the text object
gs_header-tdid = 'LTXT'. " long text
gs_header-tdspras = syst-langu.
CONCATENATE syst-langu p_pspnr
INTO gs_header-tdname.
gs_header-tdobject = 'PMS'.
CALL FUNCTION 'READ_TEXT'
EXPORTING
* CLIENT = SY-MANDT
id = gs_header-tdid
language = gs_header-tdspras
name = gs_header-tdname
object = gs_header-tdobject
* ARCHIVE_HANDLE = 0
* LOCAL_CAT = ' '
* IMPORTING
* HEADER =
TABLES
lines = gt_lines
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.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL SCREEN '0100'.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form SET_REGISTERED_EVENTS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM
set_registered_events .
* define local data
DATA:
lt_events TYPE cntl_simple_events,
ls_event TYPE cntl_simple_event.
TYPES: BEGIN OF cntl_simple_event,
eventid TYPE i,
appl_event TYPE c,
END OF cntl_simple_event.
ls_event-eventid = cl_gui_textedit=>event_context_menu.
APPEND ls_event TO lt_events.
ls_event-eventid = cl_gui_textedit=>event_context_menu_selected.
APPEND ls_event TO lt_events.
CALL METHOD go_textedit->set_registered_events
EXPORTING
events = lt_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.
ENDFORM. " SET_REGISTERED_EVENTS
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'MAIN_0100'.
* SET TITLEBAR 'xxx'.
CLEAR: gd_okcode.
IF ( go_textedit IS NOT BOUND ).
CREATE OBJECT go_docking
EXPORTING
parent = cl_gui_container=>screen0
* REPID =
* DYNNR =
* SIDE = DOCK_AT_LEFT
* EXTENSION = 50
* STYLE =
* LIFETIME = lifetime_default
* CAPTION =
* METRIC = 0
ratio = 90
* NO_AUTODEF_PROGID_DYNNR =
* NAME =
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 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.
CREATE OBJECT go_textedit
EXPORTING
* MAX_NUMBER_CHARS =
* STYLE = 0
wordwrap_mode =
c_textedit_control=>wordwrap_at_windowborder
* WORDWRAP_POSITION =
wordwrap_to_linebreak_mode =
c_textedit_control=>true
* FILEDROP_MODE = DROPFILE_EVENT_OFF
parent = go_docking
* LIFETIME =
* NAME =
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.
CALL METHOD go_textedit->set_text_as_r3table
EXPORTING
table = gt_lines
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.
CALL METHOD go_textedit->set_enable
EXPORTING
enable = cl_gui_cfw=>true
EXCEPTIONS
cntl_error = 1
cntl_system_error = 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.
PERFORM set_registered_events.
SET HANDLER:
lcl_eventhandler=>handle_context_menu FOR go_textedit,
lcl_eventhandler=>handle_ctxmenu_selected FOR go_textedit.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE gd_okcode.
WHEN 'BACK' OR
'EXIT' OR
'CANC'.
SET SCREEN 0. LEAVE SCREEN.
WHEN OTHERS.
ENDCASE.
CLEAR: gd_okcode.
ENDMODULE. " USER_COMMAND_0100 INPUT
Regards
Uwe