CodeWarrior 使用教程第六课:定制

这篇博客介绍了如何通过定制CodeWarrior IDE的菜单、工具条和命令来提高工作效率。用户可以创建脚本,执行诸如删除编译过程中的多余文件、备份输出文件或构建安装程序等任务。通过定制,开发者能更好地组织工作流程,提高编程和调试的效率。
摘要由CSDN通过智能技术生成

概   述     
    这将是最简单的一课,但它却能够帮助帮助你更好地组织你的思想和开展工作。    

   正如我们在第一课中学到的,可以有许多中方式来为手头某个特定的任务定制 CodeWarrior。你可以定制 CodeWarrior 的外观和许多设置项,以便使得编译、连接和调试你的程序变得更快、更简单。     

    下面我们来看看可用于帮助你更有效地使用 CodeWarrior 的定制选项。因为定制 CodeWarrior 会改变 IDE 的所有行为,所以我们可以想到在编辑菜单下找到这些设置项。在那儿你将找到选择、命令和键绑定(Key Bindings)等菜单。点击其中的命令项就会显示定制 IDE 命令设置的窗口。定制 IDE 命令的面板包含两个主标签页。命令标签页允许你很容易的定制出现在每个 CodeWarrior 菜单中的命令。通过该标签页你也可以修改在内置的文本编辑器中使用的命令,例如选择文本和移动光标等命令。在这个设置窗口中,你还可以创建任何用于触发某个菜单命令项的组合键(也称之为键绑定——key binding),以此来启动一个应用程序,或者执行一个脚本。当然,你也可以设定一个某个命令项是否出现在一个菜单中。     

    定制 IDE 命令的面板中的另一个标签页是工具条项目标签页,在这个标签页中你可以看到在 CodeWarrior 的工具条中显示的项目,例如显示在每个文本编辑器窗口上方(或下方,取决于你的参数设置)。     

    在工具条项目标签页中,你只需点击一个工具条图标然后把它拖到主菜单下面的工具条或者文本编辑器窗口的工具条中,就可以往相应的工具条中增加一个命令。还可以把工具条中的一个图标拉到工具条的最后。从 CodeWarrior 的窗口菜单中的工具条子菜单中选择重设窗口的工具条(Reset Window Toolbar) 或重设浮动工具条菜单项,还可以重新设置该工具条。     

    在大多数情况下,CodeWarrior 的默认设置就可以满足你的要求了。偶尔你也可能发现一个通过改变一个菜单或工具条的方式来自动完成一些任务。关于 Codewarrior 的定制,你可以参考它的在线文档获得更多的信息。

CodeWarrior 定制示例

    通过定制 CodeWarrior,你可以增强你的工作环境和提高工作效率。     除了对菜单和工具条的简单修改之外,你可能还想只需点击一个图标或键入一个组合键就可以执行一个脚本或启动一个应用程序。有时当你正在参与一个非常庞大的开发项目的时候,需要做一些定制工作来解决自动设置带来的混乱问题。例如,你可以创建一个脚本来完成以下这些工作:
•自动删除编译过程中产生的多余的文件;  
•将输出文件复制到一个本地或网络上的目录中以做备份;  
•为你的工程创建一个安装应用程序。

    对于 Windows 用户而言,可以通过 VBScript,Perl或其它使用通用对象模型(Common Object Model,COM)接口的脚本语言来驱动 CodeWarrior Pro 5 IDE 完成一系列复杂的操作。如果使用 VBscript,你还需要一个可以执行 VBScript 的的应用程序(如 Internet Explorer 5),或者是一个 Scripting Host 工具——可以从以下网址下载 http://msdn.microsoft.com/scripting/windowshost/。  

   下面的 VBScript 脚本用于指导 CodeWarrior IDE 删除当前工程中的所有目标(object)文件,以便执行一个“干净的构建(build)”,然后再执行构建工作(编译和连接操作)。该脚本还打开一个编辑器窗口来显示操作结果(成功或失败的)的总结。这个脚本是有点长,但设计得很好,因为其中包含了许多用于错误检查的代码。

      ' 文件名:Build.vbs


 
          ' 作者: Jim Trudeau, Metrowerks


 
          ' 以及版权声明信息

          option explicit                     

           '所有的变量都必须进行声明

      dim CW
           dim project                      '默认的工程
      dim textDocument           '用于保存报告的文本文档
      dim textEngine                 '用于处理文本的对象
      dim eol                            '行尾字符格式
      dim result                        '返回的值

 
