Automatic Updates When Renaming, Deleting, or Removing Project Files - MATLAB & Simulink (original) (raw)
Main Content
Project refactoring tools help you use automatic updates to find and fix files impacted by renaming, deleting, or moving files and folders.
When you rename, delete, or remove files or folders in a project or project reference, a dependency analysis checks for other impacted files and proposes updates. By default, the analysis runs on project files only. You can choose to run the analysis on all files or disable all automatic updates.
To disable all automatic updates when renaming, deleting, or removing files in a project or a project reference, on the MATLABĀ® Home tab, in the Environment section, clickSettings. In the Settings dialog box, in > , in the File Management section, set Detect file uses upon renaming, moving, or deletion in project hierarchy toNever.
You can find and fix impacts to files such as changed library links, model references, and model callbacks. Automatic renaming helps to prevent errors that result from changing names or paths manually and overlooking or mistyping one or more instances of the name.
- When renaming a library, the project offers to automatically update all library links to the renamed library.
- When renaming a class, the project offers to automatically update all classes that inherit from it. If you rename a
.m
or.mlx
file, the project offers to automatically update files and callbacks that call it. The project does not automatically update.mlx
files. You need to update them manually. - When deleting files or removing them from the project, the project prompts you if other files refer to them. You must decide how to fix the affected files manually.
- When renaming a C file, the project prompts you to update the S-function that uses it.
- When renaming buses or bus elements using the SimulinkĀ® Type Editor, the project prompts you to update all usages in the project.
You can disable the project prompt and analysis when renaming buses or bus elements while keeping automatic updates enabled for other files. On the MATLABHome tab, in the Environment section, click Settings. In the Settings dialog box, in > , in the File Management section, clearDetect impact across project hierarchy when renaming Simulink buses and bus elements.
To use automatic updates, follow these steps:
- Rename a model, library, or MATLAB file in a project. The project then runs a dependency analysis to look for impacts in other files.
- In the Rename Files dialog box, you can examine impacted files, choose to rename and update, just rename, or cancel renaming the file.
- If you choose automatic updates, you can examine the results in updated files.
To move or add project files, you can drag them to the project or use clipboard operations.
- To add files to your project, paste the files or drag them from your operating system file browser or the MATLAB Files panel onto the Project panel. When you drag a file to the Project panel, you add the file to the project. For projects under source control, you also add the file to source control.
- To move files within your project, cut and paste or drag files in the project.
For more information, see Manage Project Files.
Automatic Renaming in Project
In this example, you rename a file in the project. A dependency analysis then runs and flags several files that uses the file.
Open Example Project
Open the Airframe example project using openExample('simulink/AirframeProjectExample')
.
Rename File and Update Dependencies
In the Project panel, in the models
folder, you rename thef14_airframe.slx
model file tof14.slx
. The project runs a dependency analysis to look for impacts in other files. The refactoring tool lists the files that require updates and proposes automatic updates when possible. If it is possible to automatically update the file dependencies, the tool selects the corresponding check boxes.
In this example, the tool detects two files that require updates.
To update all dependencies, follow these steps:
- In the Rename Files dialog box, expand the rows to view the dependency details. In this example, the first dependency is due to a function call and the second is due to a model reference.
- To view the dependency highlighted in the MATLAB and Simulink editors, double-click the line in the Rename Files dialog box. For example, double-click the last line. Observe the model name on the highlighted block,
F14 Aircraft Dynamic Model
. - To update the impacted files, in the Rename Files dialog box, click Rename and Update.
The project updates the impacted files to use the new model name. When the project can automatically rename items, it reports success with a green icon. The tool reports the item that requires manual updates with a blue information icon. - To manually update the remaining dependencies, double-click every line listed under the information icon. The tool opens the files that require an update and highlights the dependency.
In this example, in thef14_airframe_test.m
file, you must update the arguments of the function calls on line 30 and 31 fromf14_airframe
tof14
. - In the Rename Files dialog box, clickClose.