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


ICodeWarriorProject

This class allows you to manipulate projects. The topics covered in this section include:


Getting a Project Name - Name

This lets you retrieve the name of a project, as shown in Listing 3.20.


Arguments

None


Return Value

BSTR* pval - the project name.


Example Usage

Getting a Project Name:


'create an instance of CodeWarrior
set CW = CreateObject("CodeWarrior.CodeWarriorApp")
projectname = "c:\testing\Test.mcp"
'*** open a project (path, visible, ask if 
`*** converting, allow revert)
set project = CW.OpenProject(projectName, true, 2, 1)
'***get the default project and name
projectName = project.Name


Getting a Project File Spec - FileSpec

This lets you retrieve the file spec of a project, as shown in Listing 3.21.


Arguments

None


Return Value

IFileSpec** pval - the project file spec.


Example Usage

Getting a Project File Spec:


'***create an instance of CodeWarrior
set CW = CreateObject("CodeWarrior.CodeWarriorApp")
projectname = "c:\testing\Test.mcp"
'*** open a project (path, visible, ask if 
`*** converting, allow revert)
set project = CW.OpenProject(projectName, true, 2, 1)
'*** get the project path
result = project.FileSpec.FullPath


Getting a List of Designs - Designs

This allows you to get a collection of all the designs. Refer to Listing 3.26 for a detailed example of working with targets.


Arguments

None


Return Value

ICodeWarriorDesignCollection** pval - the collection of targets.


Getting a List of Targets - Targets

This allows you to get a collection of all the targets in a project. Refer to Listing 3.26 for a detailed example of working with targets.


Arguments

None


Return Value

ICodeWarriorTargetCollection** pval - the collection of targets.


Seeing if a Project File is Visible - IsVisible

This lets you see if the window of a project window is visible, as shown in Listing 3.22.


Arguments

None


Return Value

VARIANT_BOOL* pval - the visibility value.


Example Usage

Seeing if a Project is Visible:


'***create an instance of CodeWarrior
set CW = CreateObject("CodeWarrior.CodeWarriorApp")
projectname = "c:\testing\Test.mcp"
'*** open a project (path, visible, ask if 
`*** converting, allow revert)
set project = CW.OpenProject(projectName, true, 2, 1)
'*** get the project visibility state
result = project.IsVisible


Getting the Version Control Object - VersionControl

This lets you obtain the version control settings for a project.


Arguments

None


Return Value

ICodeWarriorVersionControl** VersionControl - the version control object.


Closing a Project - Close

This closes a project window, as demonstrated in Listing 3.23.


Arguments

None


Return Value

None


Example Usage

Closing a Project:


'***create an instance of CodeWarrior
set CW = CreateObject("CodeWarrior.CodeWarriorApp")
projectname = "c:\testing\Test.mcp"
'*** open a project (path, visible, ask if 
`*** converting, allow revert)
set project = CW.OpenProject(projectName, true, 2, 1)
'*** close the project
project.Close		


Exporting a Project - Export

This creates an XML file containing the details of the project file. An example is shown in Listing 3.24.


Arguments

 

Argument
Functionality
BSTR filePath  
The path to the XML file to create  

ICodeWarriorProject.Export Arguments:

Return Values

None


Example Usage

Exporting a Project:


' file: groups.vbs
' author:  Kurt Marley, AG Communication Systems
' created: Jan. 23, 2000
' This script was created as an exercise for the students in
' the Scripting CodeWarrior course available from Metrowerks.

' This script creates an application object, gets the default
' project.  It then Exports the entire project in XML format
' inorder to read the XML and find all Groups in the File View.
' All Groups are displayed along with the files which are
' contained within each Group. 

option explicit

dim CW              'ICodeWarrior
dim project			'default project
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
dim projectName     'name of default project
dim FileSpecFor_xml 'XML file name
dim FSO             'IFileSystem
dim TS              'ITextStream
dim fileLine        'text line read from xml file
dim i               'loop; math
dim j               'math
dim GroupName       'group name
dim File            'file within current group
dim GroupLevel      'group nesting level
dim GroupCount      'number of groups
dim foundit         'loop flag

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

