Search code examples
iar

For IAR embedded workbench, is there a shortcut key to quickly find and open a file within your project


I'm currently using IAR Embedded Workbench V8.30.2.

The project I'm on has about 1500 source files, and it's a pain in the neck to manually browse for the desired file in the 'Workspace' pane and double-click on it.

I'd much rather some shortcut key that opens a 'finder' window, that lets me type in a few letters of the file and it then automatically locates the file for me and opens it.

For now, I've managed to cobble together a poor-man's workaround by using AHK (autohotkey) for windows.

But still wanted to put this Q out there, in-case there is a better way.


Solution

  • For now, I will share my poor man's autohotkey solution under windows.

    #Include c:\src\gurce_ahk\ExtListView.ahk
    
    ;CapsLock+F = IAR locate desired file
    CapsLock & f::
    
    ; 1) Get current path of project
    Send,^o 
    Sleep,300
    ControlGetText, txt, ToolbarWindow323, ahk_exe IarIdePm.exe
    dir := SubStr(txt, 10)
    Send,{Escape}
    
    ; 2) find source files within dir
    RunWait, cmd /c type *_Source.ewp | grep "<name>$PROJ_DIR$/.." | \cygwin0005\bin\sed "s@</name>@@" | \cygwin0005\bin\sed "s@.*/@@" | \windows\system32\sort.exe | clip , %dir%, Hide
    files := StrSplit(Clipboard, "`r`n")
    
    ; 3) Show dialog prompt
    InputBox, filename, Enter filename to open... (can be partial)
    
    ; 4) Find request in my local list
    for idx in files
    {
      ff := files[idx]
      IfInString, ff, %filename%
        break
    }
    
    ; 5) Select the desired row
    objLV := ExtListView_Initialize(ahk_exe IarIdePm.exe)
    ExtListView_ToggleSelection(objLV, 0, -1) ; deselect all
    ExtListView_ToggleFocusAndSelection(objLV, 1, 2 + idx)
    ExtListView_EnsureVisible(objLV, 2 + idx)
    ExtListView_DeInitialize(objLV)
    Send,{Enter}
    
    return
    

    Some notes on the thought process that went into this:

    • I used CapsLock+F as my shortcut key to trigger this within IAR
    • If this doesn't suit you, change it to something else like CTRL+F (^f::)
    • I initially tried using ahk to browse the SysListView321 component, hoping to browse through its list of files
    • But alas, the text within them was not visible within ahk
    • So I tried an alternate approach of scanning the project's "*.ewp" to gather a list of source files from there
    • In order to retrieve this ahk would need to know the path of the project
    • To figure this out, I did a CTRL+O (open file) which should 'hopefully' open the path of the project, and then I read out the path of it from the open-file dialog.
    • I then quickly hit the escape key to shoo this open-file dialog away
    • I had to sort the filelist in a very particular way (to match the order seen within IAR), case-insensitive and C-style so that underscores came first before alphanumeric chars
    • From what I read online, I was hoping to do that via LC_COLLATE=C \cygwin0005\bin\sort -f, but this didn't work for me (it would however work if I ran such a command from a genuine mintty/cygwin window, just not from my calling of cygwin-bash from within a windows-cmd)
    • So as an alternative, I switched to the windows sort.exe tool instead, which seemed to sort my preferred way by default.
    • Anyways, once I had a list of files that matched the list shown in IAR, I then show a popup to let the user type in a filename (partial filename is ok)
    • I then scan the list looking for a hit on one of the files in my generated list
    • Whatever index the hit is on, I then aim to select the same index inside the workspace pane (plus a bit of an offset for extra rows at the start)