eol = chr(13)                     '设置行尾字符


'创建 CodeWarrior 的一个实例
set CW = CreateObject("CodeWarrior.CodeWarriorApp")

 
'创建一个文本文档并获得其引擎(Engine)
set textDocument = CW.OpenUntitledTextDocument()
set textEngine = textDocument.TextEngine

 
'得到默认的工程
set project = CW.DefaultProject

'错误控制
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 target   '当前目标
dim buildmessages '错误和警告


'*** 获得当前目标
set target = project.GetCurrentTarget


textEngine.InsertText("Build Information" &eol)

 
'显示名字
result = target.name

textEngine.InsertText("Building target " &result &eol)

'*** 删除所有的对象代码目标
RemoveObjectCode true

'*** 获得构建代码后的消息
set buildMessages = target.BuildAndWaitToComplete

ProcessMessages (buildMessages)
end if

'========================================================= ' ProcessMessages - get errors and warnings, process them ' receives build messages '=========================================================


sub ProcessMessages (messages)

 
dim result           '返回值
dim messageList '消息收集


'*** 获得错误的数量
result = messages.ErrorCount

if result = 0 then textEngine.InsertText(eol &"Build Succeeded." &eol)
else textEngine.InsertText(eol &"!!!BUILD FAILED!!!" &eol)

'*** 显示错误的数量
textEngine.InsertText("Number of errors: " &result &eol)

'*** 获得错误清单
set messageList = messages.Errors

'*** 处理错误
ProcessMessageList (messageList)
end if


'*** 检测是否有警告信息
result = messages.WarningCount

'*** 显示数量
textEngine.InsertText("Number of warnings: " &result &eol)


'*** 取得警告信息并处理之
if result then
'*** 获得警告信息清单
set messageList = messages.Warnings

'*** 处理警告信息
ProcessMessageList (messageList)
end if


end sub
 

'========================================================= ' ProcessMessagelist - loop through messages, report info ' receives message collection, could be errors or warnings '=========================================================


sub ProcessMessageList (messageList)

 
dim result '返回值
dim index '循环计数器
dim message '个人信息


'*** 遍历消息清单
for index = 0 to messageList.Count-1
'*** 获得个人信息
set message = messageList.Item(index)


'*** 获得消息文本
result = message.MessageText

'*** 显示消息文本
textEngine.InsertText(result &eol)

****在错误中忽略一行(skip a line between errors )
textEngine.InsertText(eol)
next

end sub

    因为使用了微软公司的 OLE/COM 查看器工具,这个 IDE 支持许多 COM 对象。一个脚本语言可以使用这些对象来与 CodeWarrior IDE 进行通信。关于 CodeWarrior 定制与脚本机制,还有很多优秀的功能,但在这里就不详述了,因为 CodeWarrior 把这些功能实现得非常好。打开上面所描述到得窗口自己看看吧!当你熟练使用了 CodeWarrior 的一些功能之后,你会发现它是非常的易用!  


附原文:

An Introduction to Customization

This will be the simplest lesson, but it will provide you with the flavoring that will help you organize your thoughts and work much better. As I mentioned in Lesson 1, there are many ways to customize CodeWarrior for the specific development task at hand. You can customize the look and feel of CodeWarrior as well as a multitude of options for compiling, linking, and debugging your code faster and more easily. Let's look at some of the customization options available to help you use CodeWarrior more efficiently. Since customizing CodeWarrior affects the IDE's overall behavior, we can expect to find such settings under the Edit menu. There you'll find the menu selection, Commands, and Key Bindings. Pick this item and the Customize IDE Commands settings window appears. The Customize IDE Commands panel contains two main tabs. The Commands tab allows you to easily customize the commands that appear in each CodeWarrior menu. With it you can also modify commands used within the built-in text editor, such as selecting text and moving the cursor. Using this window, you can create any key combination (key binding) that triggers any menu command, launches an application, or executes a script. You can also choose whether an item should appear on a menu. The Toolbar Items tab allows you to see which items appear in various CodeWarrior toolbars, such as the one that appears at the top (or bottom, depending upon your preference) of each text editor window. In the Toolbar Items tab, you can add a command to the toolbar (either the toolbar under the main menu or the text editor's window toolbar) by clicking on a toolbar item icon and dragging it to the toolbar to which you want to add it. Dropping the icon on the toolbar adds it to the end of that toolbar. You can reset the toolbar by selecting Reset Window Toolbar or Reset Floating Toolbar from the Toolbar submenu in the Window menu. In most cases, CodeWarrior's default settings will work for your needs. Every once in a while, you may find a way to automate some task by changing a menu or toolbar. Consult the CodeWarrior online documentation for more information about CodeWarrior customization.

