0
votes

I'm doing a python plug-in to GNAT GPS IDE.

It uses the Locations window to shows a messages to the user, therefore highlighting a file line, like errors do. I use GPS.Locations.parse() to add such information, the (somewhat hazy) documentation is here.

The user then could select the line from the code or the Locations window to perform an action.

Get the line from the opened file is a piece of cake. But one thing that still eludes me, is how I can know which line from the Locations window the user is selecting. I tried the GPS.MDI.get("Locations") which lead me to a maze of children windows objects. I got lost.

So how can I retrieve the text from the currently selected line in Locations?

Edit

Apparently there MessageContext that would give me what I want, but I get an error message saying there's not such class, even when the window has focus. So I recon that the class wasn't instantiated.

AttributeError: 'module' object has no attribute 'MessageContext'
1

1 Answers

0
votes

I only saw this thread now. You should call GPS.current_context(), which will return an instance of GPS.Context or one of its children classes. In this case, you can likely use GPS.current_context().file()

It seems like what you want is to create an entry in the contextual menu in the Locations window. Take a look at the gps_utils.interactive hook. It wraps a python function into a GPS action. This action can then be bound to a specific contextual menu, a keybinding, a menu, a toolbar button,... You can also associate a filter with it, so that the contextual menu also shows up when the action applies (and to implement this filter, you use the above GPS.current_context().file()