Archived:Codewarrior Scripting
Contents |
Introduction
CodeWarrior has a (poor) scripting API that can be used to add nifty little helper features that can make the everyday programming task a bit more easier.
Installation
All that needs to be done is to store the perl scripts to a folder somewhere and then adding a command binding in CodeWarrior to call the script. In each script I will give the binding that I use, but they can be bound to any key combination.
To Upper/Lower Case
This is a script that implements the conversion of selected text to upper or lowercase. This comes standard in Visual Studio, but is lacking from CodeWarrior.
File: upper_case.pl
use strict;
use warnings;
use Win32::OLE;
use POSIX;
# Create instance of CodeWarrior
my $CWApp = Win32::OLE->new("CodeWarrior.CodeWarriorApp");
# Get active document
my $doc = $CWApp->ActiveDocument() or die "can't get active doc!\n";
my $text_engine = $doc->TextEngine or die "can't get TextEngine!\n";
# Check that there is a selection
if( $text_engine->HasSelection() ) {
# Get selected text
my $selected_text = $text_engine->SelectionText();
my $param = uc $ARGV[0];
if ( $param eq "L" ) {
$selected_text = lc $selected_text;
} else {
$selected_text = uc $selected_text;
}
# Reset the selected line contents
$text_engine->InsertText( $selected_text );
}

