Jeremy Quinn wrote:
> 
> I am trying to implement a Move command and am having some problems,
> has anyone got any suggestions about how to make them work better?
> 
> Here are the commands:
> 
>   <button toolTip="Move Up" icon="../icons2/up.gif">
>     <command name="moveUp" />
>   </button>
>   <button toolTip="Move Down" icon="../icons2/down.gif">
>     <command name="moveDown" />
>   </button>
> 
>   <command name="moveUp">
>     <macro>
>       <sequence>
>         <command name="cut" parameter="[implicitElement]" />
>         <command name="paste" parameter="before[implicitElement]" />
>       </sequence>
>     </macro>
>   </command>
> 
>    <command name="moveDown">
>      <macro>
>        <sequence>
>             <command name="cut" parameter="[implicitElement]" />
>          <command name="moveDotTo" parameter="nextElement" />
>          <command name="paste" parameter="after[implicitElement]" />
>        </sequence>
>      </macro>
>    </command>
> 
> Here is some sample XML:
> 
>                 <chapter type="simple" link="st_1" label="story">
>                         <meta>
>                                 <title>YOUR TITLE</title>
>                                 <desc>YOUR DESCRIPTION</desc>
>                         </meta>
>                         <p>paragraph one</p>
>                         <p>paragraph two etc.</p>
>                         <contact link="co_1" label="contact details">
>                                 <desc>For further information please contact: 
> </desc>
>                                 <who>WHO TO CONTACT</who>
>                                 <org>Institute of International Visual 
> Arts</org>
>                                 <addr>6-8 Standard Place, Rivington Street, 
> London EC2A 3BE</addr>
>                                 <email>SOMEONE at iniva.org</email>
>                                 <tel>020 7729 9616</tel>
>                         </contact>
>                 </chapter>
> 
> How they behave:
> 
>         1) select <org/> click Move Up, and it moves above <who/> : Good!
>         2) select <org/> click Move Down, and it moves below <addr/> : Good!
>         3) select <desc/> click Move Up, and it disappears : Bad!
>                 <desc/> is not allowed in <chapter/> so it cannot paste here.
>         4) select <tel/> click Move Down, and nothing happens : Good!
>                 <tel/> is not allowed in <chapter/> so it cannot paste here.
>         5) select <p/>[1] click Move Up, and it disappears: Bad!
>                 meta/desc is left with the text selection.
>                 <p/> is not allowed inside <meta/> or outside <chapter/>
>         6) select <p/>[1] click Move Down, and it moves below <p/>[2]: Good!
>         7) select <p/>[2] click Move Down, and it disappears: Bad!
>                 the text selection ends up in contact/desc (!?!)
>                 <p/> is not allowed in <contact/> but should go after it
> 
> Can anyone suggest how I can refine these commands further so as to get
> rid of the glitches in behaviour?

I think you have reached the limits of macros and/or some primitive
commands are missing to implement more powerful macros. The clean,
reliable, solution is of course to implement this by writing a custom
command in Java or in BeanShell.

If you want something that works *slightly* better, you may try
something like this (I've not tested what follows):

  <command name="moveUp">
     <macro>
       <sequence>
        <command name="cut" parameter="[implicitElement]" />
        <choice>
          <command name="paste" parameter="before[implicitElement]" />
          <command name="undo" />
         </choice>
      </sequence>
    </macro>
  </command>

Reply via email to