Thank you for the reply.

I use 10+ different context menus for different contexts.
Most of the menu items are the same in all the context menus but a few are 
different.

I try to reduce the redundancy and number of context menus. For this reason I 
want to extend the context menu so I don't have to define the same menu items 
again and again. I used the <insert/> element to include the context-menu-items 
from one context menu into another context menu. That's described in this 
section:
http://www.xmlmind.com/xmleditor/_distrib/doc/configure/menu.html
So, depending on the context, the context menu should get extended.

Example:
Standard context menu:
Insert

Context menu for element author:
Insert
------
Insert Before...
Insert After...

But it doesn't work. What am I doing wrong?

Code I tried:
<command name="contextualMenuChooser">
  <macro trace="true">
    <sequence>
      <command name="contextualMenu1" />
      <sequence>
        <match context="$implicitElement"
               pattern="author//*" />
        <command name="contextualMenu2" />
      </sequence>

      <command name="editMenu" />
    </sequence>
  </macro>
</command>

<command name="contextualMenu1">
  <menu>
    <item label="Insert..."
          command="insert" parameter="into" />
  </menu>
</command>

<command name="contextualMenu2">
  <menu>
    <insert />
    <item label="Insert Before..."
          command="insert" parameter="before[implicitElement]" />
    <item label="Insert After..."
          command="insert" parameter="after[implicitElement]" />
  </menu>
</command>

<binding>
  <mousePressed button="3"/>
  <command name="contextualMenuChooser" />
</binding>



Do you need any more information to understand my problem?






-----Urspr?ngliche Nachricht-----
Von: Hussein Shafie [mailto:hussein at xmlmind.com] 
Gesendet: Montag, 29. September 2008 21:04
An: Marc Haemmerle
Cc: xmleditor-support at xmlmind.com
Betreff: Re: [XXE] Extend context menu

--> There are *many* reasons which could cause the macro you wrote not
to function. Possible reasons:
* I don't understand your nesting of sequence and choice elements.
* May be you forgot to specify namespaces (e.g. ancestor::myns:Attribut)
* I don't understand the <insert/> element
* I don't see the binding which binds contextualMenuChooser to the right
click of the mouse.
* etc.

I would recommend to re-read this section:
http://www.xmlmind.com/xmleditor/_distrib/doc/commands/menu.html



--> Just to prove that contextual menus work fine, I've written this
code which, in my opinion, is very close to what you want to do:

---
<command name="contextualMenuChooser">
  <macro trace="true">
    <choice>
      <sequence>
        <match context="$implicitElement"
               pattern="bookinfo//author//*" />
        <command name="contextualMenu2" />
      </sequence>

      <sequence>
        <match context="$implicitElement"
               pattern="bookinfo//*" />
        <command name="contextualMenu1" />
      </sequence>

      <command name="editMenu" />
    </choice>
  </macro>
</command>

<command name="contextualMenu1">
  <menu>
    <item label="Insert..."
          command="insert" parameter="into" />
  </menu>
</command>

<command name="contextualMenu2">
  <menu>
    <item label="Insert Before..."
          command="insert" parameter="before[implicitElement]" />
    <item label="Insert After..."
          command="insert" parameter="after[implicitElement]" />
  </menu>
</command>

<binding>
  <mousePressed button="3"/>
  <command name="contextualMenuChooser" />
</binding>
---

In order to test the above code:
[1] Copy the above code in your customize.xxe file (Install add-on
called "A sample customize.xxe" if you don't have one)
[2] Restart XXE and use File|New, choose a DocBook Book template (not
DocBook 5, plain DocBook 4)
[3] Click in the empty title of the book, then right-click: you'll see
contextualMenu1
[4] Click in the empty firstname of the author of the book, then
right-click: you'll see contextualMenu2
[5] Click in the empty para, then right-click: you'll see the standard
editMenu



Marc Haemmerle wrote:
> 
> I'm using XML mind XML Editor 4.1 on Windows.
> 
> I tried to extend my own context menu, depending on the chosen element.
> 
> My code:
> 
>  
> 
>  
> 
>             <command name="contextualMenuChooser">
> 
>             <macro>
> 
>                         <sequence>
> 
>                                    <sequence>
> 
>                                                <choice>
> 
>                                                            <test
> expression="$implicitElement[ancestor::Attribut]" />
> 
>                                                </choice>
> 
>                                                <command
> name="contextualMenuAttribut" />
> 
>                                    </sequence>
> 
>                                    <sequence>
> 
>                                                 <choice>
> 
>                                                            <test
> expression="$implicitElement[ancestor::Beschreibung and
> ancestor::Attribut]" />
> 
>                                                </choice>
> 
>                                                <command
> name="contextualMenuAttributBeschreibung" />
> 
>                                    </sequence>
> 
>                         </sequence>
> 
>             </macro>
> 
>             </command>
> 
>            
> 
> <command name="contextualMenuAttribut">
> 
>  <menu label="contextualmenu">
> 
>   <item label="Insert..." command="insert" parameter="into" />
> 
> </menu>
> 
> </command>
> 
>  
> 
> <command name="contextualMenuAttributBeschreibung">
> 
> <menu label="contextualmenu">
> 
>  <insert />
> 
>   <item label="Insert Before..." command="insert"
> 
>      parameter="before[implicitElement]" />
> 
>   <item label="Insert After..." command="insert"
> 
>     parameter="after[implicitElement]" />
> 
> </menu>
> 
> </command>
> 
>  
> 
> That's not working. Is there a solution for my problem? How can I do
> what I want?
> 


Reply via email to