The things you can do with this interface are:
One of the first things you need to do in your script is create an instance of the CodeWarrior application so you can manipulate the IDE with subsequent commands, as shown in Listing 3.4. Once you have created an instance of the application to manipulate, you can then use other script commands to do useful tasks in your script.
Example Usage: Creating an Application Instance:
set CW = CreateObject("CodeWarrior.CodeWarriorApp")
This allows you to open a project file in the IDE, as demonstrated in the sample script in Listing 3.5.
OpenProject takes the arguments shown in Table 3.7:
Argument
Functionality
ECodeWarriorConvertOption convertOption
ECodeWarriorRevertPanelOption revertOption
ICodeWarriorApp.OpenProject Arguments:
You can find information about the possible enumeration values in the sections entitled "ECodeWarriorConvertOption" and "ECodeWarriorRevertPanelOption."
ICodeWarriorProject** pval - the project
projectname = "c:\testprojects\test1.mcp"
set CW = CreateObject("CodeWarrior.CodeWarriorApp")
set project = CW.OpenProject(projectname, true, 2, 0 )
If you wanted the project to be opened without showing the window,
change true to false in line 3 of Listing 3.5.
This allows you to open a project file in the IDE, as demonstrated in the sample script in Listing 3.6.
OpenProjectByFileSpec takes the arguments shown in Table 3.8:
Argument
Functionality
IFileSpec * FileSpec
ECodeWarriorConvertOption convertOption
ECodeWarriorRevertPanelOption revertOption
ICodeWarriorApp.OpenProjectByFileSpec Arguments:
You can find more information about file specs in the section entitled "IFileSpec."
ICodeWarriorProject** pval - the project.
Opening a Project By File Spec:
`First create a FileSpec as shown in "IFileSpec."set CW = CreateObject("CodeWarrior.CodeWarriorApp")
set project = CW.OpenProjectByFileSpec(projectspec, true, 2, 0 )
This allows you to retrieve the full path to the CodeWarrior executable program, as shown in Listing 3.7.
BSTR* pval -The full path to the CodeWarrior IDE executable program.
'*** create an instance of CodeWarrior
set CW = CreateObject("CodeWarrior.CodeWarriorApp")
'*** turn on user interaction
result = CW.FullName
`*** display a message box with the full path to the IDE
MsgBox CStr( result )
This allows you to retrieve the name of the CodeWarrior executable program, as shown in Listing 3.8.
BSTR* pval -The name of the CodeWarrior IDE executable program.
'*** create an instance of CodeWarrior
set CW = CreateObject("CodeWarrior.CodeWarriorApp")
'*** turn on user interaction
result = CW.Name
`*** display a message box with the name of the IDE
MsgBox CStr( result )
This allows you to see whether the CodeWarrior IDE will allow windows to be visible, as shown in Listing 3.9.
VARIANT_BOOL pval -true or false, whether visible or not.
'*** create an instance of CodeWarrior
set CW = CreateObject("CodeWarrior.CodeWarriorApp")
'*** See if visible
result = CW.Visible
`*** display a message box with True or False
MsgBox CStr( result )
This returns the current default project. An example is shown in Listing 3.10.
ICodeWarriorProject** Project - the default project.
Working with the Default Project:
option explicit 'all variables must be declared
dim CW
dim project 'default project (and others)
dim textDocument 'text document object to hold report
dim textEngine 'the object for dealing with text
dim eol 'end-of-line character for formatting
dim result 'returned values
eol = chr(13) 'set end of line character
'***create an instance of CodeWarrior
set CW = CreateObject("CodeWarrior.CodeWarriorApp")
'***create text document and get engine
set textDocument = CW.OpenUntitledTextDocument()
set textEngine = textDocument.TextEngine
'*** get the default project
set project = CW.DefaultProject
dim projectName 'path and name of project
dim projectList 'collection of open projects
dim index 'loop counter
if TypeName(project) = "Nothing" then
textEngine.InsertText("Script operates on default project." &eol)
textEngine.InsertText("There must be at least one open project." &eol)
else
textEngine.InsertText("DEFAULT PROJECT INFORMATION" &eol)
'*** get the project name
result = project.Name
textEngine.InsertText("Project: " &result &eol)
'*** get the project path
result = project.FileSpec.FullPath
textEngine.InsertText("Path: " &result &eol)
'*** get the project visibility state
result = project.IsVisible
textEngine.InsertText("Visible: " &result &eol)
end if
You can configure whether the IDE should be allowed to present
dialog boxes that interact with the user as required (or not).
Listing 3.11 shows an example of how to enable this. The default setting is
true. If you set it false, the user will not be permitted to interact with the IDE.
NOTE Due to some side effects at the time of this writing, you should probably leave this at the default first, then experiment with it later if you require this feature. It may not be fully implemented at this time.
Enabling the IDE to prompt the user with dialog boxes:
'*** create an instance of CodeWarrior
set CW = CreateObject("CodeWarrior.CodeWarriorApp")
'*** turn on user interaction
CW.AllowUserInteraction = true
This allows you to create a new project, specifying a file name and path, as shown in Listing 3.12.
ICodeWarriorApp.CreateProject Arguments:
ICodeWarriorProject** pval - the project file that is created.
'*** create an instance of CodeWarrior
set CW = CreateObject("CodeWarrior.CodeWarriorApp")
'*** make sure that the project file does not exist
projectname = "c:\testing\Test.mcp"
DeleteFile(projectName)
'*** create the project (path, no linker, no design,
`*** target myTarget, visible)
set project = CW.CreateProject(projectName, "None", "", "myTarget", true)
'*** get a list of all open projects
set projectList = CW.Projects
'*** loop through all open projects
For index = 0 to projectList.Count - 1
'*** get the individual project
set project = projectList.Item(index)
'*** close the project
project.Close
Next
'*** open a project (path, visible, ask if
`*** converting, allow revert)
set project = CW.OpenProject(projectName, true, 2, 1)
Sub DeleteFile(path)
On Error Resume Next
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
if ( fso.FileExists( path ) ) then
fso.DeleteFile(path)
end if
End Sub
This requires a valid XML-format file. You can import the XML file to create a project from the XML representation.
NOTE The best way to alter build settings at the present time is to modify an exported XML file and re-import it. By modifying the file you can alter the build settings.
ICodeWarriorApp.ImportProject Arguments:
ICodeWarriorProject** pval - the project file that is created.
This requires a valid XML-format file. You can import the XML file to create a project from the XML representation.
NOTE The best way to alter build settings at the present time is to modify an exported XML file and re-import it. By modifying the file you can alter the build settings.
Argument
Functionality
IFileSpec* textFilePath
IFileSpec* projectFilePath
ICodeWarriorApp.ImportProjectByFileSpec Arguments:
ICodeWarriorProject** pval - the project file that is created.
This can be used to query the state of settings panels (preferences) in the CodeWarrior IDE. In most cases, it won't make sense to use this, because in order to make sense of the data, you would need some internal information about the panel resources.
If you are using a scripting language that can handle streaming data (streams), you could create your own settings panels and query them. Otherwise, you would need to use a COM-based tool in order to take advantage of this capability.
ICodeWarriorApp.GetNamedPluginData Arguments:
IStream** pluginData - the stream of data.
Change Settings Panels - SetNamedPluginData
This can be used to set the state of settings panels (preferences) in the CodeWarrior IDE. In most cases, it won't make sense to use this, because in order to make sense of the data, you would need some internal information about the panel resources.
If you are using a scripting language that can handle streaming data (streams), you could create your own settings panels and set or query them. Otherwise, you would need to use a COM-based tool in order to take advantage of this capability.
NOTE You do not have the capability to change existing settings panels in the IDE. You could write your own though using the COM API (covered in a separate manual).
Argument
Functionality
IStream** pluginData
ICodeWarriorApp.SetNamedPluginData Arguments:
This allows you to get IDE Preference settings, as shown in Listing 3.13.
NOTE At this point, the only two settingsName arguments that work are SaveBeforeBuild and ContextPopupDelay. More are under development.
ICodeWarriorApp.GetSetting Arguments:
VARIANT* pval-true or false, whether to set the setting or not.
'*** create an instance of CodeWarrior
set CW = CreateObject("CodeWarrior.CodeWarriorApp")
'BUG - reports false regardless of actual state of this setting
result = CW.GetSetting("SaveBeforeBuild")
This allows you to set IDE Preference settings, as shown in Listing 3.14.
NOTE At this point, the only settingsName two arguments that work are SaveBeforeBuild and ContextPopupDelay. More are under development.
ICodeWarriorApp.SetSetting Arguments:
Force File Saves Before a Build:
'*** create an instance of CodeWarrior
set CW = CreateObject("CodeWarrior.CodeWarriorApp")
'create text document and get engine
set textDocument = CW.OpenUntitledTextDocument()
set textEngine = textDocument.TextEngine
'Note: VBScript syntax quirk: call subroutines w/o parentheses
'*** set the "SaveBeforeBuild" setting to true
CW.SetSetting "SaveBeforeBuild", true
This allows you to open an existing file window, referenced as a file spec (see "IFileSpec").
ICodeWarriorApp.OpenTextDocument Arguments:
ICodeWarriorTextDocument** document-a reference to the text document.
This allows you to open an existing file window, as shown in Listing 3.15.
ICodeWarriorApp.OpenTextDocument Arguments:
ICodeWarriorTextDocument** document-a reference to the text document.
'*** create an instance of CodeWarrior
set CW = CreateObject("CodeWarrior.CodeWarriorApp")
'open text document and get engine
set textDocument = CW.OpenTextDocument("c:\filee.c", false )
set textEngine = textDocument.TextEngine
This allows you to open a new file window for text input, as shown in Listing 3.16.
ICodeWarriorTextDocument** document-a reference to the text document.
option explicit 'all variables must be declared
dim CW
dim textDocument 'text document object to hold report
dim textEngine 'the object for dealing with text
dim eol 'end-of-line character for formatting
eol = chr(13) 'set end of line character
'*** create an instance of CodeWarrior
set CW = CreateObject("CodeWarrior.CodeWarriorApp")
'create text document and get engine
set textDocument = CW.OpenUntitledTextDocument()
set textEngine = textDocument.TextEngine
'Note: VBScript syntax quirk: call subroutines w/o parentheses
'*** set the "SaveBeforeBuild" setting to true
CW.SetSetting "SaveBeforeBuild", true
`*** put up a window
textEngine.InsertText ("APPLICATION INFORMATION" &eol)
This allows you to test a file, referenced as a file spec (see "IFileSpec").
Argument
Functionality
IFileSpec* FileSpec
ECodeWarriorVCSInteractionOption uiParameter
ICodeWarriorProject* Project
ICodeWarriorApp.AttemptModify Arguments:
This allows you to determine whether the IDE is doing a build or not, as shown in Listing 3.17.
VARIANT_BOOL * pval-true or false, whether the build is in progress or not.
Checking for whether a build is in progress:
'*** create an instance of CodeWarrior
set CW = CreateObject("CodeWarrior.CodeWarriorApp")
result = CW.IsBuildInProgress