ContextMenu plugin

Discuss and announce AkelPad plugins
  • Author
  • Message
Offline
Posts: 71
Joined: Sat Jul 05, 2008 11:30 am
Location: Odesa, Ukraine

Re: ContextMenu plugin

Post by ewild »

Instructor
Please consider adding the 'commands chain' functionality to the ContextMenu plugin (and maybe to the Toolbar plugin as well), that would allow executing several commands in a sequence, one after another, within a single menu item call.
The syntax could be pretty simple: a comma-separated list of commands.
An example:

Code: Select all

"Lines: sort A-Z" Call("Format::LineSortStrAsc"), Call("Scripts::Main",1,"fixLines.js","blank") Icon("%a\AkelFiles\Plugs\Format.dll") # sort ascending, then remove leading blank lines

Offline
Site Admin
Posts: 6436
Joined: Thu Jul 06, 2006 7:20 am

Re: ContextMenu plugin

Post by Instructor »

ewild wrote: Thu Mar 05, 2026 6:56 pmAlso, it could work directly from the context menu, but for whatever reason, it didn't:

Code: Select all

"URL max length 1024" Call("Scripts::Main", 7, 'AkelPad.SendMessage(AkelPad.GetEditWnd(), 3254, 1024, 0)')
You can use only single command in Call("Scripts::Main", 7, ...). Instead use EvalCmd.js:

Code: Select all

Call("Scripts::Main", 1, "EvalCmd.js", `AkelPad.SendMessage(AkelPad.GetEditWnd(), 3254 /*AEM_SETURLMAXLENGTH*/, 1024, 0)`)
yozhic wrote: Thu Mar 05, 2026 8:30 pmИ ещё во время тестов кажется всплыл косячок. Вот при такой записи в Tab menu:
Да, поэтому EXPLORER'у надо быть в отдельном пустом подменю.

ewild wrote: Thu Mar 12, 2026 4:53 pmSo, I believe, at least there should be a way to explicitly reset the %lb,%le variables ...
See ContextMenu v18.4

ewild wrote: Tue Mar 17, 2026 1:27 amPlease consider adding the 'commands chain' functionality ...
Use EvalCmd.js:

Code: Select all

Call("Scripts::Main", 1, "EvalCmd.js", `AkelPad.Call("Format::LineSortStrAsc"); AkelPad.Call("Scripts::Main",1,"fixLines.js","blank");`)

Offline
Site Admin
Posts: 6436
Joined: Thu Jul 06, 2006 7:20 am

Re: ContextMenu plugin

Post by Instructor »

Добавлено: переменная %lb - позиция начала URL (работает только в "Меню ссылок").
Добавлено: переменная %le - позиция конца URL (работает только в "Меню ссылок").

Added: variable %lb - URL start position (work in "URL menu" only).
Added: variable %le - URL end position (work in "URL menu" only).


ContextMenu plugin v18.4

Offline
Posts: 71
Joined: Sat Jul 05, 2008 11:30 am
Location: Odesa, Ukraine

Re: ContextMenu plugin

Post by ewild »

Instructor wrote: Tue Mar 31, 2026 11:06 pm Added: variable %lb - URL start position (work in "URL menu" only).
Added: variable %le - URL end position (work in "URL menu" only).
ContextMenu plugin v18.4
Actually, it's also:
[r4536] by instructor_
Changed: reset %lb and %le variables after URL menu closing.
Well done. Thank you.
Now the URL selection logic works as intended, allowing a script to be called with the predictable results from any context menu:

Code: Select all

// https://akelpad.sourceforge.net/forum/viewtopic.php?t=245&p=37066#p37066
// "URL select logic" Call("Scripts::Main",1,"URLselectLogicFix.js","fix -URLstart=%lb -URLend=%le")

// get command-line arguments
pArgLine = AkelPad.GetArgLine();
nURLstart = AkelPad.GetArgValue("URLstart",0);
nURLend = AkelPad.GetArgValue("URLend",0);

// use regular selection if any (from any context menu)
nSelStart = nRegStart = AkelPad.GetSelStart();
nSelEnd = nRegEnd = AkelPad.GetSelEnd();

// select URL under cursor if any when there's no selection (from URL menu only)
if (nSelStart == nSelEnd && nURLstart != nURLend){
nSelStart = nURLstart;
nSelEnd = nURLend;}

