Recent

Author Topic: How to invoke Ide Menu item programmatically?  (Read 1351 times)

yurkad

  • Full Member
  • ***
  • Posts: 173
  • development
How to invoke Ide Menu item programmatically?
« on: January 18, 2020, 11:16:51 pm »
We assume that we have an IDE menu item with KeyToShortCut (VK_C, [ssShift, ssCtrl]).

How to invoke this point programmatically?

Thanks!

winni

  • Hero Member
  • *****
  • Posts: 1901
Re: How to invoke Ide Menu item programmatically?
« Reply #1 on: January 19, 2020, 12:52:29 am »
Hi!

Have a look at the unit mouseandkeyinput in the lazarus components  directory.

Winni

GetMem

  • Hero Member
  • *****
  • Posts: 3758
Re: How to invoke Ide Menu item programmatically?
« Reply #2 on: January 19, 2020, 07:47:50 am »
@yurkad

I assume your code is in a package, and that package was added to IDE, like in your previous thread(https://forum.lazarus.freepascal.org/index.php/topic,48089.0.html):
Code: Pascal  [Select][+][-]
  1. uses IDECommands, LCLType;
  2. var
  3.   Key: Word;
  4. begin
  5.   Key := VK_C;
  6.   ExecuteIDEShortCut(Self, Key, [ssShift, ssCtrl]);    
  7. end;

yurkad

  • Full Member
  • ***
  • Posts: 173
  • development
Re: How to invoke Ide Menu item programmatically?
« Reply #3 on: January 19, 2020, 04:40:41 pm »
@winni, thanks!

@GetMem.

Thank you very much. Yes it is your sample.

Based on your example I solved my needs. But there were two things missing:

1. Invoke Ide menu point - now is fine - thanks again.

2. My new package has an old name: projectstatistics and only one projectstatisticsintf.pas file.

For two days I tried to change the name package for mine - 'GetIde', and I couldn't.
Nor could I create a new package with a new name. That's why I used your package name and the content - mine.

If you can, please help me on this too - How to change name of package.

Thank you!
« Last Edit: January 19, 2020, 04:53:42 pm by yurkad »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6675
  • Debugger - SynEdit - and more
    • wiki
Re: How to invoke Ide Menu item programmatically?
« Reply #4 on: January 19, 2020, 04:55:54 pm »
You may want to try
Code: Pascal  [Select][+][-]
  1.   boolSuccess := ExecuteIDECommand(nil, ecCompleteCode);

Then it will work, even if the keymap gets changed.

GetMem

  • Hero Member
  • *****
  • Posts: 3758
Re: How to invoke Ide Menu item programmatically?
« Reply #5 on: January 19, 2020, 07:28:32 pm »
@yurkad

1. Make backup first
2. Open package projectstatistics.lpk
3. Go to More-->Save package As...(see attached image)
4. For consistency, you should also rename projectstatisticsintf.pas(unit underlined with red in the attached image) to GetIDEIntf.pas

yurkad

  • Full Member
  • ***
  • Posts: 173
  • development
Re: How to invoke Ide Menu item programmatically?
« Reply #6 on: January 19, 2020, 11:44:56 pm »
@Martin_fr.
Thank, but I don't know how to use this. Maybe I will learn.

@GetMem.
Thank you.
Really it is easy (when there is explanation).

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6675
  • Debugger - SynEdit - and more
    • wiki
Re: How to invoke Ide Menu item programmatically?
« Reply #7 on: January 20, 2020, 12:20:09 am »
@Martin_fr.
Thank, but I don't know how to use this. Maybe I will learn.

First: I haven't tested it, but it should be fine....

You use it, like "  ExecuteIDEShortCut(Self, Key, [ssShift, ssCtrl]);"

It is defined in the same unit.
"ecCodeCompletion" is in unit KeyMapping. So you can search for the default keycombo there, and find the "ec....." constant.


--
"ec" stands for EditorCommand.

Almost every action you can perform in the Editor has an "ec" constant.

yurkad

  • Full Member
  • ***
  • Posts: 173
  • development
Re: How to invoke Ide Menu item programmatically?
« Reply #8 on: January 20, 2020, 01:40:35 am »
@Martin_fr.

From what I read it must be easy.

I am going to try.

Now I realize that I must learn everything from unit IDECommands.

By the way: command ExecuteIDEShortCut gives a Sissegv error. But I still don't ask for help - maybe I have a lot of mistakes on the issue of packages - it's new to me.
I will try to fix.

Thanks!

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6675
  • Debugger - SynEdit - and more
    • wiki
Re: How to invoke Ide Menu item programmatically?
« Reply #9 on: January 20, 2020, 02:45:51 am »
Btw, you can debug the entire IDE  (with your package).

Open one IDE, then open project "ide/lazarus.lpi"

Note that this project does not re-build the exe. So you must make sure that you do Tools->Build Lazarus
(and ensure it is linking a lazarus.exe, not a lazarus.old.exe. Check in your install folder. The "old" will happen, if the IDE is still locked. Happens if gdb crashes)

Once build, you can use F9 to run the IDE project, and a 2nd IDE opens that you can debug.



IF you search the components folder for ExecuteIDECommand, you will find several examples.

yurkad

  • Full Member
  • ***
  • Posts: 173
  • development
Re: How to invoke Ide Menu item programmatically?
« Reply #10 on: January 20, 2020, 01:21:23 pm »
@Martin_fr,

Thanks by helpful tips!

yurkad

  • Full Member
  • ***
  • Posts: 173
  • development
Re: How to invoke Ide Menu item programmatically?
« Reply #11 on: January 26, 2020, 02:49:39 pm »
Trying to solve this question.

In Ide there is a menu item
Menu->Project->Project Options... Shift+Ctrl+F11.

This point works by using mouse or using keyboard (Shift + Ctrl + F11).
I tried to invoke this point with the following code:

Code: Pascal  [Select][+][-]
  1. uses IDECommands, LCLType;
  2. var
  3.   Key: Word;
  4. begin
  5.   Key := VK_11;
  6.   ExecuteIDEShortCut(Self, Key, [ssShift, ssCtrl]);    
  7. end;

Command ExecuteIDEShortCut gives a SIGSEGV error.

Mi OS is Windows 10.
Lazarus Version: 2.0.6
FPC Version: 3.0.4
SVN Revision: 62129.

I was also trying to use package
lazmouseandkeyinput

The code:
Code: Pascal  [Select][+][-]
  1.   KeyInput.Apply([ssShift]);
  2.   KeyInput.Apply([ssCtrl]);
  3.   KeyInput.Press(VK_F11);            
  4.   KeyInput.Unapply([ssShift]);
  5.   KeyInput.Unapply([ssCtrl]);

It has no effect.

Please, any advice?

howardpc

  • Hero Member
  • *****
  • Posts: 3551
Re: How to invoke Ide Menu item programmatically?
« Reply #12 on: January 26, 2020, 03:11:54 pm »
Contributors so far assumed you are writing some sort of IDE extension, which is compiled into a running IDE instance.
Are you trying to invoke an IDE command from outside the IDE, as part of an independent project?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6675
  • Debugger - SynEdit - and more
    • wiki
Re: How to invoke Ide Menu item programmatically?
« Reply #13 on: January 26, 2020, 03:57:51 pm »
Indeed ExecuteIDEShortCut is not meant for opening the options dialog.
ExecuteIDEShortCut takes the keystroke, and translates it into an ec.... command, according to the current keysettings.
There is no ec<OpenOptions> command. So it can not do that.

However it should not crash, it should just do nothing.

As long as your package is installed into the IDE, running inside the IDE, and you are not doing this during unit initialization (wait at least until "Register" was called), you might be able to go via the MenuIntf unit
itmOptionsDialogs is a menu section, so you can iterate through its entries to find the one to open the dialog.

Or better you can use LazIDEIntf: DoOpenIDEOptions.


You will have to crawl a bit through the code to find out how to do this.
- browse the IDEInf package
- browse the unit "main" and search for related terms
- find existing packages that do what you need

If you can put your findings on the wiki, and start/extend the docs



yurkad

  • Full Member
  • ***
  • Posts: 173
  • development
Re: How to invoke Ide Menu item programmatically?
« Reply #14 on: January 26, 2020, 04:25:07 pm »
@howardpc.

Thanks by answer.
Yes, I am trying to invoke an IDE command from outside the IDE, as part of an independent project.

@Martin_fr.

Thank you. I understood.

By both answers two questions appear:

1.
How to invoke a package without using of Menu Point and without using of IDEShortCut?

2.
How to invoke a package automatically after starting IDE?

Many thanks!

« Last Edit: January 26, 2020, 04:33:00 pm by yurkad »

 

TinyPortal © 2005-2018