fidley / ABAPQuickFix

ABAP Quick Fix
https://abapblog.com
MIT License
42 stars 9 forks source link

Feature: QuickFix to create OO event handler #17

Open sandraros opened 4 years ago

sandraros commented 4 years ago

Hi,

I have asked in SAP Community if there was a way to easily create event handlers. I'll try to work on a proposal, but maybe you'd be interested or have ideas, so I post the idea here:

Every time I have to define a event handler, I do it completely manually, by typing the following lines, without assistance from Eclipse ADT to propose the available events of the object type I choose:

METHODS on_event FOR EVENT eventname OF objecttype IMPORTING ...

somewhere else, I enter:

SET HANDLER on_event FOR object.

Hopefully, there is one QuickFix to propose the possible parameters of the event, and another one to create the empty method implementation.

But I find it quite cumbersome to have to go to the object type, list its events, copy/paste them, then type the text around.

Is it possible to create one QuickFix to accelerate the typing of the event handlers?

Thank you.

Sandra

NB: the context how I use it is that I defined a dynpro application with view classes (MVC) with one event per user action (i.e. many events), and the controller class handles each event. NB2: I guess that quick fix would imply to work with two repository objects at the same time, the class containing the event handlers (where to add code) and the object type containing the event definitions. Eventually there should be a dialog to select for which events handlers are to be added.

fidley commented 4 years ago

Hello Sandra, this is definitely a nice idea, just wondering if this can be handled. As I answered you on scn https://answers.sap.com/questions/13106297/in-adt-is-there-a-quickfix-to-create-event-handler.html?childToView=13106491#comment-13106491 , so far I haven't call the backend from my extension. Let see if somehow this can be done. Cheers Łukasz

sandraros commented 4 years ago

I guess it could be acceptable to make this feature work only if both object types are opened (the class to handle the event - let's call it EH- and the object type containing the event definition - let's call it ED). This way, considering that EH is already opened, one has to open ED, then it could work only at Eclipse side.

As you correctly observed on SCN, the standard auto-completion should work for proposing the list of existing events of the object type with a sufficient support package for the ABAP backend. Consequently, I guess my feature proposal is not really a feature proposal, as I could upgrade my ABAP backend to obtain it.

I typed the following code and press Ctrl+Space between the words EVENT and OF. Nothing happened for me (tested on ABAP 7.52 SP 0 and SP 1), but you said that it works for your ABAP backend. I tested in a brand new class pool, and in a brand new executable program.


CLASS lcl_app DEFINITION PUBLIC FINAL...
PUBLIC SECTION.
METHODS event FOR EVENT | OF cl_gui_alv_grid. " <==== pipe is not a character, it's the caret (then Ctrl+Space)
ENDCLASS.
CLASS lcl_app IMPLEMENTATION.
ENDCLASS.
​```