2013-04-11 75 views
0

我想在一個viewpart的上下文菜單中定義一個子菜單項。如何提供上下文菜單的子菜單?

我想通過我自己的插件在這個子菜單中貢獻一個「連接配置文件」菜單項,我希望其他插件也可以爲這個子菜單提供菜單項。

我的plugin.xml

<extension 
     point="org.eclipse.ui.menus"> 
     <menuContribution 
      allPopups="false" 
      locationURI="popup:cn.ggfan.dmp.view.explorer"> 
     <menu 
       id="new" 
       label="New"> 
     </menu> 
     </menuContribution> 
     <menuContribution 
      allPopups="false" 
      locationURI="menu:new?after=additions"> 
     <command 
       commandId="cn.ggfan.dmp.commands.addCP" 
       label="Connection Profiles" 
       style="push"> 
     </command> 
     </menuContribution> 
    </extension> 

這行的事工作。我的代碼有什麼問題?

----------------------- 編輯 -------------------- ---
如果我像這樣定義子菜單,它可以工作。但我仍然不知道如何爲其他插件中的「新」子菜單做出貢獻。

<menuContribution 
      allPopups="false" 
      locationURI="popup:cn.ggfan.dmp.view.explorer"> 
     <menu 
       id="new" 
       label="new"> 
      <command 
        commandId="cn.ggfan.dmp.commands.addCP" 
        label="Connection Profiles" 
        style="push"> 
      </command> 
     </menu> 
     </menuContribution> 

enter image description here

回答

3

終於,我得到了它,我的「新」子菜單應爲「彈出」不是一個「菜單」等進行處理:

<extension 
     point="org.eclipse.ui.menus"> 
     <menuContribution 
      allPopups="false" 
      locationURI="popup:cn.ggfan.dmp.view.explorer"> 
     <menu 
       id="cn.ggfan.new" 
       label="New"> 
      <command 
        commandId="cn.ggfan.dmp.commands.addCP" 
        label="Connection Profile" 
        style="push"> 
      </command> 
     </menu> 
     </menuContribution> 
     <menuContribution 
      allPopups="false" 
      locationURI="popup:cn.ggfan.new?after=additions"> 
     <command 
       commandId="cn.ggfan.dmp.commands.addTable" 
       label="Table" 
       style="push"> 
     </command> 
     </menuContribution> 
    </extension> 
+0

是的...我應該認爲你有兩個不同的使用相同的ID - 新' – 2013-04-12 17:20:10

+0

完美答案! – 2017-09-14 13:13:10

1

嘗試用menu:cn.ggfan.dmp.view.explorer,而不是popup:cn.ggfan.dmp.view.explorer

Working with the menus extension point - 博客條目我差不多6年前寫的:-)

+0

謝謝! @Tonny,但它仍然沒有工作。我希望「新」條目出現在上下文菜單中(右鍵單擊菜單)。我不能訪問您的博客,因爲它是由我們國家防火牆blobced :( – CaiNiaoCoder 2013-04-12 10:56:35

+0

我已更新我的問題,請參閱我的編輯 – CaiNiaoCoder 2013-04-12 11:05:46