// otherwise select entire text (from any context menu)
if (nSelStart == nSelEnd){
nSelStart = 0;
nSelEnd = -1;}

// set selection
AkelPad.SetSel(nSelStart,nSelEnd);

// do something with selection
nResStart = AkelPad.GetSelStart();// resulting selection start offset
nResEnd = AkelPad.GetSelEnd();// resulting selection end offset

// a bit of output
pArgs    = 'ArgLine : '+pArgLine+'\r'
pRegular = 'Regular selection offsets (initial)\r'+'nRegStart = '+nRegStart+'\rnRegEnd   = '+nRegEnd+'\r'
pURLs    = 'URL selection offsets\r'+              'nURLstart = '+nURLstart+'\rnURLend   = '+nURLend+'\r'
pVariables = 'Resulting offset variables\r'+       'nSelStart = '+nSelStart+'\rnSelEnd   = '+nSelEnd+'\r'
pResulting = 'Resulting selection offsets\r'+      'nResStart = '+nResStart+'\rnResEnd   = '+nResEnd
Message  = pArgs + pRegular + pURLs + pVariables + pResulting
AkelPad.Call("Log::Output",4,Message,-1,0);

Offline
Posts: 71
Joined: Sat Jul 05, 2008 11:30 am
Location: Odesa, Ukraine

Re: ContextMenu plugin

Post by ewild »

Instructor wrote: Tue Mar 31, 2026 10:07 pm
ewild wrote: Thu Mar 05, 2026 6:56 pmAlso, it could work directly from the context menu, but for whatever reason, it didn't:

Code: Select all

"URL max length 1024" Call("Scripts::Main", 7, 'AkelPad.SendMessage(AkelPad.GetEditWnd(), 3254, 1024, 0)')
You can use only single command in Call("Scripts::Main", 7, ...). Instead use EvalCmd.js:

Code: Select all

Call("Scripts::Main", 1, "EvalCmd.js", `AkelPad.SendMessage(AkelPad.GetEditWnd(), 3254 /*AEM_SETURLMAXLENGTH*/, 1024, 0)`)
Good to know. Thank you.
However, it turns out, it works waay too loong, and with rendering issues, so I will not recommend anyone using this approach (with the EvalCmd.js as a proxy) outside of testing purposes.
Calling this method directly from a user script is much faster, with immediate effect and comfortable rendering.

Offline
Posts: 71
Joined: Sat Jul 05, 2008 11:30 am
Location: Odesa, Ukraine

Re: ContextMenu plugin

Post by ewild »

Instructor wrote: Tue Mar 31, 2026 10:07 pm
ewild wrote: Tue Mar 17, 2026 1:27 amPlease consider adding the 'commands chain' functionality ...
Use EvalCmd.js:

Code: Select all

Call("Scripts::Main", 1, "EvalCmd.js", `AkelPad.Call("Format::LineSortStrAsc"); AkelPad.Call("Scripts::Main",1,"fixLines.js","blank");`)
The syntax is not impressive, to say the least. And after trying it, I finally preferred to modify my scripts to do things internally, rather than chaining commands outside in the context menu/toolboard via EvalCmd.js.
Thank you anyway for the interesting information. It's been useful to know that it was possible in principle.

Offline
Posts: 71
Joined: Sat Jul 05, 2008 11:30 am
Location: Odesa, Ukraine

Re: ContextMenu plugin

Post by ewild »

Instructor
Is it normal and intended by design that the %le variable defines the URL end position only within AEM_SETURLMAXLENGTH, but NOT the ACTUAL URL end, and therefore misses everything beyond AEM_SETURLMAXLENGTH?
It makes working with random long URLs a pain.
Of course, as a workaround, I can* redefine AEM_SETURLMAXLENGTH each time I call %lb,%le, but it would be overkill for most of the regular use cases.
It would be great if it were possible to do something with %le behavior in that regard (e.g., allowing %le to capture the URL structure to the last character without enforcing a hard SETURLMAXLENGTH limit first).

Edit:

* No, I can not. It turns out that it is impossible to do from a script that calls %lb,%le, because %le has already been assigned before the script gets a chance to redefine SETURLMAXLENGTH. It implies I have to redefine SETURLMAXLENGTH in a separate action first, and only then will it make sense to run the script in question. So this is even worse than I initially imagined.
Still, I've been processing such long URLs en masse outside of the %lb,%le URL menu couple without any issues, so there definitely should be a way.
Post Reply