Navigation:  I Want To... > Basics >

Create a dropdown toolbar button

Previous pageReturn to chapter overviewNext page

Use Case

You want a toolbar button that activates a dropdown menu.

Relevant Architecture

Tools
Extending functionality with Tools

Relevant Types

DropDownAction
DropDownButtonAction

Sample Code

using ClearCanvas.Common;

using ClearCanvas.Desktop;

using ClearCanvas.Desktop.Actions;

using ClearCanvas.ImageViewer;

using ClearCanvas.ImageViewer.BaseTools;

 

// ... (other using namespace statements here)

 

namespace MyPlugin.Basics

{

   [DropDownAction("filter""global-toolbars/ToolbarStandard/ToolbarDropDownFilterTool""DropDownMenuModel")]

   [Tooltip("filter""TooltipDropDownFilterTool")]

   [IconSet("filter", IconScheme.Colour, "Icons.MyToolSmall.png""Icons.MyToolMedium.png""Icons.MyToolLarge.png")]

   [EnabledStateObserver("filter""Enabled""EnabledChanged")]

   // ... (other action attributes here)

   [ExtensionOf(typeof (ImageViewerToolExtensionPoint))]

   public class DropDownFilterTool : ImageViewerTool

   {

      public ActionModelNode DropDownMenuModel

      {

         get

         {

            // The filter tools are ImageViewerToolExtensions, so we have to get the

            // actions from the ImageViewerComponent. Note that while 

            // ImageViewerComponent.ExportedActions gets *all* the actions associated with

            // the ImageViewerComponent, the fact that we specify the site (i.e.

            // imageviewer-filterdropdownmenu) when we call CreateModel will cause 

            // the model to only contain those actions which have that site specified

            // in its path.

 

            return ActionModelRoot.CreateModel(

               this.GetType().FullName,

               "imageviewer-filterdropdownmenu",

               this.ImageViewer.ExportedActions);

         }

      }

   }

 

   [MenuAction("apply""imageviewer-filterdropdownmenu/MenuSharpening""Apply")]

   // ... (other action attributes here)

   //

   [ExtensionOf(typeof(ImageViewerToolExtensionPoint))]

   public class SharpeningFilterTool : ImageViewerTool

   {

      public void Apply()

      {

         // code to apply the sharpening filter

      }

   }

}

Remarks

Defining a button with a dropdown menu is a two-step process.  First, the dropdown menu must be defined.  Then, actions must be added to the menu.  In the example above, the DropDownFilterTool class defines the button and the dropdown menu.  The SharpeningFilterTool class then defines an action that is added to the dropdown menu.  Note that the programming model for a dropdown menu is like any other menu.

There is one other similar type of dropdown in the framework: the DropDownButtonAction.  This is really a cross between a ButtonAction and a DropDownAction, where there is a clickable button with a dropdown on the side.  Because it's usage is so similar to the other two action types, we don't include a detailed example.

Examples in Code Base

ClearCanvas.ImageViewer.Tools.Standard.ShowHideOverlaysTool
ClearCanvas.ImageViewer.Tools.ImageProcessing.Filter.SharpeningFilterTool