Tools+ reference
Tool Creation
Creating a new tool is fairly simple, and can be completed in a few simple steps.
Tool Name
This is the name that will be displayed in the Tools(+) dropdown menu. It will also be displayed as the tab name for tools that redirect to the Tools output window.
Command Line
Any valid command line function and switches can be placed here. Variable substitution is also accepted. The following list contains the more useful variables; see Variable expansion for the full list.
$relfile
,$file
: respectively the relative and absolute name of a selected file
$reldir
,$dir
: respectively the relative and absolute name of a selected directory
$relpath
,$path
: the relative and absolute name of the selected file or directory
$mpaths
: a list of selected files or directories (absolute paths only)
$fname
,$fext
: the name without extension and the extension without name of a selected file
$inputstr{prompt}
: prompts the user to enter a string of text which is subsituted into the command line
$if(condition){true clause}{false clause}
: resolves to false clause
if condition
is empty, 0, or false; otherwise true clause
File Types
Wildcard expressions separated by semicolons will restrict population of the right click menu of a file, directory, or multiple paths in the Project Tree, File Explorer, or Editor Pane to the specified type(s). Leave blank to handle all file/directory types.
Working Directory
The directory from which the command is executed. Code::Blocks variables, project variables, and global variables are available. Also,
- If you have specified
$dir
in the command line then you can use$dir
here also. $parentdir
is available for$relfile
,$file
,$reldir
,$dir
,$relpath
,$path
,$fname
,$fext
and is the absolute path of the directory containing the item.
Tools Menu Path
Controls the placement of the command in the Tools(+) menu, giving the option of adding submenues (multiple levels are allowed).
- Submenu/Tool1
- Submenu/Tool2
- Tool3
Will create this structure.
The command name will be used if this entry is blank. If the first character is a period, the command will be hidden.
Context Menu Path
This controls the command's placement in the right-click menu of the Projects and Files tabs of the Management pane. The same rules of structure with the Tools Menu Path apply here.
Please note that the command will not show up in the context menu unless the Command Line contains one or more of the following: $relfile
, $file
, $reldir
, $dir
, $relpath
, $path
, $fname
, and $fext
.
Output to
This determines where the output of the command will be redirected. The purpose and function of the command will determine which is best to select.
Tools Output Window
Tools that only output results command (and require no input) line generally use this setting. The program will be run invisibly and any output will be redirected to the appropriate tab of the Tools Output Window. The text [DONE] will be added upon the tool's completion.
Code::Blocks Console
This will cause the program to be run through the executable cb_console_runner (the same program that is launched after Build and run). This is generally used for command line tools with more advanced user interactions, although GUI programs can also be used (especially if the program is unstable and/or also leaves messages in the standard output). Console runner will pause the window (prevent it from closing), display the run time, and the exit code when the program finishes.
Standard Shell
This is the same as placing the command in a batch or shell script, then running it. The program will run in whatever its default method is, and when it finishes, its window will close. This setting is useful for running a program (for example a file or web browser) that must remain open after Code::Blocks is closed.
Example Tools
Open file browser to selected file
- Windows
explorer /select,"$path"
- (To do: add other file browsers)
Update Subversion directory
- Windows
path_to_svn\bin\svn update "$dir"
- Linux
svn update "$dir"
Compress active project to archive
- Windows
path_to_7z\7z a -t$if(zip == $inputstr{7z or zip?}){zip -mm=Deflate -mmt=on -mx9 -mfb=128 -mpass=10}{7z -m0=LZMA -mx9 -md=64m -mfb=64 -ms=on} -sccUTF-8 "-w$(PROJECTDIR).." "$(PROJECTDIR)..\$(PROJECT_NAME)" "$(PROJECTDIR)*"
- Linux
p7zip a -t$if(zip == $inputstr{7z or zip?}){zip -mm=Deflate -mmt=on -mx9 -mfb=128 -mpass=10}{7z -m0=LZMA -mx9 -md=64m -mfb=64 -ms=on} -sccUTF-8 "-w$(PROJECTDIR).." "$(PROJECTDIR)../$(PROJECT_NAME)" "$(PROJECTDIR)*"