'do some error control here
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  ' valid project

    ' Export the project as XML, open that XML file,
    ' read down to the <GROUPLIST> line and then parse
    ' for:
    '   <GROUP><NAME>GroupName</NAME> = beginning of group             
    '                                   with name of group;
    '                        </GROUP> = end of group; and
    '           <PATH>Filename</PATH> = file within current
    '                                   group.

    projectName = project.Name
    textEngine.InsertText("Structure of project: " &projectName &eol)
    textEngine.InsertText("====================================" &eol)

    ' *** get fullpath filespec for project and append ".xml"
    FileSpecFor_xml = project.FileSpec.FullPath & ".xml"
    
    ' *** export entire project in XML format
    project.Export(FileSpecFor_xml)
    
    ' *** Xml file exists, try to open it
    set FSO = CreateObject("Scripting.FileSystemObject")
    if ( NOT FSO.FileExists( FileSpecFor_xml ) ) then
        textEngine.InsertText("**Couldn''t open " &FileSpecFor_xml &eol)
    end if
    set TS = FSO.OpenTextFile( FileSpecFor_xml )

    GroupLevel = 0  ' group Nesting Level
    GroupCount = 0  ' number of Groups

    ' *** find beginning of <GROUPLIST> in xml file
    foundit = False
    do 
        fileLine = TS.Readline
        if( instr( fileLine, "<GROUPLIST>") <> 0 ) then
            foundit = True
        end if
    loop until( foundit OR TS.AtEndOfStream )
    
    do while( NOT TS.AtEndOfStream )  ' if Not EOF
        fileLine = TS.Readline
        if( instr( fileLine, "<GROUP>" ) <> 0) then     ' if group
            i = 6 + instr( fileLine, "<NAME>"  )
            j = instr( fileLine, "</NAME>" )
            GroupName = mid( fileLine, i, j-i)          ' extract group name
	            for i=0 to GroupLevel
	                textEngine.InsertText("|--")
	            next
	        textEngine.InsertText("Group: " &GroupName &eol)
	        GroupLevel = GroupLevel + 1
	        GroupCount = GroupCount + 1
	    elseif( instr(fileLine, "</GROUP>") <> 0 ) then ' if end of group
	        if(GroupLevel>0) then
	            GroupLevel = GroupLevel - 1             ' decr. level if non-zero
	        end if
	    elseif( instr(fileLine, "<PATH>") <> 0) then    ' if file
            i = 6 + instr( fileLine, "<PATH>")
            j = instr( fileLine, "</PATH>")
            File = mid( fileLine, i, j-i)               ' extract file name
	            for i=0 to GroupLevel
	                textEngine.InsertText("|--")
	            next
	        textEngine.InsertText("File: " &File &eol)
	    end if
	    
	loop  ' while not EOF  

    TS.close
    
    textEngine.InsertText(" " &eol)
    textEngine.InsertText("..Total number of Groups: " &GroupCount &eol)
	       	    
end if  ' valid project


Exporting a Project - ExportByFileSpec

This creates an XML file containing the details of the project file.


Arguments

 

Argument
Functionality
IFileSpec* FileSpec  
The file spec for the XML file to create  

ICodeWarriorProject.ExportByFileSpec Arguments:

Return Values

None


Removing Project Binaries - RemoveBinaries

This removes binaries from a project , as demonstrated in Listing 3.25.


Arguments

None


Return Value

None


Example Usage

Removing Binaries from a Project:


