Previously I used a large number of "Shell menu" triggers. At first it was very convenient, but as the number grew, the following problems arose:
1. QM portable version does not support it;
2. Editing trigger functions is inconvenient;
3. One function corresponds to only one shell menu;
4. It can only be integrated into a certain position of the existing system menu, which is not intuitive enough, and the position of the menu items is inconvenient to modify.
5. And many more...
To solve the above problems, I wanted to implement in QM functionality similar to the LA trigger in the post below. I wrote the following code, but I ran into some problems:
Context Menu Trigger
1. How do I determine the currently selected file(s)? (I have seen similar code on the forum, but I haven't found it yet);
2. Right-clicking on a menu item does not bring up "Edit menu item" (I have seen it pop up on some menu items);
I found the source code of the ExplorerFolder function in LA. Is there a similar function in QM? I tried using AI to convert the code to QM, but had no luck.
https://github.com/qgindi/LibreAutomate/...rFolder.cs
How convert the following Get-ExplorerSelectedItems PowerShell function into QM code?
Thanks in advance for any suggestions and help.
PS: I also thought about using LA to re-implement those QM features, but there are too many...
Function Explorer_Menu
Trigger !v"" "#32768" /EXPLORER
Powershell Get-ExplorerSelectedItems Code:
Below is the QM code generated by ChatGPT, and it will cause an error.
Function Get_ExplorerSelectedItems
Trigger F1
1. QM portable version does not support it;
2. Editing trigger functions is inconvenient;
3. One function corresponds to only one shell menu;
4. It can only be integrated into a certain position of the existing system menu, which is not intuitive enough, and the position of the menu items is inconvenient to modify.
5. And many more...
To solve the above problems, I wanted to implement in QM functionality similar to the LA trigger in the post below. I wrote the following code, but I ran into some problems:
Context Menu Trigger
1. How do I determine the currently selected file(s)? (I have seen similar code on the forum, but I haven't found it yet);
2. Right-clicking on a menu item does not bring up "Edit menu item" (I have seen it pop up on some menu items);
I found the source code of the ExplorerFolder function in LA. Is there a similar function in QM? I tried using AI to convert the code to QM, but had no luck.
https://github.com/qgindi/LibreAutomate/...rFolder.cs
How convert the following Get-ExplorerSelectedItems PowerShell function into QM code?
Thanks in advance for any suggestions and help.
PS: I also thought about using LA to re-implement those QM features, but there are too many...
Function Explorer_Menu
Trigger !v"" "#32768" /EXPLORER

int hwnd=TriggerWindow
out
ARRAY(int) a; win("" "#32768" "explorer" 0 0 0 a); if(a.len>1) ret
;1.When one or more docx files are selected, The menu pops up
sub.docx
;2.When one or more txt files are selected, The menu pops up
;sub.txt
#sub docx
str docx=
;1 docx Action1
;-
;2 docx Action2
_i=ShowMenu(docx 0 0 0 8)
out _i
#sub txt
str txt=
;1 txt Action1
;-
;2 txt Action2
_i=ShowMenu(txt 0 0 0 8)
out _iPowershell Get-ExplorerSelectedItems Code:
function Get-ExplorerSelectedItems {
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline=$true)]
[int]$Hwnd = 0,
[switch]$OnlyFilesystem
)
$shell = New-Object -ComObject Shell.Application
$windows = $shell.Windows()
$results = [System.Collections.Generic.List[string]]::new()
foreach ($win in $windows) {
$winHwnd = [int]$win.HWND
if ($Hwnd -ne 0 -and $winHwnd -ne $Hwnd) { continue }
$doc = $win.Document
if ($null -eq $doc) { continue }
$selected = $doc.SelectedItems()
if ($null -eq $selected) { continue }
for ($i = 0; $i -lt $selected.Count; $i++) {
$item = $selected.Item($i)
if ($null -eq $item) { continue }
$path = $item.Path
if ([string]::IsNullOrEmpty($path)) { continue }
if ($OnlyFilesystem -and $path -notmatch '^[a-zA-Z]:[\\/]') {
continue
}
$results.Add($path)
}
}
return $results
}
Get-ExplorerSelectedItems -Hwnd 12345Below is the QM code generated by ChatGPT, and it will cause an error.
Function Get_ExplorerSelectedItems
Trigger F1

out
int h=win
ARRAY(str) r
sub.Get_ExplorerSelectedItems r h
out r
#sub Get_ExplorerSelectedItems
function ARRAY(str)&results [int'Hwnd] [flags]
,if(getopt(nargs)=1) Hwnd=0
,Shell32.IShellDispatch5 sh._create(uuidof(Shell32.Shell))
,IShellWindows windows=sh.Windows
,int count; windows.get_Count(&count)
,int i
,for i 0 count
,,Shell32.IWebBrowserApp w=windows.Item(i)
,,if(!w) continue
,,int winHwnd=w.HWND
,,if(Hwnd and winHwnd!=Hwnd) continue
,,Shell32.IShellFolderViewDual2 doc=w.Document
,,if(!doc) continue
,,Shell32.FolderItems selected=doc.SelectedItems()
,,if(!selected) continue
,,int j
,,for j 0 selected.Count
,,,Shell32.FolderItem item=selected.Item(j)
,,,if(!item) continue
,,,str path=item.Path
,,,if(empty(path)) continue
,,,;;;flags 1 = OnlyFilesystem
,,,if(flags&1 and !matchw(path "[a-zA-Z]:\\*" 1)) continue
,,,results[] = F"{winHwnd}`t{path}"
ret