2011-08-04 102 views
4

不可能通過使用eclipse擴展來擴展由其他插件定義的Menu: org.eclipse.ui.menus。現在是否可以在eclipse中擴展Eclipse Search Menu

我想在搜索中添加一個菜單項,但不是搜索頁面。由於菜單搜索是由org.eclipse.search定義的,我不能添加它。

但我看到JDT和CDT在搜索下添加了一些菜單項。任何機構知道他們如何使其工作?

任何暗示讚賞。

+0

在Eclipse中,一切皆有可能:-) –

回答

1

您可以使用org.eclipse.ui.actionSets擴展點

這是JDT如何做來擴展其自己的行動搜索菜單其他插件擴展菜單。爲了在給定的菜單中執行操作,您必須填寫menubarPath的值。

org.eclipse.search.menu/dialogGroup 

我建議要導入的JDT UI來源和看JDT plugin.xml文件:例如,JDT爲Java搜索行動填補它。如果您需要經典的Eclipse SDK,然後在插件視圖中右鍵單擊org.eclipse.jdt.ui插件並選擇導入作爲源。

+0

其他地方已經說過,但爲了清楚起見,'org.eclipse.ui.actionSets'已被棄用。 – StockB

1

2012更新八月,如reprogrammer評論,org.eclipse.ui.actionSets被棄用:

相反,使用擴展點org.eclipse.ui.commands


原來的答覆(2011年8月)

的actionSet(extension point="org.eclipse.ui.actionSets")與Manuel Selva建議對 'menubarPath="org.eclipse.search.menu/dialogGroup"' 行動是官方的解決辦法,符合general menu contribution

但要注意一些問題,可能仍然縈繞搜索菜單的貢獻,爲周圍的(所謂固定)illustrated by this threadbug 15684
(那是在2009年,希望這個問題一直以來處理)

究竟確實工作正在重新定義了整個搜索菜單中的變通方法,仍是目前JDT 3.6中使用:

<extension 
     point="org.eclipse.ui.actionSets"> 
     <actionSet 
      label="%JavaSearchActionSet.label" 
      description="%JavaSearchActionSet.description" 
      visible="false" 
      id="org.eclipse.jdt.ui.SearchActionSet"> 
<!-- see http://bugs.eclipse.org/bugs/show_bug.cgi?id=15684 --> 
<!-- Note: The menu (re-) definition has to be here due to bug: --> 
<!-- =================================================================== --> 
<!-- Search Menu               --> 
<!-- =================================================================== --> 
     <menu 
       label="%searchMenu.label" 
       path="navigate" 
       id="org.eclipse.search.menu"> 
       <groupMarker name="internalDialogGroup"/> <!-- not to be used by clients --> 
       <groupMarker name="dialogGroup"/>   <!-- to be used by clients  --> 
       <separator name="fileSearchContextMenuActionsGroup"/> <!-- to be used by clients  --> 
       <separator name="contextMenuActionsGroup"/> <!-- to be used by clients --> 
       <separator name="occurencesActionsGroup"/> <!-- to be used by clients --> 
       <separator name="extraSearchGroup"/> <!-- to be used by clients --> 
     </menu> 
<!-- (...) --> 
+0

太好了,謝謝你的回答,但是我怎麼能控制我的菜單項的可見性,比如Search下的menuitem'C++','Java'。我嘗試了操作中的'可見性'元素,但它不起作用。 – jumpingstone

+0

@VonC:現在不推薦使用擴展點org.eclipse.ui.actionSets。請參閱http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fextension-points%2Forg_eclipse_ui_actionSets.html – reprogrammer

+0

@VonC:使用'org.eclipse。用於將項目添加到通過'actionSets'貢獻的舊菜單的ui.menu'擴展點並不簡單。看到我的意見在http://stackoverflow.com/questions/6937322/is-it-possible-to-extend-eclipse-search-menu#comment15700341_6939032和http://stackoverflow.com/questions/7941278/adding-menu- item-in-eclipse#comment15700568_7941776如果您知道如何使用新的擴展點將項目添加到舊的菜單(如JDT Refactor或Search),請更新您的答案。 – reprogrammer

1

只要您知道菜單或工具欄的ID,就可以使用org.eclipse.ui.menus擴展點來擴展它們。對於搜索菜單,此ID是org.eclipse.search.menu。如果你想添加東西到dialogGroup然後使用org.eclipse.search.menu?after=dialogGroup

+1

謝謝,我重新定義了JDT解決方案之後的搜索菜單,現在我的菜單項顯示在搜索下。 – jumpingstone

+0

@Tonny Madsen:我喜歡使用擴展點'org.eclipse.ui.menus'而不是'org.eclipse.ui.actionSets'的想法,因爲後者已被棄用(http://help.eclipse.org /juno/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fextension-points%2Forg_eclipse_ui_actionSets.html)。但是,將菜單項添加到使用actionSets定義的菜單看起來有點不同,並且您建議的標準方法不適用於此目的。 – reprogrammer