CodeWarrior Customization Examples

By customizing CodeWarrior, you can enhance your work environment and become much more productive. In addition to simple changes to menus and toolbars, you may want to execute a script or launch an application by clicking an icon or typing a key combination. Sometimes, when you work on very large development projects, there is a need to automate more intricately and customize your development environment. For example, you could create a script to do any of the following:
•Automatically delete extra files created by the build process.
•Copy your output file or files to a local or network directory for backup.
•Build an installer application for your project.

For Windows, you can drive the CodeWarrior Pro 5 IDE through a complex sequence of operations using VBScript, Perl, or another scripting language that uses the Common Object Model (COM) interface. For VBScript, you'll need an application that executes VBScript (such as Internet Explorer 5), or the Scripting Host utility, available at http://msdn.microsoft.com/scripting/windowshost/. The following VBScript directs the CodeWarrior IDE to perform a "clean build" by removing all of the object files in the current project, and then executing the build (compile and link operations). The script also opens an editor window and displays a summary of the operation (success or failure). It's a trifle long, but that's fine because the script includes a lot of error-checking code.


' file: Build.vbs


' author: Jim Trudeau, Metrowerks


' and warning messages.


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 target 'current target dim buildmessages 'errors and warnings


'*** get the current target set target = project.GetCurrentTarget


textEngine.InsertText("Build Information" &eol)


'display name result = target.name


textEngine.InsertText("Building target " &result &eol)


'*** remove all object code target.RemoveObjectCode true


'*** get messages after building code set buildMessages = target.BuildAndWaitToComplete


ProcessMessages (buildMessages) end if


'========================================================= ' ProcessMessages - get errors and warnings, process them ' receives build messages '=========================================================


sub ProcessMessages (messages)


dim result 'returned values dim messageList 'message collection


'*** get the number of errors result = messages.ErrorCount


if result = 0 then textEngine.InsertText(eol &"Build Succeeded." &eol) else textEngine.InsertText(eol &"!!!BUILD FAILED!!!" &eol)


'*** display number of errors textEngine.InsertText("Number of errors: " &result &eol)


'*** get the list of errors set messageList = messages.Errors


'*** process the errors ProcessMessageList (messageList) end if


'*** determine whether there are warnings result = messages.WarningCount


'*** display number textEngine.InsertText("Number of warnings: " &result &eol)


'*** get warnings and process them if result then '*** get the list of warnings set messageList = messages.Warnings


'*** process the warnings ProcessMessageList (messageList) end if


end sub


'========================================================= ' ProcessMessagelist - loop through messages, report info ' receives message collection, could be errors or warnings '=========================================================


sub ProcessMessageList (messageList)


dim result 'returned values dim index 'loop counter dim message 'individual message


'*** walk through the list of messages for index = 0 to messageList.Count-1 '*** get the individual message set message = messageList.Item(index)


'*** get the text of the message result = message.MessageText


'*** display the message text textEngine.InsertText(result &eol)


'skip a line between errors textEngine.InsertText(eol) next


end sub

Using Microsoft's OLE/COM Viewer utility, the IDE supports a large number of COM objects. A scripting language can use these objects to communicate with the CodeWarrior IDE. There is a lot here regarding CodeWarrior scriptability and customization, but there isn't much to say about it, since CodeWarrior implements it so elegantly. Open the windows described above and explore! You will find that CodeWarrior is even easier to use when you have precise control over some of its functions!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值