I | Apple ScriptThe applescript classes that come with the WTextView wrapper are a complete rewrite of the CWASTEEdit apple script classes. The design of the classes is different, the code is more robust, but the overall interaction with the WASTE PPlant view (in this case WTextView) is very similar. ChangesIn CWASTEEdit, apple script support was a subclass of CWASTEEdit that also inherited from LModelObject. In the new wrapper, WTextView keeps a pointer to a text model object, mTextModel. There is no subclass of WTextView that implements Apple Script. If this pointer is filled by the controller for WTextView, then WTextView will pass along appropriate calls to the Apple Script implementation. If the pointer is nil (no Apple Script is desired), the WASTE engine is called directly. Why is this better?This approach has several advantages. Using a pointer inside WTextView allows the text model implementation WTextModel to be a hierarchy of classes instead of a series of very similar classes that implement the same behavior. Compare the inheritance tree for WTextModel (the new class) to that of CAEText (the implementation that came with CWASTEEdit). Figure 1. WTextModel inheritance Figure 2. CAEText inheritance All the text model classes from CWASTEEdit inherit from LModelObject and are unrelated, while the WTextModel tree is self contained and makes better use of inheritance. This advantage really shows itself in increased code reuse and decreased complexity of the subclasses of WTextModel. This code should be much easier to use and maintain. It is possible to make the text model support dynamic by changing the pointer if the programmer really wants to. Also, WTextView is more flexible and can be used in more places since the extra apple script code doesn't have to be carried along. Starting with version 1.0.0a2 the WTextModel subclasses are simplified and take advantage of inheritance more. Much of the work is handled by WTextModel and the subclasses only make modification where necessary. If you really want to learn the guts of how this implementation works, read the code in WTextModel. It is heavily commented and hopefully easy to understand. The ImplementationIn this section I, Timothy Paustian, list a few things specific to WTextModel's AppleScript implementation. If you want to learn about the standard objects, verbs, and properties supported by WTextModel, open up it's AppleScript dictionary in ScriptEditor or another script writing application, such as UserLand's Frontier. My main goal was to implement basic things that any text processing application would want to do. I will warn you that the implementation is somewhat incomplete. The major omission is whose clause support. I may throw that in to a future release. If you want to check out the example application using Frontier, download the Frontier application from the Frontier site. There is a free demo version and a commercial version. Frontier is great software and I recommend it to anyone doing web sites. Double click on newWaste.Frontier located in the output folder for the WText Demo Application. This will install install the verb table and shared menu for the WText Demo and allow you to write scripts on Frontier that control the Demo. Have fun! Core (Standard) SuiteWTextModel supports the close, data size, get, make, open, print, save and set events in the standard suite. The application, document and window objects are included in the suite and it is possible to retrieve and set many of the properties of these objects. Miscellaneous SuiteRevert, cut, copy and paste are supported here. In the case of WTextModel, the revert event is understood by a document object, while the other events refer to the selection object of the document in question. Cut and copy will return an error if there is no selection. WTextModel's Text SuiteThe text suite in WTextModel is the standard text suite used in many word processors. This suite does not define any more events, but adds to the types of objects that can be manipulated by the other suites. It is possible to refer to the text as characters, words, lines, and paragraphs. You can also refer to ranges of text objects such as, words 1 thru 57. There are some specific things about WTextModel's text model that are worth mentioning
AppleScript DemonstrationThe best way to learn about the power of AppleScript is to try out a few scripts. I have included a demo script that will clean up a document and change some of its formatting characteristics.
WTextModel is also recordable.
As always if you have questions or comments, send them to Timothy Paustian or David Phillip Oster. Add AppleScript to your WASTE application. It's easy and useful in many cases. I hope this example application will make it even easier and don't forget to support Frontier. Frontier Support in the WASTE exampleI was blow away by a Great application called Frontier. To help further the cause for Frontier, menu sharing support has been added to the example application. If you make your application scriptable, Add menu sharing! You are already well on your way with the example application, so you have no excuse! To learn more about menu sharing, go to the Frontier web site and look at the SDKs for Frontier. I will be happy to give help and advice to anyone who wants to add menu sharing to their Power Plant app. To get people started, below I give a step by step on how to add menu sharing.
That is it. Your application should now support menu sharing. Start up your application and Frontier. If you have trouble, try quitting both apps and launching them again. If things are still whacky, check out the docs on the Frontier site. Note, with the recent releases of Frontier 4.2 and greater, creating a install object for your application using the commercial developers suite really doesn't work. My advice is to roll your own custom install files. |
Originally by Timothy Paustian. Last modified September 17, 2002. Contact David Phillip Oster <mailto:oster@ieee.org>.