[gtkada] Separating Custom Callback Code (Patches included)

Warren W. Gay VE3WWG ve3wwg at cogeco.ca
Sun Dec 23 03:52:09 CET 2001


First of all, thanks to the folks that have contributed to Gtk, and
GtkAda!

One of the things that has put me off of using glade in the past, is the
problem where my customized callback code does not always get
preserved. I found that if I kept adding callbacks, and generating the
code again, I'd sooner or later get burned with the fact that some of
my customization got deleted out (after a valiant effort at merging).

It seemed to me that there should be a better guarantee against this, and
I have started using a solution (patches for GtkAda-1.2.12 are attached).

Rationale:

Once you've indicated to glade that you want a particular callback, and 
you've
taken the generated stub and added your custom code to it, you really don't
need glade to support you any further in the callback (generated code wise).

So for example, the code in the generated file main_win_pkg-callbacks.adb
the first time around contains a one or more stubs for the callback 
routines.
Traditionally, you'd customize this file with your callback body code.

However, after using glade again, you request another callback, and 
generate
the code again, this file has the new callback stub merged into it-- and 
your
original custom code intact, if you are lucky.

To make this "life cycle" more reliable, I would like to propose the 
following
change:

In the file main_win_pkg-callbacks.adb (for example), just generate the
callback procedures and functions with the clause "is separate". For
example:

with Gtk.Accel_Group; use Gtk.Accel_Group;
...
package body Main_Win_Pkg.Callbacks is
   use Gtk.Arguments;

   -------------------------
   -- On_Main_Win_Destroy --
   -------------------------

   procedure On_Main_Win_Destroy
     (Object : access Gtk_Window_Record'Class)
   is separate;

end Main_Win_Pkg.Callbacks;

After the package body for the callbacks has been emitted, the submitted
patch then emits the separate procedures/functions (which gnatchop groks
OK). For example the separated callback code is now put into the file
main_win_pkg-callbacks-on_main_win_destroy.adb by gnatchop (by gate):

Separate(Main_Win_Pkg.Callbacks)
   -------------------------
   -- On_Main_Win_Destroy --
   -------------------------

   procedure On_Main_Win_Destroy
     (Object : access Gtk_Window_Record'Class)
   is
   begin
      Gtk.Main.Gtk_Exit(0);
   end On_Main_Win_Destroy;

Another patch, affects the gate script code. What happens there, is that
if the callback is new to the project, the procedure source file
main_win_pkg-callbacks-on_main_win_destroy.adb will not exist,
and gate will supply it as you would expect. However, if the source file
already exists for the project, then gate would delete the generated copy
of the callback stub, so that you will not lose the original (since the 
original
now contains your customized code, and does not need any further
help from gate).  All other files, would be merged if necessary, as before.

The attached tar file contains patches for GtkAda-1.2.12. The patches are
minor, and affect two GtkAda files :

   src/glib-glade.adb        (affecting gate-in.exe)
   src/gate                      (called by glade to generate Ada95 code)

The change to src/glib-glade.adb was minor. Since gate-in.exe emits all
code to standard output, and is then split into source files by gnatchop,
only a small change was needed.  The loop that generates the stubs was
modified to only emit "is separate;" instead of the null body of code.
After the body end was emitted, you re-do the loop, with the clause
"separate(<pkg-name>)" as the first line, and emit the procedure/function
null body (to be customized by the user). Gnatchop then puts these into
the correctly named separate source files.

I hope others will enjoy the benefits of this patch. It would be nice if
this could be included into the "production mode" GtkAda suite
someday, since I believe this is a safer way to keep the user's
customized code.

Thanks, Warren.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gate-patch.tar.gz
Type: application/x-gzip
Size: 10129 bytes
Desc: not available
Url : /pipermail/gtkada/attachments/20011222/aae6f907/attachment.bin 


More information about the gtkada mailing list