CLASS zcl_abapgit_gui_page DEFINITION PUBLIC ABSTRACT CREATE PUBLIC. PUBLIC SECTION. INTERFACES: zif_abapgit_gui_renderable, zif_abapgit_gui_event_handler. CONSTANTS: BEGIN OF c_global_page_action, showhotkeys TYPE string VALUE `showHotkeys` ##NO_TEXT, END OF c_global_page_action. CLASS-METHODS: get_global_hotkeys RETURNING VALUE(rt_hotkey) TYPE zif_abapgit_gui_page_hotkey=>tty_hotkey_with_name. METHODS: constructor. PROTECTED SECTION. TYPES: BEGIN OF ty_control, redirect_url TYPE string, page_title TYPE string, page_menu TYPE REF TO zcl_abapgit_html_toolbar, END OF ty_control. DATA: ms_control TYPE ty_control. METHODS render_content ABSTRACT RETURNING VALUE(ro_html) TYPE REF TO zcl_abapgit_html RAISING zcx_abapgit_exception. METHODS scripts RETURNING VALUE(ro_html) TYPE REF TO zcl_abapgit_html RAISING zcx_abapgit_exception. PRIVATE SECTION. DATA: mo_settings TYPE REF TO zcl_abapgit_settings, mt_hotkeys TYPE zif_abapgit_gui_page_hotkey=>tty_hotkey_with_name. METHODS html_head RETURNING VALUE(ro_html) TYPE REF TO zcl_abapgit_html. METHODS title RETURNING VALUE(ro_html) TYPE REF TO zcl_abapgit_html. METHODS footer RETURNING VALUE(ro_html) TYPE REF TO zcl_abapgit_html. METHODS redirect RETURNING VALUE(ro_html) TYPE REF TO zcl_abapgit_html. METHODS link_hints IMPORTING io_html TYPE REF TO zcl_abapgit_html RAISING zcx_abapgit_exception. METHODS insert_hotkeys_to_page IMPORTING io_html TYPE REF TO zcl_abapgit_html RAISING zcx_abapgit_exception. METHODS render_hotkey_overview RETURNING VALUE(ro_html) TYPE REF TO zcl_abapgit_html RAISING zcx_abapgit_exception. METHODS call_browser IMPORTING iv_url TYPE csequence RAISING zcx_abapgit_exception. METHODS define_hotkeys RETURNING VALUE(rt_hotkeys) TYPE zif_abapgit_gui_page_hotkey=>tty_hotkey_with_name RAISING zcx_abapgit_exception. METHODS get_default_hotkeys RETURNING VALUE(rt_default_hotkeys) TYPE zif_abapgit_gui_page_hotkey=>tty_hotkey_with_name. ENDCLASS. CLASS zcl_abapgit_gui_page IMPLEMENTATION. METHOD insert_hotkeys_to_page. DATA: lv_json TYPE string. FIELD-SYMBOLS: LIKE LINE OF mt_hotkeys. lv_json = `{`. LOOP AT mt_hotkeys ASSIGNING . IF sy-tabix > 1. lv_json = lv_json && |,|. ENDIF. lv_json = lv_json && | "{ -hotkey }" : "{ -action }" |. ENDLOOP. lv_json = lv_json && `}`. io_html->add( |setKeyBindings({ lv_json });| ). ENDMETHOD. METHOD call_browser. cl_gui_frontend_services=>execute( EXPORTING document = |{ iv_url }| EXCEPTIONS cntl_error = 1 error_no_gui = 2 bad_parameter = 3 file_not_found = 4 path_not_found = 5 file_extension_unknown = 6 error_execute_failed = 7 synchronous_failed = 8 not_supported_by_gui = 9 OTHERS = 10 ). IF sy-subrc <> 0. zcx_abapgit_exception=>raise_t100( ). ENDIF. ENDMETHOD. METHOD constructor. mo_settings = zcl_abapgit_persist_settings=>get_instance( )->read( ). ENDMETHOD. METHOD footer. CREATE OBJECT ro_html. ro_html->add( '' ). "#EC NOTEXT ENDMETHOD. METHOD get_global_hotkeys. " these are the global shortcuts active on all pages DATA: ls_hotkey_action LIKE LINE OF rt_hotkey. ls_hotkey_action-name = |Show hotkeys help|. ls_hotkey_action-action = c_global_page_action-showhotkeys. ls_hotkey_action-hotkey = |?|. INSERT ls_hotkey_action INTO TABLE rt_hotkey. ENDMETHOD. METHOD html_head. CREATE OBJECT ro_html. ro_html->add( '' ). "#EC NOTEXT ro_html->add( '' ). "#EC NOTEXT ro_html->add( '' ). "#EC NOTEXT ro_html->add( 'abapGit' ). "#EC NOTEXT ro_html->add( '' ). ro_html->add( '' ). ro_html->add( '' ). "#EC NOTEXT CASE mo_settings->get_icon_scaling( ). " Enforce icon scaling WHEN mo_settings->c_icon_scaling-large. ro_html->add( '' ). WHEN mo_settings->c_icon_scaling-small. ro_html->add( '' ). ENDCASE. ro_html->add( '' ). "#EC NOTEXT ENDMETHOD. METHOD link_hints. DATA: lv_link_hint_key TYPE char01, lv_background_color TYPE string. lv_link_hint_key = mo_settings->get_link_hint_key( ). lv_background_color = mo_settings->get_link_hint_background_color( ). IF mo_settings->get_link_hints_enabled( ) = abap_true AND lv_link_hint_key IS NOT INITIAL. io_html->add( |setLinkHints("{ lv_link_hint_key }","{ lv_background_color }");| ). io_html->add( |setInitialFocusWithQuerySelector('a span', true);| ). io_html->add( |enableArrowListNavigation();| ). ENDIF. ENDMETHOD. METHOD redirect. CREATE OBJECT ro_html. ro_html->add( '' ). "#EC NOTEXT ro_html->add( '' ). "#EC NOTEXT ro_html->add( '' ). "#EC NOTEXT ro_html->add( || ). "#EC NOTEXT ro_html->add( '' ). "#EC NOTEXT ro_html->add( '' ). "#EC NOTEXT ENDMETHOD. METHOD render_hotkey_overview. ro_html = zcl_abapgit_gui_chunk_lib=>render_hotkey_overview( me ). ENDMETHOD. METHOD scripts. CREATE OBJECT ro_html. link_hints( ro_html ). insert_hotkeys_to_page( ro_html ). ENDMETHOD. METHOD title. CREATE OBJECT ro_html. ro_html->add( '' ). "#EC NOTEXT ENDMETHOD. METHOD zif_abapgit_gui_event_handler~on_event. CASE iv_action. WHEN zif_abapgit_definitions=>c_action-url. call_browser( iv_getdata ). ev_state = zcl_abapgit_gui=>c_event_state-no_more_act. WHEN OTHERS. ev_state = zcl_abapgit_gui=>c_event_state-not_handled. ENDCASE. ENDMETHOD. METHOD zif_abapgit_gui_renderable~render. DATA lo_script TYPE REF TO zcl_abapgit_html. " Redirect IF ms_control-redirect_url IS NOT INITIAL. ro_html = redirect( ). RETURN. ENDIF. mt_hotkeys = define_hotkeys( ). " Real page CREATE OBJECT ro_html TYPE zcl_abapgit_html. ro_html->add( '' ). "#EC NOTEXT ro_html->add( '' ). "#EC NOTEXT ro_html->add( html_head( ) ). ro_html->add( '' ). "#EC NOTEXT ro_html->add( title( ) ). ro_html->add( render_hotkey_overview( ) ). ro_html->add( render_content( ) ). ro_html->add( footer( ) ). ro_html->add( '' ). "#EC NOTEXT lo_script = scripts( ). IF lo_script IS BOUND AND lo_script->is_empty( ) = abap_false. ro_html->add( '' ). ENDIF. ro_html->add( '' ). "#EC NOTEXT ENDMETHOD. METHOD define_hotkeys. DATA: lo_settings TYPE REF TO zcl_abapgit_settings, lt_user_defined_hotkeys TYPE zif_abapgit_definitions=>tty_hotkey. FIELD-SYMBOLS: TYPE zif_abapgit_gui_page_hotkey=>ty_hotkey_with_name, LIKE LINE OF lt_user_defined_hotkeys. rt_hotkeys = get_default_hotkeys( ). " Override default hotkeys with user defined lo_settings = zcl_abapgit_persist_settings=>get_instance( )->read( ). lt_user_defined_hotkeys = lo_settings->get_hotkeys( ). LOOP AT rt_hotkeys ASSIGNING . READ TABLE lt_user_defined_hotkeys ASSIGNING WITH TABLE KEY action COMPONENTS action = -action. IF sy-subrc = 0. -hotkey = -hotkey. ELSEIF lines( lt_user_defined_hotkeys ) > 0. " User removed the hotkey DELETE TABLE rt_hotkeys FROM . ENDIF. ENDLOOP. ENDMETHOD. METHOD get_default_hotkeys. DATA: lt_page_hotkeys LIKE mt_hotkeys. rt_default_hotkeys = get_global_hotkeys( ). TRY. CALL METHOD me->('ZIF_ABAPGIT_GUI_PAGE_HOTKEY~GET_HOTKEY_ACTIONS') RECEIVING rt_hotkey_actions = lt_page_hotkeys. INSERT LINES OF lt_page_hotkeys INTO TABLE rt_default_hotkeys. CATCH cx_root. " Current page doesn't implement hotkey interface, do nothing ENDTRY. ENDMETHOD. ENDCLASS.