Kevin Flynn wrote:
> I'm answering my own question here, but asking another:
>  
> I fixed (and improved) my workaround, so it now won't let you enter an
> ID that already exists, and also allows you to optionally add a prefix
> (%1) to the ID entered by the user, making it possible to maintain
> separate groups of IDs used for different purposes. However, I would
> like to be able to delete the inserted element if the user exits from
> the ID prompt dialog by pressing Cancel. How would I do this?
>  
>   <cfg:command name="my.insert">
>     <cfg:macro trace="true">
>       <cfg:sequence>
>         <cfg:command name="insert" parameter="%0" />
>         <cfg:choice>
>           <cfg:sequence>
>             <cfg:match context="$selectedElement" pattern="*...@id]"/>
>             <cfg:command name="my.insertId" parameter="'Enter element
> ID:' '%1'" />
>           </cfg:sequence>
>         </cfg:choice>
>       </cfg:sequence>
>     </cfg:macro>
>   </cfg:command>
>  
>   <cfg:command name="my.insertId">
>     <cfg:macro trace="true">
>       <cfg:sequence>
>         <cfg:command name="prompt" parameter="'Insert Element' '%0'" />
>         <cfg:choice>
>           <cfg:sequence>
>             <cfg:test context="$selectedElement" expression="id('%1%_')"/>
>             <cfg:command name="my.insertId" parameter="'%_ already
> exists, please try again:' '%1'"/>
>           </cfg:sequence>
>           <cfg:sequence>
>             <cfg:command name="putAttribute"
> parameter="[implicitElement] id '%1%_'" />
>           </cfg:sequence>
>         </cfg:choice>
>       </cfg:sequence>
>     </cfg:macro>
>   </cfg:command>

May be you could:
* Initialize a variable in my.insert to 0.
* Set it to 1 in my.insertId just after <cfg:command name="prompt"/>
* Test it in my.insert.

A variable shared by multiple macros must have a name in the
"http://www.xmlmind.com/xmleditor/namespace/scope/view"; namespace.
See http://www.xmlmind.com/xmleditor/_distrib/doc/commands/xpath_vars.html

Example:
---
<set ns:done
     xmlns:ns="http://www.xmlmind.com/xmleditor/namespace/scope/view";
     expression="1" />
---

(I've not tested this. This is just an idea.)




Reply via email to