Pages: 1
Print
Author Topic: Script Example: Change Text Case Functions  (Read 9243 times)
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2452



WWW
« on: November 27, 2008, 05:48:51 PM »

Product(s):
Tested with XMetaL Author Enterprise 5.1.1.017

Script Example:
Macros for changing the case of text for the selected portion of a document.

Includes the Following Functions:
  • Sentence case
  • lowercase
  • UPPERCASE
  • Capitalize
  • tOGGLE cASE

The operation of these functions is similar to those provided with popular word processors (ie: like MS Word, Open Office, etc) though they function in an XML context. We are dealing with XML so these scripts should not invalidate the document. They are primarily meant to change the case for PCDATA content, not elements (tags), attributes, or attribute values. In some cases they can be used to change the case of COMMENTS, CDATA sections and Processing Instructions. In this case you need to select a portion of these types of markup rather than the entire COMMENT, CDATA or PI node.

Legal:
* Licensed Materials - Property of JustSystems, Canada, Inc.
*
* (c) Copyright JustSystems Canada, Inc. 2008
* All rights reserved.
*
*-------------------------------------------------------------------
* The sample contained herein is provided to you "AS IS".
*
* It is furnished by JustSystems Corporation as a simple example and has not been
* thoroughly tested under all conditions. JustSystems Canada, Inc., therefore, cannot
* guarantee its reliability, serviceability or functionality.
*
* This sample may include the names of individuals, companies, brands and products
* in order to illustrate concepts as completely as possible. All of these names are
* fictitious and any similarity to the names and addresses used by actual persons or
* business enterprises is entirely coincidental.
*---------------------------------------------------------------------

Script Installation and Usage:
Important: This script is being made available for use by experienced users, administrators and/or IT departments (people that manage the installation and configuration of an XMetaL deployment). Test this script in a test environment (non-production machine) before distributing to end users. This is unsupported demo code.
   1. Download changeTextCaseFunctions.zip.
   2. Unzip the file to an empty folder of your choice.
   3. Examine the code contained in the MCR file and integrate it into your XMetaL Author or XMAX customization. The MCR file has been written so that it may simply be dropped into the <xmetal author install path>\Startup folder to provide this functionality to all DTDs and Schemas (it is an Application-level macro). The code contains detailed comments inline that explain the logic. The comments also include information on known limitations and the rationale for not attempting to resolve them. It is assumed that these limitations will not affect the vast majority of users but if you have time to resolve them please share any improvements here.
   4. Test all the functions on test documents that are as similar to what your end users will be working with before using them in production. You should be able to undo the changes each of the functions makes to a document using XMetaL Author's Undo operation.

Some Use Cases:
  • Document has a <title> element containing some words that do not begin with a capital letter. User selects the entire element, selects the function "Change Case: Capitalize". The function capitalizes the first letter in each word in the title.
  • Document has one or more words in lowercase that should be in uppercase. User selects the word(s), selects the function "Change Case: UPPERCASE". The function changes all the letters in each selected word to uppercase.
  • Ditto (but opposite) for "Change Case: lowercase".
  • The document has a <p> element containing a number of sentences, not all of which begin with a capital. User selects the entire element, selects the function "Change Case: Sentence case". The function capitalizes the first letter in the selection and every letter immediately following the sequence ". " (period+space). All other letters are made lowercase.
  • The "Change Case: tOGGLE cASE" function is (I assume) seldomly used, but most other products have it. This function simply changes uppercase letters to lowercase and vice versa.
  • The document has a lot of code (example: C++, J#, C#, VB, etc) inside a CDATA section that should be changed. User selects just a portion of the CDATA section (also applies to COMMENT and PIs) avoiding the opening and closing markup, then runs one of the functions to change the selected text. Double clicking to select a word may be useful in this case, as is the mouse sequence: double click to select a word, keep mouse button down and immediately drag to extend the selection as well as the shift + mouse click combination. Note that one of the limitations of this script occurs when it encounters an unescaped ">" character inside CDATA, COMMENT or PI. See the comments in the MCR file.


Older Releases:
Most of these scripts should function with XMetaL Author versions 2.0 and up, except for the event On_Application_Document_Context_Menu, which was introduced in the 5.0 releases. If your version of XMetaL Author does not have this event you can probably change it to On_Context_Menu and integrate all the scripts into a document-level customization instead. That has not been tested.

* changeTextCaseFunctions.zip (4.65 KB - downloaded 436 times.)

* change-case-sentence-case.jpg (48.07 KB, 647x414 - viewed 974 times.)

* change-case-lowercase.jpg (47.41 KB, 646x412 - viewed 941 times.)
« Last Edit: November 22, 2010, 01:48:29 PM by Derek Read » Logged
dcramer
Member

Posts: 120


« Reply #1 on: December 02, 2008, 12:30:48 AM »

Works in 4.6 (moving the context menu stuff to On_Context_Menu).

Thanks!
David
Logged

David Cramer
Technical Writer
Motive, an Alcatel-Lucent Company
lav25
Member

Posts: 1


« Reply #2 on: December 02, 2008, 04:22:57 AM »

Lovely feature. I've been after this for a long time!
Quick tests in 5.1 worked.
Logged
dcramer
Member

Posts: 120


« Reply #3 on: January 11, 2010, 10:13:01 AM »

One small point: the functions don't work in file entities because it tried to validate the file and says the file is invalid if it doesn't have a doctype. I removed &&(ActiveDocument.IsValid == true) to get around this. It would be nice if you could do ActiveDocument.IsWellFormed instead (perhaps you can...guess I should check that).

David
Logged

David Cramer
Technical Writer
Motive, an Alcatel-Lucent Company
Shaylesh
Member

Posts: 2


« Reply #4 on: December 30, 2015, 03:34:17 AM »

Can I create keyboard shortcuts for each of the change case functions? When I select any of these macros in the Macros dialog, the shortcut key settings in the dialog box are disabled.

Btw, I am using XMetal 6.
« Last Edit: December 30, 2015, 03:50:29 AM by Shaylesh » Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2452



WWW
« Reply #5 on: January 08, 2016, 01:49:55 PM »

If you can't alter the keys using the dialog it is probably because you do not have write permissions to the Program Files folder (which is normal for all versions of Windows since XP SP3). You'll have to manually modify the file (probably by copying it elsewhere, editing it then copying it back). Assign the value key="name" (with the appropriate key name) to each <MACRO> in the MCR file.

The easier solution would be to upgrade to version 10 as it includes this feature as built-in functionality. In version 10 you can press Ctrl+F3 to change between the 5 types of casing for the currently selected text. You can also select text and use the context menu's "Text Case" option to select one of the five options.

In the documentation for version 10 this feature is called the "Text case assistant".
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2452



WWW
« Reply #6 on: March 09, 2016, 07:07:47 PM »

This feature has been added as built-in functionality starting with XMetaL Author Essential and XMetaL Author Enterprise 10.

Refer to the Help under the topic "Text case assistant" for full details.

Three options:
1. Select text and press Ctrl+F3 repeatedly until you see what you want, or...
2. Select text, right click and select the "Text Case" submenu, then select one of 5 options, or...
3. Enable buttons for the 5 possible text case options on the Formatting toolbar (see Help topic above for details).
Logged
Pages: 1
Print
Jump to: