Whole Tomato Software - Home
  • RSS Feed

Move Selection to New File

Refactor with Move Selection to New File to split a large file into manageable pieces, to share code among modules, or to reveal previously private code.

Use other refactoring commands, e.g. Move Implementation to Source File, to move code between existing source files and header files.

Access

To move into a new file, select one or more entire lines, then choose Move Selection to New File from a refactoring menu (Shift+Alt+Q).

In the dialog that opens, enter a file name for the destination—a file that cannot exist. If the destination is a header file, you have the option of including the new file in the current file.

Your selection is moved to a new file, and formatted according to a VA Snippet. The new file is created in the same directory as your original file, and automatically added to your current project.

If you chose the option, an include directive is inserted in your original file.

If you move to a new file the declaration of one class from a multi-class header file, presumably to create manageable pieces, follow your move with another that moves the corresponding class implementation to a new source file. If you first move a class implementation, follow it with another that moves the corresponding class declaration.

Format

You can customize the content of new files by editing several VA Snippets related to refactoring. There are separate VA Snippets for separate programming languages, and in the case of C/C++, for header files and source files.

Type of destination file VA Snippet for format
C++ header Create Header File
C++ source Create Source File
C# source Create File

For example, the default VA Snippet for Create Header File makes use of the Microsoft #pragma directive.

Modify the VA Snippet if you prefer to guard with a universal #ifdef.