The Find Usages option in MPLAB X opens a dialog box for searching open or active projects for usages of classes, structures, variables, macros, functions, or files within the project's source code. The results of the search displayed in the Usages Window permit fast navigation to key search points in the project source. Find Usages application and caveats are presented here.
Accessing Find Usages
There are 3 ways of accessing the Find Usages functionality of MPLAB X shown below:
|Method 1: Edit Menu||Method 2: Class Dialog||Method 3: Source Window Right Click|
As shown in the above screenshots, ALT F7 can also be used to initiate Find Usages.
Find Usages Scope
Once Find Usages is selected for the appropriate portion of code (i.e. classes, structures, variables, macros, functions, or files), select the appropriate scope. The scope refers to whether a specific project is searched or all open projects. In the screenshot below the cursor is on a BLMedia_LoadFile() function call when Find Usages is invoked.
Running Find Usages
Click Find to run the utility and display the locations where the selection was used in the Usages Window.
An example of the results is shown below. In this case a header file called USB.h was used:
Usage Window Buttons
The buttons on the left hand side of the Usages Window have the following functionality.
|Refresh||Expand/Collapse Tree||Logical View||Physical View||Previous Occurance||Next Occurrance|
- Refresh re-runs the Find Usages utility.
- Expand/Collapse Tree compresses/decompressed the +/- for each node of the results.
- Logical View organizes the results tree to match the logical project window organization.
- Physical View organizes the results tree to match the physical arrangement of the files. (For example, .inc file hierarchy on the hard drive)
- Previous/Next Occurrence moves through the find usages results in the source editor.
General Find Usages Caveats
Moving through usages is difficult when the Usages window is minimized (meaning not pinned). When the Usages window is not pinned, it disappears each time a different usage is selected. For this reason, select:
At the top right of the Usages window instead of
At the top right of the Usages window to make browsing between instances simpler.
The cursor location and text selection can confuse Find Usages, and may result in errors such as "Find Usages Cannot Be Applied In this Context," and "The original element being refactored is not available." For this reason it may be beneficial to use Find Usages within the Class Dialog shown in step 1. The first screenshot shows the result from running Find Usages on whitespace on a blank line, while the second shows the results from running Find Usages on a commented configuration macro: