[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]


ICodeWarriorApp

The things you can do with this interface are:


Get an Application Instance - CreateObject


Example Usage

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")


Open A Project - OpenProject

This allows you to open a project file in the IDE, as demonstrated in the sample script in Listing 3.5.


Arguments

OpenProject takes the arguments shown in Table 3.7:

 

Argument
Functionality
BSTR filePath  
The quoted path to the existing project file  
VARIANT_BOOL fMakeVisible  
true or false, whether to show the open project window or not  
ECodeWarriorConvertOption   convertOption  
Whether or not to Convert the project file to the latest format if it is in an older project file format  
ECodeWarriorRevertPanelOption   revertOption  
Whether or not to Revert a project to the previously-saved file that is on the disk.  

ICodeWarriorApp.OpenProject Arguments:

You can find information about the possible enumeration values in the sections entitled "ECodeWarriorConvertOption" and "ECodeWarriorRevertPanelOption."


Return Value

ICodeWarriorProject** pval - the project


Example Usage

Opening a 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.


Open A Project By File Spec- OpenProjectByFileSpec

This allows you to open a project file in the IDE, as demonstrated in the sample script in Listing 3.6.


Arguments

OpenProjectByFileSpec takes the arguments shown in Table 3.8:

 

Argument
Functionality
IFileSpec * FileSpec  
The file spec for the existing project file  
VARIANT_BOOL fMakeVisible  
true or false, whether to show the open project window or not  
ECodeWarriorConvertOption   convertOption  
Whether or not to Convert the project file to the latest format if it is in an older file format  
ECodeWarriorRevertPanelOption   revertOption  
Whether or not to Revert a project to the previously-saved file that is on the disk.  

ICodeWarriorApp.OpenProjectByFileSpec Arguments:

You can find information about the possible enumeration values in the sections entitled "ECodeWarriorConvertOption" and "ECodeWarriorRevertPanelOption."

You can find more information about file specs in the section entitled "IFileSpec."


Return Value

ICodeWarriorProject** pval - the project.


Example Usage

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 )


Getting the Full Path Name - FullName

This allows you to retrieve the full path to the CodeWarrior executable program, as shown in Listing 3.7.


Arguments

None


Return Value

BSTR* pval -The full path to the CodeWarrior IDE executable program.


Example Usage

Getting the Full Path Name:


'*** 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 )


Getting the IDE Executable Name - Name

This allows you to retrieve the name of the CodeWarrior executable program, as shown in Listing 3.8.


Arguments

None


Return Value

BSTR* pval -The name of the CodeWarrior IDE executable program.


Example Usage

Getting IDE Name:


'*** 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 )


Getting the Visibility of the Windows - Visible

This allows you to see whether the CodeWarrior IDE will allow windows to be visible, as shown in Listing 3.9.


Arguments

None


Return Value

VARIANT_BOOL pval -true or false, whether visible or not.


Example Usage

Determining Visibility:


'*** 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 )


Getting the Default Project - DefaultProject

This returns the current default project. An example is shown in Listing 3.10.


Arguments

None


Return Value

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


Toggling User Interaction - AllowUserInteraction

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.


Arguments

None

Return Value

None


Example Usage

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


Creating a Project - CreateProject

This allows you to create a new project, specifying a file name and path, as shown in Listing 3.12.


Arguments

 

Argument
Functionality
BSTR filePath  
The full path and file name of the project file you want to create.  
BSTR linkerName  
Set this to "None" if you don't want to specify a linker. If you pass a null string then the default linker will be chosen.  
BSTR designName  
The name of the design. If not specified (i.e. you pass the null string) no design is created.  
BSTR targetName  
The name of the default target you want to create for the project. If not specified (null string) then the target is named after the project.  
VARIANT_BOOL fMakeVisible  
 

ICodeWarriorApp.CreateProject Arguments:

Return Value

ICodeWarriorProject** pval - the project file that is created.

Creating a Project:


'*** 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


Importing a Project File - ImportProject

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.



Arguments

 

Argument
Functionality
BSTR textFilePath  
The path to the XML text file.  
BSTR projectFilePath  
The path to the project file.  
VARIANT_BOOL fMakeVisible  
Whether to make the project visible or not.  

ICodeWarriorApp.ImportProject Arguments:

Return Value

ICodeWarriorProject** pval - the project file that is created.


Importing a Project File - ImportProjectByFileSpec

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.



Arguments

 

Argument
Functionality
IFileSpec* textFilePath  
The path to the XML text file.  
IFileSpec* projectFilePath  
The path to the project file.  
VARIANT_BOOL fMakeVisible  
Whether to make the project visible or not.  

ICodeWarriorApp.ImportProjectByFileSpec Arguments:

Return Value

ICodeWarriorProject** pval - the project file that is created.


Query Settings Panels - GetNamedPluginData

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.


Arguments

 

Argument
Functionality
BSTR resourceName  
The resource name  

ICodeWarriorApp.GetNamedPluginData Arguments:

Return Value

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).



Arguments

 

Argument
Functionality
BSTR resourceName  
The resource name  
IStream** pluginData  
The stream of data  

ICodeWarriorApp.SetNamedPluginData Arguments:

Return Value

None


Changing Settings - GetSetting

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.



Arguments

 

Argument
Functionality
BSTR settingsName  
The name of the setting to change  

ICodeWarriorApp.GetSetting Arguments:

Return Value

VARIANT* pval-true or false, whether to set the setting or not.


Example Usage

Get a Setting:


'*** create an instance of CodeWarrior
set CW = CreateObject("CodeWarrior.CodeWarriorApp")
'BUG - reports false regardless of actual state of this setting
result = CW.GetSetting("SaveBeforeBuild")


Changing Settings - SetSetting

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.



Arguments

 

Argument
Functionality
BSTR settingsName  
The name of the setting to change  
VARIANT pval  
true or false, whether to set the setting or not  

ICodeWarriorApp.SetSetting Arguments:

Return Value

None


Example Usage

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


Opening an Existing Text File - OpenTextDocumentByFileSpec

This allows you to open an existing file window, referenced as a file spec (see "IFileSpec").


Arguments

 

Argument
Functionality
IFileSpec* FileSpec  
The file spec for the text file  
VARIANT_BOOL create  
true or false, whether to create the document or not if it doesn't already exist  

ICodeWarriorApp.OpenTextDocument Arguments:

Return Value

ICodeWarriorTextDocument** document-a reference to the text document.


Opening an Existing Text Document - OpenTextDocument

This allows you to open an existing file window, as shown in Listing 3.15.


Arguments

None

 

Argument
Functionality
BSTR * inPath  
The full path for the text file  
VARIANT_BOOL create  
true or false, whether to create the document or not if it doesn't already exist  

ICodeWarriorApp.OpenTextDocument Arguments:

Return Value

ICodeWarriorTextDocument** document-a reference to the text document.


Example Usage

Opening Text Window:


'*** 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


Opening a New Text Document - OpenUntitledTextDocument

This allows you to open a new file window for text input, as shown in Listing 3.16.


Arguments

None


Return Value

ICodeWarriorTextDocument** document-a reference to the text document.


Example Usage

Opening Untitled Text Window:


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)


Check a File's Writability - AttemptModify

This allows you to test a file, referenced as a file spec (see "IFileSpec").


Arguments

 

Argument
Functionality
IFileSpec* FileSpec  
The file spec for the file  
ECodeWarriorVCSInteractionOption   uiParameter  
The interaction option  
ICodeWarriorProject* Project  
The CW project  

ICodeWarriorApp.AttemptModify Arguments:

Return Value

None


Build Progress - IsBuildInProgress

This allows you to determine whether the IDE is doing a build or not, as shown in Listing 3.17.


Arguments

None


Return Value

VARIANT_BOOL * pval-true or false, whether the build is in progress or not.


Example Usage

Checking for whether a build is in progress:


'*** create an instance of CodeWarrior
set CW = CreateObject("CodeWarrior.CodeWarriorApp")
result = CW.IsBuildInProgress


[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.

Last updated: August 02, 2000