Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2017-02

How to get access to TKeyCommandRelationList via the IDE Interfaces?

6 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

I'm creating a IDE add-on package and using the IDEIntf. Now I have access to the IDECommands global variable, but most of its methods are abstract.

Searching the IDE source code it seems the IDECommands is often casted to TKeyCommandRelationList before methods are called. The TKeyCommandRelationList is defined in the KeyMapping.pas unit.

But if I include the KeyMapping unit in my add-on package's uses clause, that unit can't be found. So I assume there is another way to do this - maybe another interface?

What I'm trying to do is look-up a IDE command by name, then execute that command. All done from inside my IDE add-on package.

Regards,
Graeme

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp

Reply by email

Mattias Gaertner
to Graeme Geldenhuys
[...] But if I include the KeyMapping unit in my add-on package's uses clause, that unit can't be found.

Yes, an IDE package can only use the IDEIntf units, not the IDE code itself.

Show quoted text 5 lines
So I assume there is another way to do this - maybe another interface? What I'm trying to do is look-up a IDE command by name, then execute that command. All done from inside my IDE add-on package.
uses IDECommands;
  Cmd:=IDECommandList.FindCommandByName('name');
  ExecuteIDECommand(Sender,Cmd.Command);

Mattias

Reply by email

Graeme Geldenhuys
to Mattias Gaertner
Mattias Gaertner wrote
uses IDECommands; Cmd:=IDECommandList.FindCommandByName('name'); ExecuteIDECommand(Sender,Cmd.Command);

Umm, that's exactly what I tried, but in never finds the command.

The code is as follows:

===============================
  cmd := IDECommandList.FindCommandByName('jcfAbout');
  if Assigned(cmd) then
  begin
    writeln('PASS: We found the JCF About command');
    ExecuteIDECommand(self, cmd.Command);
  end
  else
    writeln('FAIL: Unable to find JCF About command');
===============================

I have the Jedi Code Formatter package installed, and the menus are there in the IDE. I looked at the JCF package to see what the names are of the commands it registers. Just as a test, I'm trying to get the JCF About dialog to pop up, which was registered wit the 'jcfAbout' command name.

But as I said, it never finds that command.

Oh, and the above code is only triggered when I save a unit - so at that point the IDE is fully loaded.

Regards,
Graeme

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp

Reply by email

Graeme Geldenhuys
to Graeme Geldenhuys
Graeme Geldenhuys wrote
Umm, that's exactly what I tried, but in never finds the command.

As a work-around I went through the MenuIntf, found the JCF menu. Iterated that until I found the 'jcfAbout' menu. I then call it's MenuItem.Click() method.

Pretty ugly, but it worked. :) Obviously I would like to get the Command Interface working though.

Regards,
Graeme

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp

Reply by email

Mattias Gaertner
to Graeme Geldenhuys: Umm, that's exactly what I tried, but in never finds the command. The code is as follows:…
[...] Umm, that's exactly what I tried, but in never finds the command. [...]

You can list all registered names with

  for c:=0 to IDECommandList.CategoryCount-1 do begin
    Cat:=IDECommandList.Categories[c];
    for i:=0 to Cat.Count-1 do
      writeln(Cat.Name,' ',TIDECommand(Cat[i]).Name);
  end;

If it is there, check its OnExecute event.

Oh, and the above code is only triggered when I save a unit - so at that point the IDE is fully loaded.

Mattias

Reply by email

Graeme Geldenhuys
to Mattias Gaertner
Mattias Gaertner wrote
You can list all registered names with

Ah, that was very useful thanks. I managed to fin the 'jcfCurrentEditorWindow' command, but there doesn't seem to be a 'jcfAbout' command. So the latter will explain why my "proof of concept" didn't work.

Taking a closer look at the JcfIdeRegister unit, I now see my mistake. It does indeed only register one command. The other lines are RegisterIDEMenuCommand() calls, not the crutial RegisterIDECommand(). Dope!!!

Many thanks for helping with this and your quick responses. JCF formatting is now triggered on every save. I did have to modify JCF though, as the dialog prompt was annoying. I'll see if I can make that configurable and send a patch to Mantis.

Regards,
Graeme

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp

Reply by email