'***create an instance of CodeWarrior
set CW = CreateObject("CodeWarrior.CodeWarriorApp")
projectname = "c:\testing\Test.mcp"
'*** open a project (path, visible, ask if 
`*** converting, allow revert)
set project = CW.OpenProject(projectName, true, 2, 1)
'*** purge binaries from the project
project.RemoveBinaries		


Setting Current Target - SetCurrentTarget

This lets you choose which target is the current target of a project. Refer to Listing 3.26 for a detailed example of working with targets.


Arguments

 

Argument
Functionality
BSTR targetName  
The name for the target to set.  

ICodeWarriorProject.SetCurrentTarget Arguments:

Return Value

None


Creating a Target - CreateTarget

This lets you create a new target in a project. Refer to Listing 3.26 for a detailed example of working with targets.


Arguments

 

Argument
Functionality
BSTR targetName  
The name for the target to set.  
BSTR linkerName  
The linker to set for the Target. See the settings panels of the IDE user interface for the list of available targets for your tools.  
ICodeWarriorDesign* Design  
The design to associate with the target.  

ICodeWarriorProject.CreateTarget Arguments:

Return Value

ICodeWarriorTarget** Target - the target that was created.


Removing a Target - RemoveTarget

This lets you remove an existing target from a project. Refer to Listing 3.26 for a detailed example of working with targets.


Arguments

 

Argument
Functionality
ICodeWarriorTarget* Target  
The name for the target to remove.  

ICodeWarriorProject.RemoveTarget Arguments:

Return Value

None


Finding a Target - FindTarget

This lets you find an existing target in a project. Refer to Listing 3.26 for a detailed example of working with targets.


Arguments

 

Argument
Functionality
BSTR Name  
The name for the target to find.  

ICodeWarriorProject.FindTarget Arguments:

Return Value

ICodeWarriorTarget** Target - the target that was created.


Cloning a Target - CloneTarget

This lets you clone an existing target in a project. Refer to Listing 3.26 for a detailed example of working with targets.


Arguments

 

Argument
Functionality
ICodeWarriorTarget* srcTarget  
The name for the target to clone.  
ICodeWarriorProject* srcProject  
The project that the target to clone is in.  
BSTR inDestTargetName  
The name of the target to be created.  
VARIANT_BOOL fCopyFileList  
Whether to copy all the files from the source target to the destination target.  
VARIANT_BOOL fCopyTargetSettings  
Whether to copy all the target settings from the source target to the destination target.  
ICodeWarriorDesign* Design  
The design to associate with the new target.  

ICodeWarriorProject.CloneTarget Arguments:

Return Value

ICodeWarriorTarget** Target - the target that was created.


Getting the Current Target - GetCurrentTarget

This lets you get the current target in a project. Refer to Listing 3.26 for a detailed example of working with targets.


Arguments

None


Return Value

ICodeWarriorTarget** Target - the target that was created.


Creating a Design - CreateDesign

This allows you to create a new design in your project file.


Arguments

 

Argument
Functionality
BSTR designName  
The name for the design  

ICodeWarriorProject.CreateDesign Arguments:

Return Value

None


Example Usage

Working with Targets:


' file:    03Targets.vbs
' author:  Jim Trudeau, Metrowerks
' created: August 23, 1999
' modification history
'

' This script was created as an exercise for the students in
' the Scripting CodeWarrior course available from Metrowerks.

' This script creates an application object and gets the default
' project. It then creates a new target, clones an existing
' target, and adds a file to the cloned target. It then displays
' a complete list of all targets in this project. After that,
' the script gets the current target. It displays the output
' file information for the current target.

' The course project "ScriptTest.mcp" must be the default
' project for all aspects of this script to work.


option explicit		'all variables must be declared


dim CW
dim project			'default project
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

'do some error control here
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

	dim theTarget 		'target
	dim design			'null design
	dim file			'file added to a target
	dim targetList		'collection of targets
	
	'remove targets to ensure they don't exist
	'this is here to allow students to run the script repeatedly
	RemoveNewTargets
	
	'*** create a target (name, linker, design)
	set theTarget = project.CreateTarget("New Target", "Win32 x86 Linker", nothing)
		
	'*** clone the new target (copy files and settings, no design)
	set theTarget = project.CloneTarget(theTarget, project, "Cloned Target", true, true, nothing)
	
	'*** add a file to the cloned target
	set file = theTarget.FindAndAddFile ("Sample.c", "Source")
	
	'*** get all targets for this project
	set targetList = project.Targets
	
	'list the name of all targets
	ListTargets targetList
		
	'*** get the current target
	set theTarget = project.GetCurrentTarget

	'*** get the browser state for the current target
	result = theTarget.BrowserEnabled
	
	DisplayOutputInfo theTarget
	
end if


'=========================================================
' ListTargets - display name of each target in collection
' receives target collection interface
'=========================================================

sub ListTargets (targets)

	dim index
	dim target
	
	textEngine.InsertText("Targets:" &eol)

	for index = 0 to targets.Count-1
		
		'get the individual target
		set target = targets.Item(index)
		
		'display the target name
		textEngine.InsertText("  " &target.Name &eol)
	next
	
	'skip a line
	textEngine.InsertText(eol)
	
end sub


'=========================================================
' DisplayOutputInfo - display target output info
' receives target interface
'=========================================================

sub DisplayOutputInfo (target)

	dim output		'interface to ICodeWarriorTargetOutput
	dim string		'array of strings
	dim result
	
	string = Array("none", "file", "directory")
	
	textEngine.InsertText("Output Information for ")
	textEngine.InsertText(target.name &eol)

	'*** get the output object
	set output = target.GetTargetOutput

	'*** get the kind of output
	result = output.OutputKind
	textEngine.InsertText("  Output Kind: " &string(result) &eol)
	
	'*** get the name of the output file
	result = output.FileSpec.Name
	textEngine.InsertText("  Output Name: " &result &eol)
	
	'*** get the path to the output file
	result = output.FileSpec.FullPath
	textEngine.InsertText("  Location: " &result &eol)
end sub

'=========================================================
' RemoveNewTargets - check to see if targets exist
' remove them if they do to avoid generating errors
' on multiple runs of this demo script
' receives project interface
'=========================================================

sub RemoveNewTargets

	dim theTarget
	
	'find the New Target
	set theTarget = project.FindTarget("New Target")

	'if it exists
	if TypeName(theTarget) <> "Nothing" then
	
		'remove it
		project.RemoveTarget theTarget
	end if

	'find the cloned target
	set theTarget = project.FindTarget("Cloned Target")

	'if it exists
	if TypeName(theTarget) <> "Nothing" then
	
		'remove it
		project.RemoveTarget theTarget
	end if
	
end sub


[ 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