Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run jN menu commands via other plugins or add them to NPP context menu #28

Closed
ArkadiuszMichalski opened this issue Feb 28, 2016 · 7 comments

Comments

@ArkadiuszMichalski
Copy link

All scripts has own menu (in old style) so we can't add his options to NPP context menu or run them with other plugins. I test Zen Coding without any positive results:

  • NPPExec, use npp_menucommand Zen Coding|Wrap With Abbreviationd, find this item but not invoke
  • Python Script, use notepad.runMenuCommand('Zen Coding', 'Wrap with Abbreviation'), like above, find this item but not invoke
  • editing contextMenu.xml file without success

The only solution what I found is write script for WSH (.js or .vbs) with send keys (shortcut for Zen Coding commands) and run this script with above tools. But it needs to define shortcut for any actions or other scripts (created via jN) which is inconvenient. This script can be add to Npp context menu and works.

Any advice how can I solve this in a more comfortable way?

@sieukrem
Copy link
Owner

Hello Arkadiusz,
I don't know any regular way to integrate new entries to existing context menu. It is like integration of plugin menu items, only declarative way is possible. It means either at compile time of plugin or contextMenu.xml before you start Notepad++. You understand, it is to few for flexible API.
I was not enough and I built next dirty hack.
Did you see this wiki page?
Follow the article link under point 9. It describes the way how to create your own context menu, which conditionaly overrides the original one.
If you want to have context menu entries from original context menu, you can simulate them by interpreting the contextMenu.xml.

Happy scripting!

@ArkadiuszMichalski
Copy link
Author

I saw this page and possibility to create own context menu, but I don't know how can I get commands from different jN scripts and put them to this context menu. Most of them (or maybe all) are anonymous (in scope) and without refactoring code its impossible, or am I wrong? Would be nice if plugin will automaticaly collect all menu commands from all scripts and expose its somehow (via object), then it would be easy to build own context menu.

@sieukrem
Copy link
Owner

You are right! There is no regular way to collect all jN menu items. I don't think that it is good idea. Because not all of jN scripts are designed to be useful via context menu.
Indeed you can offer an API for jN scripts and than refactor them.

@ArkadiuszMichalski
Copy link
Author

Hmm it would be easier if cfg for addItem() has additional boolean property for this so scripts autor can expose them for other scripts autor whenever they want. But in other site the same can be done without change anything, needs defined some standards js API and convince others to us it (if necessary).

@ArkadiuszMichalski
Copy link
Author

@sieukrem
How can I reconstruct (get access) to command by their names (not ids), I mean both the command directly from the editor and the plugins (from Plugins menu). In contextMenu.xml file it's not a problem, but Editor.runMenuCmd() operate only on build-in menu command of Notepad++ exposed by number, so I can't rebuild original context menu. Is there any solution to solve this?

@sieukrem
Copy link
Owner

sieukrem commented Apr 3, 2016

The only one way is to use the native Windows API (GetMenuItemInfo) and Notepad++ (NPPM_GETMENUHANDLE). You can get the names of menu items and their Id's.

@ArkadiuszMichalski
Copy link
Author

Any small example how do this? Looks like it's not so easy: eight04/jn-npp-emmet#5 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants