Version 5.0.0
Date: $Date: 2010-10-01 12:54:37 +0200 (Fri, 01 Oct 2010) $
Copyright © 2002-2010 AdaCore.
This document is free; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This document is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, see http://www.gnu.org/licenses/.
A copy of the license is included in the section entitled “GNU General Public License”.
Important note: This document is not ready for release yet.
This document explains how to add your own modules to the GPS programming system.
GPS is a fully open architecture, to which one can add new features ranging from new menu items to launch external tools to full support for new languages, including cross-references.
Some of these additions can be done solely through the use of text files. These are for instance adding new key bindings to various parts of GPS, for instance in the editor. The end-user can also easily add new menus or toolbar buttons. See the customization chapters in the GPS user’s guide.
This document will focus on these additions that can only be done through programming languages.
At this point, GPS can only be extended by programming in Ada. In addition, it is planned for the near future that extensions in C or C++ can be done. Work is under way to extend python scripting in GPS.
Likewise, adding basic support for new languages will be made easier, and doable through external text files, requiring no programming. This is not available for this first release of the GPS environment.
As explained in the introduction, GPS can currently only be extended by programming in Ada. This assumes that a number of tools are available on your system, so that you can recompile your new module.
Most of these external tools and libraries are available from http://libre.act-europe.fr.
GNAT is the GNU Ada Compiler, integrated into the gcc tool chain, and developed by Ada Core Technologies and ACT Europe. GPS will not compile with other Ada compilers than GNAT.
gtk+ is a C toolkit used for the graphical interface of GPS. It is available on a number of platforms, including most UNIX systems and Windows. Available from http://www.gtk.org.
The GPS sources include the corresponding GNAT, GtkAda and GVD sources needed to build it. If needed, GNAT, GtkAda and GVD sources can be obtained seperately from anonymous cvs access from http://libre.act-europe.fr
The GPS sources contain an INSTALL file that explains how to recompile GPS itself. GPS knows how to dynamically load a module. As a result, you do not necessarily need to rebuild GPS itself to add new modules, although the dynamic loading hasn’t been fully tested yet and might not work on all platforms.
GPS is organized around the concept of modules. The only part of GPS that is mandatory is its kernel (see The GPS Kernel), all the other tools, menus and features are provided in optional modules.
Although currently all modules have to be loaded at startup, some proof of concept for dynamically loadable module was implemented, and will most likely be part of a future version of GPS.
Every new feature you implement will be part of one or more modules. We will go through the details of creating new modules all along this manual, starting from a simple Hello World module to more advanced features like providing new shell or python commands.
Generally speaking, a module provides a limited set of features, and adds new GUI features in the GPS interface, like menus, toolbar buttons, contextual menu entries, new windows,… As much as possible, a menu shouldn’t directly depend on any other module, only on the GPS kernel itself.
See the file gps-kernel-modules.ads for more information on modules.
Creating a new module is best demonstrated by going through the classical and simple example “hello world”. This example will be refined as new extension possibilities are described later on in this document.
A module is generally implemented in a separate source file, at this point an Ada package. The first thing that needs to be done is to create the specs of this package. Most of the time, a single function has to be exported, which is called Register_Module by convention. Therefore, we have to create a new directory to contain the module (we’ll call it hello_world), at the same level as other modules like the source editor.
Still by convention, the sources are put in a directory called src, and the object files are kept in a separate directory called obj.
mkdir hello_world mkdir hello_world/src mkdir hello_world/obj
In the source directory, we create the file hello_world.ads, which
contains the declaration of the Register_Module
subprogram.
with GPS.Kernel; package Hello_World is procedure Register_Module (Kernel : access GPS.Kernel.Kernel_Handle_Record'Class); end Hello_World;
Before going over the details of the implementation of Register_Module
,
we have to make sure that the rest of GPS knows about this module, and that
we know how to compile it
Until GPS provides dynamic modules, you have to modify the main subprogram of GPS to make it aware of your module.
This is done by modifying the file gps.adb, and adding two statements
in there: a with
statement that imports hello_world.ads, and
a call to Hello_World.Register_Module
. See for instance how this is
done for the keymanager module.
However, after the addition of the two statements in gps.adb, the file hello_world.ads will not be found automatically by GPS. Therefore, you need to create a project file for your new module (we’ll call it hello_world.gpr), and add a dependency to it in the root project file of GPS (gps/gps.gpr), as is currently done for all other modules.
The project file hello_world.gpr is best created by copying the
project file from any other module, for instance the aliases module
(aliases/aliases.gpr), and changing the name of the project to
Hello_World
.
You must also create a set of two Makfiles, which are used to add files other
than Ada, even if your module only uses Ada files.
Once again, this is best done by copying the two Makefiles from the
directory aliases, renaming them into Makefile and
Makefile.hello_world, and replacing the strings aliases
and
ALIASES
by resp. hello_world
and HELLO_WORLD
.
These steps will be made easier in the near future, but in any case are relatively straightforward, and only need to be done once per module. The resulting setup automatically takes into account all sources files that will be added later on to the module, either C or Ada, and compile them with the appropriate compiler.
You might also prefer in your first attempt at creating a new module to add your new files into the src directory of an existing module. In this case, you don’t have to create any of the project files or Makefile, nor to modify the gps.adb file.
Once the project file has been created, and a dependency added in gps.gpr, you might want to reload the GPS project in GPS, so that the editing of your sources can be done in an Ada-friendly context.
Back to the source files of your modules. We now need to create a body for
the procedure Register_Module
. The minimal thing this function has to
do is indicate to the GPS kernel that a new module is being declared, and
give it a name. If you only do that, there is no direct impact on the rest
of GPS. However, as we will see during in this guide, having a specific
Module_Id
is mandatory for some of the advanced feature, so it is
cleaner to always declare one from the start.
This is done by creating the file hello_world.adb, with the following contents.
with GPS.Kernel.Modules; use GPS.Kernel, GPS.Kernel.Modules; package Hello_World is procedure Register_Module (Kernel : access GPS.Kernel.Kernel_Handle_Record'Class) is Module : Module_ID; begin GPS.Kernel.Modules.Register_Module (Module, Kernel, Module_Name => "hello_world"); end Register_Module; end Hello_World;
At this point, the hello_world module is compilable, only it won’t do anything but be loaded in GPS.
The following sections will show how new features can be provided to the rest of GPS.
As described above, GPS is organized into largely independent modules. For instance, the various views, browsers, help, vcs support,... are separate modules, that can either be loaded at startup or not.
When they are not loaded, the correspondings features and menus are not available to the user.
These modules need to communicate with each other so as to provide the best possible integration between the tools. There currently exists a number of ways to send information from one module to another. However, some of these technics depend on Ada-specific types, and thus makes it harder to write modules in different languages like C or Python.
The following communication technics are currently provided:
Most of the time, a module will decide to add new entries depending on what the contextual menu applies to (the current context), although it might also decide to do that based on what module is displaying the contextual menu. Modules are identified by their name, which can easily be tested by other menus.
These contexts are also used for the contextual menus
A module can choose to emit the signal to report changes to its context by emitting the signal. Other modules can they update their content accordingly. This is how the switches editor updates the project/directory/file it is showing when a new selection is done in the project view.
These are the most powerful way for a module to react to actions taking place in other parts of GPS, and to act appropriately.
In most cases, all the subprograms in a hook are executed in turn, and thus they all get a chance to act.
However, in some other cases, the subprograms are only executed until one of them indicates that it has accomplished a useful action, and that no other subprogram from this hook should be called. These are called action hooks. This is the fundamental mechanism used by GPS to request for instance the edition of a file: the module that wishes to display a file executes the hook "open_file_action_hook" with the appropriate argument. At this point, all subprograms bound to this hook are executed, until one of them acknowledge that it knows how to edit this file (and hopefully opens an editor). Then no other subprogram from this hook is called, so that the file is not open multiple times.
This mechanism is used for instance by the module that handles the external editors. It is setup so that it binds to the "open_file_action_hook" hook. Any time a file needs to be open, the callback from this module is called first. If the user has indicated that the external editor should always be used, this external editors module opens the appropriate editor, and stops the execution of the hook. However, if the user didn’t wish to use an external editor, this module does nothing, so that the callback from the source editor module is called in turn, and can thus open the file itself.
See gps-kernel-hooks.ads for more information on hooks.
All modules should be documented, so that the users are aware of all its capabilities.
There are several levels of documentation:
Tooltips are easily added directly with gtk+: Just call
Gtk.Tooltips.Set_Tooltip
with the appropriate parameters. The
kernel itself contains a tooltip group, which should be used when
setting new tooltips. This is so that a common timeout is used for all
tooltips in the application: when a user has waited long enough for
the first tooltip to be displayed, he won’t have to wait again for the
other tooltips.
If you are developing on a linux system, it is recommended that you reconfigure your X11 server with the following setup (see the file /etc/X11/XF86Config-4):
Section "ServerFlags" Option "AllowDeactivateGrabs" "true" # Ctrl+Alt+Keypad * Option "AllowClosedownGrabs" "true" # Ctrl+Alt+Keypad / EndSection
The two key bindings described above are used to release any grab that
a GUI application might have. This is especially useful when debugging
through gdb
: it might happen that the breakpoint happens while
such a grab is in place, and would therefore prevent any input (mouse
or keyboard) to any application in your X11 session, in particular the
debugger.
It is also recommended that you recompile your own gtk+ library (on systems where this is easily doable such as Unix systems), with the following configure command:
./configure --with-debug=yes
In addition to providing the usual debugging information in the debugger, this also activates several environment variables which might be used to monitor the actions in gtk+ and its associated libraries.
These variables are the following:
export GTK_DEBUG=misc:plugsocket:text:tree:updates:keybindings; export GDK_DEBUG=updates:nograbs:events:dnd:misc:xim:colormap:gdkrb:gc:pixmap:image:input:cursor; export GOBJECT_DEBUG=objects:signals;
Some of the values for these variables can be omitted. The exact semantic (or even the exact list) of such variables depends on your version of gtk+, and you should therefore consult its documentation.
When debugging with gdb
, it is recommended that you always
specify the flag --sync
to gps. This forces any gtk+
application, and in particular GPS, to process X11 events
synchronously, and therefore makes it easier to debug possible
problems.
If your application is printing some gtk+ warnings on the console, you should do the following in the debugger:
(gdb) set args --sync (gdb) begin (gdb) break g_log (gdb) cont
This will stop the application as soon as the gtk+ warning is printed.
GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. <one line to give the program's name and a brief idea of what it does.> Copyright (C) 19yy <name of author> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. <signature of Ty Coon>, 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License.
Jump to: | A G K L M T |
---|
Jump to: | A G K L M T |
---|