Назначение панели инструментов для определенных перспектив eclipse

#eclipse #eclipse-rcp

Вопрос:

Я хотел бы показывать свою собственную панель инструментов только тогда, когда показаны некоторые специальные перспективы. Вот мои перспективы в plugin.xml:

 <extension
         point="org.eclipse.ui.perspectives">
      <perspective
            class="ui.StandViewPerspective"
            fixed="false"
            id="standViewPerspective"
            name="%perspective.name">
      </perspective>
      
      <perspective
            class="ui.StandDisPerspective"
            fixed="false"
            id="standDisPerspective"
            name="%perspective.name.0">
      </perspective>
   </extension>
 

и вот моя панель инструментов:

 <extension
         point="org.eclipse.ui.menus">
      <menuContribution
            allPopups="false"
            locationURI="toolbar:org.eclipse.ui.main.toolbar">
         <toolbar
               id="ui.standToolbar">
               
            <command
                  commandId="ui.lowerdelay"
                  disabledIcon="platform:/plugin/org.eclipse.ui/icons/full/elcl16/collapseall.png"
                  icon="platform:/plugin/org.eclipse.ui/icons/full/elcl16/collapseall.png"
                  id="ui.toolbar.decrease"
                  label="%command.decrease.delay"
                  style="push">
            </command>
            
            <command
                  commandId="ui.upperdelay"
                  disabledIcon="platform:/plugin/org.eclipse.ui/icons/full/elcl16/expandall.png"
                  icon="platform:/plugin/org.eclipse.ui/icons/full/elcl16/expandall.png"
                  id="ui.toolbar.increase"
                  label="%command.increase.delay"
                  style="push">
            </command>
         </toolbar>
      </menuContribution>
   </extension>
 

но я не нашел способа показать эту панель инструментов только для этих двух точек зрения. Я читал эту статью, но не нашел здесь ничего полезного.

Ответ №1:

Я не знаю, правильно ли это решение, но мне удалось решить свою проблему. К вашей команде вы должны добавить:

 <visibleWhen>
<with variable="activeWorkbenchWindow.activePerspective">
<equals value="perspective_id"/>
</with>
</visibleWhen>
 

окончательное решение:

 <command
commandId="ui.openDebug"                disabledIcon="platform:/plugin/org.eclipse.debug.ui/icons/full/obj16/rundebug.png"                icon="platform:/plugin/org.eclipse.debug.ui/icons/full/obj16/rundebug.png"
id="ui.toolbar.opendbg"
label="%command.open.debug"
style="push">
                  
<visibleWhen>
<with variable="activeWorkbenchWindow.activePerspective">
<equals value="ui.standViewPerspective"/>
</with>
</visibleWhen>
</command>
 

может быть, это поможет кому-то другому 😀 Вы только здесь не будете обрабатывать две или более перспектив с помощью панели инструментов.