Index: Desktop/Tools/ToolSet.cs =================================================================== --- Desktop/Tools/ToolSet.cs (revision 9580) +++ Desktop/Tools/ToolSet.cs (working copy) @@ -30,6 +30,7 @@ #endregion using System; +using System.Collections; using System.Collections.Generic; using ClearCanvas.Common; using ClearCanvas.Desktop.Actions; @@ -44,11 +45,31 @@ private List _tools; /// - /// Constructs a toolset that is initially empty. + /// This contructs a tool set containing the specified tools. The + /// is set on each tool and each tool's Initialize method is called. /// - public ToolSet() + /// The tool context to pass to each tool. + /// A set of tools to group in this ToolSet and be initialized and + /// set with the same tool context. + public ToolSet(IEnumerable tools, IToolContext context) { _tools = new List(); + + foreach (ITool tool in tools) + { + try + { + tool.SetContext(context); + tool.Initialize(); + _tools.Add(tool); + } + catch (Exception e) + { + // a tool failed to initialize - log and continue + // (this tool will not be included in the set) + Platform.Log(LogLevel.Error, e); + } + } } /// @@ -61,38 +82,25 @@ /// The tool extension point that provides the tools. /// The tool context to pass to each tool. public ToolSet(IExtensionPoint toolExtensionPoint, IToolContext context) - :this() + :this(toolExtensionPoint, context, null) { - AddTools(toolExtensionPoint, context); } /// - /// Adds tools to the toolset based on the specified extension point and context. + /// Constructs a toolset based on the specified extension point and context. /// /// - /// The toolset will attempt to instantiate and initialize all - /// extensions of the specified tool extension point. - /// + /// The toolset will attempt to instantiate and initialize all + /// extensions of the specified tool extension point that pass the + /// specified filter. + /// /// The tool extension point that provides the tools. /// The tool context to pass to each tool. - private void AddTools(IExtensionPoint toolExtensionPoint, IToolContext context) + /// Only tools that match the specified extension filter are loaded into the + /// tool set. If null, all tools extending the extension point are loaded. + public ToolSet(IExtensionPoint toolExtensionPoint, IToolContext context, ExtensionFilter filter) + :this(toolExtensionPoint.CreateExtensions(filter), context) { - object[] tools = toolExtensionPoint.CreateExtensions(); - foreach (ITool tool in tools) - { - try - { - tool.SetContext(context); - tool.Initialize(); - _tools.Add(tool); - } - catch (Exception e) - { - // a tool failed to initialize - log and continue - // (this tool will not be included in the set) - Platform.Log(LogLevel.Error, e); - } - } } /// Index: ImageViewer/ImageViewerComponent.cs =================================================================== --- ImageViewer/ImageViewerComponent.cs (revision 9580) +++ ImageViewer/ImageViewerComponent.cs (working copy) @@ -30,6 +30,7 @@ #endregion using System; +using System.Collections; using ClearCanvas.Common; using ClearCanvas.Common.Utilities; using ClearCanvas.Desktop; @@ -282,7 +283,7 @@ { base.Start(); - _toolSet = new ToolSet(new ImageViewerToolExtensionPoint(), new ImageViewerToolContext(this)); + _toolSet = new ToolSet(CreateTools(), new ImageViewerToolContext(this)); _shortcutManager = new ViewerShortcutManager(); @@ -510,6 +511,16 @@ get { return _toolSet; } } + /// + /// Creates a set of tools for this image viewer to load into its tool set. Subclasses can override + /// this to provide their own tools or cull the set of tools this creates. + /// + /// + protected virtual IEnumerable CreateTools() + { + return (new ImageViewerToolExtensionPoint()).CreateExtensions(); + } + #endregion #region Private/internal properties